mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
parent
2bdacf636e
commit
e69c7f4ae0
1 changed files with 25 additions and 19 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue