pub trait HookAlias<D: Any = NormalHook> {
type Input<'h>;
type Hookable: for<'h> Hookable<Input<'h> = Self::Input<'h>>;
}Expand description
An alias for a Hookable
This trait is not normally meant to be implemented manually,
instead, it is automatically derived for every Hookable.
You can use this if you want to use something that is not
Hookable as a Hookable alias that gets translated to an
actually Hookable type via HookAlias::Hookable. An example
of where this is used is with Widgets and Modes:
use duat::prelude::*;
pub struct CreatedStruct<T: 'static>(T);
impl<T: 'static> Hookable for CreatedStruct<T> {
type Input<'h> = &'h mut T;
fn get_input(&mut self) -> Self::Input<'_> {
&mut self.0
}
}
struct MyStructWithAVeryLongName {
pub option_1: bool,
};
// In the user's config crate:
setup_duat!(setup);
use duat::prelude::*;
fn setup() {
// This is way too long
hook::add::<CreatedStruct<MyStructWithAVeryLongName>>(|_, arg| Ok(arg.option_1 = true));
}In this case, you can do this instead:
use duat::prelude::*;
use hook::HookAlias;
pub struct CreatedStruct<T: 'static>(T);
impl<T: 'static> Hookable for CreatedStruct<T> {
type Input<'h> = &'h mut T;
fn get_input(&mut self) -> Self::Input<'_> {
&mut self.0
}
}
struct MyStructWithAVeryLongName {
pub option_1: bool,
};
struct MyDummy;
impl HookAlias<MyDummy> for MyStructWithAVeryLongName {
type Hookable = CreatedStruct<MyStructWithAVeryLongName>;
type Input<'h> = <Self::Hookable as Hookable>::Input<'h>;
}
// In the user's config crate:
setup_duat!(setup);
use duat::prelude::*;
fn setup() {
// Much better
hook::add::<MyStructWithAVeryLongName>(|_, arg| Ok(arg.option_1 = true));
}Required Associated Types§
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.