From 058554bf75c1e71c78a08edf2f5cc1f3a9276137 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 15:35:17 +0200 Subject: [PATCH] former : experimenting --- module/core/former/src/vector3.rs | 3 +- .../tests/inc/former_tests/a_primitives.rs | 241 ++++++++++++++++++ .../inc/former_tests/a_primitives_expanded.rs | 18 ++ .../inc/former_tests/a_primitives_manual.rs | 168 ++++++------ .../a_primitives_manual_original.rs | 2 +- module/core/former/tests/inc/mod.rs | 2 + 6 files changed, 348 insertions(+), 86 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/a_primitives.rs create mode 100644 module/core/former/tests/inc/former_tests/a_primitives_expanded.rs diff --git a/module/core/former/src/vector3.rs b/module/core/former/src/vector3.rs index c3300e25de..00105bea11 100644 --- a/module/core/former/src/vector3.rs +++ b/module/core/former/src/vector3.rs @@ -211,7 +211,8 @@ where storage : core::option::Option< Descriptor::Storage >, context : core::option::Option< Context >, on_end : End, - ) -> Self + ) + -> Self { Self::begin( storage, context, on_end ) } diff --git a/module/core/former/tests/inc/former_tests/a_primitives.rs b/module/core/former/tests/inc/former_tests/a_primitives.rs new file mode 100644 index 0000000000..7a63846439 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/a_primitives.rs @@ -0,0 +1,241 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ derive( Debug, PartialEq, the_module::Former ) ] +pub struct Struct1 +{ + pub int_1 : i32, + string_1 : String, + int_optional_1 : core::option::Option< i32 >, + string_optional_1 : Option< String >, +} + +// + +// // generated by former +// impl Struct1 +// { +// pub fn former() -> Struct1Former< (), the_module::ReturnStorage > +// { +// Struct1Former::new() +// } +// } +// +// // +// +// // generated by former +// pub struct Struct1FormerStorage +// { +// pub int_1 : core::option::Option< i32 >, +// pub string_1 : core::option::Option< String >, +// pub int_optional_1 : core::option::Option< i32 >, +// pub string_optional_1 : core::option::Option< String >, +// } +// +// impl 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, +// } +// } +// +// } +// +// #[ derive( Debug ) ] +// pub struct Struct1FormerDescriptor; +// +// impl Struct1FormerDescriptor +// { +// pub fn new() -> Self +// { +// Self +// } +// } +// +// impl former::FormerDescriptor +// for Struct1FormerDescriptor +// { +// type Storage = Struct1FormerStorage; +// type Formed = Struct1; +// } +// +// impl former::Storage +// for Struct1FormerStorage +// { +// type Descriptor = Struct1FormerDescriptor; +// } +// +// impl former::StoragePerform +// for Struct1FormerStorage +// { +// +// fn preform( mut self ) -> < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed +// { +// +// let int_1 = if self.int_1.is_some() +// { +// self.int_1.take().unwrap() +// } +// else +// { +// let val : i32 = Default::default(); +// val +// }; +// +// let string_1 = if self.string_1.is_some() +// { +// self.string_1.take().unwrap() +// } +// else +// { +// let val : String = Default::default(); +// val +// }; +// +// let int_optional_1 = if self.int_optional_1.is_some() +// { +// Some( self.int_optional_1.take().unwrap() ) +// } +// else +// { +// None +// }; +// +// let string_optional_1 = if self.string_optional_1.is_some() +// { +// Some( self.string_optional_1.take().unwrap() ) +// } +// else +// { +// None +// }; +// +// // xxx : Rust failt to use parameter here +// // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed +// Struct1 +// { +// int_1, +// string_1, +// int_optional_1, +// string_optional_1, +// } +// +// } +// +// } +// +// // +// +// pub struct Struct1Former +// < +// FormerContext = Struct1, +// FormerEnd = the_module::ReturnStorage, +// > +// where +// FormerEnd : the_module::FormingEnd< Struct1FormerDescriptor, FormerContext >, +// { +// storage : Struct1FormerStorage, +// context : core::option::Option< FormerContext >, +// on_end : core::option::Option< FormerEnd >, +// } +// +// impl< FormerContext, FormerEnd > Struct1Former< FormerContext, FormerEnd > +// where +// FormerEnd: the_module::FormingEnd< Struct1FormerDescriptor, FormerContext >, +// { +// +// fn preform( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed +// { +// former::StoragePerform::preform( self.storage ) +// } +// +// #[ inline( always ) ] +// pub fn perform(self) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed +// { +// let result = self.form(); +// return result; +// } +// +// #[ inline( always ) ] +// pub fn begin +// ( +// mut storage : core::option::Option< < Struct1FormerDescriptor as former::FormerDescriptor >::Storage >, +// // xxx : cover by test existance of these 3 parameters in the function +// 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 ), +// } +// } +// +// #[ inline( always ) ] +// pub fn end( mut self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed +// { +// let on_end = self.on_end.take().unwrap(); +// let context = self.context.take(); +// on_end.call( self.storage, context ) +// } +// +// #[ inline( always ) ] +// pub fn form( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed +// { +// self.end() +// } +// +// pub fn int_1< Src >( mut self, src : Src ) -> Self +// where Src : core::convert::Into< i32 >, +// { +// debug_assert!( self.storage.int_1.is_none() ); +// self.storage.int_1 = Some( src.into() ); +// self +// } +// +// pub fn string_1< Src >( mut self, src : Src ) -> Self +// where Src : core::convert::Into< String >, +// { +// debug_assert!( self.storage.string_1.is_none() ); +// self.storage.string_1 = Some( src.into() ); +// self +// } +// +// pub fn string_optional_1< Src >( mut self, src : Src ) -> Self +// where Src : core::convert::Into< String > +// { +// debug_assert!( self.storage.string_optional_1.is_none() ); +// self.storage.string_optional_1 = Some( src.into() ); +// self +// } +// +// } +// +// impl Struct1Former< (), the_module::ReturnStorage > +// { +// +// #[ inline( always ) ] +// pub fn new() -> Struct1Former< (), the_module::ReturnStorage > +// { +// Struct1Former::< (), the_module::ReturnStorage >::begin( None, None, the_module::ReturnStorage ) +// } +// +// } + +// + +// include!( "./only_test/primitives.rs" ); 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 new file mode 100644 index 0000000000..1f1a5f72c4 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -0,0 +1,18 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ derive( Debug, PartialEq, the_module::Former ) ] +#[ debug ] +pub struct Struct1 +{ + pub int_1 : i32, + string_1 : String, + int_optional_1 : core::option::Option< i32 >, + string_optional_1 : Option< String >, +} + +// + +// + +// include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index cdb73bb74f..071c6d5aef 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -15,7 +15,7 @@ pub struct Struct1 // generated by former impl Struct1 { - pub fn former() -> Struct1Former< (), the_module::ReturnStorage > + pub fn former() -> Struct1Former< (), former::ReturnStorage > { Struct1Former::new() } @@ -49,89 +49,6 @@ impl Default for Struct1FormerStorage } -#[ derive( Debug ) ] -pub struct Struct1FormerDescriptor; - -impl Struct1FormerDescriptor -{ - pub fn new() -> Self - { - Self - } -} - -impl former::FormerDescriptor -for Struct1FormerDescriptor -{ - type Storage = Struct1FormerStorage; - type Formed = Struct1; -} - -impl former::Storage -for Struct1FormerStorage -{ - type Descriptor = Struct1FormerDescriptor; -} - -impl former::StoragePerform -for Struct1FormerStorage -{ - - fn preform( mut self ) -> < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed - { - - let int_1 = if self.int_1.is_some() - { - self.int_1.take().unwrap() - } - else - { - let val : i32 = Default::default(); - val - }; - - let string_1 = if self.string_1.is_some() - { - self.string_1.take().unwrap() - } - else - { - let val : String = Default::default(); - val - }; - - let int_optional_1 = if self.int_optional_1.is_some() - { - Some( self.int_optional_1.take().unwrap() ) - } - else - { - None - }; - - let string_optional_1 = if self.string_optional_1.is_some() - { - Some( self.string_optional_1.take().unwrap() ) - } - else - { - None - }; - - // xxx : Rust failt to use parameter here - // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed - Struct1 - { - int_1, - string_1, - int_optional_1, - string_optional_1, - } - - } - -} - // pub struct Struct1Former @@ -236,6 +153,89 @@ impl Struct1Former< (), the_module::ReturnStorage > } +#[ derive( Debug ) ] +pub struct Struct1FormerDescriptor; + +impl Struct1FormerDescriptor +{ + pub fn new() -> Self + { + Self + } +} + +impl former::FormerDescriptor +for Struct1FormerDescriptor +{ + type Storage = Struct1FormerStorage; + type Formed = Struct1; +} + +impl former::Storage +for Struct1FormerStorage +{ + type Descriptor = Struct1FormerDescriptor; +} + +impl former::StoragePerform +for Struct1FormerStorage +{ + + fn preform( mut self ) -> < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed + { + + let int_1 = if self.int_1.is_some() + { + self.int_1.take().unwrap() + } + else + { + let val : i32 = Default::default(); + val + }; + + let string_1 = if self.string_1.is_some() + { + self.string_1.take().unwrap() + } + else + { + let val : String = Default::default(); + val + }; + + let int_optional_1 = if self.int_optional_1.is_some() + { + Some( self.int_optional_1.take().unwrap() ) + } + else + { + None + }; + + let string_optional_1 = if self.string_optional_1.is_some() + { + Some( self.string_optional_1.take().unwrap() ) + } + else + { + None + }; + + // xxx : Rust failt to use parameter here + // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed + Struct1 + { + int_1, + string_1, + int_optional_1, + string_optional_1, + } + + } + +} + // include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs index 80d3b5f618..5db0ab5a74 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs @@ -15,7 +15,7 @@ pub struct Struct1 // generated by former impl Struct1 { - pub fn former() -> Struct1Former< Struct1, the_module::ReturnFormed > + pub fn former() -> Struct1Former< Struct1, Former::ReturnFormed > { Struct1Former::< Struct1, the_module::ReturnFormed >::new() } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 8c608b2d62..63cd87eede 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -8,6 +8,8 @@ mod former_tests use super::*; mod a_primitives_manual; + // mod a_primitives; + // mod a_primitives_expanded; // mod a_containers_without_runtime_manual; // mod a_containers_without_runtime; // #[ cfg( not( feature = "no_std" ) ) ]