Skip to content

Commit

Permalink
fix: fixed some trait scoping
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Jan 22, 2022
1 parent ee29ba1 commit d8416e2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/perseus-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
4 changes: 3 additions & 1 deletion packages/perseus-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion packages/perseus-macro/src/rx_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
}
}
Expand All @@ -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()
Expand Down

0 comments on commit d8416e2

Please sign in to comment.