From d8416e2d4cb6a88ef93243f6224e2632ab7356dc Mon Sep 17 00:00:00 2001 From: arctic_hen7 Date: Sat, 22 Jan 2022 14:04:52 +1100 Subject: [PATCH] fix: fixed some trait scoping --- packages/perseus-macro/Cargo.toml | 1 + packages/perseus-macro/src/lib.rs | 4 +++- packages/perseus-macro/src/rx_state.rs | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/perseus-macro/Cargo.toml b/packages/perseus-macro/Cargo.toml index 7b8b4cd754..90a8f49b80 100644 --- a/packages/perseus-macro/Cargo.toml +++ b/packages/perseus-macro/Cargo.toml @@ -31,3 +31,4 @@ sycamore-reactive = "^0.7.1" trybuild = { version = "1.0", features = ["diff"] } sycamore = "^0.7.1" serde = { version = "1", features = [ "derive" ] } +perseus = { path = "../perseus", version = "0.3.2" } diff --git a/packages/perseus-macro/src/lib.rs b/packages/perseus-macro/src/lib.rs index 304a820051..fc7fb2dc90 100644 --- a/packages/perseus-macro/src/lib.rs +++ b/packages/perseus-macro/src/lib.rs @@ -134,7 +134,9 @@ pub fn test(args: TokenStream, input: TokenStream) -> TokenStream { /// /// ```rust /// use serde::{Serialize, Deserialize}; -/// # use perseus_macro::make_rx; // You might import this from `perseus` +/// use perseus::make_rx; +/// // We need this trait in scope to manually invoke `.make_rx()` +/// use perseus::state::MakeRx; /// /// #[make_rx(TestRx)] /// // Notice that we don't need to derive `Serialize`,`Deserialize`, or `Clone`, the macro does it for us diff --git a/packages/perseus-macro/src/rx_state.rs b/packages/perseus-macro/src/rx_state.rs index 91cf8435d0..b4b98921e3 100644 --- a/packages/perseus-macro/src/rx_state.rs +++ b/packages/perseus-macro/src/rx_state.rs @@ -159,7 +159,7 @@ pub fn make_rx_impl(mut orig_struct: ItemStruct, name: Ident) -> TokenStream { // Check if this field was registered as one to use nested reactivity if nested_fields_map.contains_key(field.ident.as_ref().unwrap()) { field_assignments.extend(quote! { - #field_name: self.#field_name.make_unrx(), + #field_name: self.#field_name.clone().make_unrx(), }) } else { // We can `.clone()` the field because we implement `Clone` on both the new and the original `struct`s, meaning all fields must also be `Clone` @@ -185,6 +185,7 @@ pub fn make_rx_impl(mut orig_struct: ItemStruct, name: Ident) -> TokenStream { impl#generics ::perseus::state::MakeRx for #ident#generics { type Rx = #name#generics; fn make_rx(self) -> #name#generics { + use ::perseus::state::MakeRx; #make_rx_fields } } @@ -193,11 +194,13 @@ pub fn make_rx_impl(mut orig_struct: ItemStruct, name: Ident) -> TokenStream { impl#generics ::perseus::state::MakeUnrx for #name#generics { type Unrx = #ident#generics; fn make_unrx(self) -> #ident#generics { + use ::perseus::state::MakeUnrx; #make_unrx_fields } } impl#generics ::perseus::state::Freeze for #name#generics { fn freeze(&self) -> ::std::string::String { + use ::perseus::state::MakeUnrx; let unrx = #make_unrx_fields; // TODO Is this `.unwrap()` safe? ::serde_json::to_string(&unrx).unwrap()