Skip to content

Commit

Permalink
Merge pull request #1323 from Wandalen/audit
Browse files Browse the repository at this point in the history
AUTO : Forward from audit to alpha
  • Loading branch information
Wandalen authored May 13, 2024
2 parents a3845a2 + 401a6bd commit 17e960b
Show file tree
Hide file tree
Showing 92 changed files with 2,545 additions and 1,157 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ default-features = false
# path = "module/core/type_constructor_derive_pair_meta"

[workspace.dependencies.interval_adapter]
version = "~0.19.0"
version = "~0.20.0"
path = "module/core/interval_adapter"
default-features = false
features = [ "enabled" ]
Expand All @@ -104,7 +104,7 @@ default-features = false
features = [ "enabled" ]

[workspace.dependencies.collection_tools]
version = "~0.4.0"
version = "~0.5.0"
path = "module/core/collection_tools"
default-features = false

Expand Down
2 changes: 1 addition & 1 deletion module/core/collection_tools/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "collection_tools"
version = "0.4.0"
version = "0.5.0"
edition = "2021"
authors = [
"Kostiantyn Wandalen <[email protected]>",
Expand Down
31 changes: 25 additions & 6 deletions module/core/derive_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,32 @@
#![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ]
#![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ]
#![ doc( html_root_url = "https://docs.rs/derive_tools/latest/derive_tools/" ) ]

//!
//! Collection of derives which extend STD.
//!
#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ]

// // xxx : implement derive new
//
// #[ derive( Debug, PartialEq, Default ) ]
// pub struct Property< Name >
// {
// name : Name,
// description : String,
// code : isize,
// }
//
// /// generated by new
// impl< Name > Property< Name >
// {
// #[ inline ]
// pub fn new< Description, Code >( name : Name, description : Description, code : Code ) -> Self
// where
// Name : core::convert::Into< Name >,
// Description : core::convert::Into< String >,
// Code : core::convert::Into< isize >,
// {
// Self { name : name.into(), description : description.into(), code : code.into() }
// }
// }

#[ cfg( feature = "enabled" ) ]
pub mod wtools;

Expand Down Expand Up @@ -56,7 +75,7 @@ mod derive_more
// #[ cfg( feature = "derive_reflect" ) ]
// pub mod reflect;

// use derive_tools_meta::Deref;
// use derive_tools_meta::Deref;
// use derive_tools_meta::VariadicFrom;

/// Namespace with dependencies.
Expand Down
429 changes: 257 additions & 172 deletions module/core/former/Readme.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//!
//! This example demonstrates how to effectively employ the `Former` trait to configure a `HashMap` using a container setter.
//! This example demonstrates how to effectively employ the `Former` trait to configure a `HashMap` using a collection setter.
//!
#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ]
Expand All @@ -12,7 +12,7 @@ fn main()
#[ derive( Debug, PartialEq, former::Former ) ]
pub struct StructWithMap
{
#[ container ]
#[ subform_collection ]
map : HashMap< &'static str, &'static str >,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main()
#[ derive( Debug, PartialEq, former::Former ) ]
pub struct StructWithSet
{
#[ container ]
#[ subform_collection ]
set : HashSet< &'static str >,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//!
//! This example demonstrates how to employ the `Former` trait to configure a `Vec` using a container setter in a structured manner.
//! This example demonstrates how to employ the `Former` trait to configure a `Vec` using a collection setter in a structured manner.
//!
#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ]
Expand All @@ -11,7 +11,7 @@ fn main()
#[ derive( Debug, PartialEq, former::Former ) ]
pub struct StructWithVec
{
#[ container ]
#[ subform_collection ]
vec : Vec< &'static str >,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Example former_custom_container.rs
//! Example former_custom_collection.rs
//!
//! This example demonstrates how to define and use a custom container with former.
//! The custom container implemented here is a `LoggingSet`, which extends the basic `HashSet` behavior
//! by logging each addition. This example illustrates how to integrate such custom containers with the
//! This example demonstrates how to define and use a custom collection with former.
//! The custom collection implemented here is a `LoggingSet`, which extends the basic `HashSet` behavior
//! by logging each addition. This example illustrates how to integrate such custom collections with the
//! Former trait system for use in structured data types.
#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ]
Expand All @@ -12,7 +12,7 @@ fn main()
{
use collection_tools::HashSet;

// Custom container that logs additions.
// Custom collection that logs additions.
#[ derive( Debug, PartialEq ) ]
pub struct LoggingSet< K >
where
Expand All @@ -21,7 +21,7 @@ fn main()
set : HashSet< K >, // Internal HashSet to store the elements.
}

// Implement default for the custom container.
// Implement default for the custom collection.
impl< K > Default for LoggingSet< K >
where
K : core::cmp::Eq + core::hash::Hash,
Expand All @@ -36,7 +36,7 @@ fn main()
}
}

// Allow the custom container to be converted into an iterator, to iterate over the elements.
// Allow the custom collection to be converted into an iterator, to iterate over the elements.
impl< K > IntoIterator for LoggingSet< K >
where
K : std::cmp::Eq + std::hash::Hash,
Expand Down Expand Up @@ -64,8 +64,8 @@ fn main()
}
}

