diff --git a/Cargo.toml b/Cargo.toml index 00ffdb5cdf..522f6e750a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -185,7 +185,7 @@ features = [ "enabled" ] ## mem [workspace.dependencies.mem_tools] -version = "~0.6.0" +version = "~0.7.0" path = "module/core/mem_tools" default-features = false @@ -193,7 +193,7 @@ default-features = false ## diagnostics [workspace.dependencies.diagnostics_tools] -version = "~0.8.0" +version = "~0.9.0" path = "module/core/diagnostics_tools" default-features = false @@ -209,12 +209,12 @@ default-features = false ## meta [workspace.dependencies.meta_tools] -version = "~0.10.0" +version = "~0.11.0" path = "module/core/meta_tools" default-features = false [workspace.dependencies.for_each] -version = "~0.8.0" +version = "~0.9.0" path = "module/core/for_each" default-features = false @@ -239,16 +239,16 @@ path = "module/core/former_types" default-features = false [workspace.dependencies.impls_index] -version = "~0.7.0" +version = "~0.8.0" path = "module/core/impls_index" default-features = false [workspace.dependencies.impls_index_meta] -version = "~0.7.0" +version = "~0.8.0" path = "module/core/impls_index_meta" [workspace.dependencies.mod_interface] -version = "~0.25.0" +version = "~0.26.0" path = "module/core/mod_interface" default-features = false @@ -305,12 +305,12 @@ default-features = false ## typing [workspace.dependencies.typing_tools] -version = "~0.8.0" +version = "~0.9.0" path = "module/core/typing_tools" default-features = false [workspace.dependencies.implements] -version = "~0.8.0" +version = "~0.9.0" path = "module/core/implements" default-features = false @@ -320,12 +320,12 @@ path = "module/alias/instance_of" default-features = false [workspace.dependencies.inspect_type] -version = "~0.10.0" +version = "~0.11.0" path = "module/core/inspect_type" default-features = false [workspace.dependencies.is_slice] -version = "~0.9.0" +version = "~0.10.0" path = "module/core/is_slice" default-features = false @@ -381,7 +381,7 @@ default-features = false [workspace.dependencies.process_tools_published] package = "process_tools" -version = "~0.8.0" +version = "~0.9.0" default-features = false @@ -392,7 +392,7 @@ version = "~0.4.0" path = "module/alias/wtest" [workspace.dependencies.test_tools] -version = "~0.9.0" +version = "~0.10.0" path = "module/core/test_tools" [workspace.dependencies.wtest_basic] diff --git a/module/core/diagnostics_tools/Cargo.toml b/module/core/diagnostics_tools/Cargo.toml index c2b7d7e994..f8f93610c9 100644 --- a/module/core/diagnostics_tools/Cargo.toml +++ b/module/core/diagnostics_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "diagnostics_tools" -version = "0.8.0" +version = "0.9.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/for_each/Cargo.toml b/module/core/for_each/Cargo.toml index 877ccbe184..c6387ef2cc 100644 --- a/module/core/for_each/Cargo.toml +++ b/module/core/for_each/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "for_each" -version = "0.8.0" +version = "0.9.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/format_tools/src/format.rs b/module/core/format_tools/src/format.rs index 4e55517dcc..2abf7f18a4 100644 --- a/module/core/format_tools/src/format.rs +++ b/module/core/format_tools/src/format.rs @@ -17,8 +17,8 @@ mod private macro_rules! _field_with_key { ( + $path : expr, $key : ident, - $src : expr, $how : ty, $fallback1 : ty, $fallback2 : ty @@ -28,9 +28,10 @@ mod private {{ ( ::core::stringify!( $key ), - $crate::OptionalCow::< '_, str, $how >::from + // $crate::OptionalCow::< '_, str, $how >::from + Option::Some ( - $crate::to_string_with_fallback!( $how, $fallback1, $fallback2, $src ) + $crate::to_string_with_fallback!( $how, $fallback1, $fallback2, $path ) ), ) }}; @@ -47,32 +48,39 @@ mod private macro_rules! _field { - ( & $path:ident.$( $key:ident )+, $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => + // dst.push( field!( &self.id ) ); + ( ( & $pre:ident.$( $key:tt )+ ), $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => {{ - $crate::_field!( # ( & $path . ) ( $( $key )+ ) ( $how, $fallback1, $fallback2 ) ) + $crate::_field!( # ( & $pre . ) ( $( $key )+ ) ( $how, $fallback1, $fallback2 ) ) }}; - ( $path:ident.$( $key:ident )+, $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => + // dst.push( field!( self.id ) ); + ( ( $pre:ident.$( $key:tt )+ ), $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => {{ - $crate::_field!( # ( $path . ) ( $( $key )+ ) ( $how, $fallback1, $fallback2 ) ) + $crate::_field!( # ( $pre . ) ( $( $key )+ ) ( $how, $fallback1, $fallback2 ) ) }}; - ( & $key:ident, $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => + // dst.push( field!( &tools ) ); + ( ( & $key:ident ), $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => {{ - $crate::_field!( # () ( $key ) ( $how, $fallback1, $fallback2 ) ) + $crate::_field!( # () ( & $key ) ( $how, $fallback1, $fallback2 ) ) }}; - ( $key:ident, $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => + // dst.push( field!( tools ) ); + ( ( $key:ident ), $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => {{ $crate::_field!( # () ( $key ) ( $how, $fallback1, $fallback2 ) ) }}; // private + // ( a.b. ) + // ( c.d ) + // ( $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) ( # ( $( $prefix:tt )* ) - ( $prekey:ident.$( $field:ident )+ ) + ( $prekey:ident.$( $field:tt )+ ) ( $how : ty, $fallback1 : ty, $fallback2 : ty ) ) => @@ -80,6 +88,23 @@ mod private $crate::_field!( # ( $( $prefix )* $prekey . ) ( $( $field )+ ) ( $how, $fallback1, $fallback2 ) ) }}; + // ( a.b. ) + // ( 0.d ) + // ( $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) + ( + # + ( $( $prefix:tt )* ) + ( $prekey:tt.$( $field:tt )+ ) + ( $how : ty, $fallback1 : ty, $fallback2 : ty ) + ) + => + {{ + $crate::_field!( # ( $( $prefix )* $prekey . ) ( $( $field )+ ) ( $how, $fallback1, $fallback2 ) ) + }}; + + // ( a.b.c. ) + // ( d ) + // ( $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) ( # ( $( $prefix:tt )* ) @@ -91,6 +116,9 @@ mod private $crate::_field!( # # ( $( $prefix )* ) ( $key ) ( $how, $fallback1, $fallback2 ) ) }}; + // ( a.b.c ) + // ( d ) + // ( $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) ( # # ( $( $prefix:tt )* ) @@ -99,7 +127,8 @@ mod private ) => {{ - $crate::_field_with_key!( $key, $( $prefix )* $key, $how, $fallback1, $fallback2 ) + // _field_with_key!( id, &self. id, $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline ) + $crate::_field_with_key!( $( $prefix )* $key, $key, $how, $fallback1, $fallback2 ) }}; } @@ -129,7 +158,7 @@ mod private ) => {{ - $crate::_field_with_key!( $key, $src, $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline ) + $crate::_field_with_key!( $src, $key, $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline ) }}; } @@ -144,7 +173,7 @@ mod private ( $( $t:tt )+ ) => {{ - $crate::_field!( $( $t )+, $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline ) + $crate::_field!( ( $( $t )+ ), $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline ) }} } @@ -178,7 +207,7 @@ mod private ) => {{ - $crate::_field_with_key!( $key, $src, $crate::WithRef, $crate::WithDisplay, $crate::WithDebug ) + $crate::_field_with_key!( $src, $key, $crate::WithRef, $crate::WithDisplay, $crate::WithDebug ) }}; } @@ -193,7 +222,7 @@ mod private ( $( $t:tt )+ ) => {{ - $crate::_field!( $( $t )+, $crate::WithRef, $crate::WithDisplay, $crate::WithDebug ) + $crate::_field!( ( $( $t )+ ), $crate::WithRef, $crate::WithDisplay, $crate::WithDebug ) }} } @@ -226,7 +255,7 @@ mod private ) => {{ - $crate::_field_with_key!( $key, $src, $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) + $crate::_field_with_key!( $src, $key, $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) }}; } @@ -240,7 +269,7 @@ mod private ( $( $t:tt )+ ) => {{ - $crate::_field!( $( $t )+, $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) + $crate::_field!( ( $( $t )+ ), $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) }} } @@ -261,6 +290,11 @@ pub mod table; pub mod to_string; pub mod to_string_with_fallback; +/// A strucutre for diagnostic and demonstration purpose. +#[ doc( hidden ) ] +#[ cfg( debug_assertions ) ] +pub mod test_object_without_impl; + #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use own::*; @@ -304,6 +338,14 @@ pub mod orphan ref_or_debug, }; + #[ doc( hidden ) ] + #[ cfg( debug_assertions ) ] + pub use test_object_without_impl:: + { + TestObjectWithoutImpl, + test_objects_gen, + }; + } /// Exposed namespace of the module. diff --git a/module/core/format_tools/src/format/as_table.rs b/module/core/format_tools/src/format/as_table.rs index 4e70ba233d..b1c48c159f 100644 --- a/module/core/format_tools/src/format/as_table.rs +++ b/module/core/format_tools/src/format/as_table.rs @@ -21,29 +21,29 @@ mod private /// #[ repr( transparent ) ] #[ derive( Clone, Copy ) ] - pub struct AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + pub struct AsTable< 'table, Table, RowKey, Row, CellKey> ( &'table Table, ::core::marker::PhantomData <( &'table (), - fn() -> ( &'table RowKey, Row, &'table CellKey, CellRepr ), + fn() -> ( &'table RowKey, Row, &'table CellKey ), )>, ) where RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey>, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr + // CellRepr : table::CellRepr ; - impl< 'table, Table, RowKey, Row, CellKey, CellRepr > - AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + impl< 'table, Table, RowKey, Row, CellKey> + AsTable< 'table, Table, RowKey, Row, CellKey> where RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey>, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { /// Just a constructor. pub fn new( src : &'table Table ) -> Self @@ -52,13 +52,13 @@ mod private } } - impl< 'table, Table, RowKey, Row, CellKey, CellRepr > AsRef< Table > - for AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + impl< 'table, Table, RowKey, Row, CellKey> AsRef< Table > + for AsTable< 'table, Table, RowKey, Row, CellKey> where RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey>, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { fn as_ref( &self ) -> &Table { @@ -66,13 +66,13 @@ mod private } } - impl< 'table, Table, RowKey, Row, CellKey, CellRepr > Deref - for AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + impl< 'table, Table, RowKey, Row, CellKey> Deref + for AsTable< 'table, Table, RowKey, Row, CellKey> where RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey>, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { type Target = Table; @@ -82,13 +82,13 @@ mod private } } - impl< 'table, Table, RowKey, Row, CellKey, CellRepr > From< &'table Table > - for AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + impl< 'table, Table, RowKey, Row, CellKey> From< &'table Table > + for AsTable< 'table, Table, RowKey, Row, CellKey> where RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey>, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { fn from( table : &'table Table ) -> Self { @@ -96,14 +96,14 @@ mod private } } - impl< 'table, Table, RowKey, Row, CellKey, CellRepr > fmt::Debug - for AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + impl< 'table, Table, RowKey, Row, CellKey> fmt::Debug + for AsTable< 'table, Table, RowKey, Row, CellKey> where Table : fmt::Debug, RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey>, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { @@ -130,25 +130,25 @@ mod private type RowKey : table::RowKey; /// The type representing a row, must implement `Cells`. - type Row : Cells< Self::CellKey, Self::CellRepr >; + type Row : Cells< Self::CellKey >; /// The type used to identify cells within a row, must implement `Key` and can be unsized. type CellKey : table::CellKey + ?Sized; - /// The type representing the content of a cell, must implement `CellRepr`. - type CellRepr : table::CellRepr; + // /// The type representing the content of a cell, must implement `CellRepr`. + // type // CellRepr : table::CellRepr; /// Converts the data reference into an `AsTable` reference. - fn as_table( &self ) -> AsTable< '_, Self::Table, Self::RowKey, Self::Row, Self::CellKey, Self::CellRepr >; + fn as_table( &self ) -> AsTable< '_, Self::Table, Self::RowKey, Self::Row, Self::CellKey >; } - impl< 'table, Table, RowKey, Row, CellKey, CellRepr > IntoAsTable - for AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + impl< 'table, Table, RowKey, Row, CellKey> IntoAsTable + for AsTable< 'table, Table, RowKey, Row, CellKey> where RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey>, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, Self : Copy, { @@ -156,9 +156,9 @@ mod private type RowKey = RowKey; type Row = Row; type CellKey = CellKey; - type CellRepr = CellRepr; + // type CellRepr = CellRepr; - fn as_table( &self ) -> AsTable< '_, Self::Table, Self::RowKey, Self::Row, Self::CellKey, Self::CellRepr > + fn as_table( &self ) -> AsTable< '_, Self::Table, Self::RowKey, Self::Row, Self::CellKey > { *self } @@ -168,9 +168,9 @@ mod private // impl< Row > IntoAsTable // for Vec< Row > // where -// Row : Cells< Self::CellKey, Self::CellRepr >, +// Row : Cells< Self::CellKey >, // // CellKey : table::CellKey + ?Sized, -// // CellRepr : table::CellRepr, +// // // CellRepr : table::CellRepr, // { // // type Table = Self; @@ -179,14 +179,14 @@ mod private // type CellKey = str; // type CellRepr = WithRef; // -// fn as_table( &self ) -> AsTable< '_, Self::Table, Self::RowKey, Self::Row, Self::CellKey, Self::CellRepr > +// fn as_table( &self ) -> AsTable< '_, Self::Table, Self::RowKey, Self::Row, Self::CellKey > // { // AsTable::from( self ) // } // // } - // pub struct AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + // pub struct AsTable< 'table, Table, RowKey, Row, CellKey> } diff --git a/module/core/format_tools/src/format/md_math.rs b/module/core/format_tools/src/format/md_math.rs index d4de6ae6af..196b0ee811 100644 --- a/module/core/format_tools/src/format/md_math.rs +++ b/module/core/format_tools/src/format/md_math.rs @@ -3,6 +3,8 @@ //! Provides functionality for converting multidimensional indices into flat offsets, //! useful for operations involving multidimensional arrays or grids. +// xxx : use crate mdmath + /// Internal namespace. mod private { diff --git a/module/core/format_tools/src/format/output_format.rs b/module/core/format_tools/src/format/output_format.rs index 511d12db79..69acca8515 100644 --- a/module/core/format_tools/src/format/output_format.rs +++ b/module/core/format_tools/src/format/output_format.rs @@ -1,6 +1,6 @@ //! Customizable format of printing table. //! -//! # Example of ordinary format +//! # Example of table format //! //! ```text //! sid | sname | gap @@ -74,14 +74,15 @@ mod private #[ inline( always ) ] fn default() -> Self { - super::ordinary::Ordinary::instance() + super::table::Table::instance() } } } -mod ordinary; +mod table; mod records; +mod keys; #[ allow( unused_imports ) ] pub use own::*; @@ -97,8 +98,9 @@ pub mod own #[ doc( inline ) ] pub use { - ordinary::Ordinary, + table::Table, records::Records, + keys::Keys, }; #[ doc( inline ) ] diff --git a/module/core/format_tools/src/format/output_format/keys.rs b/module/core/format_tools/src/format/output_format/keys.rs new file mode 100644 index 0000000000..55ee27b023 --- /dev/null +++ b/module/core/format_tools/src/format/output_format/keys.rs @@ -0,0 +1,107 @@ +//! Implement keys list output format. +//! +//! # Example +//! +//! ```text +//! ``` +//! + +use crate::*; +use print:: +{ + InputExtract, + Context, +}; +use core:: +{ + fmt, +}; +use std::sync::OnceLock; + +/// A struct representing the list of keys output format. +#[derive( Debug )] +pub struct Keys +{ + // /// Prefix added to each row. + // pub table_prefix : String, + // /// Postfix added to each row. + // pub table_postfix : String, + // /// Separator used between rows. + // pub table_separator : String, + // /// Prefix added to each row. + // pub row_prefix : String, + // /// Postfix added to each row. + // pub row_postfix : String, + // /// Separator used between rows. + // pub row_separator : String, + // /// Prefix added to each cell. + // pub cell_prefix : String, + // /// Postfix added to each cell. + // pub cell_postfix : String, + // /// Separator used between table columns. + // pub cell_separator : String, +} + +impl Keys +{ + /// Returns a reference to a static instance of `Keys`. + pub fn instance() -> &'static dyn TableOutputFormat + { + static INSTANCE : OnceLock< Keys > = OnceLock::new(); + INSTANCE.get_or_init( || Keys::default() ) + } +} + +impl Default for Keys +{ + fn default() -> Self + { + + // let cell_prefix = "".to_string(); + // let cell_postfix = "".to_string(); + // let cell_separator = " │ ".to_string(); + // let row_prefix = "│ ".to_string(); + // let row_postfix = " │".to_string(); + // let row_separator = "\n".to_string(); + // let table_prefix = "".to_string(); + // let table_postfix = "".to_string(); + // let table_separator = "\n".to_string(); + + Self + { + // table_prefix, + // table_postfix, + // table_separator, + // row_prefix, + // row_postfix, + // row_separator, + // cell_prefix, + // cell_postfix, + // cell_separator, + } + } +} + +impl TableOutputFormat for Keys +{ + + fn extract_write< 'buf, 'data >( + &self, + x : &InputExtract< 'data >, + c : &mut Context< 'buf >, + ) -> fmt::Result + { + + // dbg!( &x ); + + for col in &x.col_descriptors + { + write!( c.buf, " - {}\n", col.label )?; + } + + write!( c.buf, " {} fields\n", x.col_descriptors.len() )?; + + Ok(()) + } + +} diff --git a/module/core/format_tools/src/format/output_format/ordinary.rs b/module/core/format_tools/src/format/output_format/table.rs similarity index 93% rename from module/core/format_tools/src/format/output_format/ordinary.rs rename to module/core/format_tools/src/format/output_format/table.rs index 23606111f3..579ba6c783 100644 --- a/module/core/format_tools/src/format/output_format/ordinary.rs +++ b/module/core/format_tools/src/format/output_format/table.rs @@ -24,7 +24,7 @@ use std::sync::OnceLock; /// A struct representing the classic table output format. /// -/// `Ordinary` provides a standard implementation for table formatting, +/// `Table` provides a standard implementation for table formatting, /// supporting a classic style with default settings. /// /// # Example @@ -37,7 +37,7 @@ use std::sync::OnceLock; /// 10 | Boris | 5 /// ``` #[ derive( Debug ) ] -pub struct Ordinary +pub struct Table { /// Delimitting header with grid line or not. pub delimitting_header : bool, @@ -77,7 +77,7 @@ pub struct Ordinary pub corner_rb : char, } -impl Default for Ordinary +impl Default for Table { fn default() -> Self { @@ -127,30 +127,30 @@ impl Default for Ordinary } } -impl Default for &'static Ordinary +impl Default for &'static Table { fn default() -> Self { // qqq : find a better solution - static STYLES : OnceLock< Ordinary > = OnceLock::new(); + static STYLES : OnceLock< Table > = OnceLock::new(); STYLES.get_or_init( || { - Ordinary::default() + Table::default() }) } } -impl Ordinary +impl Table { - /// Returns a reference to a static instance of `Ordinary`. + /// Returns a reference to a static instance of `Table`. /// - /// This method provides access to a single shared instance of `Ordinary`, + /// This method provides access to a single shared instance of `Table`, /// ensuring efficient reuse of the classic table output format. pub fn instance() -> & 'static dyn TableOutputFormat { - static INSTANCE : OnceLock< Ordinary > = OnceLock::new(); + static INSTANCE : OnceLock< Table > = OnceLock::new(); INSTANCE.get_or_init( || { Self::default() @@ -159,7 +159,7 @@ impl Ordinary } } -impl TableOutputFormat for Ordinary +impl TableOutputFormat for Table { fn extract_write< 'buf, 'data >( &self, x : &InputExtract< 'data >, c : &mut Context< 'buf > ) -> fmt::Result { diff --git a/module/core/format_tools/src/format/print.rs b/module/core/format_tools/src/format/print.rs index 29437961b8..858bd7dd57 100644 --- a/module/core/format_tools/src/format/print.rs +++ b/module/core/format_tools/src/format/print.rs @@ -166,7 +166,7 @@ mod private /// A `String` containing the formatted table. fn table_to_string( &'data self ) -> String { - self.table_to_string_with_format( &output_format::Ordinary::default() ) + self.table_to_string_with_format( &output_format::Table::default() ) } /// Converts the table to a string representation specifying printer. @@ -197,15 +197,15 @@ mod private } /// A trait for formatting tables. - impl< 'data, T, RowKey, Row, CellKey, CellRepr > TableFormatter< 'data > - for AsTable< 'data, T, RowKey, Row, CellKey, CellRepr > + impl< 'data, T, RowKey, Row, CellKey> TableFormatter< 'data > + for AsTable< 'data, T, RowKey, Row, CellKey> where - Self : TableRows< CellKey = CellKey, CellRepr = CellRepr, RowKey = RowKey, Row = Row >, + Self : TableRows< CellKey = CellKey, RowKey = RowKey, Row = Row >, Self : TableHeader< CellKey = CellKey >, RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey>, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { fn fmt< 'a >( &'data self, c : &mut Context< 'a > ) -> fmt::Result @@ -365,7 +365,7 @@ mod private } } /// Extract input data from and collect it in a format consumable by output formatter. - pub fn extract< 't, 'context, Table, RowKey, Row, CellKey, CellRepr > + pub fn extract< 't, 'context, Table, RowKey, Row, CellKey> ( table : &'t Table, filter_col : &'context ( dyn FilterCol + 'context ), @@ -376,12 +376,12 @@ mod private where 'data : 't, // 't : 'data, - Table : TableRows< RowKey = RowKey, Row = Row, CellKey = CellKey, CellRepr = CellRepr >, + Table : TableRows< RowKey = RowKey, Row = Row, CellKey = CellKey >, Table : TableHeader< CellKey = CellKey >, RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr > + 'data, + Row : Cells< CellKey> + 'data, CellKey : table::CellKey + ?Sized + 'data, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { use md_math::MdOffset; @@ -508,7 +508,7 @@ mod private | ( key, val ) | { - let val = match val.0 + let val = match val { Some( val ) => { @@ -583,7 +583,10 @@ mod private slices[ x.slices_dim.md_offset( md_index ) ] = s; }) ; - x.col_descriptors[ icol ].label = cell.0.as_ref(); + if irow == 0 + { + x.col_descriptors[ icol ].label = cell.0.as_ref(); + } } } diff --git a/module/core/format_tools/src/format/table.rs b/module/core/format_tools/src/format/table.rs index 9ea6b1aecd..d3dc8bd71c 100644 --- a/module/core/format_tools/src/format/table.rs +++ b/module/core/format_tools/src/format/table.rs @@ -12,7 +12,7 @@ mod private // fmt, borrow::Borrow, }; - // use std::borrow::Cow; + use std::borrow::Cow; use reflect_tools:: { IteratorTrait, @@ -78,20 +78,21 @@ mod private // = /// A trait for iterating over all cells of a row. - pub trait Cells< CellKey, CellRepr > + pub trait Cells< CellKey > where - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, CellKey : table::CellKey + ?Sized, { /// Returns an iterator over all cells of the row. - fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b CellKey, OptionalCow< 'b, str, CellRepr > ) > + // fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b CellKey, OptionalCow< 'b, str > ) > + fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b CellKey, Option< Cow< 'b, str > > ) > where 'a : 'b, CellKey : 'b, ; } - impl< Row, CellKey, CellRepr > Cells< CellKey, CellRepr > + impl< Row, CellKey > Cells< CellKey > for Row where CellKey : table::CellKey + ?Sized, @@ -99,14 +100,17 @@ mod private Row : TableWithFields + Fields < &'ckv CellKey, - OptionalCow< 'ckv, str, CellRepr >, + // OptionalCow< 'ckv, str >, + Option< Cow< 'ckv, str > >, Key< 'ckv > = &'ckv CellKey, - Val< 'ckv > = OptionalCow< 'ckv, str, CellRepr >, + // Val< 'ckv > = OptionalCow< 'ckv, str >, + Val< 'ckv > = Option< Cow< 'ckv, str > >, > + 'ckv, // xxx - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { - fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b CellKey, OptionalCow< 'b, str, CellRepr > ) > + // fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b CellKey, OptionalCow< 'b, str > ) > + fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b CellKey, Option< Cow< 'b, str > > ) > where 'a : 'b, CellKey : 'b, @@ -154,15 +158,15 @@ mod private /// /// The type representing a row, which must implement `Cells` /// for the specified `CellKey` and `CellRepr`. - type Row : Cells< Self::CellKey, Self::CellRepr >; + type Row : Cells< Self::CellKey >; /// /// The type used to identify cells within a row, requiring /// implementation of the `Key` trait. type CellKey : table::CellKey + ?Sized; /// - /// The type representing the content of a cell, requiring - /// implementation of the `CellRepr` trait. - type CellRepr : table::CellRepr; + // /// The type representing the content of a cell, requiring + // /// implementation of the `CellRepr` trait. + // type // CellRepr : table::CellRepr; /// Returns an iterator over all rows of the table. fn rows( &self ) -> impl IteratorTrait< Item = &Self::Row >; @@ -171,9 +175,8 @@ mod private // Self::Row : 'a; } - impl< T, RowKey, Row, CellKey, CellRepr > - TableRows<> - for AsTable< '_, T, RowKey, Row, CellKey, CellRepr > + impl< T, RowKey, Row, CellKey > TableRows<> + for AsTable< '_, T, RowKey, Row, CellKey > where for< 'k, 'v > T : Fields @@ -185,14 +188,14 @@ mod private > + 'k + 'v, RowKey : table::RowKey, - Row : TableWithFields + Cells< CellKey, CellRepr >, + Row : TableWithFields + Cells< CellKey >, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { type RowKey = RowKey; type Row = Row; type CellKey = CellKey; - type CellRepr = CellRepr; + // type CellRepr = CellRepr; fn rows( &self ) -> impl IteratorTrait< Item = &Self::Row > // fn rows< 'a >( &'a self ) -> impl IteratorTrait< Item = &'a Self::Row > @@ -217,14 +220,14 @@ mod private // fn mcells( &self ) -> [ usize ; 2 ]; // } // -// impl< T, RowKey, Row, CellKey, CellRepr > TableSize -// for AsTable< '_, T, RowKey, Row, CellKey, CellRepr > +// impl< T, RowKey, Row, CellKey > TableSize +// for AsTable< '_, T, RowKey, Row, CellKey > // where -// Self : TableRows< RowKey = RowKey, Row = Row, CellKey = CellKey, CellRepr = CellRepr >, +// Self : TableRows< RowKey = RowKey, Row = Row, CellKey = CellKey >, // RowKey : table::RowKey, -// Row : Cells< CellKey, CellRepr >, +// Row : Cells< CellKey >, // CellKey : table::CellKey + ?Sized, -// CellRepr : table::CellRepr, +// // CellRepr : table::CellRepr, // { // fn mcells( &self ) -> [ usize ; 2 ] // { @@ -256,14 +259,14 @@ mod private fn header( &self ) -> Option< impl IteratorTrait< Item = ( &Self::CellKey, &'_ str ) > >; } - impl< T, RowKey, Row, CellKey, CellRepr > TableHeader - for AsTable< '_, T, RowKey, Row, CellKey, CellRepr > + impl< T, RowKey, Row, CellKey > TableHeader + for AsTable< '_, T, RowKey, Row, CellKey > where - Self : TableRows< RowKey = RowKey, Row = Row, CellKey = CellKey, CellRepr = CellRepr >, + Self : TableRows< RowKey = RowKey, Row = Row, CellKey = CellKey >, RowKey : table::RowKey, - Row : TableWithFields + Cells< CellKey, CellRepr >, + Row : TableWithFields + Cells< CellKey >, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { type CellKey = CellKey; diff --git a/module/core/format_tools/src/format/test_object_without_impl.rs b/module/core/format_tools/src/format/test_object_without_impl.rs new file mode 100644 index 0000000000..f61b3fe588 --- /dev/null +++ b/module/core/format_tools/src/format/test_object_without_impl.rs @@ -0,0 +1,155 @@ +//! A strucutre for diagnostic and demonstration purpose. + +// use super::*; + +// use crate:: +// { +// Fields, +// IteratorTrait, +// TableWithFields, +// WithRef, +// OptionalCow, +// }; + +use std:: +{ + collections::HashMap, + hash::Hasher, + hash::Hash, + cmp::Ordering, + // borrow::Cow, +}; + +/// Struct representing a test object with various fields. +#[ derive( Clone, Debug, PartialEq, Eq ) ] +pub struct TestObjectWithoutImpl +{ + pub id : String, + pub created_at : i64, + pub file_ids : Vec< String >, + pub tools : Option< Vec< HashMap< String, String > > >, +} + +// TableWithFields is not implemented for TestObjectWithoutImpl intentionally + +// impl TableWithFields for TestObjectWithoutImpl {} +// +// impl Fields< &'_ str, Option< Cow< '_, str > > > +// for TestObjectWithoutImpl +// { +// type Key< 'k > = &'k str; +// type Val< 'v > = Option< Cow< 'v, str > >; +// +// fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > +// { +// use format_tools::ref_or_display_or_debug_multiline::field; +// // use format_tools::ref_or_display_or_debug::field; +// let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new(); +// +// dst.push( field!( &self.id ) ); +// dst.push( field!( &self.created_at ) ); +// dst.push( field!( &self.file_ids ) ); +// +// if let Some( tools ) = &self.tools +// { +// dst.push( field!( tools ) ); +// } +// else +// { +// dst.push( ( "tools", Option::None ) ); +// } +// +// dst.into_iter() +// } +// +// } + +impl Hash for TestObjectWithoutImpl +{ + + fn hash< H: Hasher >( &self, state: &mut H ) + { + self.id.hash( state ); + self.created_at.hash( state ); + self.file_ids.hash( state ); + + if let Some( tools ) = &self.tools + { + for tool in tools + { + for ( key, value ) in tool + { + key.hash( state ); + value.hash( state ); + } + } + } + else + { + state.write_u8( 0 ); + } + } + +} + +impl PartialOrd for TestObjectWithoutImpl +{ + + fn partial_cmp( &self, other: &Self ) -> Option< Ordering > + { + Some( self.cmp( other ) ) + } + +} + +impl Ord for TestObjectWithoutImpl +{ + + fn cmp( &self, other: &Self ) -> Ordering + { + self.id + .cmp( &other.id ) + .then_with( | | self.created_at.cmp( &other.created_at ) ) + .then_with( | | self.file_ids.cmp( &other.file_ids ) ) + } + +} + +/// Generate a dynamic array of test objects. +pub fn test_objects_gen() -> Vec< TestObjectWithoutImpl > +{ + + vec! + [ + TestObjectWithoutImpl + { + id : "1".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".to_string() ], + tools : None + }, + TestObjectWithoutImpl + { + id : "2".to_string(), + created_at : 13, + file_ids : vec![ "file3".to_string(), "file4\nmore details".to_string() ], + tools : Some + ( + vec! + [ + { + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map + }, + { + let mut map = HashMap::new(); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + } + ] + ), + }, + ] + +} diff --git a/module/core/format_tools/tests/inc/collection_test.rs b/module/core/format_tools/tests/inc/collection_test.rs index 7e1607820e..6b17ce0975 100644 --- a/module/core/format_tools/tests/inc/collection_test.rs +++ b/module/core/format_tools/tests/inc/collection_test.rs @@ -6,7 +6,7 @@ use the_module:: AsTable, TableRows, WithRef, - print, + // the_module::print, }; use std:: @@ -56,14 +56,14 @@ fn dlist_basic() }; use the_module::TableFormatter; - let _as_table : AsTable< '_, Vec< TestObject >, &str, TestObject, str, WithRef > = AsTable::new( &data ); + let _as_table : AsTable< '_, Vec< TestObject >, &str, TestObject, str> = AsTable::new( &data ); let as_table = AsTable::new( &data ); let rows = TableRows::rows( &as_table ); assert_eq!( rows.len(), 2 ); let mut output = String::new(); - let mut context = print::Context::new( &mut output, Default::default() ); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); let got = as_table.table_to_string(); assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); @@ -112,14 +112,14 @@ fn hmap_basic() }; use the_module::TableFormatter; - let _as_table : AsTable< '_, HashMap< &str, TestObject >, &str, TestObject, str, WithRef > = AsTable::new( &data ); + let _as_table : AsTable< '_, HashMap< &str, TestObject >, &str, TestObject, str> = AsTable::new( &data ); let as_table = AsTable::new( &data ); let rows = TableRows::rows( &as_table ); assert_eq!( rows.len(), 2 ); let mut output = String::new(); - let mut context = print::Context::new( &mut output, Default::default() ); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); let got = as_table.table_to_string(); assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); @@ -168,14 +168,14 @@ fn bmap_basic() }; use the_module::TableFormatter; - let _as_table : AsTable< '_, Bmap< &str, TestObject >, &str, TestObject, str, WithRef > = AsTable::new( &data ); + let _as_table : AsTable< '_, Bmap< &str, TestObject >, &str, TestObject, str> = AsTable::new( &data ); let as_table = AsTable::new( &data ); let rows = TableRows::rows( &as_table ); assert_eq!( rows.len(), 2 ); let mut output = String::new(); - let mut context = print::Context::new( &mut output, Default::default() ); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); let got = as_table.table_to_string(); assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); @@ -222,14 +222,14 @@ fn bset_basic() }; use the_module::TableFormatter; - let _as_table : AsTable< '_, BTreeSet< TestObject >, &str, TestObject, str, WithRef > = AsTable::new( &data ); + let _as_table : AsTable< '_, BTreeSet< TestObject >, &str, TestObject, str> = AsTable::new( &data ); let as_table = AsTable::new( &data ); let rows = TableRows::rows( &as_table ); assert_eq!( rows.len(), 2 ); let mut output = String::new(); - let mut context = print::Context::new( &mut output, Default::default() ); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); let got = as_table.table_to_string(); assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); @@ -276,14 +276,14 @@ fn deque_basic() }; use the_module::TableFormatter; - let _as_table : AsTable< '_, VecDeque< TestObject >, &str, TestObject, str, WithRef > = AsTable::new( &data ); + let _as_table : AsTable< '_, VecDeque< TestObject >, &str, TestObject, str> = AsTable::new( &data ); let as_table = AsTable::new( &data ); let rows = TableRows::rows( &as_table ); assert_eq!( rows.len(), 2 ); let mut output = String::new(); - let mut context = print::Context::new( &mut output, Default::default() ); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); let got = as_table.table_to_string(); assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); @@ -328,16 +328,16 @@ fn hset_basic() ), }, }; - + use the_module::TableFormatter; - let _as_table : AsTable< '_, HashSet< TestObject >, &str, TestObject, str, WithRef > = AsTable::new( &data ); + let _as_table : AsTable< '_, HashSet< TestObject >, &str, TestObject, str> = AsTable::new( &data ); let as_table = AsTable::new( &data ); let rows = TableRows::rows( &as_table ); assert_eq!( rows.len(), 2 ); let mut output = String::new(); - let mut context = print::Context::new( &mut output, Default::default() ); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); let got = as_table.table_to_string(); assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); @@ -384,14 +384,14 @@ fn llist_basic() }; use the_module::TableFormatter; - let _as_table : AsTable< '_, LinkedList< TestObject >, &str, TestObject, str, WithRef > = AsTable::new( &data ); + let _as_table : AsTable< '_, LinkedList< TestObject >, &str, TestObject, str> = AsTable::new( &data ); let as_table = AsTable::new( &data ); let rows = TableRows::rows( &as_table ); assert_eq!( rows.len(), 2 ); let mut output = String::new(); - let mut context = print::Context::new( &mut output, Default::default() ); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); let got = as_table.table_to_string(); assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); diff --git a/module/core/format_tools/tests/inc/fields_test.rs b/module/core/format_tools/tests/inc/fields_test.rs index 48ba295e20..32d921bed0 100644 --- a/module/core/format_tools/tests/inc/fields_test.rs +++ b/module/core/format_tools/tests/inc/fields_test.rs @@ -26,16 +26,16 @@ pub struct TestObject pub tools : Option< Vec< HashMap< String, String > > >, } -impl Fields< &'static str, OptionalCow< '_, str, WithRef > > +impl Fields< &'_ str, Option< Cow< '_, str > > > for TestObject { - type Key< 'k > = &'static str; - type Val< 'v > = OptionalCow< 'v, str, WithRef >; + type Key< 'k > = &'k str; + type Val< 'v > = Option< Cow< 'v, str > >; - fn fields( &self ) -> impl IteratorTrait< Item = ( &'static str, OptionalCow< '_, str, WithRef > ) > + fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > { use format_tools::ref_or_display_or_debug::field; - let mut dst : Vec< ( &'static str, OptionalCow< '_, str, WithRef > ) > = Vec::new(); + let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new(); dst.push( field!( &self.id ) ); dst.push( field!( &self.created_at ) ); @@ -47,11 +47,17 @@ for TestObject } else { - dst.push( ( "tools", OptionalCow::none() ) ); + dst.push( ( "tools", Option::None ) ); } dst.into_iter() } + +} + +pub fn is_borrowed( cow : &Option< Cow< '_, str > > ) -> bool +{ + matches!( cow, Some( Cow::Borrowed( _ ) ) ) } // @@ -76,16 +82,16 @@ fn basic_with_ref_display_debug() ), }; - let fields : Vec< ( &str, OptionalCow< '_, str, WithRef > ) > = - Fields::< &'static str, OptionalCow< '_, str, WithRef > >::fields( &test_object ).collect(); + let fields : Vec< ( &str, Option< Cow< '_, str > > ) > = + Fields::< &'static str, Option< Cow< '_, str > > >::fields( &test_object ).collect(); - // let fields : Vec< ( &str, OptionalCow< '_, str, WithRef > ) > = test_object.fields().collect(); + // let fields : Vec< ( &str, Option< Cow< '_, str > > ) > = test_object.fields().collect(); assert_eq!( fields.len(), 4 ); - assert!( fields[ 0 ].1.is_borrowed() ); - assert!( !fields[ 1 ].1.is_borrowed() ); - assert!( !fields[ 2 ].1.is_borrowed() ); - assert!( !fields[ 3 ].1.is_borrowed() ); + assert!( is_borrowed( &fields[ 0 ].1 ) ); + assert!( !is_borrowed( &fields[ 1 ].1 ) ); + assert!( !is_borrowed( &fields[ 2 ].1 ) ); + assert!( !is_borrowed( &fields[ 3 ].1 ) ); assert_eq!( fields[ 0 ], ( "id", Some( Cow::Borrowed( "12345" ) ).into() ) ); assert_eq!( fields[ 0 ], ( "id", Some( Cow::Owned( "12345".to_string() ) ).into() ) ); assert_eq!( fields[ 1 ], ( "created_at", Some( Cow::Owned( "1627845583".to_string() ) ).into() ) ); diff --git a/module/core/format_tools/tests/inc/format_records_test.rs b/module/core/format_tools/tests/inc/format_records_test.rs index 8325dea020..72f23a5ff5 100644 --- a/module/core/format_tools/tests/inc/format_records_test.rs +++ b/module/core/format_tools/tests/inc/format_records_test.rs @@ -23,7 +23,7 @@ fn basic() { let test_objects = test_object::test_objects_gen(); - let _as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str, WithRef > = AsTable::new( &test_objects ); + let _as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str> = AsTable::new( &test_objects ); let as_table = AsTable::new( &test_objects ); let mut output = String::new(); diff --git a/module/core/format_tools/tests/inc/format_ordinary_test.rs b/module/core/format_tools/tests/inc/format_table_test.rs similarity index 96% rename from module/core/format_tools/tests/inc/format_ordinary_test.rs rename to module/core/format_tools/tests/inc/format_table_test.rs index 5dbe2a95d2..eb8a3b17dd 100644 --- a/module/core/format_tools/tests/inc/format_ordinary_test.rs +++ b/module/core/format_tools/tests/inc/format_table_test.rs @@ -23,7 +23,7 @@ fn basic() { let test_objects = test_object::test_objects_gen(); - let _as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str, WithRef > = AsTable::new( &test_objects ); + let _as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str> = AsTable::new( &test_objects ); let as_table = AsTable::new( &test_objects ); let mut output = String::new(); @@ -70,7 +70,7 @@ fn table_to_string() // with explicit arguments - let as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str, WithRef > = AsTable::new( &test_objects ); + let as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str> = AsTable::new( &test_objects ); let table_string = as_table.table_to_string(); println!( "\ntable_string\n{table_string}" ); assert!( table_string.contains( "id" ) ); @@ -99,7 +99,7 @@ fn custom_format() // use the_module::TableFormatter; let test_objects = test_object::test_objects_gen(); - let mut format = output_format::Ordinary::default(); + let mut format = output_format::Table::default(); format.cell_prefix = "( ".into(); format.cell_postfix = " )".into(); format.cell_separator = "|".into(); @@ -140,7 +140,7 @@ fn custom_format() use the_module::TableFormatter; - let mut format = output_format::Ordinary::default(); + let mut format = output_format::Table::default(); format.cell_prefix = "( ".into(); format.cell_postfix = " )".into(); format.cell_separator = "|".into(); @@ -175,7 +175,7 @@ fn filter_col_none() { let test_objects = test_object::test_objects_gen(); - let mut format = output_format::Ordinary::default(); + let mut format = output_format::Table::default(); format.cell_prefix = "( ".into(); format.cell_postfix = " )".into(); format.cell_separator = "|".into(); @@ -210,7 +210,7 @@ fn filter_col_callback() { let test_objects = test_object::test_objects_gen(); - let mut format = output_format::Ordinary::default(); + let mut format = output_format::Table::default(); format.cell_prefix = "( ".into(); format.cell_postfix = " )".into(); format.cell_separator = "|".into(); @@ -254,7 +254,7 @@ fn filter_row_none() { let test_objects = test_object::test_objects_gen(); - let mut format = output_format::Ordinary::default(); + let mut format = output_format::Table::default(); format.cell_prefix = "( ".into(); format.cell_postfix = " )".into(); format.cell_separator = "|".into(); @@ -286,7 +286,7 @@ fn filter_row_callback() { let test_objects = test_object::test_objects_gen(); - let mut format = output_format::Ordinary::default(); + let mut format = output_format::Table::default(); format.cell_prefix = "( ".into(); format.cell_postfix = " )".into(); format.cell_separator = "|".into(); diff --git a/module/core/format_tools/tests/inc/mod.rs b/module/core/format_tools/tests/inc/mod.rs index 5188190547..5f35b24fcc 100644 --- a/module/core/format_tools/tests/inc/mod.rs +++ b/module/core/format_tools/tests/inc/mod.rs @@ -1,18 +1,19 @@ -#[ allow( unused_imports ) ] use super::*; #[ cfg( feature = "enabled" ) ] #[ path = "." ] mod fundamental { - #[ allow( unused_imports ) ] use super::*; mod test_object; mod table_test; - mod format_ordinary_test; + mod tabe_foreign_test; + + mod format_table_test; mod format_records_test; + // mod format_keys_test; // qqq : xxx : implement mod collection_test; mod fields_test; diff --git a/module/core/format_tools/tests/inc/tabe_foreign_test.rs b/module/core/format_tools/tests/inc/tabe_foreign_test.rs new file mode 100644 index 0000000000..6cbfd68249 --- /dev/null +++ b/module/core/format_tools/tests/inc/tabe_foreign_test.rs @@ -0,0 +1,131 @@ +use super::*; + +use the_module:: +{ + AsTable, + Cells, + TableRows, + TableHeader, + WithRef, +}; + +use std:: +{ + borrow::Cow, +}; + +// + +#[ test ] +fn iterator_over_objects_without_impl() +{ + use the_module::TestObjectWithoutImpl as TestObjectWithoutImpl; + use the_module:: + { + Fields, + IteratorTrait, + TableWithFields, + WithRef, + OptionalCow, + output_format, + }; + + // xxx : Clone should not be required + #[ derive( Debug, Clone ) ] + pub struct TestObjecWrap( TestObjectWithoutImpl ); + + impl TableWithFields for TestObjecWrap {} + impl Fields< &'_ str, Option< Cow< '_, str > > > + for TestObjecWrap + { + type Key< 'k > = &'k str; + type Val< 'v > = Option< Cow< 'v, str > >; + + fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > + { + use format_tools::ref_or_display_or_debug_multiline::field; + let mut dst = Vec::new(); + + dst.push( field!( &self.0.id ) ); + dst.push( field!( &self.0.created_at ) ); + dst.push( field!( &self.0.file_ids ) ); + + if let Some( tools ) = &self.0.tools + { + dst.push( field!( tools ) ); + } + else + { + dst.push( ( "tools", Option::None ) ); + } + + dst.into_iter() + } + + } + + let data : collection_tools::Vec< TestObjecWrap > = the_module::test_objects_gen() + .into_iter() + .map( | e | TestObjecWrap( e ) ) + .collect() + ; + + use the_module::TableFormatter; + let _as_table : AsTable< '_, Vec< TestObjecWrap >, &str, TestObjecWrap, str > = AsTable::new( &data ); + let as_table = AsTable::new( &data ); + + let rows = TableRows::rows( &as_table ); + assert_eq!( rows.len(), 2 ); + + let mut output = String::new(); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); + let _result = the_module::TableFormatter::fmt( &as_table, &mut context ); + + // = output as table + + let got = as_table.table_to_string(); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + + let got = AsTable::new( &data ).table_to_string(); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + + let got = AsTable::new( &data ).table_to_string_with_format( &output_format::Table::default() ); + println!( "{}", &got ); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + + // = output as records + + // let format = output_format::Records::default(); + let mut output = String::new(); + let format = the_module::output_format::Records::default(); + let printer = the_module::print::Printer::with_format( &format ); + let mut context = the_module::print::Context::new( &mut output, printer ); + let got = the_module::TableFormatter::fmt( &as_table, &mut context ); + assert!( got.is_ok() ); + + let got = AsTable::new( &data ).table_to_string_with_format( &output_format::Records::default() ); + println!( "{}", &got ); + assert!( got.contains( "│ id │ 1 │" ) ); + assert!( got.contains( "│ created_at │ 1627845583 │" ) ); + assert!( got.contains( "│ id │ 2 │" ) ); + assert!( got.contains( "│ created_at │ 13 │" ) ); + + // = output as keys + + let got = AsTable::new( &data ).table_to_string_with_format( &output_format::Keys::default() ); + println!( "{}", &got ); + assert!( got.contains( "- id" ) ); + assert!( got.contains( "- created_at" ) ); + assert!( got.contains( "- file_ids" ) ); + assert!( got.contains( "- tools" ) ); + assert!( got.contains( "4 fields" ) ); + + // assert!( false ); + +} diff --git a/module/core/format_tools/tests/inc/table_test.rs b/module/core/format_tools/tests/inc/table_test.rs index 2357d44aea..c5fd38a8e9 100644 --- a/module/core/format_tools/tests/inc/table_test.rs +++ b/module/core/format_tools/tests/inc/table_test.rs @@ -10,6 +10,11 @@ use the_module:: WithRef, }; +use std:: +{ + borrow::Cow, +}; + // #[ test ] @@ -19,13 +24,13 @@ fn basic() { let test_objects = test_object::test_objects_gen(); - let cells = Cells::< str, WithRef >::cells( &test_objects[ 0 ] ); + let cells = Cells::< str>::cells( &test_objects[ 0 ] ); assert_eq!( cells.len(), 4 ); - let cells = Cells::< str, WithRef >::cells( &test_objects[ 1 ] ); + let cells = Cells::< str>::cells( &test_objects[ 1 ] ); assert_eq!( cells.len(), 4 ); drop( cells ); - let as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str, WithRef > = AsTable::new( &test_objects ); + let as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str> = AsTable::new( &test_objects ); // let mcells = TableSize::mcells( &as_table ); // assert_eq!( mcells, [ 4, 3 ] ); let rows = TableRows::rows( &as_table ); @@ -45,3 +50,251 @@ fn basic() dbg!( header.collect::< Vec< _ > >() ); } + +// + +#[ test ] +fn iterator_over_optional_cow() +{ + // use test_object::TestObject2 as TestObject2; + use the_module:: + { + Fields, + IteratorTrait, + TableWithFields, + WithRef, + OptionalCow, + }; + + /// Struct representing a test object with various fields. + #[ derive( Clone, Debug, PartialEq, Eq ) ] + pub struct TestObject2 + { + pub id : String, + pub created_at : i64, + pub file_ids : Vec< String >, + pub tools : Option< Vec< HashMap< String, String > > >, + } + + impl TableWithFields for TestObject2 {} + + impl Fields< &'_ str, Option< Cow< '_, str > > > + for TestObject2 + { + type Key< 'k > = &'k str; + type Val< 'v > = Option< Cow< 'v, str > >; + + fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > + { + use format_tools::ref_or_display_or_debug_multiline::field; + // use format_tools::ref_or_display_or_debug::field; + let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new(); + + // trace_macros!( true ); + dst.push( field!( &self.id ) ); + // trace_macros!( false ); + + dst.push( field!( &self.created_at ) ); + dst.push( field!( &self.file_ids ) ); + + if let Some( tools ) = &self.tools + { + dst.push( field!( tools ) ); + } + else + { + dst.push( ( "tools", Option::None ) ); + } + + dst.into_iter() + } + + } + + let data : collection_tools::Vec< TestObject2 > = dlist! + { + TestObject2 + { + id : "1".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".to_string() ], + tools : None + }, + TestObject2 + { + id : "2".to_string(), + created_at : 13, + file_ids : vec![ "file3".to_string(), "file4\nmore details".to_string() ], + tools : Some + ( + vec! + [ + { + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map + }, + { + let mut map = HashMap::new(); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + } + ] + ), + }, + }; + + use the_module::TableFormatter; + let _as_table : AsTable< '_, Vec< TestObject2 >, &str, TestObject2, str> = AsTable::new( &data ); + let as_table = AsTable::new( &data ); + + let rows = TableRows::rows( &as_table ); + assert_eq!( rows.len(), 2 ); + + let mut output = String::new(); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); + let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); + let got = as_table.table_to_string(); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + + let got = AsTable::new( &data ).table_to_string(); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + +} + +// + +#[ test ] +fn iterator_over_strings() +{ + + fn to_owned< 'a, T1 >( src : ( T1, Option< Cow< 'a, str > > ) ) -> ( T1, String ) + { + let val = match src.1 + { + Some( c ) => c.into_owned(), + None => String::default(), + }; + ( src.0, val ) + } + + // fn into< 'a, T1, T2 : Copy >( src : ( T1, OptionalCow< 'a, str, T2 > ) ) -> ( T1, Option< Cow< 'a, str > > ) + // { + // ( src.0, src.1.into() ) + // } + + // use test_object::TestObject as TestObject3; + use the_module:: + { + Fields, + IteratorTrait, + TableWithFields, + WithRef, + OptionalCow, + }; + + use std::borrow::Cow; + + /// Struct representing a test object with various fields. + #[ derive( Clone, Debug, PartialEq, Eq ) ] + pub struct TestObject3 + { + pub id : String, + pub created_at : i64, + pub file_ids : Vec< String >, + pub tools : Option< Vec< HashMap< String, String > > >, + } + + impl TableWithFields for TestObject3 {} + + impl Fields< &'_ str, String > + for TestObject3 + { + type Key< 'k > = &'k str; + type Val< 'v > = String; + + fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, String ) > + { + use format_tools::ref_or_display_or_debug_multiline::field; + // use format_tools::ref_or_display_or_debug::field; + let mut dst : Vec< ( &'_ str, String ) > = Vec::new(); + + dst.push( to_owned( field!( &self.id ) ) ); + + dst.push( to_owned( field!( &self.created_at ) ) ); + dst.push( to_owned( field!( &self.file_ids ) ) ); + + if let Some( tools ) = &self.tools + { + dst.push( to_owned( field!( tools ) ) ); + } + else + { + dst.push( ( "tools", String::default() ) ); + } + + dst.into_iter() + } + + } + + let _data : collection_tools::Vec< TestObject3 > = dlist! + { + TestObject3 + { + id : "1".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".to_string() ], + tools : None + }, + TestObject3 + { + id : "2".to_string(), + created_at : 13, + file_ids : vec![ "file3".to_string(), "file4\nmore details".to_string() ], + tools : Some + ( + vec! + [ + { + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map + }, + { + let mut map = HashMap::new(); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + } + ] + ), + }, + }; + + // no variability in what Fields iterate over by design! + + // use the_module::TableFormatter; + // let _as_table : AsTable< '_, Vec< TestObject3 >, &str, TestObject3, str> = AsTable::new( &data ); + // let as_table = AsTable::new( &data ); + +// let rows = TableRows::rows( &as_table ); +// assert_eq!( rows.len(), 2 ); +// +// let mut output = String::new(); +// let mut context = the_module::print::Context::new( &mut output, Default::default() ); +// let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); +// let got = as_table.table_to_string(); +// assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); +// assert!( got.contains( "│ 13 │ [ │ [ │" ) ); +// assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + +// let got = AsTable::new( &data ).table_to_string(); +// assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); +// assert!( got.contains( "│ 13 │ [ │ [ │" ) ); +// assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + +} diff --git a/module/core/format_tools/tests/inc/test_object.rs b/module/core/format_tools/tests/inc/test_object.rs index 6bb7555aa8..f710266a4d 100644 --- a/module/core/format_tools/tests/inc/test_object.rs +++ b/module/core/format_tools/tests/inc/test_object.rs @@ -15,12 +15,12 @@ use std:: collections::HashMap, hash::Hasher, hash::Hash, - cmp::Ordering - // borrow::Cow, + cmp::Ordering, + borrow::Cow, }; /// Struct representing a test object with various fields. -#[ derive( Clone, Debug ) ] +#[ derive( Clone, Debug, PartialEq, Eq ) ] pub struct TestObject { pub id : String, @@ -31,19 +31,51 @@ pub struct TestObject impl TableWithFields for TestObject {} -impl Fields< &'_ str, OptionalCow< '_, str, WithRef > > +// impl Fields< &'_ str, Option< Cow< '_, str > > > +// for TestObject +// { +// type Key< 'k > = &'k str; +// type Val< 'v > = OptionalCow< 'v, str>; +// +// fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > +// { +// use format_tools::ref_or_display_or_debug_multiline::field; +// // use format_tools::ref_or_display_or_debug::field; +// let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new(); +// +// dst.push( field!( &self.id ) ); +// dst.push( field!( &self.created_at ) ); +// dst.push( field!( &self.file_ids ) ); +// +// if let Some( tools ) = &self.tools +// { +// dst.push( field!( tools ) ); +// } +// else +// { +// dst.push( ( "tools", OptionalCow::none() ) ); +// } +// +// dst.into_iter() +// } +// +// } + +impl Fields< &'_ str, Option< Cow< '_, str > > > for TestObject { type Key< 'k > = &'k str; - type Val< 'v > = OptionalCow< 'v, str, WithRef >; + type Val< 'v > = Option< Cow< 'v, str > >; - fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, OptionalCow< '_, str, WithRef > ) > + fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > { use format_tools::ref_or_display_or_debug_multiline::field; // use format_tools::ref_or_display_or_debug::field; - let mut dst : Vec< ( &'_ str, OptionalCow< '_, str, WithRef > ) > = Vec::new(); + let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new(); + // trace_macros!( true ); dst.push( field!( &self.id ) ); + // trace_macros!( false ); dst.push( field!( &self.created_at ) ); dst.push( field!( &self.file_ids ) ); @@ -53,7 +85,7 @@ for TestObject } else { - dst.push( ( "tools", OptionalCow::none() ) ); + dst.push( ( "tools", Option::None ) ); } dst.into_iter() @@ -61,27 +93,27 @@ for TestObject } -impl Hash for TestObject +impl Hash for TestObject { - fn hash< H: Hasher >( &self, state: &mut H ) + fn hash< H: Hasher >( &self, state: &mut H ) { self.id.hash( state ); self.created_at.hash( state ); self.file_ids.hash( state ); - if let Some( tools ) = &self.tools + if let Some( tools ) = &self.tools { - for tool in tools + for tool in tools { - for ( key, value ) in tool + for ( key, value ) in tool { key.hash( state ); value.hash( state ); } } - } - else + } + else { state.write_u8( 0 ); } @@ -89,44 +121,44 @@ impl Hash for TestObject } -impl PartialEq for TestObject -{ - - fn eq( &self, other: &Self ) -> bool - { - self.id == other.id && - self.created_at == other.created_at && - self.file_ids == other.file_ids && - self.tools == other.tools - } - -} +// impl PartialEq for TestObject +// { +// +// fn eq( &self, other: &Self ) -> bool +// { +// self.id == other.id && +// self.created_at == other.created_at && +// self.file_ids == other.file_ids && +// self.tools == other.tools +// } +// +// } +// +// impl Eq for TestObject +// { +// } -impl Eq for TestObject +impl PartialOrd for TestObject { -} -impl PartialOrd for TestObject -{ - - fn partial_cmp( &self, other: &Self ) -> Option< Ordering > + fn partial_cmp( &self, other: &Self ) -> Option< Ordering > { Some( self.cmp( other ) ) } } -impl Ord for TestObject +impl Ord for TestObject { - fn cmp( &self, other: &Self ) -> Ordering + fn cmp( &self, other: &Self ) -> Ordering { self.id .cmp( &other.id ) .then_with( | | self.created_at.cmp( &other.created_at ) ) .then_with( | | self.file_ids.cmp( &other.file_ids ) ) } - + } // diff --git a/module/core/format_tools/tests/smoke_test.rs b/module/core/format_tools/tests/smoke_test.rs index 828e9b016b..cd7b1f36a8 100644 --- a/module/core/format_tools/tests/smoke_test.rs +++ b/module/core/format_tools/tests/smoke_test.rs @@ -1,12 +1,13 @@ +//! Smoke tests. - +/// Smoke test of local version of the crate. #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } - +/// Smoke test of published version of the crate. #[ test ] fn published_smoke_test() { diff --git a/module/core/format_tools/tests/tests.rs b/module/core/format_tools/tests/tests.rs index eae1668ea0..4fca6dbc07 100644 --- a/module/core/format_tools/tests/tests.rs +++ b/module/core/format_tools/tests/tests.rs @@ -1,10 +1,10 @@ -// #![ feature( trace_macros ) ] +//! Primary tests. + +#![ feature( trace_macros ) ] +#![ allow( unused_imports ) ] -#[ allow( unused_imports ) ] use format_tools as the_module; -#[ allow( unused_imports ) ] use test_tools::exposed::*; #[ cfg( feature = "enabled" ) ] mod inc; - diff --git a/module/core/implements/Cargo.toml b/module/core/implements/Cargo.toml index 44a51ad680..283004045e 100644 --- a/module/core/implements/Cargo.toml +++ b/module/core/implements/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "implements" -version = "0.8.0" +version = "0.9.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/impls_index/Cargo.toml b/module/core/impls_index/Cargo.toml index ea67dfa107..65c5781edd 100644 --- a/module/core/impls_index/Cargo.toml +++ b/module/core/impls_index/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "impls_index" -version = "0.7.0" +version = "0.8.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/impls_index_meta/Cargo.toml b/module/core/impls_index_meta/Cargo.toml index ce629d78b3..e680f0cc47 100644 --- a/module/core/impls_index_meta/Cargo.toml +++ b/module/core/impls_index_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "impls_index_meta" -version = "0.7.0" +version = "0.8.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/inspect_type/Cargo.toml b/module/core/inspect_type/Cargo.toml index cebba6d857..5bb17bb058 100644 --- a/module/core/inspect_type/Cargo.toml +++ b/module/core/inspect_type/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "inspect_type" -version = "0.10.0" +version = "0.11.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/inspect_type/src/lib.rs b/module/core/inspect_type/src/lib.rs index 27e60ce850..8f65d3fb63 100644 --- a/module/core/inspect_type/src/lib.rs +++ b/module/core/inspect_type/src/lib.rs @@ -2,7 +2,9 @@ #![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] #![ doc( html_root_url = "https://docs.rs/inspect_type/latest/inspect_type/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] +#![ allow( unexpected_cfgs ) ] +// #[ allow( unexpected_cfgs ) ] // #[ cfg( RUSTC_IS_NIGHTLY ) ] #[ cfg( not( RUSTC_IS_STABLE ) ) ] mod nightly diff --git a/module/core/inspect_type/tests/inc/inspect_type_test.rs b/module/core/inspect_type/tests/inc/inspect_type_test.rs index 58eb0b82b1..01445f74c4 100644 --- a/module/core/inspect_type/tests/inc/inspect_type_test.rs +++ b/module/core/inspect_type/tests/inc/inspect_type_test.rs @@ -1,3 +1,4 @@ + #[ allow( unused_imports ) ] use super::*; diff --git a/module/core/inspect_type/tests/tests.rs b/module/core/inspect_type/tests/tests.rs index 1b4624edf8..8e5818a1f9 100644 --- a/module/core/inspect_type/tests/tests.rs +++ b/module/core/inspect_type/tests/tests.rs @@ -1,3 +1,5 @@ +// #![ allow( unexpected_cfgs ) ] + // #![ no_std ] // #![ cfg_attr( feature = "no_std", no_std ) ] diff --git a/module/core/is_slice/Cargo.toml b/module/core/is_slice/Cargo.toml index b0945c3613..17dc95d0f2 100644 --- a/module/core/is_slice/Cargo.toml +++ b/module/core/is_slice/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "is_slice" -version = "0.9.0" +version = "0.10.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/mem_tools/Cargo.toml b/module/core/mem_tools/Cargo.toml index fd90f9d727..79a60f163b 100644 --- a/module/core/mem_tools/Cargo.toml +++ b/module/core/mem_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mem_tools" -version = "0.6.0" +version = "0.7.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/meta_tools/Cargo.toml b/module/core/meta_tools/Cargo.toml index 282db2f43f..c34c79a376 100644 --- a/module/core/meta_tools/Cargo.toml +++ b/module/core/meta_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "meta_tools" -version = "0.10.0" +version = "0.11.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/mod_interface/Cargo.toml b/module/core/mod_interface/Cargo.toml index 4c7f49cca8..6d05d0387c 100644 --- a/module/core/mod_interface/Cargo.toml +++ b/module/core/mod_interface/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mod_interface" -version = "0.25.0" +version = "0.26.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -28,8 +28,6 @@ all-features = false [features] default = [ "enabled" ] full = [ "enabled" ] -no_std = [] -use_alloc = [ "no_std" ] enabled = [ "mod_interface_meta/enabled" ] # keep these examples in directories diff --git a/module/core/mod_interface/src/lib.rs b/module/core/mod_interface/src/lib.rs index 30c7731f89..726b166188 100644 --- a/module/core/mod_interface/src/lib.rs +++ b/module/core/mod_interface/src/lib.rs @@ -1,4 +1,4 @@ -#![ cfg_attr( feature = "no_std", no_std ) ] +#![ no_std ] #![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] #![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] #![ doc( html_root_url = "https://docs.rs/mod_interface/latest/mod_interface/" ) ] diff --git a/module/core/mod_interface_meta/src/lib.rs b/module/core/mod_interface_meta/src/lib.rs index 0505641d53..f215f7f2ac 100644 --- a/module/core/mod_interface_meta/src/lib.rs +++ b/module/core/mod_interface_meta/src/lib.rs @@ -5,6 +5,19 @@ #![ warn( dead_code ) ] +// /// Derives. +// layer derive; +// own use super::derive; +// // xxx : change to remove need to write explicitly that + +// xxx : change to remove need to write explicitly that +// crate::mod_interface! +// { +// /// Derives. +// layer derive; +// own use super::derive; // xxx : change to remove need to write explicitly that +// } + // xxx : clean up, ad solve problems // - example based on simpified version of test::layer_have_layer with single sublayer // - example with attribute `#![ debug ]` diff --git a/module/core/reflect_tools/src/reflect/fields/vec.rs b/module/core/reflect_tools/src/reflect/fields/vec.rs index bdf3977601..0a18259738 100644 --- a/module/core/reflect_tools/src/reflect/fields/vec.rs +++ b/module/core/reflect_tools/src/reflect/fields/vec.rs @@ -9,6 +9,7 @@ use collection_tools::Vec; impl< V, Borrowed > Fields< usize, &'_ Borrowed > for Vec< V > where Borrowed : std::borrow::ToOwned + 'static + ?Sized, + // Borrowed : ?Sized + 'static, V : std::borrow::Borrow< Borrowed >, { @@ -28,6 +29,7 @@ where impl< V, Borrowed > Fields< usize, Option< Cow< '_, Borrowed > > > for Vec< V > where Borrowed : std::borrow::ToOwned + 'static + ?Sized, + // Borrowed : ?Sized + 'static, V : std::borrow::Borrow< Borrowed >, { @@ -39,6 +41,7 @@ where fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > { + // self.iter().enumerate().map( move | ( key, val ) | ( key, Some( Cow::Borrowed( &val ) ) ) ) self.iter().enumerate().map( move | ( key, val ) | ( key, Some( Cow::Borrowed( val.borrow() ) ) ) ) } @@ -47,6 +50,7 @@ where impl< V, Borrowed, Marker > Fields< usize, OptionalCow< '_, Borrowed, Marker > > for Vec< V > where Borrowed : std::borrow::ToOwned + 'static + ?Sized, + // Borrowed : ?Sized + 'static, V : std::borrow::Borrow< Borrowed >, Marker : Clone + Copy + 'static, { diff --git a/module/core/reflect_tools/src/reflect/wrapper.rs b/module/core/reflect_tools/src/reflect/wrapper.rs index defbe192f1..31ad09a99a 100644 --- a/module/core/reflect_tools/src/reflect/wrapper.rs +++ b/module/core/reflect_tools/src/reflect/wrapper.rs @@ -7,7 +7,7 @@ mod private { } -mod maybe_as; +mod optional_cow; #[ doc( inline ) ] #[ allow( unused_imports ) ] @@ -40,7 +40,7 @@ pub mod exposed #[ allow( unused_imports ) ] pub use super:: { - maybe_as::OptionalCow, + optional_cow::OptionalCow, }; } diff --git a/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs b/module/core/reflect_tools/src/reflect/wrapper/optional_cow.rs similarity index 88% rename from module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs rename to module/core/reflect_tools/src/reflect/wrapper/optional_cow.rs index f1351f8c92..5f329cc459 100644 --- a/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs +++ b/module/core/reflect_tools/src/reflect/wrapper/optional_cow.rs @@ -20,6 +20,19 @@ where Marker : Clone + Copy + 'static, { + /// Creates owned data from borrowed data, usually by cloning. + #[ inline( always ) ] + pub fn into_owned( &self ) -> < T as std::borrow::ToOwned >::Owned + where + < T as std::borrow::ToOwned >::Owned : Default, + { + match self.0.as_ref() + { + Some( c ) => c.clone().into_owned(), + None => < T as std::borrow::ToOwned >::Owned::default(), + } + } + /// Check is it borrowed. #[ inline( always ) ] pub fn is_borrowed( &self ) -> bool @@ -212,3 +225,15 @@ where T : Eq, { } + +impl< 'a, T, Marker > From< OptionalCow< 'a, T, Marker > > for Option< Cow< 'a, T > > +where + T : std::borrow::ToOwned + ?Sized, + Marker : Clone + Copy + 'static, +{ + #[ inline( always ) ] + fn from( src : OptionalCow< 'a, T, Marker > ) -> Self + { + src.0 + } +} diff --git a/module/core/reflect_tools/tests/inc/fundamental/fields_bset.rs b/module/core/reflect_tools/tests/inc/fundamental/fields_bset.rs index 5a811ad569..abaee19fd5 100644 --- a/module/core/reflect_tools/tests/inc/fundamental/fields_bset.rs +++ b/module/core/reflect_tools/tests/inc/fundamental/fields_bset.rs @@ -4,7 +4,6 @@ use super::*; use the_module:: { Fields, - }; // xxx : implement for other collections diff --git a/module/core/test_tools/Cargo.toml b/module/core/test_tools/Cargo.toml index 2093e6b0b2..0ac5366bb4 100644 --- a/module/core/test_tools/Cargo.toml +++ b/module/core/test_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test_tools" -version = "0.9.0" +version = "0.10.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/test_tools/src/lib.rs b/module/core/test_tools/src/lib.rs index efe6e6d7f0..ba768f7641 100644 --- a/module/core/test_tools/src/lib.rs +++ b/module/core/test_tools/src/lib.rs @@ -87,6 +87,8 @@ mod private {} prelude use ::collection_tools as collection; // prelude use ::process_tools as process; + use ::collection_tools; // xxx : do that for all dependencies + prelude use ::meta_tools:: { impls, @@ -95,6 +97,7 @@ mod private {} tests_impls_optional, tests_index, }; + prelude use ::typing_tools::{ implements }; } diff --git a/module/core/typing_tools/Cargo.toml b/module/core/typing_tools/Cargo.toml index 5b128ba0e5..c61c60c278 100644 --- a/module/core/typing_tools/Cargo.toml +++ b/module/core/typing_tools/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "typing_tools" -version = "0.8.0" +version = "0.9.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/move/assistant/Cargo.toml b/module/move/assistant/Cargo.toml index 6e2af1a870..144cfb6557 100644 --- a/module/move/assistant/Cargo.toml +++ b/module/move/assistant/Cargo.toml @@ -34,10 +34,11 @@ enabled = [ [dependencies] # xxx : qqq : optimze features +mod_interface = { workspace = true, features = [ "full" ] } former = { workspace = true, features = [ "full" ] } format_tools = { workspace = true, features = [ "full" ] } reflect_tools = { workspace = true, features = [ "full" ] } -openai-api-rs = { version = "4.0.9" } +openai-api-rs = { version = "=5.0.11" } tokio = { version = "1", features = ["full"] } dotenv = "0.15" diff --git a/module/move/assistant/Readme.md b/module/move/assistant/Readme.md index 0e9402c634..9296447b86 100644 --- a/module/move/assistant/Readme.md +++ b/module/move/assistant/Readme.md @@ -3,7 +3,9 @@ # Module :: assistant [![experimental](https://raster.shields.io/static/v1?label=stability&message=experimental&color=orange&logoColor=eee)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/ModuleassistantPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/ModuleassistantPush.yml) [![docs.rs](https://img.shields.io/docsrs/assistant?color=e3e8f0&logo=docs.rs)](https://docs.rs/assistant) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) -Assist AI in writing code. +**NOT ready for production** + + -Graphs tools. +**NOT ready for production** + - ```rust #[ cfg( all( feature = "cell_factory", feature = "use_std" ) ) ] { @@ -37,3 +36,4 @@ cd wTools cd examples/graphs_tools_trivial cargo run ``` +--> diff --git a/module/move/plot_interface/Readme.md b/module/move/plot_interface/Readme.md index 0e604acfb8..6102a14813 100644 --- a/module/move/plot_interface/Readme.md +++ b/module/move/plot_interface/Readme.md @@ -5,11 +5,12 @@ [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_plot_interface_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_plot_interface_push.yml) [![docs.rs](https://img.shields.io/docsrs/plot_interface?color=e3e8f0&logo=docs.rs)](https://docs.rs/plot_interface) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) -Plot interface. +**NOT ready for production** + + ```rust ``` @@ -27,4 +28,4 @@ git clone https://github.com/Wandalen/wTools cd wTools cd examples/plot_interface_trivial cargo run -``` +``` -->