make optional props accept T or Option<T>
This commit is contained in:
1 parent
e0fbed7eea
commit
be94c69f11
2 files changed
+15
-24
No files matched your search
@@ -12,6 +12,12 @@ fn main() {
|
|||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
|
Button {
|
||||||
|
a: "asd".to_string(),
|
||||||
|
c: "asd".to_string(),
|
||||||
|
d: Some("asd".to_string()),
|
||||||
|
e: Some("asd".to_string()),
|
||||||
|
}
|
||||||
Button {
|
Button {
|
||||||
a: "asd".to_string(),
|
a: "asd".to_string(),
|
||||||
c: "asd".to_string(),
|
c: "asd".to_string(),
|
||||||
|
|||||||
@@ -783,31 +783,16 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|||||||
None => quote!(),
|
None => quote!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// NOTE: both auto_into and strip_option affect `arg_type` and `arg_expr`, but the order of
|
let arg_type = field_type;
|
||||||
// nesting is different so we have to do this little dance.
|
let (arg_type, arg_expr) =
|
||||||
let arg_type = if field.builder_attr.strip_option {
|
if field.builder_attr.auto_into || field.builder_attr.strip_option {
|
||||||
field.type_from_inside_option(false).ok_or_else(|| {
|
(
|
||||||
Error::new_spanned(
|
quote!(impl ::core::convert::Into<#arg_type>),
|
||||||
field_type,
|
quote!(#field_name.into()),
|
||||||
"can't `strip_option` - field is not `Option<...>`",
|
|
||||||
)
|
)
|
||||||
})?
|
} else {
|
||||||
} else {
|
(quote!(#arg_type), quote!(#field_name))
|
||||||
field_type
|
};
|
||||||
};
|
|
||||||
let (arg_type, arg_expr) = if field.builder_attr.auto_into {
|
|
||||||
(
|
|
||||||
quote!(impl ::core::convert::Into<#arg_type>),
|
|
||||||
quote!(#field_name.into()),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
(quote!(#arg_type), quote!(#field_name))
|
|
||||||
};
|
|
||||||
let arg_expr = if field.builder_attr.strip_option {
|
|
||||||
quote!(Some(#arg_expr))
|
|
||||||
} else {
|
|
||||||
arg_expr
|
|
||||||
};
|
|
||||||
|
|
||||||
let repeated_fields_error_type_name = syn::Ident::new(
|
let repeated_fields_error_type_name = syn::Ident::new(
|
||||||
&format!(
|
&format!(
|
||||||
|
|||||||
Reference in new issue
Block a user