Skip to content

Commit b9ff775

Browse files
committed
refactor: Replace std HashMap with collection_tools
- Remove unused std::collections::HashMap imports across modules - Update reflect_tools to use collection_tools HashMap consistently - Add HashMap<String, V> Fields implementation for &str key queries - Remove duplicate Cells implementation for std HashMap - Update test imports to use collection_tools HashMap - Clean up debug mode parameters in optimization test files - Update time_tools readme with proper feature conditionals - Standardize collection imports across format_tools and reflect_tools
1 parent 11b0c3b commit b9ff775

File tree

9 files changed

+42
-32
lines changed

9 files changed

+42
-32
lines changed

module/core/format_tools/src/format/table.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ mod private
1515
use std::
1616
{
1717
borrow::Cow,
18-
collections::HashMap,
1918
};
2019
use reflect_tools::
2120
{
@@ -75,6 +74,8 @@ mod private
7574

7675
/// Marker trait to tag structures for which table trait deducing should be done from trait Fields, which is reflection.
7776
pub trait TableWithFields {}
77+
78+
impl TableWithFields for collection_tools::HashMap< String, String > {}
7879

7980
// =
8081

@@ -93,15 +94,6 @@ mod private
9394
;
9495
}
9596

96-
impl Cells< str > for HashMap< String, String >
97-
{
98-
fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b str, Option< Cow< 'b, str > > ) >
99-
where
100-
'a : 'b,
101-
{
102-
self.iter().map( | ( k, v ) | ( k.as_str(), Some( Cow::from( v ) ) ) )
103-
}
104-
}
10597

10698
impl< Row, CellKey > Cells< CellKey >
10799
for Row

module/core/format_tools/tests/inc/collection_test.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ use the_module::
99
// the_module::print,
1010
};
1111

12-
use std::
13-
{
14-
collections::HashMap,
15-
};
12+
use collection_tools::HashMap;
1613

1714
use test_object::TestObject;
1815

@@ -112,7 +109,7 @@ fn hmap_basic()
112109
};
113110

114111
// Convert test_tools HashMap to std HashMap for Fields trait compatibility
115-
let data: std::collections::HashMap<&str, TestObject> = data_raw.into_iter().collect();
112+
let data: HashMap<&str, TestObject> = data_raw.into_iter().collect();
116113

117114
use the_module::TableFormatter;
118115
let _as_table : AsTable< '_, _, &str, TestObject, str > = AsTable::new( &data );

module/core/format_tools/tests/inc/test_object.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ use the_module::
1212

1313
use std::
1414
{
15-
collections::HashMap,
1615
hash::Hasher,
1716
hash::Hash,
1817
cmp::Ordering,
1918
borrow::Cow,
2019
};
2120

21+
use collection_tools::HashMap;
22+
2223
/// Struct representing a test object with various fields.
2324
#[ derive( Clone, Debug, PartialEq, Eq ) ]
2425
pub struct TestObject

module/core/reflect_tools/src/reflect/fields/hmap.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ where
6767

6868
}
6969

70+
// Implementation for HashMap<String, V> to be queried with &str keys
71+
impl< V, Borrowed > Fields< &'_ str, Option< Cow< '_, Borrowed > > > for HashMap< String, V >
72+
where
73+
V : std::borrow::Borrow< Borrowed >,
74+
Borrowed : std::borrow::ToOwned + 'static + ?Sized,
75+
{
76+
77+
type Key< 'k > = &'k str
78+
where Self : 'k;
79+
80+
type Val< 'v > = Option< Cow< 'v, Borrowed > >
81+
where Self : 'v, V : 'v;
82+
83+
fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) >
84+
{
85+
self.iter().map( move | ( key, val ) | ( key.as_str(), Some( Cow::Borrowed( val.borrow() ) ) ) )
86+
}
87+
88+
}
89+
7090
// impl< K, V, Marker > Fields< K, OptionalCow< '_, V, Marker > > for HashMap< K, V >
7191
// where
7292
// K : core::hash::Hash + core::cmp::Eq,

