Skip to content

Commit

Permalink
feat: add #[store(skip)] for #[derive(Store)] (closes #2946) (#2958)
Browse files Browse the repository at this point in the history
  • Loading branch information
brofrain authored Sep 10, 2024
1 parent 97282f4 commit 43a83c0
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions reactive_stores_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl Parse for Model {
#[derive(Clone)]
enum SubfieldMode {
Keyed(Ident, Type),
Skip,
}

impl Parse for SubfieldMode {
Expand All @@ -91,8 +92,10 @@ impl Parse for SubfieldMode {
let _col: Token!(:) = input.parse()?;
let ty: Type = input.parse()?;
Ok(SubfieldMode::Keyed(ident, ty))
} else if mode == "skip" {
Ok(SubfieldMode::Skip)
} else {
Err(input.error("expected `key = <ident>: <Type>`"))
Err(input.error("expected `key = <ident>: <Type>` or `skip`"))
}
}
}
Expand Down Expand Up @@ -283,21 +286,25 @@ fn field_to_tokens(
if let Some(modes) = modes {
if modes.len() == 1 {
let mode = &modes[0];
// Can replace with a match if additional modes added
// TODO keyed_by
let SubfieldMode::Keyed(_keyed_by, key_ty) = mode;
let signature = quote! {
fn #ident(self) -> #library_path::KeyedField<#any_store_field, #name #generics, #ty, #key_ty>
};
return if include_body {
quote! {
#signature {
todo!()
}

match mode {
// TODO keyed_by
SubfieldMode::Keyed(_keyed_by, key_ty) => {
let signature = quote! {
fn #ident(self) -> #library_path::KeyedField<#any_store_field, #name #generics, #ty, #key_ty>
};
return if include_body {
quote! {
#signature {
todo!()
}
}
} else {
quote! { #signature; }
};
}
} else {
quote! { #signature; }
};
SubfieldMode::Skip => return quote! {},
}
} else {
abort!(
orig_ident
Expand Down

0 comments on commit 43a83c0

Please sign in to comment.