pub trait UseHookExt {
// Required methods
fn use_hook_as<T: Hook<D>, D: Deps>(
&mut self,
id: Id,
hook: T,
deps: D,
) -> T::Output;
fn use_hook<T: Hook<D>, D: Deps>(&mut self, hook: T, deps: D) -> T::Output;
fn use_state<T: Send + Sync + 'static, D: Deps>(
&mut self,
default: impl FnOnce() -> T,
deps: D,
) -> State<T>;
fn use_persisted_state<T: SerializableAny, D: Deps>(
&mut self,
default: impl FnOnce() -> T,
deps: D,
) -> State<T>;
fn use_memo<T: Clone + Send + Sync + 'static, F: FnMut() -> T, D: Deps>(
&mut self,
callback: F,
deps: D,
) -> T;
fn use_effect<F: FnOnce() + Send + Sync, D: Deps>(
&mut self,
callback: F,
deps: D,
);
fn use_cleanup<F: FnOnce() + Send + Sync + 'static, D: Deps>(
&mut self,
callback: F,
deps: D,
);
fn use_kv<K: Send + Sync + 'static, V: Send + Sync + 'static>(
&mut self,
) -> Kv<K, V>;
fn use_persisted_kv<K: SerializableAny + Eq + Hash, V: SerializableAny>(
&mut self,
) -> Kv<K, V>;
fn use_2f_kv<K: Clone + Eq + Hash + Send + Sync + 'static, V: Send + Sync + 'static>(
&mut self,
) -> TwoFrameKv<K, V>;
fn use_persisted_2f_kv<K: Clone + Eq + Hash + SerializableAny, V: SerializableAny>(
&mut self,
) -> TwoFrameKv<K, V>;
fn use_ephemeral_kv<K: Eq + Hash + Send + Sync + 'static, V: Send + Sync + 'static>(
&mut self,
) -> EphemeralKv<K, V>;
}
Required Methods§
Sourcefn use_hook_as<T: Hook<D>, D: Deps>(
&mut self,
id: Id,
hook: T,
deps: D,
) -> T::Output
fn use_hook_as<T: Hook<D>, D: Deps>( &mut self, id: Id, hook: T, deps: D, ) -> T::Output
Use a hook in the context of a widget with the given id.
fn use_hook<T: Hook<D>, D: Deps>(&mut self, hook: T, deps: D) -> T::Output
fn use_state<T: Send + Sync + 'static, D: Deps>( &mut self, default: impl FnOnce() -> T, deps: D, ) -> State<T>
fn use_persisted_state<T: SerializableAny, D: Deps>( &mut self, default: impl FnOnce() -> T, deps: D, ) -> State<T>
fn use_memo<T: Clone + Send + Sync + 'static, F: FnMut() -> T, D: Deps>( &mut self, callback: F, deps: D, ) -> T
fn use_effect<F: FnOnce() + Send + Sync, D: Deps>( &mut self, callback: F, deps: D, )
fn use_cleanup<F: FnOnce() + Send + Sync + 'static, D: Deps>( &mut self, callback: F, deps: D, )
fn use_kv<K: Send + Sync + 'static, V: Send + Sync + 'static>( &mut self, ) -> Kv<K, V>
fn use_persisted_kv<K: SerializableAny + Eq + Hash, V: SerializableAny>( &mut self, ) -> Kv<K, V>
fn use_2f_kv<K: Clone + Eq + Hash + Send + Sync + 'static, V: Send + Sync + 'static>( &mut self, ) -> TwoFrameKv<K, V>
fn use_persisted_2f_kv<K: Clone + Eq + Hash + SerializableAny, V: SerializableAny>( &mut self, ) -> TwoFrameKv<K, V>
fn use_ephemeral_kv<K: Eq + Hash + Send + Sync + 'static, V: Send + Sync + 'static>( &mut self, ) -> EphemeralKv<K, V>
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.
Implementations on Foreign Types§
Source§impl UseHookExt for Ui
impl UseHookExt for Ui
Source§fn use_state<T: Send + Sync + 'static, D: Deps>(
&mut self,
default: impl FnOnce() -> T,
deps: D,
) -> State<T>
fn use_state<T: Send + Sync + 'static, D: Deps>( &mut self, default: impl FnOnce() -> T, deps: D, ) -> State<T>
Returns a state that is initialized with the given default value.
A state is resetted to new default value when the dependencies are changed.
If you need to mutate the state as like normal variable, put .into_var()
after this.
§Example
let ctx = egui::Context::default();
let _ = ctx.run(Default::default(), |ctx| {
egui::Area::new("test".into()).show(ctx, |ui| {
use egui_hooks::UseHookExt as _;
let mut state = ui.use_state(|| 42, ());
let mut var_state = ui.use_state(|| 42, ()).into_var();
});
});