diff --git a/crates/relax-macros/src/lib.rs b/crates/relax-macros/src/lib.rs index c2e6b82..bc22927 100644 --- a/crates/relax-macros/src/lib.rs +++ b/crates/relax-macros/src/lib.rs @@ -143,6 +143,11 @@ fn derive_impl(input: syn::DeriveInput) -> syn::Result { 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 { 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),* diff --git a/crates/relax/src/lib.rs b/crates/relax/src/lib.rs index 5325a7c..12adb9a 100644 --- a/crates/relax/src/lib.rs +++ b/crates/relax/src/lib.rs @@ -9,6 +9,8 @@ pub trait Relax: TryFrom { pub trait Relaxed: From { type Complete; + + fn new() -> Self; fn merge(self, optb: Self) -> Self; }