1#[cfg(any(feature = "initial_value", doc))]
2use serde::Deserialize;
3use serde::{de::DeserializeOwned, Serialize};
4#[cfg(not(target_family = "wasm"))]
5use tauri::{AppHandle, Error, Wry};
6
7#[cfg(not(target_family = "wasm"))]
8#[doc(cfg(not(target_family = "wasm")))]
9pub use emit::*;
10#[cfg(any(target_family = "wasm", doc))]
11#[doc(cfg(target_family = "wasm"))]
12pub use listen::*;
13#[cfg(doc)]
14use tauri_interop_macro::{Emit, EmitField, Event, Listen, ListenField};
15
16#[cfg(not(target_family = "wasm"))]
18#[doc(cfg(not(target_family = "wasm")))]
19mod emit;
20
21#[cfg(any(target_family = "wasm", doc))]
23#[doc(cfg(target_family = "wasm"))]
24mod listen;
25
26#[allow(clippy::needless_doctest_main)]
27pub trait Field<P>
56where
57 P: Parent,
58 Self::Type: Default + Clone + Serialize + DeserializeOwned + 'static,
59{
60 type Type;
62
63 const EVENT_NAME: &'static str;
65
66 #[allow(async_fn_in_trait)]
68 #[cfg(any(all(target_family = "wasm", feature = "initial_value"), doc))]
69 #[doc(cfg(all(target_family = "wasm", feature = "initial_value")))]
70 async fn get_value() -> Result<Self::Type, EventError>;
71
72 #[cfg(not(target_family = "wasm"))]
73 #[doc(cfg(not(target_family = "wasm")))]
74 fn emit(parent: &P, handle: &AppHandle<Wry>) -> Result<(), Error>;
78
79 #[cfg(not(target_family = "wasm"))]
80 #[doc(cfg(not(target_family = "wasm")))]
81 fn update(s: &mut P, handle: &AppHandle<Wry>, v: Self::Type) -> Result<(), Error>;
85}
86
87#[cfg(any(feature = "initial_value", doc))]
88#[doc(cfg(feature = "initial_value"))]
89#[derive(Debug, Serialize, Deserialize, thiserror::Error)]
91pub enum EventError {
92 #[error("{0} is not as tauri state registered")]
94 StateIsNotRegistered(String),
95}