pub trait SharedHandler<'a>: Send + Sync {
// Required methods
fn request_restart(&self);
fn request_process(&self);
fn request_callback(&self);
// Provided method
fn initializing(&self, instance: InitializingPluginHandle<'a>) { ... }
}Expand description
Host data and callbacks that are tied to [thread-safe] operations.
This trait requires both Send and Sync, as those callbacks and data can be used from
multiple different threads at the same time.
This trait is bound to a lifetime ('a) that lives at least as long as the plugin instance
does. Since the plugin can call host callbacks during its destructor, this is actually kept alive
slightly longer.
See the module docs for more information, and for an example implementation.
Required Methods§
Sourcefn request_restart(&self)
fn request_restart(&self)
Called by the plugin when it requests to be deactivated and then restarted by the host.
This operation may be delayed by the host.
Sourcefn request_process(&self)
fn request_process(&self)
Called by the plugin when it requests to be activated and/or to start processing.
Sourcefn request_callback(&self)
fn request_callback(&self)
Called by the plugin when it requests a call to the
on_main_thread callback
to be scheduled on the main thread.
Provided Methods§
Sourcefn initializing(&self, instance: InitializingPluginHandle<'a>)
fn initializing(&self, instance: InitializingPluginHandle<'a>)
Called either during the plugin’s initialization, or right after it has completed.
More specifically, this is called if the plugin calls any of the host’s provided callbacks
during its initialization process (i.e. during the call of its provided init() function).
If it hasn’t called any by the time init() finishes, the initializing method is
then called right afterward.
During this time, the host is only allowed to query the plugin’s extensions but nothing else.
The given InitializingPluginHandle therefore only allows that operation.
The full capability of the PluginSharedHandle is only
given once MainThreadHandler::initialized is called, and can be obtained through its given
InitializedPluginHandle.
This function may be called multiple times concurrently while the plugin is initializing, if it performs multithreaded accesses during that time.
It is also possible for other host callbacks to be called before this, if the plugin’s
get_extension() method calls host callbacks re-entrantly for some reason.
This SharedHandler implementation should handle both of these cases as gracefully as
possible.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".