diff --git a/Cargo.lock b/Cargo.lock
index 5696267..c7afd88 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3319,7 +3319,7 @@ dependencies = [
[[package]]
name = "tauri-interop"
-version = "2.1.0"
+version = "2.1.1"
dependencies = [
"js-sys",
"leptos",
@@ -3327,7 +3327,7 @@ dependencies = [
"serde",
"serde-wasm-bindgen",
"tauri",
- "tauri-interop-macro 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tauri-interop-macro",
"thiserror",
"wasm-bindgen",
"wasm-bindgen-futures",
@@ -3335,7 +3335,7 @@ dependencies = [
[[package]]
name = "tauri-interop-macro"
-version = "2.1.0"
+version = "2.1.1"
dependencies = [
"convert_case 0.6.0",
"lazy_static",
@@ -3349,20 +3349,6 @@ dependencies = [
"tauri-interop",
]
-[[package]]
-name = "tauri-interop-macro"
-version = "2.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f6107bb6b43eaa7663d5b5e6aa4558f81fad2589f21c9a069802432b0a0a6e4e"
-dependencies = [
- "convert_case 0.6.0",
- "lazy_static",
- "proc-macro-error",
- "proc-macro2",
- "quote",
- "syn 2.0.52",
-]
-
[[package]]
name = "tauri-macros"
version = "1.4.3"
diff --git a/Cargo.toml b/Cargo.toml
index 9e22e19..46aa422 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,8 +24,8 @@ description = "Easily connect your rust frontend and backend without writing dup
readme = "README.md"
[dependencies]
-#tauri-interop-macro = { path = "./tauri-interop-macro" }
-tauri-interop-macro = "2.1.1"
+tauri-interop-macro = { path = "./tauri-interop-macro" }
+#tauri-interop-macro = "2.1.1"
js-sys = "0.3"
serde = { version = "1.0", features = ["derive"] }
@@ -43,8 +43,8 @@ leptos = { version = "0.6", optional = true }
tauri = { version = "1.6", default-features = false, features = ["wry"] }
[target.'cfg(target_family = "wasm")'.dependencies]
-#tauri-interop-macro = { path = "./tauri-interop-macro", features = ["_wasm"] }
-tauri-interop-macro = { version = "2.1.1", features = [ "_wasm" ] }
+tauri-interop-macro = { path = "./tauri-interop-macro", features = ["_wasm"] }
+#tauri-interop-macro = { version = "2.1.1", features = [ "_wasm" ] }
[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
tauri = "1.6"
diff --git a/README.md b/README.md
index 96a0c7d..b6fbd57 100644
--- a/README.md
+++ b/README.md
@@ -20,3 +20,11 @@ The crates therefore provides the following features:
- collect and register all defined tauri-commands
- QOL-macros to exclude multiple imports in wasm or the host architecture
- easier usage of [tauri's event feature](https://tauri.app/v1/guides/features/events/)
+
+### Note
+
+The library uses a resolver 2 features to allow easy inclusion without configuration. When working with virtual
+workspaces the resolver defaults to 1. In that case it is required to set the resolver manually to version 2,
+otherwise the [target specific compilation](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies)
+will not resolve correctly. When the wrong resolver is used, an error should state that the `Listen` trait is missing.
+
diff --git a/src/event.rs b/src/event.rs
index 578c196..b2e8607 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -8,6 +8,8 @@ pub use emit::*;
#[cfg(any(target_family = "wasm", doc))]
#[doc(cfg(target_family = "wasm"))]
pub use listen::*;
+#[cfg(doc)]
+use tauri_interop_macro::{Emit, EmitField, Event, Listen, ListenField};
/// traits for event emitting in the host code
#[cfg(not(target_family = "wasm"))]
@@ -19,7 +21,34 @@ mod emit;
#[doc(cfg(target_family = "wasm"))]
mod listen;
+#[allow(clippy::needless_doctest_main)]
/// 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, event::ManagedEmit};
+///
+/// #[derive(Default, Clone, Serialize, Deserialize)]
+/// struct Bar {
+/// foo: u16
+/// }
+///
+/// #[derive(Event)]
+/// struct Test {
+/// bar: Bar
+/// }
+///
+/// impl ManagedEmit for Test {}
+///
+/// fn main() {
+/// let _ = test::FBar;
+/// }
+/// ```
pub trait Field
where
P: Parent,
diff --git a/src/event/emit.rs b/src/event/emit.rs
index 34cb1df..25c735c 100644
--- a/src/event/emit.rs
+++ b/src/event/emit.rs
@@ -36,7 +36,7 @@ where
get_field_value: impl Fn(&Self) -> F::Type,
) -> Option
where
- Self: Sized + Send + Sync,
+ Self: Send + Sync,
{
use tauri::Manager;
@@ -47,7 +47,7 @@ where
}
/// Trait that defines the available event emitting methods
-pub trait Emit {
+pub trait Emit: Sized {
/// Emit all field events
///
/// ### Example
@@ -89,14 +89,14 @@ pub trait Emit {
///
/// #[tauri_interop::command]
/// fn emit_bar(handle: TauriAppHandle) {
- /// Test::default().emit::(&handle).expect("emitting failed");
+ /// Test::default().emit::(&handle).expect("emitting failed");
/// }
///
/// fn main() {}
/// ```
fn emit>(&self, handle: &AppHandle) -> Result<(), Error>
where
- Self: Sized + Parent;
+ Self: Parent;
/// Update a single field and emit it afterward
///
@@ -116,7 +116,7 @@ pub trait Emit {
///
/// #[tauri_interop::command]
/// fn emit_bar(handle: TauriAppHandle) {
- /// Test::default().update::(&handle, true).expect("emitting failed");
+ /// Test::default().update::(&handle, true).expect("emitting failed");
/// }
///
/// fn main() {}
@@ -127,5 +127,5 @@ pub trait Emit {
field: F::Type,
) -> Result<(), Error>
where
- Self: Sized + Parent;
+ Self: Parent;
}
diff --git a/src/event/listen.rs b/src/event/listen.rs
index aba279f..7e53a01 100644
--- a/src/event/listen.rs
+++ b/src/event/listen.rs
@@ -7,7 +7,7 @@ use wasm_bindgen::{closure::Closure, JsCast, JsValue};
use crate::command::bindings::listen;
#[cfg(doc)]
-use super::Emit;
+use super::{Emit, Parent};
use super::Field;
/// The trait which needs to be implemented for a [Field]
@@ -95,15 +95,16 @@ impl ListenHandle {
/// Registers a given event and binds a returned signal to these event changes
///
- /// Providing [None] will unwrap into the default value. When feature `initial_value`
+ /// Providing [None] will unwrap into the default value. When feature `initial_value`
/// is enabled [None] will try to get the value from tauri.
- ///
+ ///
/// Internally it stores a created [ListenHandle] for `event` in a [leptos::RwSignal] to hold it in
/// scope, while it is used in a leptos [component](https://docs.rs/leptos_macro/0.5.2/leptos_macro/attr.component.html)
#[cfg(feature = "leptos")]
#[doc(cfg(feature = "leptos"))]
pub fn use_register>(initial_value: Option) -> ReadSignal
- where P: Sized + super::Parent
+ where
+ P: Parent,
{
use leptos::SignalSet;
@@ -116,10 +117,10 @@ impl ListenHandle {
if cfg!(feature = "initial_value") && acquire_initial_value {
match F::get_value().await {
Ok(value) => set_signal.set(value),
- Err(why) => log::error!("{why}")
+ Err(why) => log::error!("{why}"),
}
}
-
+
let listen_handle = ListenHandle::register(F::EVENT_NAME, move |value: F::Type| {
log::trace!("update for {}", F::EVENT_NAME);
set_signal.set(value)
@@ -136,7 +137,7 @@ impl ListenHandle {
}
/// Trait that defines the available listen methods
-pub trait Listen {
+pub trait Listen: Sized {
/// Registers a callback to a [Field]
///
/// Default Implementation: see [ListenHandle::register]
@@ -164,7 +165,7 @@ pub trait Listen {
callback: impl Fn(F::Type) + 'static,
) -> impl std::future::Future