Skip to content

Commit 22c36e1

Browse files
committed
fixing format_tools
1 parent 5d2fb42 commit 22c36e1

File tree

5 files changed

+97
-57
lines changed

5 files changed

+97
-57
lines changed

module/core/format_tools/src/format.rs

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ mod private
1717
macro_rules! _field_with_key
1818
{
1919
(
20+
$path : expr,
2021
$key : ident,
21-
$src : expr,
2222
$how : ty,
2323
$fallback1 : ty,
2424
$fallback2 : ty
@@ -31,7 +31,7 @@ mod private
3131
// $crate::OptionalCow::< '_, str, $how >::from
3232
Option::Some
3333
(
34-
$crate::to_string_with_fallback!( $how, $fallback1, $fallback2, $src )
34+
$crate::to_string_with_fallback!( $how, $fallback1, $fallback2, $path )
3535
),
3636
)
3737
}};
@@ -48,39 +48,63 @@ mod private
4848
macro_rules! _field
4949
{
5050

51-
( & $path:ident.$( $key:ident )+, $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) =>
51+
// dst.push( field!( &self.id ) );
52+
( ( & $pre:ident.$( $key:tt )+ ), $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) =>
5253
{{
53-
$crate::_field!( # ( & $path . ) ( $( $key )+ ) ( $how, $fallback1, $fallback2 ) )
54+
$crate::_field!( # ( & $pre . ) ( $( $key )+ ) ( $how, $fallback1, $fallback2 ) )
5455
}};
5556

56-
( $path:ident.$( $key:ident )+, $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) =>
57+
// dst.push( field!( self.id ) );
58+
( ( $pre:ident.$( $key:tt )+ ), $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) =>
5759
{{
58-
$crate::_field!( # ( $path . ) ( $( $key )+ ) ( $how, $fallback1, $fallback2 ) )
60+
$crate::_field!( # ( $pre . ) ( $( $key )+ ) ( $how, $fallback1, $fallback2 ) )
5961
}};
6062

61-
( & $key:ident, $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) =>
63+
// dst.push( field!( &tools ) );
64+
( ( & $key:ident ), $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) =>
6265
{{
63-
$crate::_field!( # () ( $key ) ( $how, $fallback1, $fallback2 ) )
66+
$crate::_field!( # () ( & $key ) ( $how, $fallback1, $fallback2 ) )
6467
}};
6568

66-
( $key:ident, $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) =>
69+
// dst.push( field!( tools ) );
70+
( ( $key:ident ), $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) =>
6771
{{
6872
$crate::_field!( # () ( $key ) ( $how, $fallback1, $fallback2 ) )
6973
}};
7074

7175
// private
7276

77+
// ( a.b. )
78+
// ( c.d )
79+
// ( $crate::WithRef, $crate::WithDebug, $crate::WithDebug )
80+
(
81+
#
82+
( $( $prefix:tt )* )
83+
( $prekey:ident.$( $field:tt )+ )
84+
( $how : ty, $fallback1 : ty, $fallback2 : ty )
85+
)
86+
=>
87+
{{
88+
$crate::_field!( # ( $( $prefix )* $prekey . ) ( $( $field )+ ) ( $how, $fallback1, $fallback2 ) )
89+
}};
90+
91+
// ( a.b. )
92+
// ( 0.d )
93+
// ( $crate::WithRef, $crate::WithDebug, $crate::WithDebug )
7394
(
7495
#
7596
( $( $prefix:tt )* )
76-
( $prekey:ident.$( $field:ident )+ )
97+
( $prekey:tt.$( $field:tt )+ )
7798
( $how : ty, $fallback1 : ty, $fallback2 : ty )
7899
)
79100
=>
80101
{{
81102
$crate::_field!( # ( $( $prefix )* $prekey . ) ( $( $field )+ ) ( $how, $fallback1, $fallback2 ) )
82103
}};
83104

105+
// ( a.b.c. )
106+
// ( d )
107+
// ( $crate::WithRef, $crate::WithDebug, $crate::WithDebug )
84108
(
85109
#
86110
( $( $prefix:tt )* )
@@ -92,6 +116,9 @@ mod private
92116
$crate::_field!( # # ( $( $prefix )* ) ( $key ) ( $how, $fallback1, $fallback2 ) )
93117
}};
94118

119+
// ( a.b.c )
120+
// ( d )
121+
// ( $crate::WithRef, $crate::WithDebug, $crate::WithDebug )
95122
(
96123
# #
97124
( $( $prefix:tt )* )
@@ -100,7 +127,8 @@ mod private
100127
)
101128
=>
102129
{{
103-
$crate::_field_with_key!( $key, $( $prefix )* $key, $how, $fallback1, $fallback2 )
130+
// _field_with_key!( id, &self. id, $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline )
131+
$crate::_field_with_key!( $( $prefix )* $key, $key, $how, $fallback1, $fallback2 )
104132
}};
105133

106134
}
@@ -130,7 +158,7 @@ mod private
130158
)
131159
=>
132160
{{
133-
$crate::_field_with_key!( $key, $src, $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline )
161+
$crate::_field_with_key!( $src, $key, $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline )
134162
}};
135163
}
136164

@@ -145,7 +173,7 @@ mod private
145173
( $( $t:tt )+ )
146174
=>
147175
{{
148-
$crate::_field!( $( $t )+, $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline )
176+
$crate::_field!( ( $( $t )+ ), $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline )
149177
}}
150178
}
151179

@@ -179,7 +207,7 @@ mod private
179207
)
180208
=>
181209
{{
182-
$crate::_field_with_key!( $key, $src, $crate::WithRef, $crate::WithDisplay, $crate::WithDebug )
210+
$crate::_field_with_key!( $src, $key, $crate::WithRef, $crate::WithDisplay, $crate::WithDebug )
183211
}};
184212
}
185213

@@ -194,7 +222,7 @@ mod private
194222
( $( $t:tt )+ )
195223
=>
196224
{{
197-
$crate::_field!( $( $t )+, $crate::WithRef, $crate::WithDisplay, $crate::WithDebug )
225+
$crate::_field!( ( $( $t )+ ), $crate::WithRef, $crate::WithDisplay, $crate::WithDebug )
198226
}}
199227
}
200228

@@ -227,7 +255,7 @@ mod private
227255
)
228256
=>
229257
{{
230-
$crate::_field_with_key!( $key, $src, $crate::WithRef, $crate::WithDebug, $crate::WithDebug )
258+
$crate::_field_with_key!( $src, $key, $crate::WithRef, $crate::WithDebug, $crate::WithDebug )
231259
}};
232260
}
233261

@@ -241,7 +269,7 @@ mod private
241269
( $( $t:tt )+ )
242270
=>
243271
{{
244-
$crate::_field!( $( $t )+, $crate::WithRef, $crate::WithDebug, $crate::WithDebug )
272+
$crate::_field!( ( $( $t )+ ), $crate::WithRef, $crate::WithDebug, $crate::WithDebug )
245273
}}
246274
}
247275

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

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,54 @@ fn iterator_over_optional_cow()
3030
OptionalCow,
3131
};
3232

