pub trait NativeModule: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn methods(&self) -> Vec<MethodDescriptor>;
// Provided methods
fn invoke_sync(&self, method: &str, args: &[ModuleArg]) -> ModuleResult { ... }
fn invoke_async(
&self,
method: &str,
args: &[ModuleArg],
) -> Pin<Box<dyn Future<Output = ModuleResult> + Send + '_>> { ... }
fn on_init(&self) { ... }
fn on_destroy(&self) { ... }
}Expand description
Trait that all native modules must implement.
Modules must be Send + Sync to be safely shared across threads.
Required Methods§
Sourcefn methods(&self) -> Vec<MethodDescriptor>
fn methods(&self) -> Vec<MethodDescriptor>
List of methods this module exposes.
Provided Methods§
Sourcefn invoke_sync(&self, method: &str, args: &[ModuleArg]) -> ModuleResult
fn invoke_sync(&self, method: &str, args: &[ModuleArg]) -> ModuleResult
Invoke a synchronous method. Must not block for long.
Sourcefn invoke_async(
&self,
method: &str,
args: &[ModuleArg],
) -> Pin<Box<dyn Future<Output = ModuleResult> + Send + '_>>
fn invoke_async( &self, method: &str, args: &[ModuleArg], ) -> Pin<Box<dyn Future<Output = ModuleResult> + Send + '_>>
Invoke an asynchronous method. Returns a boxed future. Default implementation returns MethodNotFound.
Sourcefn on_destroy(&self)
fn on_destroy(&self)
Called when the module is being torn down.