feat(#2946): add #[store(skip)] for #[derive(Store)] (#2975)

This commit is contained in:
Kajetan Welc 2024-09-17 03:57:57 +02:00 committed by GitHub
parent 2bdacf636e
commit e69c7f4ae0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -80,6 +80,7 @@ impl Parse for Model {
#[derive(Clone)] #[derive(Clone)]
enum SubfieldMode { enum SubfieldMode {
Keyed(ExprClosure, Type), Keyed(ExprClosure, Type),
Skip,
} }
impl Parse for SubfieldMode { impl Parse for SubfieldMode {
@ -91,6 +92,8 @@ impl Parse for SubfieldMode {
let _eq: Token!(=) = input.parse()?; let _eq: Token!(=) = input.parse()?;
let ident: ExprClosure = input.parse()?; let ident: ExprClosure = input.parse()?;
Ok(SubfieldMode::Keyed(ident, ty)) Ok(SubfieldMode::Keyed(ident, ty))
} else if mode == "skip" {
Ok(SubfieldMode::Skip)
} else { } else {
Err(input.error("expected `key = <ident>: <Type>`")) Err(input.error("expected `key = <ident>: <Type>`"))
} }
@ -280,8 +283,8 @@ fn field_to_tokens(
if let Some(modes) = modes { if let Some(modes) = modes {
if modes.len() == 1 { if modes.len() == 1 {
let mode = &modes[0]; let mode = &modes[0];
// Can replace with a match if additional modes added match mode {
let SubfieldMode::Keyed(keyed_by, key_ty) = mode; SubfieldMode::Keyed(keyed_by, key_ty) => {
let signature = quote! { let signature = quote! {
fn #ident(self) -> #library_path::KeyedSubfield<#any_store_field, #name #generics, #key_ty, #ty> fn #ident(self) -> #library_path::KeyedSubfield<#any_store_field, #name #generics, #key_ty, #ty>
}; };
@ -300,6 +303,9 @@ fn field_to_tokens(
} else { } else {
quote! { #signature; } quote! { #signature; }
}; };
}
SubfieldMode::Skip => return quote! {},
}
} else { } else {
abort!( abort!(
orig_ident orig_ident