Skip to content

Commit

Permalink
Merge pull request #1333 from YBoy-git/collection_tools_refactoring
Browse files Browse the repository at this point in the history
READY : (collection_tools) : Reexports, collections utils tests
  • Loading branch information
Wandalen authored May 15, 2024
2 parents c39b70c + 94ad256 commit 2203d9c
Show file tree
Hide file tree
Showing 21 changed files with 543 additions and 148 deletions.
10 changes: 5 additions & 5 deletions module/core/collection_tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ no_std = [
]

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

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

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

enabled = []
prelude = []
reexports = []

# Collection constructors, like `hmap!{ "key" => "val" }`
collection_constructors = []
Expand Down
8 changes: 6 additions & 2 deletions module/core/collection_tools/src/collections/bmap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use alloc::collections::btree_map::*;

/// Creates a `BTreeMap` from a list of key-value pairs.
///
/// The `bmap` macro facilitates the convenient creation of a `BTreeMap` with initial elements.
Expand Down Expand Up @@ -66,7 +70,7 @@ macro_rules! bmap
)
=>
{{
let mut _map = collection_tools::BTreeMap::new();
let mut _map = $crate::bmap::BTreeMap::new();
$(
let _ = _map.insert( $key , $value );
)*
Expand Down Expand Up @@ -159,7 +163,7 @@ macro_rules! into_bmap
)
=>
{{
let mut _map = collection_tools::BTreeMap::new();
let mut _map = $crate::bmap::BTreeMap::new();
$(
let _ = _map.insert( Into::into( $key ), Into::into( $value ) );
)*
Expand Down
8 changes: 6 additions & 2 deletions module/core/collection_tools/src/collections/bset.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use alloc::collections::btree_set::*;

/// Creates a `BTreeSet` from a list of elements.
///
/// The `bset` macro allows for convenient creation of a `BTreeSet` with initial elements.
Expand Down Expand Up @@ -52,7 +56,7 @@ macro_rules! bset
)
=>
{{
let mut _set = collection_tools::BTreeSet::new();
let mut _set = $crate::bset::BTreeSet::new();
$(
_set.insert( $key );
)*
Expand Down Expand Up @@ -145,7 +149,7 @@ macro_rules! into_bset
)
=>
{{
let mut _set = collection_tools::BTreeSet::new();
let mut _set = $crate::bset::BTreeSet::new();
$(
_set.insert( Into::into( $key ) );
)*
Expand Down
8 changes: 6 additions & 2 deletions module/core/collection_tools/src/collections/heap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use alloc::collections::binary_heap::*;

/// Creates a `BinaryHeap` from a list of elements.
///
/// The `into_heap` macro simplifies the creation of a `BinaryHeap` with initial elements.
Expand Down Expand Up @@ -53,7 +57,7 @@ macro_rules! heap
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _heap = collection_tools::BinaryHeap::with_capacity( _cap );
let mut _heap = $crate::heap::BinaryHeap::with_capacity( _cap );
$(
_heap.push( $key );
)*
Expand Down Expand Up @@ -142,7 +146,7 @@ macro_rules! into_heap
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _heap = collection_tools::BinaryHeap::with_capacity( _cap );
let mut _heap = $crate::heap::BinaryHeap::with_capacity( _cap );
$(
_heap.push( Into::into( $key ) );
)*
Expand Down
13 changes: 11 additions & 2 deletions module/core/collection_tools/src/collections/hmap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#[ cfg( 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 ) ]
pub use std::collections::hash_map::*;

/// Creates a `HashMap` from a list of key-value pairs.
///
/// The `hmap` macro allows for convenient creation of a `HashMap` with initial elements.
Expand Down Expand Up @@ -68,7 +77,7 @@ macro_rules! hmap
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _map = collection_tools::HashMap::with_capacity( _cap );
let mut _map = $crate::hmap::HashMap::with_capacity( _cap );
$(
let _ = _map.insert( $key, $value );
)*
Expand Down Expand Up @@ -163,7 +172,7 @@ macro_rules! into_hmap
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _map = collection_tools::HashMap::with_capacity( _cap );
let mut _map = $crate::hmap::HashMap::with_capacity( _cap );
$(
let _ = _map.insert( Into::into( $key ), Into::into( $value ) );
)*
Expand Down
13 changes: 11 additions & 2 deletions module/core/collection_tools/src/collections/hset.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#[ 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 ) ]
pub use std::collections::hash_set::*;

/// Creates a `HashSet` from a list of elements.
///
/// The `hset` macro allows for convenient creation of a `HashSet` with initial elements.
Expand Down Expand Up @@ -68,7 +77,7 @@ macro_rules! hset
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _set = collection_tools::HashSet::with_capacity( _cap );
let mut _set = $crate::hset::HashSet::with_capacity( _cap );
$(
let _ = _set.insert( $key );
)*
Expand Down Expand Up @@ -164,7 +173,7 @@ macro_rules! into_hset
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _set = collection_tools::HashSet::with_capacity( _cap );
let mut _set = $crate::hset::HashSet::with_capacity( _cap );
$(
let _ = _set.insert( Into::into( $key ) );
)*
Expand Down
8 changes: 6 additions & 2 deletions module/core/collection_tools/src/collections/list.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use alloc::collections::linked_list::*;

/// Creates a `LinkedList` from a list of elements.
///
/// The `list` macro facilitates the creation of a `LinkedList` with initial elements.
Expand Down Expand Up @@ -66,7 +70,7 @@ macro_rules! list
{{
// "The LinkedList allows pushing and popping elements at either end in constant time."
// So no `with_capacity`
let mut _lst = collection_tools::LinkedList::new();
let mut _lst = $crate::list::LinkedList::new();
$(
_lst.push_back( $key );
)*
Expand Down Expand Up @@ -160,7 +164,7 @@ macro_rules! into_list
{{
// "The LinkedList allows pushing and popping elements at either end in constant time."
// So no `with_capacity`
let mut _lst = collection_tools::LinkedList::new();
let mut _lst = $crate::list::LinkedList::new();
$(
_lst.push_back( Into::into( $key ) );
)*
Expand Down
11 changes: 9 additions & 2 deletions module/core/collection_tools/src/collections/vec.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use alloc::vec::*;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use core::slice::{ Iter, IterMut };

/// Creates a `Vec` from a list of elements.
///
/// The `vec` macro simplifies the creation of a `Vec` with initial elements.
Expand Down Expand Up @@ -66,7 +73,7 @@ macro_rules! vec
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _vec = collection_tools::Vec::with_capacity( _cap );
let mut _vec = $crate::vec::Vec::with_capacity( _cap );
$(
_vec.push( $key );
)*
Expand Down Expand Up @@ -160,7 +167,7 @@ macro_rules! into_vec
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _vec = collection_tools::Vec::with_capacity( _cap );
let mut _vec = $crate::vec::Vec::with_capacity( _cap );
$(
_vec.push( Into::into( $key ) );
)*
Expand Down
8 changes: 6 additions & 2 deletions module/core/collection_tools/src/collections/vecd.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use alloc::collections::vec_deque::*;

/// Creates a `VecDeque` from a list of elements.
///
/// The `vecd` macro allows for the convenient creation of a `VecDeque` with initial elements.
Expand Down Expand Up @@ -71,7 +75,7 @@ macro_rules! vecd
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _vecd = collection_tools::VecDeque::with_capacity( _cap );
let mut _vecd = $crate::vecd::VecDeque::with_capacity( _cap );
$(
_vecd.push_back( $key );
)*
Expand Down Expand Up @@ -164,7 +168,7 @@ macro_rules! into_vecd
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _vecd = collection_tools::VecDeque::with_capacity( _cap );
let mut _vecd = $crate::vecd::VecDeque::with_capacity( _cap );
$(
_vecd.push_back( Into::into( $key ) );
)*
Expand Down
79 changes: 31 additions & 48 deletions module/core/collection_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
#![ doc( html_root_url = "https://docs.rs/collection_tools/latest/collection_tools/" ) ]
#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ]

extern crate alloc;

// qqq : make subdirectory for each container -- done

// qqq : move out of lib.rs file -- moved to `collections.rs`

/// Module containing all collection macros
#[ cfg( feature = "enabled" ) ]
pub mod collections;
mod collections;
pub use collections::*;

/// Namespace with dependencies.
#[ cfg( feature = "enabled" ) ]
Expand All @@ -36,27 +39,6 @@ pub mod protected
#[ allow( unused_imports ) ]
pub use super::orphan::*;

extern crate alloc;

#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use alloc::vec::Vec;

#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use alloc::collections::{ BinaryHeap, BTreeMap, BTreeSet, LinkedList, VecDeque };

// qqq : what is comnination `use_alloc` + !`no_std`
#[ cfg( feature = "use_alloc" ) ]
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::dependency::hashbrown::{ HashMap, HashSet };

#[ cfg( not( feature = "no_std" ) ) ]
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use std::collections::{ HashMap, HashSet };

}

/// Parented namespace of the module.
Expand All @@ -82,30 +64,31 @@ pub mod exposed
pub mod prelude
{

// qqq : for Anton : uncomment, make it working and cover by tests
// #[ cfg( feature = "prelude" ) ]
// #[ doc( inline ) ]
// #[ allow( unused_imports ) ]
// pub use crate::
// {
// HashMap as Map,
// HashSet as Set,
// HashMap,
// HashSet,
// VecDeque,
// BTreeMap,
// BTreeSet,
// BinaryHeap,
// LinkedList,
// };

// #[ cfg( feature = "prelude" ) ]
// #[ doc( inline ) ]
// #[ allow( unused_imports ) ]
// pub use crate::
// {
// Vec,
// Vec as DynArray,
// };

// qqq : for Anton : uncomment, make it working and cover by tests -- renamed to reexports
#[ cfg( feature = "reexports" ) ]
#[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ]
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use crate::
{
bmap::BTreeMap,
bset::BTreeSet,
heap::BinaryHeap,
hmap::HashMap,
hset::HashSet,
list::LinkedList,
vec::Vec,
vecd::VecDeque,
};

#[ cfg( feature = "reexports" ) ]
#[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ]
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use
{
HashMap as Map,
HashSet as Set,
Vec as DynArray,
};
}
Loading

0 comments on commit 2203d9c

Please sign in to comment.