feat: add new
function to Relaxed trait
This commit is contained in:
parent
2012cef856
commit
79ec0721bf
2 changed files with 13 additions and 0 deletions
|
@ -143,6 +143,11 @@ fn derive_impl(input: syn::DeriveInput) -> syn::Result<TokenStream> {
|
|||
|
||||
let base = &input.ident;
|
||||
|
||||
let new_fields = fields.iter().map(|field| {
|
||||
let name = field.ident.as_ref();
|
||||
quote! { #name: ::std::option::Option::None }
|
||||
});
|
||||
|
||||
let from_fields = fields.iter().map(|field| {
|
||||
let name = field.ident.as_ref();
|
||||
let ty = &field.ty;
|
||||
|
@ -216,6 +221,12 @@ fn derive_impl(input: syn::DeriveInput) -> syn::Result<TokenStream> {
|
|||
impl #generics ::relax::Relaxed for #partial #generics {
|
||||
type Complete = #base #generics;
|
||||
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
#(#new_fields),*
|
||||
}
|
||||
}
|
||||
|
||||
fn merge(self, optb: Self) -> Self {
|
||||
Self {
|
||||
#(#merge_fields),*
|
||||
|
|
|
@ -9,6 +9,8 @@ pub trait Relax: TryFrom<Self::Partial, Error = RequiredFieldNotSet> {
|
|||
|
||||
pub trait Relaxed: From<Self::Complete> {
|
||||
type Complete;
|
||||
|
||||
fn new() -> Self;
|
||||
fn merge(self, optb: Self) -> Self;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue