pub trait WrapEventEx<State: 'static + PartialEq, Input: Dispatchable + 'static> {
// Required method
fn wrap(
self,
) -> impl FnMut(DispatchPair, AccessCell<'_, '_, State>) -> InputResult<()>;
}
Expand description
This trait is used to wrap rust lambdas into AppEvent<AppData>
objects that can be boxed for
use in App::new
. These lambdas must always take the form of |evt: AnEventEnum, state: AccessCell<AppData>| -> InputResult<()> {}
After implorting this extension trait, you will be able to call WrapEventEx::wrap
on a
qualifying lambda.
§Examples
use feather_ui::component::{ mouse_area, window::Window };
use feather_ui::persist::{ FnPersist2, FnPersistStore };
use feather_ui::{ SourceID, ScopeID, App, AccessCell };
use std::sync::Arc;
#[derive(Clone, PartialEq)]
struct MyState {
count: i32
}
// Remember to use the extension trait here so you can call `.wrap()` on a qualifying lambda.
use crate::feather_ui::WrapEventEx;
let onclick = |_: mouse_area::MouseAreaEvent,
mut appdata: AccessCell<MyState>|
-> feather_ui::InputResult<()> {
{
appdata.count += 1;
feather_ui::InputResult::Consume(())
}
}
.wrap();
struct MyApp {}
impl FnPersistStore for MyApp { type Store = (); }
impl FnPersist2<MyState, ScopeID<'_>, im::HashMap<Arc<SourceID>, Option<Window>>> for MyApp {
fn init(&self) -> Self::Store { () }
fn call(&mut self, _: Self::Store, _: MyState, _: ScopeID<'_>) -> (Self::Store, im::HashMap<Arc<SourceID>, Option<Window>>) {
((), im::HashMap::new())
}
}
App::<MyState, MyApp>::new::<()>(MyState { count: 0 }, vec![Box::new(onclick)], MyApp {}, |_| ());
Required Methods§
Sourcefn wrap(
self,
) -> impl FnMut(DispatchPair, AccessCell<'_, '_, State>) -> InputResult<()>
fn wrap( self, ) -> impl FnMut(DispatchPair, AccessCell<'_, '_, State>) -> InputResult<()>
Wraps a lambda with the appropriate type signature. See WrapEventEx
for examples.
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.