Trait Listen

Source
pub trait Listen: Sized {
    // Provided methods
    fn listen_to<F: Field<Self>>(
        callback: impl Fn(F::Type) + 'static,
    ) -> impl Future<Output = ListenResult>
       where Self: Parent { ... }
    fn use_field<F: Field<Self>>(
        initial: Option<F::Type>,
    ) -> ReadSignal<<F as Field<Self>>::Type, LocalStorage>
       where Self: Parent { ... }
}
Available on target_family="wasm" and crate feature event only.
Expand description

Trait that defines the available listen methods

Provided Methods§

Source

fn listen_to<F: Field<Self>>( callback: impl Fn(F::Type) + 'static, ) -> impl Future<Output = ListenResult>
where Self: Parent,

Registers a callback to a Field

Default Implementation: see ListenHandle::register

§Example
use tauri_interop::Event;

#[derive(Default, Event)]
pub struct Test {
    foo: String,
    pub bar: bool,
}

async fn main() {
    use tauri_interop::event::listen::Listen;

    let _listen_handle: ListenHandle<'_> = Test::listen_to::<test::Foo>(|foo| {
        /* use received foo: String here */
    }).await;
}
Source

fn use_field<F: Field<Self>>( initial: Option<F::Type>, ) -> ReadSignal<<F as Field<Self>>::Type, LocalStorage>
where Self: Parent,

Available on crate feature leptos only.

Creates a signal to a Field

Default Implementation: see ListenHandle::use_register

§Example
use tauri_interop::Event;

#[derive(Default, Event)]
pub struct Test {
    foo: String,
    pub bar: bool,
}

fn main() {
  use tauri_interop::event::listen::Listen;

  let foo: leptos::ReadSignal<String> = Test::use_field::<test::Foo>(String::default());
}

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.

Implementors§