// Implement the Container trait to integrate with the former system.
impl< K > former::Container for LoggingSet< K >
// Implement the Collection trait to integrate with the former system.
impl< K > former::Collection for LoggingSet< K >
where
K : core::cmp::Eq + core::hash::Hash,
{
Expand All @@ -79,8 +79,8 @@ fn main()
}
}

// Implement ContainerAdd to handle adding elements to the custom container.
impl< K > former::ContainerAdd for LoggingSet< K >
// Implement CollectionAdd to handle adding elements to the custom collection.
impl< K > former::CollectionAdd for LoggingSet< K >
where
K : core::cmp::Eq + core::hash::Hash,
{
Expand All @@ -91,8 +91,8 @@ fn main()
}
}

// Implement ContainerAssign to handle bulk assignment of elements.
impl< K > former::ContainerAssign for LoggingSet< K >
// Implement CollectionAssign to handle bulk assignment of elements.
impl< K > former::CollectionAssign for LoggingSet< K >
where
K : core::cmp::Eq + core::hash::Hash,
{
Expand All @@ -106,8 +106,8 @@ fn main()
}
}

// Implement ContainerValToEntry to convert values back to entries.
impl< K > former::ContainerValToEntry< K > for LoggingSet< K >
// Implement CollectionValToEntry to convert values back to entries.
impl< K > former::CollectionValToEntry< K > for LoggingSet< K >
where
K : core::cmp::Eq + core::hash::Hash,
{
Expand All @@ -121,7 +121,7 @@ fn main()

// = storage

// Define storage behavior for the custom container.
// Define storage behavior for the custom collection.
impl< K > former::Storage
for LoggingSet< K >
where
Expand All @@ -138,13 +138,13 @@ fn main()
{
fn preform( self ) -> Self::Preformed
{
self // Return the container as is.
self // Return the collection as is.
}
}

// = definition types

// Definitions related to the type settings for the LoggingSet, which detail how the container should behave with former.
// Definitions related to the type settings for the LoggingSet, which detail how the collection should behave with former.

/// Holds generic parameter types for forming operations related to `LoggingSet`.
#[ derive( Debug, Default ) ]
Expand Down Expand Up @@ -249,17 +249,17 @@ fn main()

// = subformer

// Subformer type alias simplifies the usage of `ContainerFormer` with `LoggingSet`.
// Subformer type alias simplifies the usage of `CollectionFormer` with `LoggingSet`.
pub type LoggingSetAsSubformer< K, Context, Formed, End > =
former::ContainerFormer::< K, LoggingSetDefinition< K, Context, Formed, End > >;
former::CollectionFormer::< K, LoggingSetDefinition< K, Context, Formed, End > >;

// == use custom container
// == use custom collection

/// Parent required for the template.
#[ derive( Debug, Default, PartialEq, former::Former ) ]
pub struct Parent
{
#[ container ]
#[ subform_collection ]
children : LoggingSet< i32 >,
}

Expand Down
91 changes: 0 additions & 91 deletions module/core/former/examples/former_custom_container_setter.rs

This file was deleted.

8 changes: 4 additions & 4 deletions module/core/former/examples/former_custom_definition.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! ## Example : Custom Definition
//!
//! Define a custom former definition and custom forming logic, and apply them to a container.
//! Define a custom former definition and custom forming logic, and apply them to a collection.
//!
//! The example showcases how to accumulate elements into a container and then transform them into a single result
//! The example showcases how to accumulate elements into a collection and then transform them into a single result
//! using a custom `FormingEnd` implementation. This pattern is useful for scenarios where the formation process
//! involves aggregation or transformation of input elements into a different type or form.
Expand All @@ -19,7 +19,7 @@ fn main()
// This trait defines the types used during the forming process.
impl former::FormerDefinitionTypes for Sum
{
type Storage = Vec<i32>; // Container for the integers.
type Storage = Vec<i32>; // Collection for the integers.
type Formed = i32; // The final type after forming, which is a single integer.
type Context = (); // No additional context is used in this example.
}
Expand Down Expand Up @@ -59,7 +59,7 @@ fn main()
}

