From 4094317269795305888df3086e023fa84a2fb26e Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 13:23:43 +0200 Subject: [PATCH] former : experimenting --- module/core/former/src/axiomatic3.rs | 10 +++++-- module/core/former/src/hash_map.rs | 30 +++++++++++-------- module/core/former/src/hash_set.rs | 20 ++++++++----- module/core/former/src/vector3.rs | 11 +++++-- .../inc/former_tests/a_primitives_manual.rs | 11 +++++-- .../inc/former_tests/only_test/primitives.rs | 2 +- 6 files changed, 55 insertions(+), 29 deletions(-) diff --git a/module/core/former/src/axiomatic3.rs b/module/core/former/src/axiomatic3.rs index 6089a5a814..1c16f54205 100644 --- a/module/core/former/src/axiomatic3.rs +++ b/module/core/former/src/axiomatic3.rs @@ -1,10 +1,14 @@ //! .... -/// xxx -pub trait StoragePerform : ::core::default::Default +pub trait Storage : ::core::default::Default { type Descriptor : FormerDescriptor< Storage = Self >; - fn preform( self ) -> < < Self as StoragePerform >::Descriptor as FormerDescriptor >::Formed; +} + +/// xxx +pub trait StoragePerform : Storage +{ + fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed; } /// xxx diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 169c9baa19..771a8b30cb 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -65,30 +65,36 @@ where } } -impl< K, E > StoragePerform +impl< K, E > FormerDescriptor +for HashMapDescriptor< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Storage = HashMap< K, E >; + type Formed = HashMap< K, E >; +} + +impl< K, E > Storage for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - // type Formed = Self; - // fn preform( self ) -> Self::Formed + type Descriptor = HashMapDescriptor< K, E >; + // fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed // { // self // } - type Descriptor = HashMapDescriptor< K, E >; - fn preform( self ) -> < < Self as StoragePerform >::Descriptor as FormerDescriptor >::Formed - { - self - } } -impl< K, E > FormerDescriptor -for HashMapDescriptor< K, E > +impl< K, E > StoragePerform +for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Storage = HashMap< K, E >; - type Formed = HashMap< K, E >; + fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed + { + self + } } /// A builder for constructing hash map-like structures with a fluent interface. diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index a2ac818a72..07b274b5c3 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -53,23 +53,29 @@ where } } -impl< K > StoragePerform +impl< K > Storage for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { type Descriptor = HashSetDescriptor< K >; - fn preform( self ) -> < < Self as StoragePerform >::Descriptor as FormerDescriptor >::Formed - { - self - } - // type Formed = Self; - // fn preform( self ) -> Self::Formed + // fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed // { // self // } } +impl< K > StoragePerform +for HashSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed + { + self + } +} + impl< K > FormerDescriptor for HashSetDescriptor< K > where diff --git a/module/core/former/src/vector3.rs b/module/core/former/src/vector3.rs index 4fa91ea0a9..c3300e25de 100644 --- a/module/core/former/src/vector3.rs +++ b/module/core/former/src/vector3.rs @@ -44,12 +44,17 @@ for VectorDescriptor< E > type Formed = Vec< E >; } -impl< E > StoragePerform +impl< E > Storage for Vec< E > { - // type Formed = Self; type Descriptor = VectorDescriptor< E >; - fn preform( self ) -> < < Self as StoragePerform >::Descriptor as FormerDescriptor >::Formed +} + +impl< E > StoragePerform +for Vec< E > +{ + // type Descriptor = VectorDescriptor< E >; + fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed { self } 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 410af863b5..cdb73bb74f 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 @@ -67,12 +67,17 @@ for Struct1FormerDescriptor type Formed = Struct1; } -impl former::StoragePerform +impl former::Storage for Struct1FormerStorage { type Descriptor = Struct1FormerDescriptor; +} + +impl former::StoragePerform +for Struct1FormerStorage +{ - fn preform( mut self ) -> < < Self as former::StoragePerform >::Descriptor as former::FormerDescriptor >::Formed + fn preform( mut self ) -> < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed { let int_1 = if self.int_1.is_some() @@ -114,7 +119,7 @@ for Struct1FormerStorage }; // xxx : Rust failt to use parameter here - // < < Self as former::StoragePerform >::Descriptor as former::FormerDescriptor >::Formed + // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed Struct1 { int_1, diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 064323516b..546e1679ae 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -100,7 +100,7 @@ tests_impls! a_id!( got, exp ); // storage exists - let got = < < Struct1FormerStorage as the_module::StoragePerform >::Descriptor as the_module::FormerDescriptor >::Formed::former().form(); + let got = < < Struct1FormerStorage as the_module::Storage >::Descriptor as the_module::FormerDescriptor >::Formed::former().form(); let exp = Struct1::former().form(); a_id!( got, exp );