pub trait Plugin<U: Ui>: 'static {
type Cache: Default + Serialize + Deserialize<'static> + 'static
where Self: Sized;
// Required method
fn new(cache: Self::Cache) -> Self
where Self: Sized;
}Expand description
A plugin for Duat
A plugin is something that can be invoked in the configuration crate for Duat, and can apply a multitude of effects upon its creation.
Required Associated Types§
Sourcetype Cache: Default + Serialize + Deserialize<'static> + 'static
where
Self: Sized
type Cache: Default + Serialize + Deserialize<'static> + 'static where Self: Sized
A cacheable struct for your plugin
If you want data to be stored between executions, you can
store it in this struct, and it will be returned to the
plugin when Duat is executed in the future. If you don’t
need this feature, you can set type Cache = ();
Required Methods§
Sourcefn new(cache: Self::Cache) -> Selfwhere
Self: Sized,
fn new(cache: Self::Cache) -> Selfwhere
Self: Sized,
Returns a new instance from an old cache
If this is the first time the plugin was loaded, it will
receive Cache::default() as the argument.
struct AutoSaver;
impl<U: Ui> Plugin<U> for AutoSaver {
type Cache = ();
fn new(cache: Self::Cache) -> Self {
hooks::add::<KeySentTo<File, U>>(move |&(key, _)| {
// Assuming that we are leaving an insert mode
if let key!(KeyCode::Esc) = key {
cmd::run("write").unwrap();
}
});
AutoSaver
}
}