pub trait Plugin<U: Ui>: Sized {
// Required methods
fn new() -> Self;
fn plug(self);
}Expand description
A plugin for Duat
Plugins must follow the builder pattern, and can be specific to
certain Uis. Generally, plugins should do all the setup
necessary for their function when Plugin::plug is called.
Plugin will usually be plugged by a macro in the Duat
config crate. This macro requires that the Plugin be
compatible with the Ui. And this can cause some inconvenience
for the end user. For example, say we have a plugin like this:
struct MyPlugin;
impl<U: Ui> Plugin<U> for MyPlugin {
fn new() -> Self {
MyPlugin
}
fn plug(self) {
//..
}
}
impl MyPlugin {
pub fn modify(self) -> Self {
//..
}
}In the config crate, the user would have to add the plugin in a really awkward way:
plug!(<MyPlugin as Plugin<Ui>>::new().modify());To prevent that, just add a Ui PhantomData parameter:
struct MyPlugin<U>(PhantomData<U>);
impl<U: Ui> Plugin<U> for MyPlugin<U> {
fn new() -> Self {
MyPlugin(PhantomData)
}
fn plug(self) {
//..
}
}
impl<U> MyPlugin<U> {
pub fn modify(self) -> Self {
//..
}
}And now the plugin can be plugged much more normally:
plug!(MyPlugin::new().modify());Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.