pub unsafe trait ExtensionLibrary {
    // Provided methods
    fn editor_run_behavior() -> EditorRunBehavior { ... }
    fn min_level() -> InitLevel { ... }
    fn on_level_init(_level: InitLevel) { ... }
    fn on_level_deinit(_level: InitLevel) { ... }
}
Expand description

Defines the entry point for a GDExtension Rust library.

Every library should have exactly one implementation of this trait. It is always used in combination with the #[gdextension] proc-macro attribute.

The simplest usage is as follows. This will automatically perform the necessary init and cleanup routines, and register all classes marked with #[derive(GodotClass)], without needing to mention them in a central list. The order in which classes are registered is not specified.

// This is just a type tag without any functionality.
// Its name is irrelevant.
struct MyExtension;

#[gdextension]
unsafe impl ExtensionLibrary for MyExtension {}

§Safety

By using godot-rust, you accept the safety considerations as outlined in the book. Please make sure you fully understand the implications.

The library cannot enforce any safety guarantees outside Rust code, which means that you as a user are responsible to uphold them: namely in GDScript code or other GDExtension bindings loaded by the engine. Violating this may cause undefined behavior, even when invoking safe functions.

Provided Methods§

fn editor_run_behavior() -> EditorRunBehavior

Determines if and how an extension’s code is run in the editor.

fn min_level() -> InitLevel

Determines the initialization level at which the extension is loaded (Scene by default).

If the level is lower than InitLevel::Scene, the engine needs to be restarted to take effect.

fn on_level_init(_level: InitLevel)

Custom logic when a certain init-level of Godot is loaded.

This will only be invoked for levels >= Self::min_level(), in ascending order. Use if or match to hook to specific levels.

fn on_level_deinit(_level: InitLevel)

Custom logic when a certain init-level of Godot is unloaded.

This will only be invoked for levels >= Self::min_level(), in descending order. Use if or match to hook to specific levels.

Object Safety§

This trait is not object safe.

Implementors§