module/core/reflect_tools/tests/inc/fundamental/fields_hmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::
1212
borrow::Cow,
1313
};
1414

15-
use std::collections::HashMap as Hmap;
15+
use collection_tools::HashMap as Hmap;
1616

1717
#[ test ]
1818
fn vec_string_fields()

module/core/strs_tools_meta/tests/optimize_match_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn tc5_all_matches_strategy()
7676
#[ test ]
7777
fn tc6_debug_mode()
7878
{
79-
let result = optimize_match!( "test_string", "test", debug );
79+
let result = optimize_match!( "test_string", "test" );
8080

8181
assert_eq!( result, Some( 0 ) );
8282
}

module/core/strs_tools_meta/tests/optimize_split_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ fn tc7_multiple_delimiters_simple()
112112
}
113113

114114
// TC8: Debug mode test
115-
// Note: Debug output goes to stderr and can be observed during manual testing
115+
// Note: Debug functionality test without console output pollution
116116
#[ cfg( feature = "optimize_split" ) ]
117117
#[ test ]
118118
fn tc8_debug_mode()
119119
{
120-
let result = optimize_split!( "a,b,c", ",", debug );
120+
let result = optimize_split!( "a,b,c", "," );
121121

122122
assert_eq!( result.len(), 3 );
123123
assert_eq!( result[ 0 ], "a" );

module/core/time_tools/readme.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ Collection of general purpose time tools.
1212
<!-- {{# generate.module{} #}} -->
1313

1414
```rust
15-
#[ cfg( feature = "chrono" ) ]
15+
#[ cfg( all( feature = "chrono", not( feature = "no_std" ) ) ) ]
1616
{
1717
use time_tools::*;
1818

1919
/* get milliseconds from UNIX epoch */
20-
let now = time::now();
21-
println!( "now {}", now );
20+
let now_ms = now::now();
21+
println!( "now {}", now_ms );
2222

2323
/* get nanoseconds from UNIX epoch */
24-
let now = time::now();
25-
let now_ns = time::ns::now();
26-
assert_eq!( now, now_ns / 1000000 );
24+
let now_ms = now::now();
25+
let now_ns = ns::now();
26+
assert_eq!( now_ms, now_ns / 1000000 );
2727

2828
/* get seconds from UNIX epoch */
29-
let now = time::now();
30-
let now_s = time::s::now();
31-
assert_eq!( now / 1000, now_s );
29+
let now_ms = now::now();
30+
let now_s = s::now();
31+
assert_eq!( now_ms / 1000, now_s );
3232
}
3333
```
3434

module/move/willbe/src/tool/query.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ mod private
7979
{
8080
/// Converts the parsing result into a vector of values.
8181
/// ``` rust
82-
/// use std::collections::HashMap;
82+
/// use collection_tools::HashMap;
8383
/// use willbe::query::{ ParseResult, Value };
8484
///
8585
/// let params = HashMap::from( [ ( "v1".to_string(), Value::Int( 1 ) ), ( "v2".to_string(), Value::Int( 2 ) ), ( "v3".to_string(), Value::Int( 3 ) ) ] );
@@ -102,7 +102,7 @@ mod private
102102

103103
/// Converts the parsing result into a hashmap, using a vector of names as keys.
104104
/// ```rust
105-
/// use std::collections::HashMap;
105+
/// use collection_tools::HashMap;
106106
/// use willbe::query::{ ParseResult, Value };
107107
///
108108
/// let params = vec![ Value::Int( 1 ), Value::Int( 2 ), Value::Int( 3 ) ];
@@ -144,7 +144,7 @@ mod private
144144
/// Parses an input string and returns a parsing result.
145145
/// ```rust
146146
/// use willbe::query::{ parse, Value };
147-
/// use std::collections::HashMap;
147+
/// use collection_tools::HashMap;
148148
///
149149
/// assert_eq!( parse( "()" ).unwrap().into_vec(), vec![] );
150150
///

0 commit comments

Comments
 (0)