33-
// // xxx : that should fail
34-
// impl TableWithFields for TestObjectWithoutImpl {}
35-
//
36-
// impl Fields< &'_ str, Option< Cow< '_, str > > >
37-
// for TestObjectWithoutImpl
38-
// {
39-
// type Key< 'k > = &'k str;
40-
// type Val< 'v > = Option< Cow< 'v, str > >;
41-
//
42-
// fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) >
43-
// {
44-
// use format_tools::ref_or_display_or_debug_multiline::field;
45-
// // use format_tools::ref_or_display_or_debug::field;
46-
// let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new();
47-
//
48-
// dst.push( field!( &self.id ) );
49-
// dst.push( field!( &self.created_at ) );
50-
// dst.push( field!( &self.file_ids ) );
51-
//
52-
// if let Some( tools ) = &self.tools
53-
// {
54-
// dst.push( field!( tools ) );
55-
// }
56-
// else
57-
// {
58-
// dst.push( ( "tools", Option::None ) );
59-
// }
60-
//
61-
// dst.into_iter()
62-
// }
63-
//
64-
// }
33+
pub struct TestObjecWrap( TestObjectWithoutImpl );
6534

66-
let data : collection_tools::Vec< TestObjectWithoutImpl > = the_module::test_objects_gen();
35+
// xxx : that should fail
36+
impl TableWithFields for TestObjecWrap {}
37+
38+
impl Fields< &'_ str, Option< Cow< '_, str > > >
39+
for TestObjecWrap
40+
{
41+
type Key< 'k > = &'k str;
42+
type Val< 'v > = Option< Cow< 'v, str > >;
43+
44+
fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) >
45+
{
46+
use format_tools::ref_or_display_or_debug_multiline::field;
47+
// use format_tools::ref_or_display_or_debug::field;
48+
let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new();
49+
50+
// trace_macros!( true );
51+
dst.push( field!( &self.0.id ) );
52+
// trace_macros!( false );
53+
54+
dst.push( field!( &self.0.created_at ) );
55+
dst.push( field!( &self.0.file_ids ) );
56+
57+
if let Some( tools ) = &self.0.tools
58+
{
59+
dst.push( field!( tools ) );
60+
}
61+
else
62+
{
63+
dst.push( ( "tools", Option::None ) );
64+
}
65+
66+
dst.into_iter()
67+
}
68+
69+
}
70+
71+
let data : collection_tools::Vec< TestObjecWrap > = the_module::test_objects_gen()
72+
.into_iter()
73+
.map( | e | TestObjecWrap( e ) )
74+
.collect()
75+
;
76+
77+
use the_module::TableFormatter;
78+
// let _as_table : AsTable< '_, Vec< TestObjecWrap >, &str, TestObjectWithoutImpl, str> = AsTable::new( &data );
79+
// let as_table = AsTable::new( &data );
6780

68-
// use the_module::TableFormatter;
69-
// let _as_table : AsTable< '_, Vec< TestObjectWithoutImpl >, &str, TestObjectWithoutImpl, str> = AsTable::new( &data );
70-
// let as_table = AsTable::new( &data );
71-
//
7281
// let rows = TableRows::rows( &as_table );
7382
// assert_eq!( rows.len(), 2 );
7483
//

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ fn iterator_over_optional_cow()
9090
// use format_tools::ref_or_display_or_debug::field;
9191
let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new();
9292

93+
// trace_macros!( true );
9394
dst.push( field!( &self.id ) );
95+
// trace_macros!( false );
96+
9497
dst.push( field!( &self.created_at ) );
9598
dst.push( field!( &self.file_ids ) );
9699

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ for TestObject
7373
// use format_tools::ref_or_display_or_debug::field;
7474
let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new();
7575

76+
// trace_macros!( true );
7677
dst.push( field!( &self.id ) );
78+
// trace_macros!( false );
7779
dst.push( field!( &self.created_at ) );
7880
dst.push( field!( &self.file_ids ) );
7981

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
//! Primary tests.
22
3-
// #![ feature( trace_macros ) ]
3+
#![ feature( trace_macros ) ]
44
#![ allow( unused_imports ) ]
55

6-
76
use format_tools as the_module;
87
use test_tools::exposed::*;
98

109
#[ cfg( feature = "enabled" ) ]
1110
mod inc;
12-

0 commit comments

Comments
 (0)