mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 04:48:20 +02:00
Add unified deprecation system and @deprecated attribute (#15770)
This commit is contained in:
@ -68,6 +68,7 @@ impl ParseAttrs for ContainerAttributes {
|
||||
#[derive(Debug, Default)]
|
||||
pub struct MemberAttributes {
|
||||
pub rename: Option<String>,
|
||||
pub default: bool,
|
||||
}
|
||||
|
||||
impl ParseAttrs for MemberAttributes {
|
||||
@ -79,6 +80,9 @@ impl ParseAttrs for MemberAttributes {
|
||||
let rename = rename.value();
|
||||
self.rename = Some(rename);
|
||||
}
|
||||
"default" => {
|
||||
self.default = true;
|
||||
}
|
||||
ident => {
|
||||
return Err(DeriveError::UnexpectedAttribute {
|
||||
meta_span: ident.span(),
|
||||
|
@ -570,16 +570,15 @@ fn parse_value_via_fields(
|
||||
let ident_s =
|
||||
name_resolver.resolve_ident(ident, container_attrs, &member_attrs, None)?;
|
||||
let ty = &field.ty;
|
||||
fields_ts.push(match type_is_option(ty) {
|
||||
true => quote! {
|
||||
fields_ts.push(match (type_is_option(ty), member_attrs.default) {
|
||||
(true, _) => quote! {
|
||||
#ident: record
|
||||
.remove(#ident_s)
|
||||
.map(|v| <#ty as nu_protocol::FromValue>::from_value(v))
|
||||
.transpose()?
|
||||
.flatten()
|
||||
},
|
||||
|
||||
false => quote! {
|
||||
(false, false) => quote! {
|
||||
#ident: <#ty as nu_protocol::FromValue>::from_value(
|
||||
record
|
||||
.remove(#ident_s)
|
||||
@ -590,6 +589,13 @@ fn parse_value_via_fields(
|
||||
})?,
|
||||
)?
|
||||
},
|
||||
(false, true) => quote! {
|
||||
#ident: record
|
||||
.remove(#ident_s)
|
||||
.map(|v| <#ty as nu_protocol::FromValue>::from_value(v))
|
||||
.transpose()?
|
||||
.unwrap_or_default()
|
||||
},
|
||||
});
|
||||
}
|
||||
Ok(quote! {
|
||||
|
Reference in New Issue
Block a user