Skip to content

Commit

Permalink
test_tools : rid off cyclic dependcy wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Nov 5, 2024
1 parent 665cfaf commit 7c430bf
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 106 deletions.
4 changes: 1 addition & 3 deletions module/core/collection_tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ keywords = [ "fundamental", "general-purpose" ]
[lints]
workspace = true


[package.metadata.docs.rs]
features = [ "full" ]
all-features = false
Expand All @@ -32,9 +31,8 @@ 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", # qqq : use only use_alloc, eliminate feature no_std
"hashbrown",
# "test_tools/use_alloc", // why is it needed? -- not needed, removed
]

default = [
Expand Down
152 changes: 144 additions & 8 deletions module/core/collection_tools/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,154 @@ macro_rules! count
}

/// [std::collections::BTreeMap] macros
pub mod bmap;
pub mod btree_map;
/// [std::collections::BTreeSet] macros
pub mod bset;
pub mod btree_set;
/// [std::collections::BinaryHeap] macros
pub mod heap;
pub mod binary_heap;
/// [std::collections::HashMap] macros
pub mod hmap;
pub mod hash_map;
/// [std::collections::HashSet] macros
pub mod hset;
pub mod hash_set;
/// [std::collections::LinkedList] macros
pub mod llist;
pub mod linked_list;
/// [Vec] macros
pub mod vec;
pub mod vector;
/// [std::collections::VecDeque] macros
pub mod deque;
pub mod vec_deque;

#[ doc( inline ) ]
#[ allow( unused_imports ) ]
#[ cfg( feature = "enabled" ) ]
pub use own::*;

/// Own namespace of the module.
#[ cfg( feature = "enabled" ) ]
#[ allow( unused_imports ) ]
pub mod own
{
use super::*;

#[ doc( inline ) ]
pub use super::super::collection;

pub use super::super::collection::
{
btree_map,
btree_set,
binary_heap,
hash_map,
hash_set,
linked_list,
vector,
vec_deque,
};

#[ doc( inline ) ]
pub use orphan::*;

}

/// Parented namespace of the module.
#[ cfg( feature = "enabled" ) ]
#[ allow( unused_imports ) ]
pub mod orphan
{
use super::*;
#[ doc( inline ) ]
pub use exposed::*;
}

/// Exposed namespace of the module.
#[ cfg( feature = "enabled" ) ]
#[ allow( unused_imports ) ]
pub mod exposed
{
use super::*;

#[ doc( inline ) ]
pub use prelude::*;

// #[ doc( inline ) ]
// #[ cfg( any( feature = "use_alloc", all( feature = "collection_constructors", not( feature = "no_std" ) ) ) ) ]
// pub use crate::
// {
// vec as dlist,
// };

// #[ doc( inline ) ]
// #[ cfg( any( feature = "use_alloc", all( feature = "collection_into_constructors", not( feature = "no_std" ) ) ) ) ]
// pub use crate::
// {
// into_vec as into_dlist,
// };

#[ doc( inline ) ]
#[ cfg( any( feature = "use_alloc", all( feature = "collection_constructors", not( feature = "no_std" ) ) ) ) ]
pub use crate::
{
vec as dlist,
deque,
llist,
hset,
hmap,
bmap,
bset,
};

#[ doc( inline ) ]
#[ cfg( any( feature = "use_alloc", all( feature = "collection_into_constructors", not( feature = "no_std" ) ) ) ) ]
pub use crate::
{
into_vec,
into_vec as into_dlist,
into_vecd,
into_llist,
into_hset,
into_hmap,
into_bmap,
into_bset,
};

// #[ cfg( feature = "reexports" ) ]
#[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ]
#[ doc( inline ) ]
pub use
{
btree_map::BTreeMap,
btree_set::BTreeSet,
binary_heap::BinaryHeap,
hash_map::HashMap,
hash_set::HashSet,
linked_list::LinkedList,
vector::Vec,
vec_deque::VecDeque,
};

// #[ cfg( feature = "reexports" ) ]
#[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ]
#[ doc( inline ) ]
pub use
{
LinkedList as Llist,
Vec as Dlist,
VecDeque as Deque,
HashMap as Map,
HashMap as Hmap,
HashSet as Set,
HashSet as Hset,
BTreeMap as Bmap,
BTreeSet as Bset,
};

// qqq : cover by tests presence of all containers immidiately in collection_tools::* and in collection_tools::exposed::*

}

/// Prelude to use essentials: `use my_module::prelude::*`.
#[ cfg( feature = "enabled" ) ]
#[ allow( unused_imports ) ]
pub mod prelude
{
use super::*;
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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 +146,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
Expand Up @@ -70,7 +70,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 +163,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
Expand Up @@ -56,7 +56,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 +149,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
Expand Up @@ -77,7 +77,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 Down Expand Up @@ -172,7 +172,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
Expand Up @@ -77,7 +77,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,7 +96,7 @@ 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 `hashbrown`, if `use_alloc` flag if on
Expand Down Expand Up @@ -173,7 +173,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
Expand Up @@ -70,7 +70,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 +164,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
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ macro_rules! deque
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _vecd = $crate::deque::VecDeque::with_capacity( _cap );
let mut _vecd = $crate::collection::VecDeque::with_capacity( _cap );
$(
_vecd.push_back( $key );
)*
Expand Down Expand Up @@ -168,7 +168,7 @@ macro_rules! into_vecd
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _vecd = $crate::deque::VecDeque::with_capacity( _cap );
let mut _vecd = $crate::collection::VecDeque::with_capacity( _cap );
$(
_vecd.push_back( Into::into( $key ) );
)*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ macro_rules! vec
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _vec = $crate::vec::Vec::with_capacity( _cap );
let mut _vec = $crate::collection::Vec::with_capacity( _cap );
$(
_vec.push( $key );
)*
Expand Down Expand Up @@ -167,7 +167,7 @@ macro_rules! into_vec
=>
{{
let _cap = count!( @count $( $key ),* );
let mut _vec = $crate::vec::Vec::with_capacity( _cap );
let mut _vec = $crate::collection::Vec::with_capacity( _cap );
$(
_vec.push( Into::into( $key ) );
)*
Expand Down
Loading

0 comments on commit 7c430bf

Please sign in to comment.