Skip to content

Commit

Permalink
AUTO : Forward from refactoring_2 to alpha (#1477)
Browse files Browse the repository at this point in the history
decycling test_tools wip
  • Loading branch information
wtools-bot authored Nov 6, 2024
1 parent fa11a44 commit 99b1fb0
Show file tree
Hide file tree
Showing 147 changed files with 1,900 additions and 1,072 deletions.
22 changes: 21 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -536,4 +536,24 @@ version = "0.1.83"
[workspace.dependencies.tokio]
version = "1.41.0"
features = []
default-features = false
default-features = false

[workspace.dependencies.anyhow]
version = "~1.0"
# features = []
# default-features = false

[workspace.dependencies.thiserror]
version = "~1.0"
# features = []
# default-features = false

[workspace.dependencies.hashbrown]
version = "~0.14.3"
# optional = true
default-features = false
# features = [ "default" ]

[workspace.dependencies.paste]
version = "~1.0.14"
default-features = false
13 changes: 3 additions & 10 deletions module/core/collection_tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,41 @@ documentation = "https://docs.rs/collection_tools"
repository = "https://github.com/Wandalen/wTools/tree/master/module/core/collection_tools"
homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/collection_tools"
description = """
Collection of general purpose tools to manipulate collections( containers like Vec/HashMap/HashSet ).
General purpose tools to manipulate collections( containers like Vec/HashMap/HashSet ).
"""
categories = [ "algorithms", "development-tools" ]
keywords = [ "fundamental", "general-purpose" ]


[lints]
workspace = true


[package.metadata.docs.rs]
features = [ "full" ]
all-features = false

[features]

no_std = [
# "test_tools/no_std",
]

use_alloc = [
"no_std", # qqq : for Anton : why is that better? -- use_alloc means that we do not use std, but alloc and hashbrown
"no_std",
"hashbrown",
# "test_tools/use_alloc", // why is it needed? -- not needed, removed
]

default = [
"enabled",
# "reexports",
"collection_constructors",
"collection_into_constructors",
]

full = [
"enabled",
# "reexports",
"collection_constructors",
"collection_into_constructors",
]

enabled = []
# reexports = []

# Collection constructors, like `hmap!{ "key" => "val" }`
collection_constructors = []
Expand All @@ -63,7 +56,7 @@ collection_into_constructors = []
[dependencies]

## external
hashbrown = { version = "~0.14.3", optional = true, default-features = false, features = [ "default" ] }
hashbrown = { workspace = true, optional = true, default-features = false, features = [ "default" ] }

[dev-dependencies]
test_tools = { workspace = true }
Expand Down
9 changes: 5 additions & 4 deletions module/core/collection_tools/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_collection_tools_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_collection_tools_push.yml) [![docs.rs](https://img.shields.io/docsrs/collection_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/collection_tools) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fcollection_tools%2Fexamples%2Fcollection_tools_trivial.rs,RUN_POSTFIX=--example%20collection_tools_trivial/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY)
<!--{ generate.module_header.end }-->

Collection of general purpose tools to manipulate collections( containers like Vec/HashMap/HashSet... ).
General purpose tools to manipulate collections( containers like Vec/HashMap/HashSet... ).

### Basic Use Case :: Variadic Constructors for Collections

Expand Down Expand Up @@ -71,7 +71,7 @@ assert_eq!( meta_list, meta_list );

### Basic Use Case :: `no_std` `HashSet` / `HashMap`

When implementing a `no_std` environment with the `use_alloc` feature in your Rust project, you'll encounter a challenge: collections like `Vec` are imported differently depending on the availability of the `std` library. Moreover, to use data structures such as `HashSet` or `HashMap` in a `no_std` context, it's necessary to depend on third-party crates, as these are not provided by the `alloc` crate directly. This crate aims to simplify the process of designing Rust libraries or applications that require these collections in a `no_std` environment, offering a more streamlined approach to working with dynamic data structures without the standard library.
When implementing a `no_std` ( `!use_std` ) environment with the `use_alloc` feature in your Rust project, you'll encounter a challenge: collections like `Vec` are imported differently depending on the availability of the `std` library. Moreover, to use data structures such as `HashSet` or `HashMap` in a `no_std` context, it's necessary to depend on third-party crates, as these are not provided by the `alloc` crate directly. This crate aims to simplify the process of designing Rust libraries or applications that require these collections in a `no_std` environment, offering a more streamlined approach to working with dynamic data structures without the standard library.

You can do

Expand All @@ -98,7 +98,7 @@ Instead of
# #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ]
# {

#[ cfg( feature = "use_alloc" ) ]
#[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ]
use hashbrown::HashSet; // a `no_std` replacement for `HashSet`
#[ cfg( not( feature = "no_std" ) ) ]
use std::collections::HashSet;
Expand All @@ -120,7 +120,8 @@ While strict macros require you to have all members of the same type, more relax

For example:
```rust
# #[ cfg( all( feature = "enabled", feature = "collection_into_constructors", any( not( feature = "no_std" ), feature = "use_alloc" ) ) ) ]
# #[ cfg( all( feature = "enabled", feature = "collection_into_constructors" ) ) ]
# #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ]
# {
use std::borrow::Cow;
let vec : Vec< String > = collection_tools::into_vec!( "&str", "String".to_string(), Cow::from( "Cow" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@
//! a `HashMap`, making your code cleaner and more concise. This is particularly useful in cases
//! where you need to define a map with a known set of key-value pairs upfront.

#[ cfg( not( all
(
// not( feature = "use_alloc" ) ) ],
all( feature = "enabled", feature = "collection_constructors" ),
any( not( feature = "no_std" ), feature = "use_alloc" )
#[ cfg( not( all(
feature = "enabled",
feature = "collection_constructors",
any( feature = "use_alloc", not( feature = "no_std" ) )
)))]
fn main(){}
fn main() {}

// zzz : aaa : rid of `#[ cfg( not( feature = "use_alloc" ) ) ]` -- Rid of by not relying on std
// #[ cfg( not( feature = "use_alloc" ) ) ]
#[ cfg( all( feature = "enabled", feature = "collection_constructors" ) ) ]
#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ]
#[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ]
fn main()
{
use collection_tools::*;
Expand Down
32 changes: 0 additions & 32 deletions module/core/collection_tools/src/collection.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#[ allow( unused_imports ) ]
use super::*;

#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use alloc::collections::binary_heap::*;
pub use alloc::collections::binary_heap::*;

/// Creates a `BinaryHeap` from a list of elements.
///
Expand Down Expand Up @@ -57,7 +60,7 @@ macro_rules! heap
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _heap = $crate::heap::BinaryHeap::with_capacity( _cap );
let mut _heap = $crate::collection::BinaryHeap::with_capacity( _cap );
$(
_heap.push( $key );
)*
Expand Down Expand Up @@ -146,7 +149,7 @@ macro_rules! into_heap
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _heap = $crate::heap::BinaryHeap::with_capacity( _cap );
let mut _heap = $crate::collection::BinaryHeap::with_capacity( _cap );
$(
_heap.push( Into::into( $key ) );
)*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[ allow( unused_imports ) ]
use super::*;

#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use alloc::collections::btree_map::*;
Expand Down Expand Up @@ -70,7 +73,7 @@ macro_rules! bmap
)
=>
{{
let mut _map = $crate::bmap::BTreeMap::new();
let mut _map = $crate::collection::BTreeMap::new();
$(
let _ = _map.insert( $key , $value );
)*
Expand Down Expand Up @@ -163,7 +166,7 @@ macro_rules! into_bmap
)
=>
{{
let mut _map = $crate::bmap::BTreeMap::new();
let mut _map = $crate::collection::BTreeMap::new();
$(
let _ = _map.insert( Into::into( $key ), Into::into( $value ) );
)*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[ allow( unused_imports ) ]
use super::*;

#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use alloc::collections::btree_set::*;
Expand Down Expand Up @@ -56,7 +59,7 @@ macro_rules! bset
)
=>
{{
let mut _set = $crate::bset::BTreeSet::new();
let mut _set = $crate::collection::BTreeSet::new();
$(
_set.insert( $key );
)*
Expand Down Expand Up @@ -149,7 +152,7 @@ macro_rules! into_bset
)
=>
{{
let mut _set = $crate::bset::BTreeSet::new();
let mut _set = $crate::collection::BTreeSet::new();
$(
_set.insert( Into::into( $key ) );
)*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#[ cfg( feature = "use_alloc" ) ]
#[ allow( unused_imports ) ]
use super::*;

// xxx : qqq : wrong
#[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ]
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use crate::dependency::hashbrown::hash_map::*;

#[ cfg( not( feature = "no_std" ) ) ]
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
Expand All @@ -14,7 +19,7 @@ pub use std::collections::hash_map::*;
/// # Origin
///
/// This collection can be reexported from different crates:
/// - from `std`, if `no_std` flag if off
/// - from `std`, if `use_std` is on ( `no_std` flag if off )
/// - from `hashbrown`, if `use_alloc` flag if on
///
/// # Syntax
Expand Down Expand Up @@ -77,7 +82,7 @@ macro_rules! hmap
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _map = $crate::hmap::HashMap::with_capacity( _cap );
let mut _map = $crate::collection::HashMap::with_capacity( _cap );
$(
let _ = _map.insert( $key, $value );
)*
Expand All @@ -98,7 +103,7 @@ macro_rules! hmap
/// # Origin
///
/// This collection can be reexported from different crates:
/// - from `std`, if `no_std` flag if off
/// - from `std`, if `use_std` is on ( `no_std` flag if off )
/// - from `hashbrown`, if `use_alloc` flag if on
///
/// # Syntax
Expand Down Expand Up @@ -172,7 +177,7 @@ macro_rules! into_hmap
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _map = $crate::hmap::HashMap::with_capacity( _cap );
let mut _map = $crate::collection::HashMap::with_capacity( _cap );
$(
let _ = _map.insert( Into::into( $key ), Into::into( $value ) );
)*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#[ allow( unused_imports ) ]
use super::*;

#[ cfg( feature = "use_alloc" ) ]
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use crate::dependency::hashbrown::hash_set::*;

#[ cfg( not( feature = "no_std" ) ) ]
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
Expand All @@ -14,7 +18,7 @@ pub use std::collections::hash_set::*;
/// # Origin
///
/// This collection can be reexported from different crates:
/// - from `std`, if `no_std` flag if off
/// - from `std`, if `use_std` is on ( `no_std` flag if off )
/// - from `hashbrown`, if `use_alloc` flag if on
///
/// # Syntax
Expand Down Expand Up @@ -77,7 +81,7 @@ macro_rules! hset
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _set = $crate::hset::HashSet::with_capacity( _cap );
let mut _set = $crate::collection::HashSet::with_capacity( _cap );
$(
let _ = _set.insert( $key );
)*
Expand All @@ -96,9 +100,9 @@ macro_rules! hset
/// type `T` used in the `HashSet`. Also, this means that sometimes you must specify the type of collection's items.
///
/// # Origin
///
///
/// This collection can be reexported from different crates:
/// - from `std`, if `no_std` flag if off
/// - from `std`, if `use_std` is on ( `no_std` flag if off )
/// - from `hashbrown`, if `use_alloc` flag if on
///
/// # Syntax
Expand Down Expand Up @@ -173,7 +177,7 @@ macro_rules! into_hset
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _set = $crate::hset::HashSet::with_capacity( _cap );
let mut _set = $crate::collection::HashSet::with_capacity( _cap );
$(
let _ = _set.insert( Into::into( $key ) );
)*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[ allow( unused_imports ) ]
use super::*;

#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use alloc::collections::linked_list::*;
Expand Down Expand Up @@ -70,7 +73,7 @@ macro_rules! llist
{{
// "The LinkedList allows pushing and popping elements at either end in constant time."
// So no `with_capacity`
let mut _lst = $crate::llist::LinkedList::new();
let mut _lst = $crate::collection::LinkedList::new();
$(
_lst.push_back( $key );
)*
Expand Down Expand Up @@ -164,7 +167,7 @@ macro_rules! into_llist
{{
// "The LinkedList allows pushing and popping elements at either end in constant time."
// So no `with_capacity`
let mut _lst = $crate::llist::LinkedList::new();
let mut _lst = $crate::collection::LinkedList::new();
$(
_lst.push_back( Into::into( $key ) );
)*
Expand Down
Loading

0 comments on commit 99b1fb0

Please sign in to comment.