// Use the custom `Former` to sum a list of integers.
let got = former::ContainerFormer::<i32, Sum>::new(Sum)
let got = former::CollectionFormer::<i32, Sum>::new(Sum)
.add( 1 ) // Add an integer to the storage.
.add( 2 ) // Add another integer.
.add( 10 ) // Add another integer.
Expand Down
16 changes: 9 additions & 7 deletions module/core/former/examples/former_custom_scalar_setter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
//!
//! Use of a scalar setter within a `Former` trait implementation to directly assign a `HashMap` of `Child` entities to a `Parent` structure using a custom setter function.
//!
//! Unlike the more complex subform and container setters shown in previous examples, this example focuses on a straightforward approach to directly set a scalar value within a parent entity. The `Parent` struct manages a `HashMap` of `Child` entities, and the scalar setter is used to set the entire `HashMap` directly. The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case.
//! Unlike the more complex subform and collection setters shown in previous examples, this example focuses on a straightforward approach to directly set a scalar value within a parent entity. The `Parent` struct manages a `HashMap` of `Child` entities, and the scalar setter is used to set the entire `HashMap` directly. The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a collection—each child entity in this case.
//!
//! #### Types of Setters
//! #### Types of Setters / Subformers
//!
//! It's crucial to understand the differences among subform setters, container setters, and scalar setters:
//! Understanding the distinctions among the types of setters or subformers is essential for effectively employing the builder pattern in object construction. Each type of setter is designed to meet specific needs in building complex, structured data entities:
//!
//! - **Scalar Setter**: Directly sets scalar values or simple fields within the forming entity. Unlike subform or container setters that manage complex objects or collections, scalar setters handle basic data types or individual fields. These are typically straightforward setter methods that do not involve nested formers or additional structuring.
//! - **Scalar Setter**: Handles the direct assignment of scalar values or simple fields within an entity. These setters manage basic data types or individual fields and do not involve nested formers or complex structuring.
//!
//! - **Container Setter**: Returns a former of the container itself, offering an interface to manage the container as a whole rather than its individual elements. This type of setter is useful for applying configurations or validations to the entire collection, such as a `HashMap` of children.
//! - **Subform Collection Setter**: Facilitates the management of a collection as a whole by returning a former that provides an interface to configure the entire collection. This setter is beneficial for applying uniform configurations or validations to all elements in a collection, such as a `HashMap` of children.
//!
//! - **Subform Setter**: Returns a former of an element within a container, providing an interface to individually form each element. For example, the `child` method acts as a subform setter, allowing for the addition and configuration of individual `Child` entities within the `Parent`'s `HashMap`.
//! - **Subform Entry Setter**: This setter allows for the individual formation of elements within a collection. It returns a former for each element, enabling detailed configuration and addition of complex elements within collections, exemplified by managing `Child` entities within a `Parent`'s `HashMap`.
//!
//! Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required.
//! - **Subform Scalar Setter**: Similar to the subform entry setter but designed for scalar fields that have a former implementation. This setter does not collect instances into a collection because there is no collection involved, only a scalar field. It is used when the scalar field itself needs to be configured or modified through its dedicated former.
//!
//! These setters ensure that developers can precisely and efficiently set properties, manage collections, and configure complex structures within their applications.
//!
#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ]
Expand Down
Loading

0 comments on commit 17e960b

Please sign in to comment.