Trait Field

Source
pub trait Field<P>
where P: Parent, Self::Type: Default + Clone + Serialize + DeserializeOwned + 'static,
{ type Type; const EVENT_NAME: &'static str; // Required methods async fn get_value() -> Result<Self::Type, EventError>; fn emit(parent: &P, handle: &AppHandle<Wry>) -> Result<(), Error>; fn update( s: &mut P, handle: &AppHandle<Wry>, v: Self::Type, ) -> Result<(), Error>; }
Available on crate feature event only.
Expand description

Trait defining a Field to a related struct implementing Parent with the related Field::Type

When using Event, Emit or Listen, for each field of the struct, a struct named after the field is generated. The field naming is snake_case to PascalCase, but because of the possibility that the type and the field name are the same, the generated field has a “F” appended at the beginning to separate each other and avoid type collision.

use serde::{Deserialize, Serialize};
use tauri_interop::Event;

#[derive(Default, Clone, Serialize, Deserialize)]
struct Bar {
    foo: u16
}

#[derive(Event)]
struct Test {
    bar: Bar
}

#[cfg(feature = "initial_value")]
impl tauri_interop::event::ManagedEmit for Test {}

fn main() {
    let _ = test::FBar;
}

Required Associated Constants§

Source

const EVENT_NAME: &'static str

The event of the field

Required Associated Types§

Source

type Type

The type of the field

Required Methods§

Source

async fn get_value() -> Result<Self::Type, EventError>

Available on target_family="wasm" and crate feature initial_value only.

Tries to retrieve the current value from the backend

Source

fn emit(parent: &P, handle: &AppHandle<Wry>) -> Result<(), Error>

Available on non-target_family="wasm" only.

Emits event of the related field with their value

not in wasm available

Source

fn update( s: &mut P, handle: &AppHandle<Wry>, v: Self::Type, ) -> Result<(), Error>

Available on non-target_family="wasm" only.

Updates the related field and emit its event

not in wasm available

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§