diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs index 78c093d807..8771d29773 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -1,9 +1,8 @@ #[ allow( unused_imports ) ] use super::*; -#[ derive( Debug, PartialEq ) ] -// #[ derive( Debug, PartialEq, the_module::Former ) ] -// #[ debug ] +// #[ derive( Debug, PartialEq ) ] +#[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] pub struct Struct1 { pub int_1 : i32, @@ -14,235 +13,6 @@ pub struct Struct1 // = formed -#[automatically_derived] -impl Struct1 -{ - #[doc = r""] - #[doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step."] - #[doc = r""] - #[inline(always)] - pub fn former() -> Struct1Former<(), former::ReturnStorage> - { - Struct1Former::new() - } -} - -#[derive(Debug)] -pub struct Struct1FormerDescriptor; - -impl Struct1FormerDescriptor -{ - pub fn new() -> Self - { - Self - } -} - -impl former::FormerDescriptor for Struct1FormerDescriptor -{ - type Storage = Struct1FormerStorage; - type Formed = Struct1; -} - -#[doc = "Container of a corresponding former."] -pub struct Struct1FormerStorage -{ - #[doc = r" A field"] - pub int_1 : ::core::option::Option, - #[doc = r" A field"] - pub string_1 : ::core::option::Option, - #[doc = r" A field"] - pub int_optional_1 : core::option::Option, - #[doc = r" A field"] - pub string_optional_1 : Option, -} - -impl ::core::default::Default for Struct1FormerStorage -{ - #[inline(always)] - fn default() -> Self - { - Self - { - int_1 : ::core::option::Option::None, - string_1 : ::core::option::Option::None, - int_optional_1 : ::core::option::Option::None, - string_optional_1 : ::core::option::Option::None, - } - } -} - -impl former::Storage for Struct1FormerStorage -{ - type Descriptor = Struct1FormerDescriptor; -} - -impl former::StoragePerform for Struct1FormerStorage -{ - fn preform(mut self) -> Struct1 - { - Struct1 - { - int_1 : self.int_1.take().or_else(|| Some(::core::marker::PhantomData::::maybe_default())).unwrap(), - string_1 : self.string_1.take().or_else(|| Some(::core::marker::PhantomData::::maybe_default())).unwrap(), - int_optional_1 : self.int_optional_1, - string_optional_1 : self.string_optional_1, - } - } -} - -trait MaybeDefault -{ - fn maybe_default() -> T; -} - -impl MaybeDefault for ::core::marker::PhantomData -where i32 : ::core::default::Default, -{ - fn maybe_default() -> i32 - { - i32::default() - } -} - -impl MaybeDefault for ::core::marker::PhantomData -where String : ::core::default::Default, -{ - fn maybe_default() -> String - { - String::default() - } -} - -#[doc = -" Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -#[automatically_derived] -pub struct Struct1Former<__FormerContext = Struct1, __FormerEnd = former::ReturnStorage> -where __FormerEnd : former::FormingEnd, -{ - storage : Struct1FormerStorage, - context : core::option::Option<__FormerContext>, - on_end : core::option::Option<__FormerEnd>, -} - -#[automatically_derived] -impl<__FormerContext, __FormerEnd> Struct1Former<__FormerContext, __FormerEnd> -where __FormerEnd : former::FormingEnd, -{ - #[doc = r""] - #[doc = r" Finish setting options and return formed entity."] - #[doc = r""] - #[inline(always)] - pub fn preform(self) -> ::Formed - { - ::preform(self.storage) - } - - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] - #[doc = r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] - #[inline(always)] - pub fn perform(self) -> ::Formed - { - let result = self.form(); - return result; - } - - #[doc = r""] - #[doc = r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] - #[inline(always)] - pub fn begin(mut storage : core::option::Option, context : core::option::Option<__FormerContext>, on_end : __FormerEnd,) -> Self - { - if storage.is_none() - { - storage = Some(::core::default::Default::default()); - } - Self - { - storage : storage.unwrap(), - context : context, - on_end : ::core::option::Option::Some(on_end), - } - } - - #[doc = r""] - #[doc = r" End the process of forming returning original context of forming."] - #[doc = r""] - #[inline(always)] - pub fn form(self) -> ::Formed - { - self.end() - } - - #[doc = r""] - #[doc = r" End the process of forming returning original context of forming."] - #[doc = r""] - #[inline(always)] - pub fn end(mut self) -> ::Formed - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - on_end.call(self.storage, context) - } - - #[doc = "Setter for the 'int_1' field."] - #[inline] - pub fn int_1(mut self, src: Src) -> Self - where Src : ::core::convert::Into, - { - debug_assert!(self.storage.int_1.is_none()); - self.storage.int_1 = ::core::option::Option::Some(src.into()); - self - } - - #[doc = "Setter for the 'string_1' field."] - #[inline] - pub fn string_1(mut self, src: Src) -> Self - where Src : ::core::convert::Into, - { - debug_assert!(self.storage.string_1.is_none()); - self.storage.string_1 = ::core::option::Option::Some(src.into()); - self - } - - #[doc = "Setter for the 'int_optional_1' field."] - #[inline] - pub fn int_optional_1(mut self, src: Src) -> Self - where Src : ::core::convert::Into, - { - debug_assert!(self.storage.int_optional_1.is_none()); - self.storage.int_optional_1 = ::core::option::Option::Some(src.into()); - self - } - - #[doc = "Setter for the 'string_optional_1' field."] - #[inline] - pub fn string_optional_1(mut self, src: Src) -> Self - where Src : ::core::convert::Into, - { - debug_assert!(self.storage.string_optional_1.is_none()); - self.storage.string_optional_1 = ::core::option::Option::Some(src.into()); - self - } -} - -#[automatically_derived] -impl Struct1Former<(), former::ReturnStorage> -{ - #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] - #[inline(always)] - pub fn new() -> Self - { - Self::begin(None, None, former::ReturnStorage,) - } -} - // // include!( "./only_test/primitives.rs" ); diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 6a7162a36e..ec54b2ad41 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -404,9 +404,9 @@ fn field_form_map( field : &FormerField< '_ > ) -> Result< TokenStream > qt! { - let #ident = if self.storage.#ident.is_some() + let #ident = if self.#ident.is_some() { - ::core::option::Option::Some( self.storage.#ident.take().unwrap() ) + ::core::option::Option::Some( self.#ident.take().unwrap() ) } else { @@ -464,9 +464,9 @@ fn field_form_map( field : &FormerField< '_ > ) -> Result< TokenStream > qt! { - let #ident = if self.storage.#ident.is_some() + let #ident = if self.#ident.is_some() { - self.storage.#ident.take().unwrap() + self.#ident.take().unwrap() } else { @@ -1001,17 +1001,16 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { // fn preform( mut self ) -> #former_storage_name_ident #generics_ty - fn preform( mut self ) -> < former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + fn preform( mut self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed { - Self + #( #fields_form )* + // Rust does not support that, yet + // let result = < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + let result = #name_ident #generics_ty { - #( #fields_form )* - let result = #name_ident - { - #( #fields_names, )* - }; - return result; - } + #( #fields_names, )* + }; + return result; } } @@ -1038,7 +1037,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// Finish setting options and return formed entity. /// #[ inline( always ) ] - pub fn preform( self ) -> < former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + pub fn preform( self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed // #name_ident #generics_ty { < #former_storage_name_ident #generics_ty as former::StoragePerform >::preform( self.storage ) @@ -1090,7 +1089,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn form( self ) -> < former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + pub fn form( self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed { self.end() } @@ -1099,7 +1098,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn end( mut self ) -> < former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + pub fn end( mut self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take();