Skip to content

Commit 29263cc

Browse files
committed
test_tools : rid of cyclic dependcy wip
1 parent 821daf1 commit 29263cc

File tree

17 files changed

+103
-39
lines changed

17 files changed

+103
-39
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,9 @@ version = "~1.0"
547547
version = "~1.0"
548548
# features = []
549549
# default-features = false
550+
551+
[workspace.dependencies.hashbrown]
552+
version = "~0.14.3"
553+
# optional = true
554+
# default-features = false
555+
# features = [ "default" ]

module/core/collection_tools/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ all-features = false
2727
[features]
2828

2929
no_std = [
30-
# "test_tools/no_std",
3130
]
3231

3332
use_alloc = [
34-
"no_std", # qqq : use only use_alloc, eliminate feature no_std
33+
"no_std",
3534
"hashbrown",
3635
]
3736

@@ -61,7 +60,7 @@ collection_into_constructors = []
6160
[dependencies]
6261

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

6665
[dev-dependencies]
6766
test_tools = { workspace = true }

module/core/collection_tools/Readme.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ assert_eq!( meta_list, meta_list );
7171

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

74-
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.
74+
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.
7575

7676
You can do
7777

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

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

121121
For example:
122122
```rust
123-
# #[ cfg( all( feature = "enabled", feature = "collection_into_constructors", any( not( feature = "no_std" ), feature = "use_alloc" ) ) ) ]
123+
# #[ cfg( all( feature = "enabled", feature = "collection_into_constructors" ) ) ]
124+
# #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ]
124125
# {
125126
use std::borrow::Cow;
126127
let vec : Vec< String > = collection_tools::into_vec!( "&str", "String".to_string(), Cow::from( "Cow" ) );

module/core/collection_tools/examples/collection_tools_trivial.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@
1919
//! a `HashMap`, making your code cleaner and more concise. This is particularly useful in cases
2020
//! where you need to define a map with a known set of key-value pairs upfront.
2121
22-
#[ cfg( not( all
23-
(
24-
// not( feature = "use_alloc" ) ) ],
25-
all( feature = "enabled", feature = "collection_constructors" ),
26-
any( not( feature = "no_std" ), feature = "use_alloc" )
22+
#[ cfg( not( all(
23+
feature = "enabled",
24+
feature = "collection_constructors",
25+
any( feature = "use_alloc", not( feature = "no_std" ) )
2726
)))]
28-
fn main(){}
27+
fn main() {}
2928

30-
// zzz : aaa : rid of `#[ cfg( not( feature = "use_alloc" ) ) ]` -- Rid of by not relying on std
31-
// #[ cfg( not( feature = "use_alloc" ) ) ]
3229
#[ cfg( all( feature = "enabled", feature = "collection_constructors" ) ) ]
33-
#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ]
30+
#[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ]
3431
fn main()
3532
{
3633
use collection_tools::*;

module/core/collection_tools/src/collection/binary_heap.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
#[ allow( unused_imports ) ]
2+
use super::*;
3+
14
#[ doc( inline ) ]
25
#[ allow( unused_imports ) ]
3-
pub use alloc::collections::binary_heap::*;
6+
pub use alloc::collections::binary_heap::*;
47

58
/// Creates a `BinaryHeap` from a list of elements.
69
///

module/core/collection_tools/src/collection/btree_map.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[ allow( unused_imports ) ]
2+
use super::*;
3+
14
#[ doc( inline ) ]
25
#[ allow( unused_imports ) ]
36
pub use alloc::collections::btree_map::*;

module/core/collection_tools/src/collection/btree_set.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[ allow( unused_imports ) ]
2+
use super::*;
3+
14
#[ doc( inline ) ]
25
#[ allow( unused_imports ) ]
36
pub use alloc::collections::btree_set::*;

module/core/collection_tools/src/collection/hash_map.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
#[ cfg( feature = "use_alloc" ) ]
1+
#[ allow( unused_imports ) ]
2+
use super::*;
3+
4+
// xxx : qqq : wrong
5+
#[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ]
26
#[ doc( inline ) ]
37
#[ allow( unused_imports ) ]
48
pub use crate::dependency::hashbrown::hash_map::*;
9+
510
#[ cfg( not( feature = "no_std" ) ) ]
611
#[ doc( inline ) ]
712
#[ allow( unused_imports ) ]
@@ -14,7 +19,7 @@ pub use std::collections::hash_map::*;
1419
/// # Origin
1520
///
1621
/// This collection can be reexported from different crates:
17-
/// - from `std`, if `no_std` flag if off
22+
/// - from `std`, if `use_std` is on ( `no_std` flag if off )
1823
/// - from `hashbrown`, if `use_alloc` flag if on
1924
///
2025
/// # Syntax
@@ -98,7 +103,7 @@ macro_rules! hmap
98103
/// # Origin
99104
///
100105
/// This collection can be reexported from different crates:
101-
/// - from `std`, if `no_std` flag if off
106+
/// - from `std`, if `use_std` is on ( `no_std` flag if off )
102107
/// - from `hashbrown`, if `use_alloc` flag if on
103108
///
104109
/// # Syntax

module/core/collection_tools/src/collection/hash_set.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
#[ allow( unused_imports ) ]
2+
use super::*;
3+
14
#[ cfg( feature = "use_alloc" ) ]
25
#[ doc( inline ) ]
36
#[ allow( unused_imports ) ]
47
pub use crate::dependency::hashbrown::hash_set::*;
8+
59
#[ cfg( not( feature = "no_std" ) ) ]
610
#[ doc( inline ) ]
711
#[ allow( unused_imports ) ]
@@ -14,7 +18,7 @@ pub use std::collections::hash_set::*;
1418
/// # Origin
1519
///
1620
/// This collection can be reexported from different crates:
17-
/// - from `std`, if `no_std` flag if off
21+
/// - from `std`, if `use_std` is on ( `no_std` flag if off )
1822
/// - from `hashbrown`, if `use_alloc` flag if on
1923
///
2024
/// # Syntax
@@ -98,7 +102,7 @@ macro_rules! hset
98102
/// # Origin
99103
///
100104
/// This collection can be reexported from different crates:
101-
/// - from `std`, if `no_std` flag if off
105+
/// - from `std`, if `use_std` is on ( `no_std` flag if off )
102106
/// - from `hashbrown`, if `use_alloc` flag if on
103107
///
104108
/// # Syntax

module/core/collection_tools/src/collection/linked_list.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[ allow( unused_imports ) ]
2+
use super::*;
3+
14
#[ doc( inline ) ]
25
#[ allow( unused_imports ) ]
36
pub use alloc::collections::linked_list::*;

0 commit comments

Comments
 (0)