From 86d3433a595223395dc612a57a77a6563b0aa850 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 08:44:36 +0300 Subject: [PATCH 001/143] initial crates --- module/alias/cargo_will/tests/smoke_test.rs | 4 +-- module/alias/file_tools/tests/smoke_test.rs | 4 +-- .../fundamental_data_type/tests/smoke_test.rs | 4 +-- module/alias/instance_of/tests/smoke_test.rs | 4 +-- module/alias/multilayer/tests/smoke_test.rs | 4 +-- .../proc_macro_tools/tests/smoke_test.rs | 4 +-- module/alias/proper_tools/tests/smoke_test.rs | 4 +-- module/alias/werror/tests/smoke_test.rs | 4 +-- module/alias/willbe2/tests/smoke_test.rs | 4 +-- module/alias/wproc_macro/tests/smoke_test.rs | 4 +-- .../alias/wstring_tools/tests/smoke_test.rs | 4 +-- module/alias/wtest/tests/smoke_test.rs | 4 +-- module/alias/wtest_basic/tests/smoke_test.rs | 4 +-- module/blank/brain_tools/Cargo.toml | 34 +++++++++++++++++++ module/blank/brain_tools/License | 22 ++++++++++++ module/blank/brain_tools/Readme.md | 33 ++++++++++++++++++ module/blank/brain_tools/src/lib.rs | 11 ++++++ .../blank/brain_tools/tests/inc/basic_test.rs | 7 ++++ module/blank/brain_tools/tests/inc/mod.rs | 4 +++ module/blank/brain_tools/tests/smoke_test.rs | 12 +++++++ module/blank/brain_tools/tests/tests.rs | 10 ++++++ module/blank/exe_tools/tests/smoke_test.rs | 4 +-- module/blank/image_tools/tests/smoke_test.rs | 4 +-- module/blank/math_tools/tests/smoke_test.rs | 4 +-- module/blank/paths_tools/Cargo.toml | 34 +++++++++++++++++++ module/blank/paths_tools/License | 22 ++++++++++++ module/blank/paths_tools/Readme.md | 33 ++++++++++++++++++ module/blank/paths_tools/src/lib.rs | 11 ++++++ .../blank/paths_tools/tests/inc/basic_test.rs | 7 ++++ module/blank/paths_tools/tests/inc/mod.rs | 4 +++ module/blank/paths_tools/tests/smoke_test.rs | 12 +++++++ module/blank/paths_tools/tests/tests.rs | 10 ++++++ module/blank/rustql/tests/smoke_test.rs | 4 +-- module/blank/second_brain/Cargo.toml | 34 +++++++++++++++++++ module/blank/second_brain/License | 22 ++++++++++++ module/blank/second_brain/Readme.md | 33 ++++++++++++++++++ module/blank/second_brain/src/lib.rs | 11 ++++++ .../second_brain/tests/inc/basic_test.rs | 7 ++++ module/blank/second_brain/tests/inc/mod.rs | 4 +++ module/blank/second_brain/tests/smoke_test.rs | 12 +++++++ module/blank/second_brain/tests/tests.rs | 10 ++++++ module/blank/w4d/tests/smoke_test.rs | 4 +-- module/blank/willbe_old/tests/smoke_test.rs | 4 +-- module/blank/wlang/tests/smoke_test.rs | 4 +-- module/core/clone_dyn/tests/smoke_test.rs | 4 +-- .../core/clone_dyn_meta/tests/smoke_test.rs | 4 +-- .../core/collection_tools/tests/smoke_test.rs | 4 +-- module/core/data_type/tests/smoke_test.rs | 4 +-- module/core/derive_tools/tests/smoke_test.rs | 4 +-- .../diagnostics_tools/tests/smoke_test.rs | 4 +-- module/core/error_tools/tests/smoke_test.rs | 4 +-- module/core/for_each/tests/smoke_test.rs | 4 +-- module/core/former/tests/smoke_test.rs | 4 +-- module/core/former_meta/tests/smoke_test.rs | 4 +-- module/core/former_types/tests/smoke_test.rs | 4 +-- module/core/fs_tools/tests/smoke_test.rs | 4 +-- module/core/implements/tests/smoke_test.rs | 4 +-- module/core/impls_index/tests/smoke_test.rs | 4 +-- module/core/include_md/tests/smoke_test.rs | 4 +-- module/core/inspect_type/tests/smoke_test.rs | 4 +-- module/core/is_slice/tests/smoke_test.rs | 4 +-- module/core/iter_tools/tests/smoke_test.rs | 4 +-- module/core/macro_tools/tests/smoke_test.rs | 4 +-- module/core/mem_tools/tests/smoke_test.rs | 4 +-- module/core/meta_tools/tests/smoke_test.rs | 4 +-- module/core/mod_interface/tests/smoke_test.rs | 4 +-- .../mod_interface_meta/tests/smoke_test.rs | 4 +-- module/core/process_tools/tests/smoke_test.rs | 4 +-- module/core/program_tools/tests/smoke_test.rs | 4 +-- .../proper_path_tools/tests/smoke_test.rs | 4 +-- module/core/reflect_tools/tests/smoke_test.rs | 4 +-- module/core/strs_tools/tests/smoke_test.rs | 4 +-- module/core/test_tools/tests/smoke_test.rs | 4 +-- module/core/time_tools/tests/smoke_test.rs | 4 +-- module/core/typing_tools/tests/smoke_test.rs | 4 +-- module/core/variadic_from/tests/smoke_test.rs | 4 +-- module/core/wtools/tests/smoke_test.rs | 4 +-- module/move/assistant/Cargo.toml | 34 +++++++++++++++++++ module/move/assistant/License | 22 ++++++++++++ module/move/assistant/Readme.md | 33 ++++++++++++++++++ module/move/assistant/src/lib.rs | 11 ++++++ module/move/assistant/tests/inc/basic_test.rs | 7 ++++ module/move/assistant/tests/inc/mod.rs | 4 +++ module/move/assistant/tests/smoke_test.rs | 12 +++++++ module/move/assistant/tests/tests.rs | 10 ++++++ module/move/crates_tools/tests/smoke_test.rs | 4 +-- module/move/graphs_tools/tests/smoke_test.rs | 4 +-- .../move/plot_interface/tests/smoke_test.rs | 4 +-- module/move/refiner/tests/smoke_test.rs | 4 +-- module/move/sqlx_query/tests/smoke_test.rs | 4 +-- module/move/wca/tests/smoke_test.rs | 4 +-- module/move/willbe/tests/smoke_test.rs | 4 +-- module/move/wplot/tests/smoke_test.rs | 4 +-- .../_video_experiment/tests/smoke_test.rs | 4 +-- .../automata_tools/tests/smoke_test.rs | 4 +-- module/postponed/non_std/tests/smoke_test.rs | 4 +-- .../postponed/std_tools/tests/smoke_test.rs | 4 +-- module/postponed/std_x/tests/smoke_test.rs | 4 +-- .../type_constructor/tests/smoke_test.rs | 4 +-- .../postponed/wautomata/tests/smoke_test.rs | 4 +-- .../postponed/wpublisher/tests/smoke_test.rs | 4 +-- module/step/meta/tests/smoke_test.rs | 4 +-- .../template_alias/tests/smoke_test.rs | 4 +-- .../template_blank/Cargo.toml.template | 2 -- .../template_blank/tests/smoke_test.rs | 2 -- .../tests/smoke_test.rs | 4 +-- .../tests/smoke_test.rs | 4 +-- .../tests/smoke_test.rs | 4 +-- 108 files changed, 680 insertions(+), 152 deletions(-) create mode 100644 module/blank/brain_tools/Cargo.toml create mode 100644 module/blank/brain_tools/License create mode 100644 module/blank/brain_tools/Readme.md create mode 100644 module/blank/brain_tools/src/lib.rs create mode 100644 module/blank/brain_tools/tests/inc/basic_test.rs create mode 100644 module/blank/brain_tools/tests/inc/mod.rs create mode 100644 module/blank/brain_tools/tests/smoke_test.rs create mode 100644 module/blank/brain_tools/tests/tests.rs create mode 100644 module/blank/paths_tools/Cargo.toml create mode 100644 module/blank/paths_tools/License create mode 100644 module/blank/paths_tools/Readme.md create mode 100644 module/blank/paths_tools/src/lib.rs create mode 100644 module/blank/paths_tools/tests/inc/basic_test.rs create mode 100644 module/blank/paths_tools/tests/inc/mod.rs create mode 100644 module/blank/paths_tools/tests/smoke_test.rs create mode 100644 module/blank/paths_tools/tests/tests.rs create mode 100644 module/blank/second_brain/Cargo.toml create mode 100644 module/blank/second_brain/License create mode 100644 module/blank/second_brain/Readme.md create mode 100644 module/blank/second_brain/src/lib.rs create mode 100644 module/blank/second_brain/tests/inc/basic_test.rs create mode 100644 module/blank/second_brain/tests/inc/mod.rs create mode 100644 module/blank/second_brain/tests/smoke_test.rs create mode 100644 module/blank/second_brain/tests/tests.rs create mode 100644 module/move/assistant/Cargo.toml create mode 100644 module/move/assistant/License create mode 100644 module/move/assistant/Readme.md create mode 100644 module/move/assistant/src/lib.rs create mode 100644 module/move/assistant/tests/inc/basic_test.rs create mode 100644 module/move/assistant/tests/inc/mod.rs create mode 100644 module/move/assistant/tests/smoke_test.rs create mode 100644 module/move/assistant/tests/tests.rs diff --git a/module/alias/cargo_will/tests/smoke_test.rs b/module/alias/cargo_will/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/alias/cargo_will/tests/smoke_test.rs +++ b/module/alias/cargo_will/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/alias/file_tools/tests/smoke_test.rs b/module/alias/file_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/alias/file_tools/tests/smoke_test.rs +++ b/module/alias/file_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/alias/fundamental_data_type/tests/smoke_test.rs b/module/alias/fundamental_data_type/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/alias/fundamental_data_type/tests/smoke_test.rs +++ b/module/alias/fundamental_data_type/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/alias/instance_of/tests/smoke_test.rs b/module/alias/instance_of/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/alias/instance_of/tests/smoke_test.rs +++ b/module/alias/instance_of/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/alias/multilayer/tests/smoke_test.rs b/module/alias/multilayer/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/alias/multilayer/tests/smoke_test.rs +++ b/module/alias/multilayer/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/alias/proc_macro_tools/tests/smoke_test.rs b/module/alias/proc_macro_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/alias/proc_macro_tools/tests/smoke_test.rs +++ b/module/alias/proc_macro_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/alias/proper_tools/tests/smoke_test.rs b/module/alias/proper_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/alias/proper_tools/tests/smoke_test.rs +++ b/module/alias/proper_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/alias/werror/tests/smoke_test.rs b/module/alias/werror/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/alias/werror/tests/smoke_test.rs +++ b/module/alias/werror/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/alias/willbe2/tests/smoke_test.rs b/module/alias/willbe2/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/alias/willbe2/tests/smoke_test.rs +++ b/module/alias/willbe2/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/alias/wproc_macro/tests/smoke_test.rs b/module/alias/wproc_macro/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/alias/wproc_macro/tests/smoke_test.rs +++ b/module/alias/wproc_macro/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/alias/wstring_tools/tests/smoke_test.rs b/module/alias/wstring_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/alias/wstring_tools/tests/smoke_test.rs +++ b/module/alias/wstring_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/alias/wtest/tests/smoke_test.rs b/module/alias/wtest/tests/smoke_test.rs index fddef25d11..dda3313c2e 100644 --- a/module/alias/wtest/tests/smoke_test.rs +++ b/module/alias/wtest/tests/smoke_test.rs @@ -1,5 +1,5 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] #[ ignore ] fn local_smoke_test() @@ -7,7 +7,7 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/alias/wtest_basic/tests/smoke_test.rs b/module/alias/wtest_basic/tests/smoke_test.rs index fddef25d11..dda3313c2e 100644 --- a/module/alias/wtest_basic/tests/smoke_test.rs +++ b/module/alias/wtest_basic/tests/smoke_test.rs @@ -1,5 +1,5 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] #[ ignore ] fn local_smoke_test() @@ -7,7 +7,7 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/blank/brain_tools/Cargo.toml b/module/blank/brain_tools/Cargo.toml new file mode 100644 index 0000000000..be2c9858a0 --- /dev/null +++ b/module/blank/brain_tools/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "brain_tools" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/brain_tools" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/brain_tools" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/brain_tools" +description = """ +Tools for second brain. +""" +categories = [ "algorithms", "development-tools" ] +keywords = [ "fundamental", "general-purpose" ] + +[lints] +workspace = true + +[package.metadata.docs.rs] +features = [ "full" ] +all-features = false + +[features] +default = [ "enabled" ] +full = [ "enabled" ] +enabled = [] + +[dependencies] + +[dev-dependencies] +test_tools = { workspace = true } diff --git a/module/blank/brain_tools/License b/module/blank/brain_tools/License new file mode 100644 index 0000000000..6d5ef8559f --- /dev/null +++ b/module/blank/brain_tools/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/blank/brain_tools/Readme.md b/module/blank/brain_tools/Readme.md new file mode 100644 index 0000000000..37d9acc46e --- /dev/null +++ b/module/blank/brain_tools/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: brain_tools +[![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/Modulebrain_toolsPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/Modulebrain_toolsPush.yml) [![docs.rs](https://img.shields.io/docsrs/brain_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/brain_tools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Tools for second brain. + + diff --git a/module/blank/brain_tools/src/lib.rs b/module/blank/brain_tools/src/lib.rs new file mode 100644 index 0000000000..db476fbaad --- /dev/null +++ b/module/blank/brain_tools/src/lib.rs @@ -0,0 +1,11 @@ +#![ cfg_attr( feature = "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/brain_tools/latest/brain_tools/" ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/blank/brain_tools/tests/inc/basic_test.rs b/module/blank/brain_tools/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/brain_tools/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/brain_tools/tests/inc/mod.rs b/module/blank/brain_tools/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/brain_tools/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/blank/brain_tools/tests/smoke_test.rs b/module/blank/brain_tools/tests/smoke_test.rs new file mode 100644 index 0000000000..663dd6fb9f --- /dev/null +++ b/module/blank/brain_tools/tests/smoke_test.rs @@ -0,0 +1,12 @@ + +#[ test ] +fn local_smoke_test() +{ + ::test_tools::smoke_test_for_local_run(); +} + +#[ test ] +fn published_smoke_test() +{ + ::test_tools::smoke_test_for_published_run(); +} diff --git a/module/blank/brain_tools/tests/tests.rs b/module/blank/brain_tools/tests/tests.rs new file mode 100644 index 0000000000..574f34b114 --- /dev/null +++ b/module/blank/brain_tools/tests/tests.rs @@ -0,0 +1,10 @@ + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use brain_tools as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/blank/exe_tools/tests/smoke_test.rs b/module/blank/exe_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/blank/exe_tools/tests/smoke_test.rs +++ b/module/blank/exe_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/blank/image_tools/tests/smoke_test.rs b/module/blank/image_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/blank/image_tools/tests/smoke_test.rs +++ b/module/blank/image_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/blank/math_tools/tests/smoke_test.rs b/module/blank/math_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/blank/math_tools/tests/smoke_test.rs +++ b/module/blank/math_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/blank/paths_tools/Cargo.toml b/module/blank/paths_tools/Cargo.toml new file mode 100644 index 0000000000..e71fb6027c --- /dev/null +++ b/module/blank/paths_tools/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "paths_tools" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/paths_tools" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/paths_tools" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/paths_tools" +description = """ +Tools to work with file paths. +""" +categories = [ "algorithms", "development-tools" ] +keywords = [ "fundamental", "general-purpose" ] + +[lints] +workspace = true + +[package.metadata.docs.rs] +features = [ "full" ] +all-features = false + +[features] +default = [ "enabled" ] +full = [ "enabled" ] +enabled = [] + +[dependencies] + +[dev-dependencies] +test_tools = { workspace = true } diff --git a/module/blank/paths_tools/License b/module/blank/paths_tools/License new file mode 100644 index 0000000000..6d5ef8559f --- /dev/null +++ b/module/blank/paths_tools/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/blank/paths_tools/Readme.md b/module/blank/paths_tools/Readme.md new file mode 100644 index 0000000000..adbca63b03 --- /dev/null +++ b/module/blank/paths_tools/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: paths_tools +[![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/Modulepaths_toolsPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/Modulepaths_toolsPush.yml) [![docs.rs](https://img.shields.io/docsrs/paths_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/paths_tools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Tools to work with file paths. + + diff --git a/module/blank/paths_tools/src/lib.rs b/module/blank/paths_tools/src/lib.rs new file mode 100644 index 0000000000..716f0aaf83 --- /dev/null +++ b/module/blank/paths_tools/src/lib.rs @@ -0,0 +1,11 @@ +#![ cfg_attr( feature = "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/paths_tools/latest/paths_tools/" ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/blank/paths_tools/tests/inc/basic_test.rs b/module/blank/paths_tools/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/paths_tools/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/paths_tools/tests/inc/mod.rs b/module/blank/paths_tools/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/paths_tools/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/blank/paths_tools/tests/smoke_test.rs b/module/blank/paths_tools/tests/smoke_test.rs new file mode 100644 index 0000000000..663dd6fb9f --- /dev/null +++ b/module/blank/paths_tools/tests/smoke_test.rs @@ -0,0 +1,12 @@ + +#[ test ] +fn local_smoke_test() +{ + ::test_tools::smoke_test_for_local_run(); +} + +#[ test ] +fn published_smoke_test() +{ + ::test_tools::smoke_test_for_published_run(); +} diff --git a/module/blank/paths_tools/tests/tests.rs b/module/blank/paths_tools/tests/tests.rs new file mode 100644 index 0000000000..7900d6181b --- /dev/null +++ b/module/blank/paths_tools/tests/tests.rs @@ -0,0 +1,10 @@ + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use paths_tools as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/blank/rustql/tests/smoke_test.rs b/module/blank/rustql/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/blank/rustql/tests/smoke_test.rs +++ b/module/blank/rustql/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/blank/second_brain/Cargo.toml b/module/blank/second_brain/Cargo.toml new file mode 100644 index 0000000000..1242baec92 --- /dev/null +++ b/module/blank/second_brain/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "second_brain" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/second_brain" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/second_brain" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/second_brain" +description = """ +Tools for second brain. +""" +categories = [ "algorithms", "development-tools" ] +keywords = [ "fundamental", "general-purpose" ] + +[lints] +workspace = true + +[package.metadata.docs.rs] +features = [ "full" ] +all-features = false + +[features] +default = [ "enabled" ] +full = [ "enabled" ] +enabled = [] + +[dependencies] + +[dev-dependencies] +test_tools = { workspace = true } diff --git a/module/blank/second_brain/License b/module/blank/second_brain/License new file mode 100644 index 0000000000..6d5ef8559f --- /dev/null +++ b/module/blank/second_brain/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/blank/second_brain/Readme.md b/module/blank/second_brain/Readme.md new file mode 100644 index 0000000000..8680c3b72a --- /dev/null +++ b/module/blank/second_brain/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: second_brain +[![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/Modulesecond_brainPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/Modulesecond_brainPush.yml) [![docs.rs](https://img.shields.io/docsrs/second_brain?color=e3e8f0&logo=docs.rs)](https://docs.rs/second_brain) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Tools for second brain. + + diff --git a/module/blank/second_brain/src/lib.rs b/module/blank/second_brain/src/lib.rs new file mode 100644 index 0000000000..b2f8ce127d --- /dev/null +++ b/module/blank/second_brain/src/lib.rs @@ -0,0 +1,11 @@ +#![ cfg_attr( feature = "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/second_brain/latest/second_brain/" ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/blank/second_brain/tests/inc/basic_test.rs b/module/blank/second_brain/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/second_brain/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/second_brain/tests/inc/mod.rs b/module/blank/second_brain/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/second_brain/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/blank/second_brain/tests/smoke_test.rs b/module/blank/second_brain/tests/smoke_test.rs new file mode 100644 index 0000000000..663dd6fb9f --- /dev/null +++ b/module/blank/second_brain/tests/smoke_test.rs @@ -0,0 +1,12 @@ + +#[ test ] +fn local_smoke_test() +{ + ::test_tools::smoke_test_for_local_run(); +} + +#[ test ] +fn published_smoke_test() +{ + ::test_tools::smoke_test_for_published_run(); +} diff --git a/module/blank/second_brain/tests/tests.rs b/module/blank/second_brain/tests/tests.rs new file mode 100644 index 0000000000..962e97321e --- /dev/null +++ b/module/blank/second_brain/tests/tests.rs @@ -0,0 +1,10 @@ + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use second_brain as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/blank/w4d/tests/smoke_test.rs b/module/blank/w4d/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/blank/w4d/tests/smoke_test.rs +++ b/module/blank/w4d/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/blank/willbe_old/tests/smoke_test.rs b/module/blank/willbe_old/tests/smoke_test.rs index 8a9c649677..2678ac06fe 100644 --- a/module/blank/willbe_old/tests/smoke_test.rs +++ b/module/blank/willbe_old/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] #[ ignore ] fn published_smoke_test() diff --git a/module/blank/wlang/tests/smoke_test.rs b/module/blank/wlang/tests/smoke_test.rs index fddef25d11..dda3313c2e 100644 --- a/module/blank/wlang/tests/smoke_test.rs +++ b/module/blank/wlang/tests/smoke_test.rs @@ -1,5 +1,5 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] #[ ignore ] fn local_smoke_test() @@ -7,7 +7,7 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/clone_dyn/tests/smoke_test.rs b/module/core/clone_dyn/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/clone_dyn/tests/smoke_test.rs +++ b/module/core/clone_dyn/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/clone_dyn_meta/tests/smoke_test.rs b/module/core/clone_dyn_meta/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/clone_dyn_meta/tests/smoke_test.rs +++ b/module/core/clone_dyn_meta/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/collection_tools/tests/smoke_test.rs b/module/core/collection_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/collection_tools/tests/smoke_test.rs +++ b/module/core/collection_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/data_type/tests/smoke_test.rs b/module/core/data_type/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/data_type/tests/smoke_test.rs +++ b/module/core/data_type/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/derive_tools/tests/smoke_test.rs b/module/core/derive_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/derive_tools/tests/smoke_test.rs +++ b/module/core/derive_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/diagnostics_tools/tests/smoke_test.rs b/module/core/diagnostics_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/diagnostics_tools/tests/smoke_test.rs +++ b/module/core/diagnostics_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/error_tools/tests/smoke_test.rs b/module/core/error_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/error_tools/tests/smoke_test.rs +++ b/module/core/error_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/for_each/tests/smoke_test.rs b/module/core/for_each/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/for_each/tests/smoke_test.rs +++ b/module/core/for_each/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/former/tests/smoke_test.rs b/module/core/former/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/former/tests/smoke_test.rs +++ b/module/core/former/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/former_meta/tests/smoke_test.rs b/module/core/former_meta/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/former_meta/tests/smoke_test.rs +++ b/module/core/former_meta/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/former_types/tests/smoke_test.rs b/module/core/former_types/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/former_types/tests/smoke_test.rs +++ b/module/core/former_types/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/fs_tools/tests/smoke_test.rs b/module/core/fs_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/fs_tools/tests/smoke_test.rs +++ b/module/core/fs_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/implements/tests/smoke_test.rs b/module/core/implements/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/implements/tests/smoke_test.rs +++ b/module/core/implements/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/impls_index/tests/smoke_test.rs b/module/core/impls_index/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/impls_index/tests/smoke_test.rs +++ b/module/core/impls_index/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/include_md/tests/smoke_test.rs b/module/core/include_md/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/include_md/tests/smoke_test.rs +++ b/module/core/include_md/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/inspect_type/tests/smoke_test.rs b/module/core/inspect_type/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/inspect_type/tests/smoke_test.rs +++ b/module/core/inspect_type/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/is_slice/tests/smoke_test.rs b/module/core/is_slice/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/is_slice/tests/smoke_test.rs +++ b/module/core/is_slice/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/iter_tools/tests/smoke_test.rs b/module/core/iter_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/iter_tools/tests/smoke_test.rs +++ b/module/core/iter_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/macro_tools/tests/smoke_test.rs b/module/core/macro_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/macro_tools/tests/smoke_test.rs +++ b/module/core/macro_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/mem_tools/tests/smoke_test.rs b/module/core/mem_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/mem_tools/tests/smoke_test.rs +++ b/module/core/mem_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/meta_tools/tests/smoke_test.rs b/module/core/meta_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/meta_tools/tests/smoke_test.rs +++ b/module/core/meta_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/mod_interface/tests/smoke_test.rs b/module/core/mod_interface/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/mod_interface/tests/smoke_test.rs +++ b/module/core/mod_interface/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/mod_interface_meta/tests/smoke_test.rs b/module/core/mod_interface_meta/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/mod_interface_meta/tests/smoke_test.rs +++ b/module/core/mod_interface_meta/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/process_tools/tests/smoke_test.rs b/module/core/process_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/process_tools/tests/smoke_test.rs +++ b/module/core/process_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/program_tools/tests/smoke_test.rs b/module/core/program_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/program_tools/tests/smoke_test.rs +++ b/module/core/program_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/proper_path_tools/tests/smoke_test.rs b/module/core/proper_path_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/proper_path_tools/tests/smoke_test.rs +++ b/module/core/proper_path_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/reflect_tools/tests/smoke_test.rs b/module/core/reflect_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/reflect_tools/tests/smoke_test.rs +++ b/module/core/reflect_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/strs_tools/tests/smoke_test.rs b/module/core/strs_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/strs_tools/tests/smoke_test.rs +++ b/module/core/strs_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/test_tools/tests/smoke_test.rs b/module/core/test_tools/tests/smoke_test.rs index 8d83b8d34e..d05a55b089 100644 --- a/module/core/test_tools/tests/smoke_test.rs +++ b/module/core/test_tools/tests/smoke_test.rs @@ -1,5 +1,5 @@ -// #[ cfg( feature = "default" ) ] + #[ cfg( feature = "enabled" ) ] #[ cfg( not( feature = "no_std" ) ) ] #[ test ] @@ -8,7 +8,7 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ cfg( feature = "enabled" ) ] #[ cfg( not( feature = "no_std" ) ) ] #[ test ] diff --git a/module/core/time_tools/tests/smoke_test.rs b/module/core/time_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/time_tools/tests/smoke_test.rs +++ b/module/core/time_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/typing_tools/tests/smoke_test.rs b/module/core/typing_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/typing_tools/tests/smoke_test.rs +++ b/module/core/typing_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/variadic_from/tests/smoke_test.rs b/module/core/variadic_from/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/variadic_from/tests/smoke_test.rs +++ b/module/core/variadic_from/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/core/wtools/tests/smoke_test.rs b/module/core/wtools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/core/wtools/tests/smoke_test.rs +++ b/module/core/wtools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/move/assistant/Cargo.toml b/module/move/assistant/Cargo.toml new file mode 100644 index 0000000000..18a487c82e --- /dev/null +++ b/module/move/assistant/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "assistant" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/assistant" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/assistant" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/assistant" +description = """ +Assist AI in writing code. +""" +categories = [ "algorithms", "development-tools" ] +keywords = [ "fundamental", "general-purpose" ] + +[lints] +workspace = true + +[package.metadata.docs.rs] +features = [ "full" ] +all-features = false + +[features] +default = [ "enabled" ] +full = [ "enabled" ] +enabled = [] + +[dependencies] + +[dev-dependencies] +test_tools = { workspace = true } diff --git a/module/move/assistant/License b/module/move/assistant/License new file mode 100644 index 0000000000..6d5ef8559f --- /dev/null +++ b/module/move/assistant/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/move/assistant/Readme.md b/module/move/assistant/Readme.md new file mode 100644 index 0000000000..0e9402c634 --- /dev/null +++ b/module/move/assistant/Readme.md @@ -0,0 +1,33 @@ + + +# 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. + + diff --git a/module/move/assistant/src/lib.rs b/module/move/assistant/src/lib.rs new file mode 100644 index 0000000000..00e36b8970 --- /dev/null +++ b/module/move/assistant/src/lib.rs @@ -0,0 +1,11 @@ +#![ cfg_attr( feature = "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/assistant/latest/assistant/" ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/move/assistant/tests/inc/basic_test.rs b/module/move/assistant/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/move/assistant/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/move/assistant/tests/inc/mod.rs b/module/move/assistant/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/move/assistant/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/move/assistant/tests/smoke_test.rs b/module/move/assistant/tests/smoke_test.rs new file mode 100644 index 0000000000..663dd6fb9f --- /dev/null +++ b/module/move/assistant/tests/smoke_test.rs @@ -0,0 +1,12 @@ + +#[ test ] +fn local_smoke_test() +{ + ::test_tools::smoke_test_for_local_run(); +} + +#[ test ] +fn published_smoke_test() +{ + ::test_tools::smoke_test_for_published_run(); +} diff --git a/module/move/assistant/tests/tests.rs b/module/move/assistant/tests/tests.rs new file mode 100644 index 0000000000..c94c4d074f --- /dev/null +++ b/module/move/assistant/tests/tests.rs @@ -0,0 +1,10 @@ + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use assistant as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/move/crates_tools/tests/smoke_test.rs b/module/move/crates_tools/tests/smoke_test.rs index 781e173398..7827ff5737 100644 --- a/module/move/crates_tools/tests/smoke_test.rs +++ b/module/move/crates_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ ignore ] #[ test ] fn published_smoke_test() diff --git a/module/move/graphs_tools/tests/smoke_test.rs b/module/move/graphs_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/move/graphs_tools/tests/smoke_test.rs +++ b/module/move/graphs_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/move/plot_interface/tests/smoke_test.rs b/module/move/plot_interface/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/move/plot_interface/tests/smoke_test.rs +++ b/module/move/plot_interface/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/move/refiner/tests/smoke_test.rs b/module/move/refiner/tests/smoke_test.rs index 7853994b3a..3499e82321 100644 --- a/module/move/refiner/tests/smoke_test.rs +++ b/module/move/refiner/tests/smoke_test.rs @@ -1,5 +1,5 @@ -// #[ cfg( feature = "default" ) ] + #[ ignore ] #[ test ] fn local_smoke_test() @@ -7,7 +7,7 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/move/sqlx_query/tests/smoke_test.rs b/module/move/sqlx_query/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/move/sqlx_query/tests/smoke_test.rs +++ b/module/move/sqlx_query/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/move/wca/tests/smoke_test.rs b/module/move/wca/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/move/wca/tests/smoke_test.rs +++ b/module/move/wca/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/move/willbe/tests/smoke_test.rs b/module/move/willbe/tests/smoke_test.rs index febf7e83a0..dd681c20c1 100644 --- a/module/move/willbe/tests/smoke_test.rs +++ b/module/move/willbe/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/move/wplot/tests/smoke_test.rs b/module/move/wplot/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/move/wplot/tests/smoke_test.rs +++ b/module/move/wplot/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/postponed/_video_experiment/tests/smoke_test.rs b/module/postponed/_video_experiment/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/postponed/_video_experiment/tests/smoke_test.rs +++ b/module/postponed/_video_experiment/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/postponed/automata_tools/tests/smoke_test.rs b/module/postponed/automata_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/postponed/automata_tools/tests/smoke_test.rs +++ b/module/postponed/automata_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/postponed/non_std/tests/smoke_test.rs b/module/postponed/non_std/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/postponed/non_std/tests/smoke_test.rs +++ b/module/postponed/non_std/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/postponed/std_tools/tests/smoke_test.rs b/module/postponed/std_tools/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/postponed/std_tools/tests/smoke_test.rs +++ b/module/postponed/std_tools/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/postponed/std_x/tests/smoke_test.rs b/module/postponed/std_x/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/postponed/std_x/tests/smoke_test.rs +++ b/module/postponed/std_x/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/postponed/type_constructor/tests/smoke_test.rs b/module/postponed/type_constructor/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/postponed/type_constructor/tests/smoke_test.rs +++ b/module/postponed/type_constructor/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/postponed/wautomata/tests/smoke_test.rs b/module/postponed/wautomata/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/postponed/wautomata/tests/smoke_test.rs +++ b/module/postponed/wautomata/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/postponed/wpublisher/tests/smoke_test.rs b/module/postponed/wpublisher/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/postponed/wpublisher/tests/smoke_test.rs +++ b/module/postponed/wpublisher/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/step/meta/tests/smoke_test.rs b/module/step/meta/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/step/meta/tests/smoke_test.rs +++ b/module/step/meta/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/template/template_alias/tests/smoke_test.rs b/module/template/template_alias/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/template/template_alias/tests/smoke_test.rs +++ b/module/template/template_alias/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/template/template_blank/Cargo.toml.template b/module/template/template_blank/Cargo.toml.template index 26aa549abe..1cc7fb96d0 100644 --- a/module/template/template_blank/Cargo.toml.template +++ b/module/template/template_blank/Cargo.toml.template @@ -26,8 +26,6 @@ all-features = false [features] default = [ "enabled" ] full = [ "enabled" ] -no_std = [] -use_alloc = [ "no_std" ] enabled = [] [dependencies] diff --git a/module/template/template_blank/tests/smoke_test.rs b/module/template/template_blank/tests/smoke_test.rs index 7fd288e61d..663dd6fb9f 100644 --- a/module/template/template_blank/tests/smoke_test.rs +++ b/module/template/template_blank/tests/smoke_test.rs @@ -1,12 +1,10 @@ -// #[ cfg( feature = "default" ) ] #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] #[ test ] fn published_smoke_test() { diff --git a/module/template/template_procedural_macro/tests/smoke_test.rs b/module/template/template_procedural_macro/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/template/template_procedural_macro/tests/smoke_test.rs +++ b/module/template/template_procedural_macro/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/template/template_procedural_macro_meta/tests/smoke_test.rs b/module/template/template_procedural_macro_meta/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/template/template_procedural_macro_meta/tests/smoke_test.rs +++ b/module/template/template_procedural_macro_meta/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { diff --git a/module/template/template_procedural_macro_runtime/tests/smoke_test.rs b/module/template/template_procedural_macro_runtime/tests/smoke_test.rs index 7fd288e61d..828e9b016b 100644 --- a/module/template/template_procedural_macro_runtime/tests/smoke_test.rs +++ b/module/template/template_procedural_macro_runtime/tests/smoke_test.rs @@ -1,12 +1,12 @@ -// #[ cfg( feature = "default" ) ] + #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } -// #[ cfg( feature = "default" ) ] + #[ test ] fn published_smoke_test() { From fc251c8a206aa6c83c16885dd0a4ad4c70996108 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 09:35:27 +0300 Subject: [PATCH 002/143] assistant: initial setup --- .gitignore | 3 +-- module/move/assistant/Cargo.toml | 3 ++- module/move/assistant/api/list.http | 3 +++ module/move/assistant/src/bin.rs | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 module/move/assistant/api/list.http create mode 100644 module/move/assistant/src/bin.rs diff --git a/.gitignore b/.gitignore index 8cba9a9a97..5a51787e86 100755 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,6 @@ !/.circleci !/.* -/build -/builder /binding /target /node_modules @@ -14,6 +12,7 @@ /.vscode /_* +.env _key _data target diff --git a/module/move/assistant/Cargo.toml b/module/move/assistant/Cargo.toml index 18a487c82e..e8472594bc 100644 --- a/module/move/assistant/Cargo.toml +++ b/module/move/assistant/Cargo.toml @@ -26,9 +26,10 @@ all-features = false [features] default = [ "enabled" ] full = [ "enabled" ] -enabled = [] +enabled = [ "former/enabled" ] [dependencies] +former = { workspace = true, features = [ "full" ] } [dev-dependencies] test_tools = { workspace = true } diff --git a/module/move/assistant/api/list.http b/module/move/assistant/api/list.http new file mode 100644 index 0000000000..32a3263f5a --- /dev/null +++ b/module/move/assistant/api/list.http @@ -0,0 +1,3 @@ +get https://api.openai.com/v1/models +Authorization: Bearer {{openai_token}} +# Content-Type: application/json diff --git a/module/move/assistant/src/bin.rs b/module/move/assistant/src/bin.rs new file mode 100644 index 0000000000..3cdadf15d7 --- /dev/null +++ b/module/move/assistant/src/bin.rs @@ -0,0 +1,14 @@ +#![ cfg_attr( feature = "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/assistant/latest/assistant/" ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Entry point. +#[ cfg( feature = "enabled" ) ] +pub fn main() +{ + + + +} From d5723ed61c7990e2fc699f34ba60301be0e24fba Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 16:29:32 +0300 Subject: [PATCH 003/143] experimenting --- module/move/assistant/Cargo.toml | 3 + module/move/assistant/src/lib.rs | 36 ++++++++- module/move/assistant/src/{bin.rs => main.rs} | 20 ++++- module/move/assistant/src/print.rs | 81 +++++++++++++++++++ module/move/assistant/src/reflect.rs | 15 ++++ module/move/assistant/tests/inc/basic_test.rs | 7 -- .../move/assistant/tests/inc/fields_test.rs | 69 ++++++++++++++++ module/move/assistant/tests/inc/mod.rs | 2 +- 8 files changed, 219 insertions(+), 14 deletions(-) rename module/move/assistant/src/{bin.rs => main.rs} (59%) create mode 100644 module/move/assistant/src/print.rs create mode 100644 module/move/assistant/src/reflect.rs delete mode 100644 module/move/assistant/tests/inc/basic_test.rs create mode 100644 module/move/assistant/tests/inc/fields_test.rs diff --git a/module/move/assistant/Cargo.toml b/module/move/assistant/Cargo.toml index e8472594bc..3626006c1c 100644 --- a/module/move/assistant/Cargo.toml +++ b/module/move/assistant/Cargo.toml @@ -30,6 +30,9 @@ enabled = [ "former/enabled" ] [dependencies] former = { workspace = true, features = [ "full" ] } +openai-api-rs = { version = "4.0.9" } +tokio = { version = "1", features = ["full"] } +dotenv = "0.15" [dev-dependencies] test_tools = { workspace = true } diff --git a/module/move/assistant/src/lib.rs b/module/move/assistant/src/lib.rs index 00e36b8970..67b1447653 100644 --- a/module/move/assistant/src/lib.rs +++ b/module/move/assistant/src/lib.rs @@ -4,8 +4,38 @@ #![ doc( html_root_url = "https://docs.rs/assistant/latest/assistant/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -/// Function description. -#[ cfg( feature = "enabled" ) ] -pub fn f1() +pub use openai_api_rs::v1:: { + api::Client, + assistant::AssistantObject, +}; + +use std:: +{ + env, + error::Error, +}; + +use former::Former; + +/// Reflections. +pub mod reflect; +pub use reflect::*; +/// Nice print. +pub mod print; +pub use print::*; + +/// Options for configuring the OpenAI API client. +#[ derive( Former, Debug ) ] +pub struct ClientOptions +{ + /// The API key for authenticating with the OpenAI API. + pub api_key : Option< String >, +} + +/// Creates a new OpenAI API client using the API key from the environment variable `OPENAI_API_KEY`. +pub fn client() -> Result< Client, Box< dyn Error > > +{ + let api_key = env::var( "OPENAI_API_KEY" )?; + Ok( Client::new( api_key ) ) } diff --git a/module/move/assistant/src/bin.rs b/module/move/assistant/src/main.rs similarity index 59% rename from module/move/assistant/src/bin.rs rename to module/move/assistant/src/main.rs index 3cdadf15d7..ad03e3549a 100644 --- a/module/move/assistant/src/bin.rs +++ b/module/move/assistant/src/main.rs @@ -4,11 +4,25 @@ #![ doc( html_root_url = "https://docs.rs/assistant/latest/assistant/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -/// Entry point. -#[ cfg( feature = "enabled" ) ] -pub fn main() +use std:: { + env, + error::Error, +}; +use dotenv::dotenv; +use assistant:: +{ + client, +}; +#[ tokio::main ] +async fn main() -> Result< (), Box< dyn Error > > +{ + dotenv().ok(); + let client = client()?; + let assistants = client.list_assistant( None, None, None, None )?; + println!( "Assistants: {:?}", assistants.data ); + Ok( () ) } diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs new file mode 100644 index 0000000000..3944a2a078 --- /dev/null +++ b/module/move/assistant/src/print.rs @@ -0,0 +1,81 @@ + +use super::*; +use core::fmt; +use former::Former; + +// /// +// /// A trait for converting any type that implements `Debug` into a `String`. +// /// +// pub trait DebugToString +// { +// /// Converts the value into a `String` using its `Debug` representation. +// /// +// /// # Returns +// /// A `String` containing the `Debug` representation of the value. +// fn debug_to_string( &self ) -> String; +// } +// +// impl< T > DebugToString for T +// where +// T : fmt::Debug, +// { +// /// Converts the value into a `String` using its `Debug` representation. +// /// +// /// # Returns +// /// +// /// A `String` containing the `Debug` representation of the value. +// /// +// fn debug_to_string( &self ) -> String +// { +// format!( "{:?}", self ) +// } +// } + +/// Struct to hold table options. +#[ derive( Debug, Default, Former ) ] +pub struct TableOptions +{ + /// Optional header row for the table. + pub header : Option< Vec< String > >, + /// Optional delimiter for separating table columns. + pub delimiter : Option< String >, +} + +impl TableOptions +{ + + /// Creates a new instance of `TableOptions`. + pub fn new( header : Option< Vec< String > >, delimiter : Option< String > ) -> Self + { + TableOptions { header, delimiter } + } + + /// Function to print a table based on the iterator of items implementing `Fields` trait. + pub fn perform< I, F, K, E >( &self, iter : I ) + where + I : Iterator< Item = F >, + F : Fields< K, E >, + K : fmt::Debug, + E : fmt::Debug, + { + let delimiter = self.delimiter.clone().unwrap_or_else( || ",".to_string() ); + + // Print the header if provided + if let Some( header ) = &self.header + { + println!( "{}", header.join( &delimiter ) ); + } + + // Print each row + for item in iter + { + let fields : Vec< String > = item + .fields() + .map( |field| format!( "{:?}", field ) ) + .collect(); + + println!( "{}", fields.join( &delimiter ) ); + } + } + +} diff --git a/module/move/assistant/src/reflect.rs b/module/move/assistant/src/reflect.rs new file mode 100644 index 0000000000..abd27d0199 --- /dev/null +++ b/module/move/assistant/src/reflect.rs @@ -0,0 +1,15 @@ + + +// use core::fmt; + +/// A trait for iterating over all fields of a specified type within an entity. +/// +/// # Type Parameters +/// +/// - `K`: The key type. +/// - `E`: The element type. +pub trait Fields< K, E > +{ + /// Returns an iterator over all fields of the specified type within the entity. + fn fields( &self ) -> impl Iterator< Item = ( K, E ) > + Clone; +} diff --git a/module/move/assistant/tests/inc/basic_test.rs b/module/move/assistant/tests/inc/basic_test.rs deleted file mode 100644 index 60c9a81cfb..0000000000 --- a/module/move/assistant/tests/inc/basic_test.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[ allow( unused_imports ) ] -use super::*; - -#[ test ] -fn basic() -{ -} diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs new file mode 100644 index 0000000000..fe31052336 --- /dev/null +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -0,0 +1,69 @@ +#[ allow( unused_imports ) ] +use super::*; + +use assistant:: +{ + Fields, +}; + +use std:: +{ + collections::HashMap, +}; + +/// Struct representing a test object with various fields. +pub struct TestObject +{ + pub id : String, + pub created_at : i64, + pub file_ids : Vec< String >, + pub tools : Option< Vec< HashMap< String, String > > >, +} + +impl Fields< &'static str, String > for TestObject +{ + fn fields( &self ) -> impl Iterator< Item = ( &'static str, String ) > + Clone + { + let mut vec : Vec< ( &'static str, String ) > = Vec::new(); + + vec.push( ( "id", self.id.clone() ) ); + vec.push( ( "created_at", self.created_at.to_string() ) ); + vec.push( ( "file_ids", format!( "{:?}", self.file_ids ) ) ); + + if let Some( tools ) = &self.tools + { + vec.push( ( "tools", format!( "{:?}", tools ) ) ); + } + + vec.into_iter() + } +} + +#[ test ] +fn basic() +{ + let test_object = TestObject + { + id : "12345".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".to_string() ], + tools : Some + ( + vec! + [{ + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + }] + ), + }; + + let fields: Vec<( &'static str, String )> = test_object.fields().collect(); + + assert_eq!( fields.len(), 4 ); + assert_eq!( fields[ 0 ], ( "id", "12345".to_string() ) ); + assert_eq!( fields[ 1 ], ( "created_at", "1627845583".to_string() ) ); + assert_eq!( fields[ 2 ], ( "file_ids", "[\"file1\", \"file2\"]".to_string() ) ); + assert_eq!( fields[ 3 ].0, "tools" ); +} \ No newline at end of file diff --git a/module/move/assistant/tests/inc/mod.rs b/module/move/assistant/tests/inc/mod.rs index dde9de6f94..fbbbbb931e 100644 --- a/module/move/assistant/tests/inc/mod.rs +++ b/module/move/assistant/tests/inc/mod.rs @@ -1,4 +1,4 @@ #[ allow( unused_imports ) ] use super::*; -mod basic_test; +mod fields_test; From f44afa97fc8d231906a5d49ec95e6fff9ab31fbd Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 16:51:34 +0300 Subject: [PATCH 004/143] experimenting --- module/move/assistant/src/print.rs | 87 ++++++++++--------- module/move/assistant/tests/inc/mod.rs | 2 + module/move/assistant/tests/inc/print_test.rs | 47 ++++++++++ 3 files changed, 94 insertions(+), 42 deletions(-) create mode 100644 module/move/assistant/tests/inc/print_test.rs diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 3944a2a078..e7bc3bb024 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -3,53 +3,21 @@ use super::*; use core::fmt; use former::Former; -// /// -// /// A trait for converting any type that implements `Debug` into a `String`. -// /// -// pub trait DebugToString -// { -// /// Converts the value into a `String` using its `Debug` representation. -// /// -// /// # Returns -// /// A `String` containing the `Debug` representation of the value. -// fn debug_to_string( &self ) -> String; -// } -// -// impl< T > DebugToString for T -// where -// T : fmt::Debug, -// { -// /// Converts the value into a `String` using its `Debug` representation. -// /// -// /// # Returns -// /// -// /// A `String` containing the `Debug` representation of the value. -// /// -// fn debug_to_string( &self ) -> String -// { -// format!( "{:?}", self ) -// } -// } - -/// Struct to hold table options. +/// Struct to hold options to print data as table. #[ derive( Debug, Default, Former ) ] pub struct TableOptions { /// Optional header row for the table. pub header : Option< Vec< String > >, + /// Rows with data for the table. + /// Its length should be equal to header length. + pub rows : Vec< String >, /// Optional delimiter for separating table columns. pub delimiter : Option< String >, } impl TableOptions { - - /// Creates a new instance of `TableOptions`. - pub fn new( header : Option< Vec< String > >, delimiter : Option< String > ) -> Self - { - TableOptions { header, delimiter } - } - /// Function to print a table based on the iterator of items implementing `Fields` trait. pub fn perform< I, F, K, E >( &self, iter : I ) where @@ -66,16 +34,51 @@ impl TableOptions println!( "{}", header.join( &delimiter ) ); } - // Print each row + // Collect rows + let mut all_rows : Vec< Vec< String > > = Vec::new(); for item in iter { let fields : Vec< String > = item - .fields() - .map( |field| format!( "{:?}", field ) ) - .collect(); + .fields() + .map( | ( key, value ) | format!( "{:?}: {:?}", key, value ) ) + .collect(); + all_rows.push( fields ); + } - println!( "{}", fields.join( &delimiter ) ); + // Find the maximum width for each column + let mut col_widths : Vec< usize > = Vec::new(); + if let Some( header ) = &self.header + { + for col in header + { + col_widths.push( col.len() ); + } + } + + for row in &all_rows + { + for ( i, col ) in row.iter().enumerate() + { + if col_widths.len() <= i + { + col_widths.push( col.len() ); + } + else if col.len() > col_widths[ i ] + { + col_widths[ i ] = col.len(); + } + } } - } + // Print rows with proper alignment + for row in all_rows + { + let formatted_row : Vec< String > = row + .iter() + .enumerate() + .map( | ( i, col ) | format!( "{:width$}", col, width = col_widths[ i ] ) ) + .collect(); + println!( "{}", formatted_row.join( &delimiter ) ); + } + } } diff --git a/module/move/assistant/tests/inc/mod.rs b/module/move/assistant/tests/inc/mod.rs index fbbbbb931e..707889e650 100644 --- a/module/move/assistant/tests/inc/mod.rs +++ b/module/move/assistant/tests/inc/mod.rs @@ -2,3 +2,5 @@ use super::*; mod fields_test; +mod print_test; + diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs new file mode 100644 index 0000000000..32f7916722 --- /dev/null +++ b/module/move/assistant/tests/inc/print_test.rs @@ -0,0 +1,47 @@ +#[ allow( unused_imports ) ] +use super::*; + +use assistant:: +{ + Fields, +}; + +use std:: +{ + collections::HashMap, +}; + +/// Struct representing a test object with various fields. +pub struct TestObject +{ + pub id : String, + pub created_at : i64, + pub file_ids : Vec< String >, + pub tools : Option< Vec< HashMap< String, String > > >, +} + +impl Fields< &'static str, String > for TestObject +{ + fn fields( &self ) -> impl Iterator< Item = ( &'static str, String ) > + Clone + { + let mut vec : Vec< ( &'static str, String ) > = Vec::new(); + + vec.push( ( "id", self.id.clone() ) ); + vec.push( ( "created_at", self.created_at.to_string() ) ); + vec.push( ( "file_ids", format!( "{:?}", self.file_ids ) ) ); + + if let Some( tools ) = &self.tools + { + vec.push( ( "tools", format!( "{:?}", tools ) ) ); + } + + vec.into_iter() + } +} + +#[ test ] +fn basic() +{ + + +} \ No newline at end of file From 0662842138e2b0145080792fc7090d19e8a16339 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 17:28:46 +0300 Subject: [PATCH 005/143] experimenting --- module/move/assistant/src/print.rs | 92 ++++++++++++++++++++++++---- module/move/assistant/src/reflect.rs | 18 ++++++ 2 files changed, 99 insertions(+), 11 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index e7bc3bb024..b0f5e352d0 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -3,6 +3,14 @@ use super::*; use core::fmt; use former::Former; +/// Struct to hold options to print data as table. +#[ derive( Debug, Default, Former ) ] +pub struct Styles +{ + /// Optional delimiter for separating table columns. + pub delimiter : Option< String >, +} + /// Struct to hold options to print data as table. #[ derive( Debug, Default, Former ) ] pub struct TableOptions @@ -12,26 +20,86 @@ pub struct TableOptions /// Rows with data for the table. /// Its length should be equal to header length. pub rows : Vec< String >, - /// Optional delimiter for separating table columns. - pub delimiter : Option< String >, + /// Styles. + pub styles : Styles, +} + +/// A trait for iterating over all fields of a specified type within an entity to print it. +pub trait TableRows< Row, Cell > +where + Row : RowFields< Cell >, + Cell : fmt::Debug, +{ + /// Returns an iterator over all fields of the specified type within the entity. + fn rows( &self ) -> impl Iterator< Item = Row > + Clone; +} + +/// A trait for iterating over all fields of a specified type within an entity to print it. +pub trait RowFields< Cell > +where + Cell : fmt::Debug, +{ + /// Returns an iterator over all fields of the specified type within the entity. + fn row_fields( &self ) -> impl Iterator< Item = Cell > + Clone; +} + +/// Trait returning headers of a table if any. +pub trait TableHeader< Title > +where + Title : fmt::Debug, +{ + /// Returns an iterator over all fields of the specified type within the entity. + fn header( &self ) -> Option< impl Iterator< Item = Title > + Clone >; } -impl TableOptions +// impl TableHeader for I +// where +// I : Fields< K, E >, +// { +// } + +/// Struct for formatting tables. +pub struct Formatter< 'a > +{ + buf : &'a mut dyn fmt::Write, + styles : Styles, +} + +impl< 'a > Formatter< 'a > +{ + /// Creates a new `Formatter` with the given buffer and delimiter. + pub fn new( buf : &'a mut dyn fmt::Write, styles : Styles ) -> Self + { + Formatter { buf, styles } + } +} + +/// A trait for formatting tables. +pub trait TableFormatter { - /// Function to print a table based on the iterator of items implementing `Fields` trait. - pub fn perform< I, F, K, E >( &self, iter : I ) + fn fmt< I, F, K, E >( &self, f : &mut Formatter<'_>, iter : I ) -> fmt::Result + where + I : Iterator< Item = F >, + F : Fields< K, E >, + K : fmt::Debug, + E : fmt::Debug; +} + +impl TableFormatter for TableOptions +{ + fn fmt< I, F, K, E >( &self, f : &mut Formatter<'_>, iter : I ) -> fmt::Result where I : Iterator< Item = F >, F : Fields< K, E >, K : fmt::Debug, E : fmt::Debug, { - let delimiter = self.delimiter.clone().unwrap_or_else( || ",".to_string() ); + let delimiter = &self.styles.delimiter.clone().unwrap_or_else( || ",".to_string() ); - // Print the header if provided + // Write the header if provided if let Some( header ) = &self.header { - println!( "{}", header.join( &delimiter ) ); + writeln!( f.buf, "{}", header.join( delimiter ) )?; } // Collect rows @@ -70,7 +138,7 @@ impl TableOptions } } - // Print rows with proper alignment + // Write rows with proper alignment for row in all_rows { let formatted_row : Vec< String > = row @@ -78,7 +146,9 @@ impl TableOptions .enumerate() .map( | ( i, col ) | format!( "{:width$}", col, width = col_widths[ i ] ) ) .collect(); - println!( "{}", formatted_row.join( &delimiter ) ); + writeln!( f.buf, "{}", formatted_row.join( delimiter ) )?; } + + Ok(()) } -} +} \ No newline at end of file diff --git a/module/move/assistant/src/reflect.rs b/module/move/assistant/src/reflect.rs index abd27d0199..d22391d1dc 100644 --- a/module/move/assistant/src/reflect.rs +++ b/module/move/assistant/src/reflect.rs @@ -13,3 +13,21 @@ pub trait Fields< K, E > /// Returns an iterator over all fields of the specified type within the entity. fn fields( &self ) -> impl Iterator< Item = ( K, E ) > + Clone; } + +/// Trait returning name of type of variable. +pub trait TypeName +{ + /// Return name of type of variable. + fn type_name( &self ) -> &'static str; +} + +impl< T > TypeName for T +where + T : ?Sized, +{ + #[ inline( always ) ] + fn type_name( &self ) -> &'static str + { + ::core::any::type_name_of_val( self ) + } +} From 457b306f9ba54e2202e765151c58625bc23b2fa8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 18:11:41 +0300 Subject: [PATCH 006/143] experimenting --- module/move/assistant/src/print.rs | 165 ++++++++++++++++------------- 1 file changed, 90 insertions(+), 75 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index b0f5e352d0..7db0f11335 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -3,44 +3,34 @@ use super::*; use core::fmt; use former::Former; -/// Struct to hold options to print data as table. -#[ derive( Debug, Default, Former ) ] -pub struct Styles -{ - /// Optional delimiter for separating table columns. - pub delimiter : Option< String >, -} +// == -/// Struct to hold options to print data as table. -#[ derive( Debug, Default, Former ) ] -pub struct TableOptions +// pub type Iterator2< Item > = Iterator< Item = Item > + ExactSizeIterator + Clone; + +/// A trait for iterating over all rows of a table. +pub trait TableSize { - /// Optional header row for the table. - pub header : Option< Vec< String > >, - /// Rows with data for the table. - /// Its length should be equal to header length. - pub rows : Vec< String >, - /// Styles. - pub styles : Styles, + /// Returns size of a table. + fn size( &self ) -> [ usize ; 2 ]; } -/// A trait for iterating over all fields of a specified type within an entity to print it. +/// A trait for iterating over all rows of a table. pub trait TableRows< Row, Cell > where - Row : RowFields< Cell >, + Row : Cells< Cell >, Cell : fmt::Debug, { - /// Returns an iterator over all fields of the specified type within the entity. - fn rows( &self ) -> impl Iterator< Item = Row > + Clone; + /// Returns an iterator over all rows of the table. + fn rows( &self ) -> impl Iterator< Item = Row > + ExactSizeIterator + Clone; } -/// A trait for iterating over all fields of a specified type within an entity to print it. -pub trait RowFields< Cell > +/// A trait for iterating over all cells of a row. +pub trait Cells< Cell > where Cell : fmt::Debug, { - /// Returns an iterator over all fields of the specified type within the entity. - fn row_fields( &self ) -> impl Iterator< Item = Cell > + Clone; + /// Returns an iterator over all cells of the row. + fn cells( &self ) -> impl Iterator< Item = Cell > + ExactSizeIterator + Clone; } /// Trait returning headers of a table if any. @@ -49,14 +39,31 @@ where Title : fmt::Debug, { /// Returns an iterator over all fields of the specified type within the entity. - fn header( &self ) -> Option< impl Iterator< Item = Title > + Clone >; + fn header( &self ) -> Option< impl Iterator< Item = Title > + ExactSizeIterator + Clone >; } -// impl TableHeader for I -// where -// I : Fields< K, E >, -// { -// } +// == + +/// Struct to hold options to print data as table. +#[ derive( Debug, Default, Former ) ] +pub struct Styles +{ + /// Delimiter for separating table columns. + pub separator : String, +} + +/// Struct to hold options to print data as table. +#[ derive( Debug, Default, Former ) ] +pub struct TableOptions +{ + /// Optional header row for the table. + pub header : Option< Vec< String > >, + /// Rows with data for the table. + /// Its length should be equal to header length. + pub rows : Vec< String >, + /// Styles. + pub styles : Styles, +} /// Struct for formatting tables. pub struct Formatter< 'a > @@ -67,7 +74,7 @@ pub struct Formatter< 'a > impl< 'a > Formatter< 'a > { - /// Creates a new `Formatter` with the given buffer and delimiter. + /// Creates a new `Formatter` with the given buffer and separator. pub fn new( buf : &'a mut dyn fmt::Write, styles : Styles ) -> Self { Formatter { buf, styles } @@ -75,65 +82,73 @@ impl< 'a > Formatter< 'a > } /// A trait for formatting tables. -pub trait TableFormatter -{ - fn fmt< I, F, K, E >( &self, f : &mut Formatter<'_>, iter : I ) -> fmt::Result - where - I : Iterator< Item = F >, - F : Fields< K, E >, - K : fmt::Debug, - E : fmt::Debug; -} - -impl TableFormatter for TableOptions +pub trait TableFormatter< Row, Cell, Title > +where + Self : TableRows< Row, Cell >, + Self : TableHeader< Title >, + Self : TableSize, + Row : Cells< Cell >, + Title : fmt::Debug, + Cell : fmt::Debug, { - fn fmt< I, F, K, E >( &self, f : &mut Formatter<'_>, iter : I ) -> fmt::Result - where - I : Iterator< Item = F >, - F : Fields< K, E >, - K : fmt::Debug, - E : fmt::Debug, + fn fmt( &self, f : &mut Formatter< '_ > ) -> fmt::Result { - let delimiter = &self.styles.delimiter.clone().unwrap_or_else( || ",".to_string() ); + let size = self.size(); + let mut col_widths : Vec< usize > = vec![ 0 ; size[ 1 ] ]; + let separator = &f.styles.separator; // Write the header if provided - if let Some( header ) = &self.header + if let Some( header ) = self.header() { - writeln!( f.buf, "{}", header.join( delimiter ) )?; + let mut first = true; + let mut i = 0; + for title in header + { + if !first + { + write!( f.buf, "{}", separator )?; + } + col_widths[ i ] = format!( "{:?}", title ).len(); + // zzz : avoid extra allocation of memory + write!( f.buf, "{:?}", title )?; + first = false; + } + writeln!( f.buf )?; } // Collect rows let mut all_rows : Vec< Vec< String > > = Vec::new(); - for item in iter + for row in self.rows() { - let fields : Vec< String > = item - .fields() - .map( | ( key, value ) | format!( "{:?}: {:?}", key, value ) ) - .collect(); + let fields : Vec< String > = row + .cells() + // .map( | ( key, value ) | format!( "{:?}: {:?}", key, value ) ) + .map( | e | format!( "{:?}", e ) ) + .collect(); all_rows.push( fields ); } - // Find the maximum width for each column - let mut col_widths : Vec< usize > = Vec::new(); - if let Some( header ) = &self.header - { - for col in header - { - col_widths.push( col.len() ); - } - } + // // Find the maximum width for each column + // let mut col_widths : Vec< usize > = Vec::new(); + // if let Some( header ) = self.header() + // { + // for col in header + // { + // col_widths.push( col.len() ); + // } + // } for row in &all_rows { - for ( i, col ) in row.iter().enumerate() + for ( i, cell ) in row.iter().enumerate() { if col_widths.len() <= i { - col_widths.push( col.len() ); + col_widths.push( cell.len() ); } - else if col.len() > col_widths[ i ] + else if cell.len() > col_widths[ i ] { - col_widths[ i ] = col.len(); + col_widths[ i ] = cell.len(); } } } @@ -142,11 +157,11 @@ impl TableFormatter for TableOptions for row in all_rows { let formatted_row : Vec< String > = row - .iter() - .enumerate() - .map( | ( i, col ) | format!( "{:width$}", col, width = col_widths[ i ] ) ) - .collect(); - writeln!( f.buf, "{}", formatted_row.join( delimiter ) )?; + .iter() + .enumerate() + .map( | ( i, col ) | format!( "{:width$}", col, width = col_widths[ i ] ) ) + .collect(); + writeln!( f.buf, "{}", formatted_row.join( separator ) )?; } Ok(()) From 9c1cac2ca94ef5103764719aa178b97aea652357 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 18:37:14 +0300 Subject: [PATCH 007/143] experimenting --- module/move/assistant/src/as_table.rs | 111 ++++++++++++++++++++++++++ module/move/assistant/src/lib.rs | 3 + module/move/assistant/src/print.rs | 41 +++------- 3 files changed, 127 insertions(+), 28 deletions(-) create mode 100644 module/move/assistant/src/as_table.rs diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs new file mode 100644 index 0000000000..a9e301fc73 --- /dev/null +++ b/module/move/assistant/src/as_table.rs @@ -0,0 +1,111 @@ + +use super::*; +use core::ops::{ Deref, DerefMut }; +use core::marker::PhantomData; +use core::fmt; + +/// Transparent wrapper for table-like structures. +#[ derive( Debug ) ] +#[ repr( transparent ) ] +pub struct AsTable< T, Row, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( Row, Title, Cell ) > ) +where + T : TableRows< Row, Cell >, + T : TableHeader< Title >, + T : TableSize, + Row : Cells< Cell >, + Title : fmt::Debug, + Cell : fmt::Debug, +; + +impl< T, Row, Cell, Title > AsRef< T > for AsTable< T, Row, Cell, Title > +where + T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, + Row : Cells< Cell >, + Title : fmt::Debug, + Cell : fmt::Debug +{ + fn as_ref( &self ) -> &T + { + &self.0 + } +} + +impl< T, Row, Cell, Title > AsMut< T > for AsTable< T, Row, Cell, Title > +where + T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, + Row : Cells< Cell >, + Title : fmt::Debug, + Cell : fmt::Debug +{ + fn as_mut( &mut self ) -> &mut T + { + &mut self.0 + } +} + +impl< T, Row, Cell, Title > Deref for AsTable< T, Row, Cell, Title > +where + T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, + Row : Cells< Cell >, + Title : fmt::Debug, + Cell : fmt::Debug +{ + type Target = T; + + fn deref( &self ) -> &Self::Target + { + &self.0 + } +} + +impl< T, Row, Cell, Title > DerefMut for AsTable< T, Row, Cell, Title > +where + T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, + Row : Cells< Cell >, + Title : fmt::Debug, + Cell : fmt::Debug +{ + fn deref_mut( &mut self ) -> &mut Self::Target + { + &mut self.0 + } +} + +impl< T, Row, Cell, Title > From< T > for AsTable< T, Row, Cell, Title > +where + T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, + Row : Cells< Cell >, + Title : fmt::Debug, + Cell : fmt::Debug +{ + fn from( table : T ) -> Self + { + AsTable( table, PhantomData ) + } +} + +// impl< T, Row, Cell, Title > From< AsTable< T, Row, Cell, Title > > for T +// where +// T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, +// Row : Cells< Cell >, +// Title : fmt::Debug, +// Cell : fmt::Debug +// { +// fn from( as_table : AsTable< T, Row, Cell, Title > ) -> Self +// { +// as_table.0 +// } +// } + +impl< T, Row, Cell, Title > Default for AsTable< T, Row, Cell, Title > +where + T : Default + TableRows< Row, Cell > + TableHeader< Title > + TableSize, + Row : Cells< Cell >, + Title : fmt::Debug, + Cell : fmt::Debug +{ + fn default() -> Self + { + AsTable( T::default(), PhantomData ) + } +} diff --git a/module/move/assistant/src/lib.rs b/module/move/assistant/src/lib.rs index 67b1447653..a3b1b213e0 100644 --- a/module/move/assistant/src/lib.rs +++ b/module/move/assistant/src/lib.rs @@ -24,6 +24,9 @@ pub use reflect::*; /// Nice print. pub mod print; pub use print::*; +/// Nice print's wrapper. +pub mod as_table; +pub use as_table::*; /// Options for configuring the OpenAI API client. #[ derive( Former, Debug ) ] diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 7db0f11335..73aa92b499 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -44,6 +44,8 @@ where // == +// == + /// Struct to hold options to print data as table. #[ derive( Debug, Default, Former ) ] pub struct Styles @@ -52,19 +54,6 @@ pub struct Styles pub separator : String, } -/// Struct to hold options to print data as table. -#[ derive( Debug, Default, Former ) ] -pub struct TableOptions -{ - /// Optional header row for the table. - pub header : Option< Vec< String > >, - /// Rows with data for the table. - /// Its length should be equal to header length. - pub rows : Vec< String >, - /// Styles. - pub styles : Styles, -} - /// Struct for formatting tables. pub struct Formatter< 'a > { @@ -82,11 +71,17 @@ impl< 'a > Formatter< 'a > } /// A trait for formatting tables. -pub trait TableFormatter< Row, Cell, Title > +pub trait TableFormatter +{ + fn fmt( &self, f : &mut Formatter< '_ > ) -> fmt::Result; +} + +/// A trait for formatting tables. +impl< T, Row, Cell, Title > TableFormatter for AsTable< T, Row, Cell, Title > where - Self : TableRows< Row, Cell >, - Self : TableHeader< Title >, - Self : TableSize, + T : TableRows< Row, Cell >, + T : TableHeader< Title >, + T : TableSize, Row : Cells< Cell >, Title : fmt::Debug, Cell : fmt::Debug, @@ -128,16 +123,6 @@ where all_rows.push( fields ); } - // // Find the maximum width for each column - // let mut col_widths : Vec< usize > = Vec::new(); - // if let Some( header ) = self.header() - // { - // for col in header - // { - // col_widths.push( col.len() ); - // } - // } - for row in &all_rows { for ( i, cell ) in row.iter().enumerate() @@ -166,4 +151,4 @@ where Ok(()) } -} \ No newline at end of file +} From 4d086ded70f643dfd268d00b8d7c25b18563f644 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 19:05:49 +0300 Subject: [PATCH 008/143] experimenting --- module/move/assistant/src/as_table.rs | 17 +++++++- module/move/assistant/src/print.rs | 59 +++++++++++++++++++++++++++ module/move/assistant/src/reflect.rs | 14 ++++++- 3 files changed, 88 insertions(+), 2 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index a9e301fc73..3a73061ef1 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -5,7 +5,7 @@ use core::marker::PhantomData; use core::fmt; /// Transparent wrapper for table-like structures. -#[ derive( Debug ) ] +// #[ derive( Debug ) ] #[ repr( transparent ) ] pub struct AsTable< T, Row, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( Row, Title, Cell ) > ) where @@ -109,3 +109,18 @@ where AsTable( T::default(), PhantomData ) } } + +impl< T, Row, Cell, Title > fmt::Debug for AsTable< T, Row, Cell, Title > +where + T : TableRows< Row, Cell > + TableHeader< Title > + TableSize + fmt::Debug, + Row : Cells< Cell >, + Title : fmt::Debug, + Cell : fmt::Debug +{ + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f.debug_struct( "AsTable" ) + .field( "0", &self.0 ) + .finish() + } +} \ No newline at end of file diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 73aa92b499..a8c10794d3 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -44,6 +44,46 @@ where // == +impl< T, Row, Cell, Title > TableSize +for AsTable< T, Row, Cell, Title > +where + T : TableRows< Row, Cell >, + T : TableHeader< Title >, + T : TableSize, + T : FieldsLen< Row >, + Row : Cells< Cell >, + Row : FieldsLen< Cell >, + Title : fmt::Debug, + Cell : fmt::Debug, +{ + fn size( &self ) -> [ usize ; 2 ] + { + let mut rows = self.rows(); + let nrows = rows.len(); + let row = rows.next(); + if let Some( row ) = row + { + let ncells = row.cells().len(); + [ nrows, ncells ] + } + else + { + [ 0, 0 ] + } + } +} + +// impl< T, Row > TableSize +// for T +// where +// T : FieldsLen< Row >, +// { +// fn size( &self ) -> [ usize ; 2 ] +// { +// [ 0, 0 ] +// } +// } + // == /// Struct to hold options to print data as table. @@ -61,6 +101,18 @@ pub struct Formatter< 'a > styles : Styles, } +impl fmt::Debug for Formatter< '_ > +{ + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f + .debug_struct( "Formatter" ) + .field( "buf", &"dyn fmt::Write" ) + .field( "styles", &self.styles ) + .finish() + } +} + impl< 'a > Formatter< 'a > { /// Creates a new `Formatter` with the given buffer and separator. @@ -71,8 +123,14 @@ impl< 'a > Formatter< 'a > } /// A trait for formatting tables. +/// +/// This trait defines a method for formatting tables, allowing implementations +/// to specify how a table should be formatted and displayed. +/// + pub trait TableFormatter { + /// Formats the table and writes the result to the given formatter. fn fmt( &self, f : &mut Formatter< '_ > ) -> fmt::Result; } @@ -107,6 +165,7 @@ where // zzz : avoid extra allocation of memory write!( f.buf, "{:?}", title )?; first = false; + i += 1; } writeln!( f.buf )?; } diff --git a/module/move/assistant/src/reflect.rs b/module/move/assistant/src/reflect.rs index d22391d1dc..16f83101a2 100644 --- a/module/move/assistant/src/reflect.rs +++ b/module/move/assistant/src/reflect.rs @@ -2,7 +2,7 @@ // use core::fmt; -/// A trait for iterating over all fields of a specified type within an entity. +/// A trait for iterating over all fields convertible into a specified type within an entity. /// /// # Type Parameters /// @@ -14,6 +14,18 @@ pub trait Fields< K, E > fn fields( &self ) -> impl Iterator< Item = ( K, E ) > + Clone; } +/// Return number of fields convertible into a specified type withing an entity. +/// +/// # Type Parameters +/// +/// - `E`: The element type. +/// +pub trait FieldsLen< E > +{ + /// Return number of fields convertible into a specified type withing an entity. + fn len( &self ) -> usize; +} + /// Trait returning name of type of variable. pub trait TypeName { From 8ca99dfd10749fe09ee115f9875240615be4166b Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 19:12:24 +0300 Subject: [PATCH 009/143] experimenting --- module/move/assistant/src/print.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index a8c10794d3..3ecf232895 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -122,6 +122,34 @@ impl< 'a > Formatter< 'a > } } +/// A trait for converting tables to a string representation. +pub trait TableToString +{ + /// Converts the table to a string representation. + /// + /// # Returns + /// + /// A `String` containing the formatted table. + fn table_to_string( &self ) -> String; +} + +impl< T > TableToString for T +where + T : TableFormatter +{ + fn table_to_string( &self ) -> String + { + let mut output = String::new(); + let mut formatter = Formatter + { + buf : &mut output, + styles : Styles::default(), + }; + T::fmt( self, &mut formatter ).expect( "Formatting failed" ); + output + } +} + /// A trait for formatting tables. /// /// This trait defines a method for formatting tables, allowing implementations From 727750b50873c9c9f57ad4a37f5cf10577c20558 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 19:22:41 +0300 Subject: [PATCH 010/143] experimenting --- module/move/assistant/src/as_table.rs | 20 ++++++------- module/move/assistant/src/print.rs | 41 +++++++++++++++++++-------- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 3a73061ef1..24b1c54cc3 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -7,7 +7,7 @@ use core::fmt; /// Transparent wrapper for table-like structures. // #[ derive( Debug ) ] #[ repr( transparent ) ] -pub struct AsTable< T, Row, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( Row, Title, Cell ) > ) +pub struct AsTable< T, Row, Key, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( Row, Key, Cell, Title ) > ) where T : TableRows< Row, Cell >, T : TableHeader< Title >, @@ -17,7 +17,7 @@ where Cell : fmt::Debug, ; -impl< T, Row, Cell, Title > AsRef< T > for AsTable< T, Row, Cell, Title > +impl< T, Row, Key, Cell, Title > AsRef< T > for AsTable< T, Row, Key, Cell, Title > where T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, Row : Cells< Cell >, @@ -30,7 +30,7 @@ where } } -impl< T, Row, Cell, Title > AsMut< T > for AsTable< T, Row, Cell, Title > +impl< T, Row, Key, Cell, Title > AsMut< T > for AsTable< T, Row, Key, Cell, Title > where T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, Row : Cells< Cell >, @@ -43,7 +43,7 @@ where } } -impl< T, Row, Cell, Title > Deref for AsTable< T, Row, Cell, Title > +impl< T, Row, Key, Cell, Title > Deref for AsTable< T, Row, Key, Cell, Title > where T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, Row : Cells< Cell >, @@ -58,7 +58,7 @@ where } } -impl< T, Row, Cell, Title > DerefMut for AsTable< T, Row, Cell, Title > +impl< T, Row, Key, Cell, Title > DerefMut for AsTable< T, Row, Key, Cell, Title > where T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, Row : Cells< Cell >, @@ -71,7 +71,7 @@ where } } -impl< T, Row, Cell, Title > From< T > for AsTable< T, Row, Cell, Title > +impl< T, Row, Key, Cell, Title > From< T > for AsTable< T, Row, Key, Cell, Title > where T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, Row : Cells< Cell >, @@ -84,20 +84,20 @@ where } } -// impl< T, Row, Cell, Title > From< AsTable< T, Row, Cell, Title > > for T +// impl< T, Row, Key, Cell, Title > From< AsTable< T, Row, Key, Cell, Title > > for T // where // T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, // Row : Cells< Cell >, // Title : fmt::Debug, // Cell : fmt::Debug // { -// fn from( as_table : AsTable< T, Row, Cell, Title > ) -> Self +// fn from( as_table : AsTable< T, Row, Key, Cell, Title > ) -> Self // { // as_table.0 // } // } -impl< T, Row, Cell, Title > Default for AsTable< T, Row, Cell, Title > +impl< T, Row, Key, Cell, Title > Default for AsTable< T, Row, Key, Cell, Title > where T : Default + TableRows< Row, Cell > + TableHeader< Title > + TableSize, Row : Cells< Cell >, @@ -110,7 +110,7 @@ where } } -impl< T, Row, Cell, Title > fmt::Debug for AsTable< T, Row, Cell, Title > +impl< T, Row, Key, Cell, Title > fmt::Debug for AsTable< T, Row, Key, Cell, Title > where T : TableRows< Row, Cell > + TableHeader< Title > + TableSize + fmt::Debug, Row : Cells< Cell >, diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 3ecf232895..db26b3d699 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -24,15 +24,6 @@ where fn rows( &self ) -> impl Iterator< Item = Row > + ExactSizeIterator + Clone; } -/// A trait for iterating over all cells of a row. -pub trait Cells< Cell > -where - Cell : fmt::Debug, -{ - /// Returns an iterator over all cells of the row. - fn cells( &self ) -> impl Iterator< Item = Cell > + ExactSizeIterator + Clone; -} - /// Trait returning headers of a table if any. pub trait TableHeader< Title > where @@ -42,10 +33,19 @@ where fn header( &self ) -> Option< impl Iterator< Item = Title > + ExactSizeIterator + Clone >; } +/// A trait for iterating over all cells of a row. +pub trait Cells< Cell > +where + Cell : fmt::Debug, +{ + /// Returns an iterator over all cells of the row. + fn cells( &self ) -> impl Iterator< Item = Cell > + ExactSizeIterator + Clone; +} + // == -impl< T, Row, Cell, Title > TableSize -for AsTable< T, Row, Cell, Title > +impl< T, Row, Key, Cell, Title > TableSize +for AsTable< T, Row, Key, Cell, Title > where T : TableRows< Row, Cell >, T : TableHeader< Title >, @@ -73,6 +73,23 @@ where } } +// impl< T, Row, Key, Cell, Title, K > TableRows< Row, Cell > +// for AsTable< T, Row, Key, Cell, Title > +// where +// T : TableRows< Row, Cell >, +// T : TableHeader< Title >, +// T : TableSize, +// T : Fields< K, Row >, +// Row : Cells< Cell >, +// Title : fmt::Debug, +// Cell : fmt::Debug, +// { +// fn rows( &self ) -> impl Iterator< Item = Row > + ExactSizeIterator + Clone +// { +// self.fields().map( | ( k, e ) | e ) +// } +// } + // impl< T, Row > TableSize // for T // where @@ -163,7 +180,7 @@ pub trait TableFormatter } /// A trait for formatting tables. -impl< T, Row, Cell, Title > TableFormatter for AsTable< T, Row, Cell, Title > +impl< T, Row, Key, Cell, Title > TableFormatter for AsTable< T, Row, Key, Cell, Title > where T : TableRows< Row, Cell >, T : TableHeader< Title >, From 62baab02789c6c743e8f3aea847328bbc8a56333 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 19:24:07 +0300 Subject: [PATCH 011/143] experimenting --- module/move/assistant/src/print.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index db26b3d699..69d4da5daa 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -25,21 +25,21 @@ where } /// Trait returning headers of a table if any. -pub trait TableHeader< Title > +pub trait TableHeader< Key, Title > where Title : fmt::Debug, { /// Returns an iterator over all fields of the specified type within the entity. - fn header( &self ) -> Option< impl Iterator< Item = Title > + ExactSizeIterator + Clone >; + fn header( &self ) -> Option< impl Iterator< Item = ( Key, Title ) > + ExactSizeIterator + Clone >; } /// A trait for iterating over all cells of a row. -pub trait Cells< Cell > +pub trait Cells< Key, Cell > where Cell : fmt::Debug, { /// Returns an iterator over all cells of the row. - fn cells( &self ) -> impl Iterator< Item = Cell > + ExactSizeIterator + Clone; + fn cells( &self ) -> impl Iterator< Item = ( Key, Cell ) > + ExactSizeIterator + Clone; } // == From 7102e288e3dfc70b61f9cb7e1b44d82a10af69fc Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 19:31:38 +0300 Subject: [PATCH 012/143] experimenting --- module/move/assistant/src/as_table.rs | 38 +++++++++++++-------------- module/move/assistant/src/print.rs | 30 ++++++++++----------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 24b1c54cc3..85ead74b5d 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -9,18 +9,18 @@ use core::fmt; #[ repr( transparent ) ] pub struct AsTable< T, Row, Key, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( Row, Key, Cell, Title ) > ) where - T : TableRows< Row, Cell >, - T : TableHeader< Title >, + T : TableRows< Row, Key, Cell >, + T : TableHeader< Key, Title >, T : TableSize, - Row : Cells< Cell >, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug, ; impl< T, Row, Key, Cell, Title > AsRef< T > for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, - Row : Cells< Cell >, + T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -32,8 +32,8 @@ where impl< T, Row, Key, Cell, Title > AsMut< T > for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, - Row : Cells< Cell >, + T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -45,8 +45,8 @@ where impl< T, Row, Key, Cell, Title > Deref for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, - Row : Cells< Cell >, + T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -60,8 +60,8 @@ where impl< T, Row, Key, Cell, Title > DerefMut for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, - Row : Cells< Cell >, + T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -73,8 +73,8 @@ where impl< T, Row, Key, Cell, Title > From< T > for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, - Row : Cells< Cell >, + T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -86,8 +86,8 @@ where // impl< T, Row, Key, Cell, Title > From< AsTable< T, Row, Key, Cell, Title > > for T // where -// T : TableRows< Row, Cell > + TableHeader< Title > + TableSize, -// Row : Cells< Cell >, +// T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, +// Row : Cells< Key, Cell >, // Title : fmt::Debug, // Cell : fmt::Debug // { @@ -99,8 +99,8 @@ where impl< T, Row, Key, Cell, Title > Default for AsTable< T, Row, Key, Cell, Title > where - T : Default + TableRows< Row, Cell > + TableHeader< Title > + TableSize, - Row : Cells< Cell >, + T : Default + TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -112,8 +112,8 @@ where impl< T, Row, Key, Cell, Title > fmt::Debug for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Cell > + TableHeader< Title > + TableSize + fmt::Debug, - Row : Cells< Cell >, + T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize + fmt::Debug, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 69d4da5daa..d4534eb486 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -15,9 +15,9 @@ pub trait TableSize } /// A trait for iterating over all rows of a table. -pub trait TableRows< Row, Cell > +pub trait TableRows< Row, Key, Cell > where - Row : Cells< Cell >, + Row : Cells< Key, Cell >, Cell : fmt::Debug, { /// Returns an iterator over all rows of the table. @@ -47,11 +47,11 @@ where impl< T, Row, Key, Cell, Title > TableSize for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Cell >, - T : TableHeader< Title >, + T : TableRows< Row, Key, Cell >, + T : TableHeader< Key, Title >, T : TableSize, T : FieldsLen< Row >, - Row : Cells< Cell >, + Row : Cells< Key, Cell >, Row : FieldsLen< Cell >, Title : fmt::Debug, Cell : fmt::Debug, @@ -73,14 +73,14 @@ where } } -// impl< T, Row, Key, Cell, Title, K > TableRows< Row, Cell > +// impl< T, Row, Key, Cell, Title, K > TableRows< Row, Key, Cell > // for AsTable< T, Row, Key, Cell, Title > // where -// T : TableRows< Row, Cell >, -// T : TableHeader< Title >, +// T : TableRows< Row, Key, Cell >, +// T : TableHeader< Key, Title >, // T : TableSize, // T : Fields< K, Row >, -// Row : Cells< Cell >, +// Row : Cells< Key, Cell >, // Title : fmt::Debug, // Cell : fmt::Debug, // { @@ -182,10 +182,10 @@ pub trait TableFormatter /// A trait for formatting tables. impl< T, Row, Key, Cell, Title > TableFormatter for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Cell >, - T : TableHeader< Title >, + T : TableRows< Row, Key, Cell >, + T : TableHeader< Key, Title >, T : TableSize, - Row : Cells< Cell >, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug, { @@ -200,7 +200,7 @@ where { let mut first = true; let mut i = 0; - for title in header + for ( _key, title ) in header { if !first { @@ -222,7 +222,7 @@ where let fields : Vec< String > = row .cells() // .map( | ( key, value ) | format!( "{:?}: {:?}", key, value ) ) - .map( | e | format!( "{:?}", e ) ) + .map( | ( _key, cell ) | format!( "{:?}", cell ) ) .collect(); all_rows.push( fields ); } @@ -248,7 +248,7 @@ where let formatted_row : Vec< String > = row .iter() .enumerate() - .map( | ( i, col ) | format!( "{:width$}", col, width = col_widths[ i ] ) ) + .map( | ( i, cell ) | format!( "{:width$}", cell, width = col_widths[ i ] ) ) .collect(); writeln!( f.buf, "{}", formatted_row.join( separator ) )?; } From 08c58c938b61d2b844fd425af48fdd5483b9527e Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 21:28:42 +0300 Subject: [PATCH 013/143] experimenting --- module/move/assistant/src/print.rs | 4 +- module/move/assistant/src/reflect.rs | 48 ++++++++++++++----- .../move/assistant/tests/inc/fields_test.rs | 2 +- module/move/assistant/tests/inc/print_test.rs | 2 +- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index d4534eb486..6b095f240f 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -50,9 +50,9 @@ where T : TableRows< Row, Key, Cell >, T : TableHeader< Key, Title >, T : TableSize, - T : FieldsLen< Row >, + // T : FieldsLen< Row >, Row : Cells< Key, Cell >, - Row : FieldsLen< Cell >, + // Row : FieldsLen< Cell >, Title : fmt::Debug, Cell : fmt::Debug, { diff --git a/module/move/assistant/src/reflect.rs b/module/move/assistant/src/reflect.rs index 16f83101a2..6e6251c73a 100644 --- a/module/move/assistant/src/reflect.rs +++ b/module/move/assistant/src/reflect.rs @@ -2,6 +2,30 @@ // use core::fmt; +// pub trait _IteratorTrait< T > +// where +// Self : core::iter::Iterator + ExactSizeIterator +// { +// } +// +// impl _IteratorTrait for T +// where +// Self : core::iter::Iterator + ExactSizeIterator +// { +// } +// +// pub trait Iterator +// where +// Self : _IteratorTrait + Clone +// { +// } +// +// impl Iterator for T +// where +// Self : _IteratorTrait + Clone +// { +// } + /// A trait for iterating over all fields convertible into a specified type within an entity. /// /// # Type Parameters @@ -11,20 +35,20 @@ pub trait Fields< K, E > { /// Returns an iterator over all fields of the specified type within the entity. - fn fields( &self ) -> impl Iterator< Item = ( K, E ) > + Clone; + fn fields( &self ) -> impl Iterator< Item = ( K, E ) > + ExactSizeIterator + Clone; } -/// Return number of fields convertible into a specified type withing an entity. -/// -/// # Type Parameters -/// -/// - `E`: The element type. -/// -pub trait FieldsLen< E > -{ - /// Return number of fields convertible into a specified type withing an entity. - fn len( &self ) -> usize; -} +// /// Return number of fields convertible into a specified type withing an entity. +// /// +// /// # Type Parameters +// /// +// /// - `E`: The element type. +// /// +// pub trait FieldsLen< E > +// { +// /// Return number of fields convertible into a specified type withing an entity. +// fn len( &self ) -> usize; +// } /// Trait returning name of type of variable. pub trait TypeName diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index fe31052336..925bfa5455 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -22,7 +22,7 @@ pub struct TestObject impl Fields< &'static str, String > for TestObject { - fn fields( &self ) -> impl Iterator< Item = ( &'static str, String ) > + Clone + fn fields( &self ) -> impl Iterator< Item = ( &'static str, String ) > + ExactSizeIterator + Clone { let mut vec : Vec< ( &'static str, String ) > = Vec::new(); diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 32f7916722..8b20b827ed 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -22,7 +22,7 @@ pub struct TestObject impl Fields< &'static str, String > for TestObject { - fn fields( &self ) -> impl Iterator< Item = ( &'static str, String ) > + Clone + fn fields( &self ) -> impl Iterator< Item = ( &'static str, String ) > + ExactSizeIterator + Clone { let mut vec : Vec< ( &'static str, String ) > = Vec::new(); From dd9e7c8b8817b2c1eb35d31474a1c67150113cee Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 21:33:55 +0300 Subject: [PATCH 014/143] experimenting --- module/move/assistant/src/print.rs | 6 +-- module/move/assistant/src/reflect.rs | 50 ++++++++++--------- .../move/assistant/tests/inc/fields_test.rs | 3 +- module/move/assistant/tests/inc/print_test.rs | 3 +- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 6b095f240f..262c97f9b9 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -5,8 +5,6 @@ use former::Former; // == -// pub type Iterator2< Item > = Iterator< Item = Item > + ExactSizeIterator + Clone; - /// A trait for iterating over all rows of a table. pub trait TableSize { @@ -21,7 +19,7 @@ where Cell : fmt::Debug, { /// Returns an iterator over all rows of the table. - fn rows( &self ) -> impl Iterator< Item = Row > + ExactSizeIterator + Clone; + fn rows( &self ) -> impl IteratorTrait< Item = Row >; } /// Trait returning headers of a table if any. @@ -84,7 +82,7 @@ where // Title : fmt::Debug, // Cell : fmt::Debug, // { -// fn rows( &self ) -> impl Iterator< Item = Row > + ExactSizeIterator + Clone +// fn rows( &self ) -> impl IteratorTrait< Item = Row > // { // self.fields().map( | ( k, e ) | e ) // } diff --git a/module/move/assistant/src/reflect.rs b/module/move/assistant/src/reflect.rs index 6e6251c73a..2d540a58b4 100644 --- a/module/move/assistant/src/reflect.rs +++ b/module/move/assistant/src/reflect.rs @@ -2,29 +2,31 @@ // use core::fmt; -// pub trait _IteratorTrait< T > -// where -// Self : core::iter::Iterator + ExactSizeIterator -// { -// } -// -// impl _IteratorTrait for T -// where -// Self : core::iter::Iterator + ExactSizeIterator -// { -// } -// -// pub trait Iterator -// where -// Self : _IteratorTrait + Clone -// { -// } -// -// impl Iterator for T -// where -// Self : _IteratorTrait + Clone -// { -// } +/// A trait for iterators that are also `ExactSizeIterator`. +pub trait _IteratorTrait +where + Self : core::iter::Iterator + ExactSizeIterator +{ +} + +impl< T > _IteratorTrait for T +where + Self : core::iter::Iterator + ExactSizeIterator +{ +} + +/// A trait for iterators that implement `_IteratorTrait` and `Clone`. +pub trait IteratorTrait +where + Self : _IteratorTrait + Clone +{ +} + +impl< T > IteratorTrait for T +where + Self : _IteratorTrait + Clone +{ +} /// A trait for iterating over all fields convertible into a specified type within an entity. /// @@ -35,7 +37,7 @@ pub trait Fields< K, E > { /// Returns an iterator over all fields of the specified type within the entity. - fn fields( &self ) -> impl Iterator< Item = ( K, E ) > + ExactSizeIterator + Clone; + fn fields( &self ) -> impl IteratorTrait< Item = ( K, E ) >; } // /// Return number of fields convertible into a specified type withing an entity. diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 925bfa5455..93edcad3d9 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -4,6 +4,7 @@ use super::*; use assistant:: { Fields, + IteratorTrait, }; use std:: @@ -22,7 +23,7 @@ pub struct TestObject impl Fields< &'static str, String > for TestObject { - fn fields( &self ) -> impl Iterator< Item = ( &'static str, String ) > + ExactSizeIterator + Clone + fn fields( &self ) -> impl IteratorTrait< Item = ( &'static str, String ) > { let mut vec : Vec< ( &'static str, String ) > = Vec::new(); diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 8b20b827ed..eb0e3f2237 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -4,6 +4,7 @@ use super::*; use assistant:: { Fields, + IteratorTrait, }; use std:: @@ -22,7 +23,7 @@ pub struct TestObject impl Fields< &'static str, String > for TestObject { - fn fields( &self ) -> impl Iterator< Item = ( &'static str, String ) > + ExactSizeIterator + Clone + fn fields( &self ) -> impl IteratorTrait< Item = ( &'static str, String ) > { let mut vec : Vec< ( &'static str, String ) > = Vec::new(); From c6057c0c8d33df19c542f4fede2085891a5bc881 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 21:44:39 +0300 Subject: [PATCH 015/143] experimenting --- module/move/assistant/src/as_table.rs | 38 ++++++++++---------- module/move/assistant/src/print.rs | 51 ++++++++++++++------------- 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 85ead74b5d..54cac9c8a5 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -9,18 +9,18 @@ use core::fmt; #[ repr( transparent ) ] pub struct AsTable< T, Row, Key, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( Row, Key, Cell, Title ) > ) where - T : TableRows< Row, Key, Cell >, - T : TableHeader< Key, Title >, + T : TableRows< Row = Row, Key = Key, Cell = Cell >, + T : TableHeader< Key = Key, Title = Title >, T : TableSize, - Row : Cells< Key, Cell >, + Row : Cells< Key = Key, Cell = Cell >, Title : fmt::Debug, Cell : fmt::Debug, ; impl< T, Row, Key, Cell, Title > AsRef< T > for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : Cells< Key, Cell >, + T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, + Row : Cells< Key = Key, Cell = Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -32,8 +32,8 @@ where impl< T, Row, Key, Cell, Title > AsMut< T > for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : Cells< Key, Cell >, + T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, + Row : Cells< Key = Key, Cell = Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -45,8 +45,8 @@ where impl< T, Row, Key, Cell, Title > Deref for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : Cells< Key, Cell >, + T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, + Row : Cells< Key = Key, Cell = Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -60,8 +60,8 @@ where impl< T, Row, Key, Cell, Title > DerefMut for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : Cells< Key, Cell >, + T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, + Row : Cells< Key = Key, Cell = Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -73,8 +73,8 @@ where impl< T, Row, Key, Cell, Title > From< T > for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : Cells< Key, Cell >, + T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, + Row : Cells< Key = Key, Cell = Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -86,8 +86,8 @@ where // impl< T, Row, Key, Cell, Title > From< AsTable< T, Row, Key, Cell, Title > > for T // where -// T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, -// Row : Cells< Key, Cell >, +// T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, +// Row : Cells< Key = Key, Cell = Cell >, // Title : fmt::Debug, // Cell : fmt::Debug // { @@ -99,8 +99,8 @@ where impl< T, Row, Key, Cell, Title > Default for AsTable< T, Row, Key, Cell, Title > where - T : Default + TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : Cells< Key, Cell >, + T : Default + TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, + Row : Cells< Key = Key, Cell = Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -112,8 +112,8 @@ where impl< T, Row, Key, Cell, Title > fmt::Debug for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize + fmt::Debug, - Row : Cells< Key, Cell >, + T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize + fmt::Debug, + Row : Cells< Key = Key, Cell = Cell >, Title : fmt::Debug, Cell : fmt::Debug { diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 262c97f9b9..5de2e2a749 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -13,31 +13,34 @@ pub trait TableSize } /// A trait for iterating over all rows of a table. -pub trait TableRows< Row, Key, Cell > -where - Row : Cells< Key, Cell >, - Cell : fmt::Debug, +pub trait TableRows { + type Row : Cells< Key = Self::Key, Cell = Self::Cell >; + type Key; + type Cell : fmt::Debug; + /// Returns an iterator over all rows of the table. - fn rows( &self ) -> impl IteratorTrait< Item = Row >; + fn rows( &self ) -> impl IteratorTrait< Item = Self::Row >; } /// Trait returning headers of a table if any. -pub trait TableHeader< Key, Title > -where - Title : fmt::Debug, +pub trait TableHeader { + type Key; + type Title : fmt::Debug; + /// Returns an iterator over all fields of the specified type within the entity. - fn header( &self ) -> Option< impl Iterator< Item = ( Key, Title ) > + ExactSizeIterator + Clone >; + fn header( &self ) -> Option< impl IteratorTrait< Item = ( Self::Key, Self::Title ) > >; } /// A trait for iterating over all cells of a row. -pub trait Cells< Key, Cell > -where - Cell : fmt::Debug, +pub trait Cells { + type Key; + type Cell : fmt::Debug; + /// Returns an iterator over all cells of the row. - fn cells( &self ) -> impl Iterator< Item = ( Key, Cell ) > + ExactSizeIterator + Clone; + fn cells( &self ) -> impl IteratorTrait< Item = ( Self::Key, Self::Cell ) >; } // == @@ -45,12 +48,10 @@ where impl< T, Row, Key, Cell, Title > TableSize for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell >, - T : TableHeader< Key, Title >, + T : TableRows< Row = Row, Key = Key, Cell = Cell >, + T : TableHeader< Key = Key, Title = Title >, T : TableSize, - // T : FieldsLen< Row >, - Row : Cells< Key, Cell >, - // Row : FieldsLen< Cell >, + Row : Cells< Key = Key, Cell = Cell >, Title : fmt::Debug, Cell : fmt::Debug, { @@ -71,14 +72,14 @@ where } } -// impl< T, Row, Key, Cell, Title, K > TableRows< Row, Key, Cell > +// impl< T, Row, Key, Cell, Title, K > TableRows< Row = Row, Key = Key, Cell = Cell > // for AsTable< T, Row, Key, Cell, Title > // where -// T : TableRows< Row, Key, Cell >, -// T : TableHeader< Key, Title >, +// T : TableRows< Row = Row, Key = Key, Cell = Cell >, +// T : TableHeader< Key = Key, Title = Title >, // T : TableSize, // T : Fields< K, Row >, -// Row : Cells< Key, Cell >, +// Row : Cells< Key = Key, Cell = Cell >, // Title : fmt::Debug, // Cell : fmt::Debug, // { @@ -180,10 +181,10 @@ pub trait TableFormatter /// A trait for formatting tables. impl< T, Row, Key, Cell, Title > TableFormatter for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell >, - T : TableHeader< Key, Title >, + T : TableRows< Row = Row, Key = Key, Cell = Cell >, + T : TableHeader< Key = Key, Title = Title >, T : TableSize, - Row : Cells< Key, Cell >, + Row : Cells< Key = Key, Cell = Cell >, Title : fmt::Debug, Cell : fmt::Debug, { From e0e9c83016b955895cf57fb8f4073253f215a553 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 21:52:50 +0300 Subject: [PATCH 016/143] experimenting --- module/move/assistant/src/print.rs | 36 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 5de2e2a749..24444af673 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -72,22 +72,26 @@ where } } -// impl< T, Row, Key, Cell, Title, K > TableRows< Row = Row, Key = Key, Cell = Cell > -// for AsTable< T, Row, Key, Cell, Title > -// where -// T : TableRows< Row = Row, Key = Key, Cell = Cell >, -// T : TableHeader< Key = Key, Title = Title >, -// T : TableSize, -// T : Fields< K, Row >, -// Row : Cells< Key = Key, Cell = Cell >, -// Title : fmt::Debug, -// Cell : fmt::Debug, -// { -// fn rows( &self ) -> impl IteratorTrait< Item = Row > -// { -// self.fields().map( | ( k, e ) | e ) -// } -// } +impl< T, Row, Key, Cell, Title > TableRows +for AsTable< T, Row, Key, Cell, Title > +where + T : TableRows< Row = Row, Key = Key, Cell = Cell >, + T : TableHeader< Key = Key, Title = Title >, + T : TableSize, + T : Fields< Key, Row >, + Row : Cells< Key = Key, Cell = Cell >, + Title : fmt::Debug, + Cell : fmt::Debug, +{ + type Row = Row; + type Key = Key; + type Cell = Cell; + + fn rows( &self ) -> impl IteratorTrait< Item = Row > + { + self.fields().map( | ( _k, e ) | e ) + } +} // impl< T, Row > TableSize // for T From 5016bc55b38d729fc17204ef901ea71b23ab985c Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 22:20:53 +0300 Subject: [PATCH 017/143] experimenting --- module/move/assistant/src/print.rs | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 24444af673..7c74715ee5 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -91,6 +91,38 @@ where { self.fields().map( | ( _k, e ) | e ) } + +} + +impl< T, Row, Key, Cell, Title > TableHeader +for AsTable< T, Row, Key, Cell, Title > +where + T : TableRows< Row = Row, Key = Key, Cell = Cell >, + T : TableHeader< Key = Key, Title = Title >, + T : TableSize, + Row : Cells< Key = Key, Cell = Cell >, + Row : Fields< Key, Title >, + Key : Clone, + Title : fmt::Debug + Clone, + Cell : fmt::Debug, +{ + type Key = Key; + type Title = Title; + + fn header( &self ) -> Option< impl IteratorTrait< Item = ( Self::Key, Self::Title ) > > + { + let mut rows = self.rows(); + let row = rows.next(); + if let Some( row ) = row + { + Some( row.fields().collect::< Vec< _ > >().into_iter() ) + } + else + { + None + } + } + } // impl< T, Row > TableSize From 2109b36087ecaad2854bac705209c2f229f30479 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 22:28:29 +0300 Subject: [PATCH 018/143] experimenting --- module/move/assistant/src/print.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 7c74715ee5..c1a5e63c9b 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -125,15 +125,28 @@ where } -// impl< T, Row > TableSize -// for T +// /// A trait for iterating over all cells of a row. +// pub trait Cells2< Key, Cell > // where -// T : FieldsLen< Row >, +// Cell : fmt::Debug, // { -// fn size( &self ) -> [ usize ; 2 ] +// /// Returns an iterator over all cells of the row. +// fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) >; +// } + +// impl< Row, Key, Cell > Cells< Key, Cell > +// for Row +// where +// // Row : Cells< Key = Key, Cell = Cell >, +// Row : Fields< Key, Cell >, +// Cell : fmt::Debug, +// { +// +// fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) > // { -// [ 0, 0 ] +// self.fields() // } +// // } // == From 325b18ca5f27e94fcf12c9f1bdf6a8f2da717338 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 22:34:36 +0300 Subject: [PATCH 019/143] experimenting --- module/move/assistant/src/as_table.rs | 40 ++++++------ module/move/assistant/src/print.rs | 92 ++++++++++++--------------- 2 files changed, 62 insertions(+), 70 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 54cac9c8a5..b75d8ef10b 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -9,18 +9,18 @@ use core::fmt; #[ repr( transparent ) ] pub struct AsTable< T, Row, Key, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( Row, Key, Cell, Title ) > ) where - T : TableRows< Row = Row, Key = Key, Cell = Cell >, - T : TableHeader< Key = Key, Title = Title >, + T : TableRows< Row, Key, Cell >, + T : TableHeader< Key, Title >, T : TableSize, - Row : Cells< Key = Key, Cell = Cell >, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug, ; impl< T, Row, Key, Cell, Title > AsRef< T > for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, - Row : Cells< Key = Key, Cell = Cell >, + T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -32,8 +32,8 @@ where impl< T, Row, Key, Cell, Title > AsMut< T > for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, - Row : Cells< Key = Key, Cell = Cell >, + T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -45,8 +45,8 @@ where impl< T, Row, Key, Cell, Title > Deref for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, - Row : Cells< Key = Key, Cell = Cell >, + T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -60,8 +60,8 @@ where impl< T, Row, Key, Cell, Title > DerefMut for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, - Row : Cells< Key = Key, Cell = Cell >, + T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -73,8 +73,8 @@ where impl< T, Row, Key, Cell, Title > From< T > for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, - Row : Cells< Key = Key, Cell = Cell >, + T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -86,8 +86,8 @@ where // impl< T, Row, Key, Cell, Title > From< AsTable< T, Row, Key, Cell, Title > > for T // where -// T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, -// Row : Cells< Key = Key, Cell = Cell >, +// T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, +// Row : Cells< Key, Cell >, // Title : fmt::Debug, // Cell : fmt::Debug // { @@ -99,8 +99,8 @@ where impl< T, Row, Key, Cell, Title > Default for AsTable< T, Row, Key, Cell, Title > where - T : Default + TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize, - Row : Cells< Key = Key, Cell = Cell >, + T : Default + TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -112,8 +112,8 @@ where impl< T, Row, Key, Cell, Title > fmt::Debug for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row = Row, Key = Key, Cell = Cell > + TableHeader< Key = Key, Title = Title > + TableSize + fmt::Debug, - Row : Cells< Key = Key, Cell = Cell >, + T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize + fmt::Debug, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug { @@ -123,4 +123,4 @@ where .field( "0", &self.0 ) .finish() } -} \ No newline at end of file +} diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index c1a5e63c9b..32e46b3f9c 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -13,34 +13,31 @@ pub trait TableSize } /// A trait for iterating over all rows of a table. -pub trait TableRows +pub trait TableRows< Row, Key, Cell > +where + Row : Cells< Key, Cell >, + Cell : fmt::Debug, { - type Row : Cells< Key = Self::Key, Cell = Self::Cell >; - type Key; - type Cell : fmt::Debug; - /// Returns an iterator over all rows of the table. - fn rows( &self ) -> impl IteratorTrait< Item = Self::Row >; + fn rows( &self ) -> impl IteratorTrait< Item = Row >; } /// Trait returning headers of a table if any. -pub trait TableHeader +pub trait TableHeader< Key, Title > +where + Title : fmt::Debug, { - type Key; - type Title : fmt::Debug; - /// Returns an iterator over all fields of the specified type within the entity. - fn header( &self ) -> Option< impl IteratorTrait< Item = ( Self::Key, Self::Title ) > >; + fn header( &self ) -> Option< impl IteratorTrait< Item = ( Key, Title ) > >; } /// A trait for iterating over all cells of a row. -pub trait Cells +pub trait Cells< Key, Cell > +where + Cell : fmt::Debug, { - type Key; - type Cell : fmt::Debug; - /// Returns an iterator over all cells of the row. - fn cells( &self ) -> impl IteratorTrait< Item = ( Self::Key, Self::Cell ) >; + fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) >; } // == @@ -48,10 +45,10 @@ pub trait Cells impl< T, Row, Key, Cell, Title > TableSize for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row = Row, Key = Key, Cell = Cell >, - T : TableHeader< Key = Key, Title = Title >, + T : TableRows< Row, Key, Cell >, + T : TableHeader< Key, Title >, T : TableSize, - Row : Cells< Key = Key, Cell = Cell >, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug, { @@ -72,20 +69,17 @@ where } } -impl< T, Row, Key, Cell, Title > TableRows +impl< T, Row, Key, Cell, Title > TableRows< Row, Key, Cell > for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row = Row, Key = Key, Cell = Cell >, - T : TableHeader< Key = Key, Title = Title >, + T : TableRows< Row, Key, Cell >, + T : TableHeader< Key, Title >, T : TableSize, T : Fields< Key, Row >, - Row : Cells< Key = Key, Cell = Cell >, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug, { - type Row = Row; - type Key = Key; - type Cell = Cell; fn rows( &self ) -> impl IteratorTrait< Item = Row > { @@ -94,22 +88,20 @@ where } -impl< T, Row, Key, Cell, Title > TableHeader +impl< T, Row, Key, Cell, Title > TableHeader< Key, Title > for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row = Row, Key = Key, Cell = Cell >, - T : TableHeader< Key = Key, Title = Title >, + T : TableRows< Row, Key, Cell >, + T : TableHeader< Key, Title >, T : TableSize, - Row : Cells< Key = Key, Cell = Cell >, + Row : Cells< Key, Cell >, Row : Fields< Key, Title >, Key : Clone, Title : fmt::Debug + Clone, Cell : fmt::Debug, { - type Key = Key; - type Title = Title; - fn header( &self ) -> Option< impl IteratorTrait< Item = ( Self::Key, Self::Title ) > > + fn header( &self ) -> Option< impl IteratorTrait< Item = ( Key, Title ) > > { let mut rows = self.rows(); let row = rows.next(); @@ -134,20 +126,20 @@ where // fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) >; // } -// impl< Row, Key, Cell > Cells< Key, Cell > -// for Row -// where -// // Row : Cells< Key = Key, Cell = Cell >, -// Row : Fields< Key, Cell >, -// Cell : fmt::Debug, -// { -// -// fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) > -// { -// self.fields() -// } -// -// } +impl< Row, Key, Cell > Cells< Key, Cell > +for Row +where + // Row : Cells< Key, Cell >, + Row : Fields< Key, Cell >, + Cell : fmt::Debug, +{ + + fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) > + { + self.fields() + } + +} // == @@ -230,10 +222,10 @@ pub trait TableFormatter /// A trait for formatting tables. impl< T, Row, Key, Cell, Title > TableFormatter for AsTable< T, Row, Key, Cell, Title > where - T : TableRows< Row = Row, Key = Key, Cell = Cell >, - T : TableHeader< Key = Key, Title = Title >, + T : TableRows< Row, Key, Cell >, + T : TableHeader< Key, Title >, T : TableSize, - Row : Cells< Key = Key, Cell = Cell >, + Row : Cells< Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug, { From 063a17f374324d0a0fc90166863150f465d68d60 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 23:19:02 +0300 Subject: [PATCH 020/143] experimenting --- module/move/assistant/src/print.rs | 9 --------- module/move/assistant/tests/inc/print_test.rs | 8 ++++++++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 32e46b3f9c..ee30dd5a63 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -117,15 +117,6 @@ where } -// /// A trait for iterating over all cells of a row. -// pub trait Cells2< Key, Cell > -// where -// Cell : fmt::Debug, -// { -// /// Returns an iterator over all cells of the row. -// fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) >; -// } - impl< Row, Key, Cell > Cells< Key, Cell > for Row where diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index eb0e3f2237..98780a2c63 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -40,6 +40,14 @@ impl Fields< &'static str, String > for TestObject } } +// impl< 'a > Fields< usize, &'a TestObject > for Vec< TestObject > +// { +// fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, &'a TestObject ) > +// { +// self.iter().enumerate() +// } +// } + #[ test ] fn basic() { From 37cbe7775bf54652493317f7fc3af7e842c1e90b Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 00:11:09 +0300 Subject: [PATCH 021/143] experimenting --- module/move/assistant/src/as_table.rs | 56 ++--- module/move/assistant/src/print.rs | 197 +++++++++--------- module/move/assistant/src/reflect.rs | 6 +- .../move/assistant/tests/inc/fields_test.rs | 43 ++-- module/move/assistant/tests/inc/print_test.rs | 57 ++++- 5 files changed, 214 insertions(+), 145 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index b75d8ef10b..1dc92aa606 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -7,22 +7,22 @@ use core::fmt; /// Transparent wrapper for table-like structures. // #[ derive( Debug ) ] #[ repr( transparent ) ] -pub struct AsTable< T, Row, Key, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( Row, Key, Cell, Title ) > ) +pub struct AsTable< 'a, T, Row, Key, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( Row, Key, Cell, Title, &'a () ) > ) where T : TableRows< Row, Key, Cell >, T : TableHeader< Key, Title >, T : TableSize, - Row : Cells< Key, Cell >, + Row : 'a + Clone + Cells< Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug, + Cell : fmt::Debug + Clone, ; -impl< T, Row, Key, Cell, Title > AsRef< T > for AsTable< T, Row, Key, Cell, Title > +impl< 'a, T, Row, Key, Cell, Title > AsRef< T > for AsTable< 'a, T, Row, Key, Cell, Title > where T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : Cells< Key, Cell >, + Row : 'a + Clone + Cells< Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Cell : fmt::Debug + Clone { fn as_ref( &self ) -> &T { @@ -30,12 +30,12 @@ where } } -impl< T, Row, Key, Cell, Title > AsMut< T > for AsTable< T, Row, Key, Cell, Title > +impl< 'a, T, Row, Key, Cell, Title > AsMut< T > for AsTable< 'a, T, Row, Key, Cell, Title > where T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : Cells< Key, Cell >, + Row : 'a + Clone + Cells< Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Cell : fmt::Debug + Clone { fn as_mut( &mut self ) -> &mut T { @@ -43,12 +43,12 @@ where } } -impl< T, Row, Key, Cell, Title > Deref for AsTable< T, Row, Key, Cell, Title > +impl< 'a, T, Row, Key, Cell, Title > Deref for AsTable< 'a, T, Row, Key, Cell, Title > where T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : Cells< Key, Cell >, + Row : 'a + Clone + Cells< Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Cell : fmt::Debug + Clone { type Target = T; @@ -58,12 +58,12 @@ where } } -impl< T, Row, Key, Cell, Title > DerefMut for AsTable< T, Row, Key, Cell, Title > +impl< 'a, T, Row, Key, Cell, Title > DerefMut for AsTable< 'a, T, Row, Key, Cell, Title > where T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : Cells< Key, Cell >, + Row : 'a + Clone + Cells< Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Cell : fmt::Debug + Clone { fn deref_mut( &mut self ) -> &mut Self::Target { @@ -71,12 +71,12 @@ where } } -impl< T, Row, Key, Cell, Title > From< T > for AsTable< T, Row, Key, Cell, Title > +impl< 'a, T, Row, Key, Cell, Title > From< T > for AsTable< 'a, T, Row, Key, Cell, Title > where T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : Cells< Key, Cell >, + Row : 'a + Clone + Cells< Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Cell : fmt::Debug + Clone { fn from( table : T ) -> Self { @@ -84,25 +84,25 @@ where } } -// impl< T, Row, Key, Cell, Title > From< AsTable< T, Row, Key, Cell, Title > > for T +// impl< 'a, T, Row, Key, Cell, Title > From< AsTable< 'a, T, Row, Key, Cell, Title > > for T // where // T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, -// Row : Cells< Key, Cell >, +// Row : 'a + Clone + Cells< Key, Cell >, // Title : fmt::Debug, -// Cell : fmt::Debug +// Cell : fmt::Debug + Clone // { -// fn from( as_table : AsTable< T, Row, Key, Cell, Title > ) -> Self +// fn from( as_table : AsTable< 'a, T, Row, Key, Cell, Title > ) -> Self // { // as_table.0 // } // } -impl< T, Row, Key, Cell, Title > Default for AsTable< T, Row, Key, Cell, Title > +impl< 'a, T, Row, Key, Cell, Title > Default for AsTable< 'a, T, Row, Key, Cell, Title > where T : Default + TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : Cells< Key, Cell >, + Row : 'a + Clone + Cells< Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Cell : fmt::Debug + Clone { fn default() -> Self { @@ -110,12 +110,12 @@ where } } -impl< T, Row, Key, Cell, Title > fmt::Debug for AsTable< T, Row, Key, Cell, Title > +impl< 'a, T, Row, Key, Cell, Title > fmt::Debug for AsTable< 'a, T, Row, Key, Cell, Title > where T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize + fmt::Debug, - Row : Cells< Key, Cell >, + Row : 'a + Clone + Cells< Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Cell : fmt::Debug + Clone { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index ee30dd5a63..320f979641 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -15,8 +15,8 @@ pub trait TableSize /// A trait for iterating over all rows of a table. pub trait TableRows< Row, Key, Cell > where - Row : Cells< Key, Cell >, - Cell : fmt::Debug, + Row : Clone + Cells< Key, Cell >, + Cell : fmt::Debug + Clone, { /// Returns an iterator over all rows of the table. fn rows( &self ) -> impl IteratorTrait< Item = Row >; @@ -34,7 +34,7 @@ where /// A trait for iterating over all cells of a row. pub trait Cells< Key, Cell > where - Cell : fmt::Debug, + Cell : fmt::Debug + Clone, { /// Returns an iterator over all cells of the row. fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) >; @@ -42,95 +42,101 @@ where // == -impl< T, Row, Key, Cell, Title > TableSize -for AsTable< T, Row, Key, Cell, Title > -where - T : TableRows< Row, Key, Cell >, - T : TableHeader< Key, Title >, - T : TableSize, - Row : Cells< Key, Cell >, - Title : fmt::Debug, - Cell : fmt::Debug, -{ - fn size( &self ) -> [ usize ; 2 ] - { - let mut rows = self.rows(); - let nrows = rows.len(); - let row = rows.next(); - if let Some( row ) = row - { - let ncells = row.cells().len(); - [ nrows, ncells ] - } - else - { - [ 0, 0 ] - } - } -} - -impl< T, Row, Key, Cell, Title > TableRows< Row, Key, Cell > -for AsTable< T, Row, Key, Cell, Title > -where - T : TableRows< Row, Key, Cell >, - T : TableHeader< Key, Title >, - T : TableSize, - T : Fields< Key, Row >, - Row : Cells< Key, Cell >, - Title : fmt::Debug, - Cell : fmt::Debug, -{ - - fn rows( &self ) -> impl IteratorTrait< Item = Row > - { - self.fields().map( | ( _k, e ) | e ) - } - -} - -impl< T, Row, Key, Cell, Title > TableHeader< Key, Title > -for AsTable< T, Row, Key, Cell, Title > -where - T : TableRows< Row, Key, Cell >, - T : TableHeader< Key, Title >, - T : TableSize, - Row : Cells< Key, Cell >, - Row : Fields< Key, Title >, - Key : Clone, - Title : fmt::Debug + Clone, - Cell : fmt::Debug, -{ - - fn header( &self ) -> Option< impl IteratorTrait< Item = ( Key, Title ) > > - { - let mut rows = self.rows(); - let row = rows.next(); - if let Some( row ) = row - { - Some( row.fields().collect::< Vec< _ > >().into_iter() ) - } - else - { - None - } - } - -} - -impl< Row, Key, Cell > Cells< Key, Cell > -for Row -where - // Row : Cells< Key, Cell >, - Row : Fields< Key, Cell >, - Cell : fmt::Debug, -{ - - fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) > - { - self.fields() - } - -} +// impl< 'a, T, Row, Key, Cell, Title > TableSize +// for AsTable< 'a, T, Row, Key, Cell, Title > +// where +// T : TableRows< Row, Key, Cell >, +// T : TableHeader< Key, Title >, +// T : TableSize, +// Row : Clone + Cells< Key, Cell >, +// Title : fmt::Debug, +// Cell : fmt::Debug + Clone, +// { +// fn size( &self ) -> [ usize ; 2 ] +// { +// let mut rows = self.rows(); +// let nrows = rows.len(); +// let row = rows.next(); +// if let Some( row ) = row +// { +// let ncells = row.cells().len(); +// [ nrows, ncells ] +// } +// else +// { +// [ 0, 0 ] +// } +// } +// } +// +// impl< 'a, T, Row, Key, Cell, Title > TableRows< Row, Key, Cell > +// for AsTable< 'a, T, Row, Key, Cell, Title > +// where +// Self : 'a, +// // Self : 'static, +// T : TableRows< Row, Key, Cell >, +// T : TableHeader< Key, Title >, +// T : TableSize, +// T : Fields< 'a, Key, Row >, +// Row : Clone + Cells< Key, Cell >, +// Row : 'static, +// Title : fmt::Debug, +// Cell : fmt::Debug + Clone, +// { +// +// fn rows( &self ) -> impl IteratorTrait< Item = Row > +// where +// // Self : 'a, +// // Self : 'static, +// { +// self.fields().map( move | ( _k, e ) | e.into_owned() ) +// } +// +// } +// +// impl< 'a, T, Row, Key, Cell, Title > TableHeader< Key, Title > +// for AsTable< 'a, T, Row, Key, Cell, Title > +// where +// T : TableRows< Row, Key, Cell >, +// T : TableHeader< Key, Title >, +// T : TableSize, +// Row : Clone + Cells< Key, Cell >, +// Row : Fields< 'a, Key, Title >, +// Key : Clone, +// Title : fmt::Debug + Clone, +// Cell : fmt::Debug + Clone, +// { +// +// fn header( &self ) -> Option< impl IteratorTrait< Item = ( Key, Title ) > > +// { +// let mut rows = self.rows(); +// let row = rows.next(); +// if let Some( row ) = row +// { +// Some( row.fields().collect::< Vec< _ > >().into_iter() ) +// } +// else +// { +// None +// } +// } +// +// } +// +// impl< 'a, Row, Key, Cell > Cells< Key, Cell > +// for Row +// where +// // Row : Clone + Cells< Key, Cell >, +// Row : Fields< 'a, Key, Cell >, +// Cell : fmt::Debug + Clone, +// { +// +// fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) > +// { +// self.fields() +// } +// +// } // == @@ -211,14 +217,15 @@ pub trait TableFormatter } /// A trait for formatting tables. -impl< T, Row, Key, Cell, Title > TableFormatter for AsTable< T, Row, Key, Cell, Title > +impl< 'a, T, Row, Key, Cell, Title > TableFormatter +for AsTable< 'a, T, Row, Key, Cell, Title > where T : TableRows< Row, Key, Cell >, T : TableHeader< Key, Title >, T : TableSize, - Row : Cells< Key, Cell >, + Row : Clone + Cells< Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug, + Cell : fmt::Debug + Clone, { fn fmt( &self, f : &mut Formatter< '_ > ) -> fmt::Result { diff --git a/module/move/assistant/src/reflect.rs b/module/move/assistant/src/reflect.rs index 2d540a58b4..271fcc34d3 100644 --- a/module/move/assistant/src/reflect.rs +++ b/module/move/assistant/src/reflect.rs @@ -34,10 +34,12 @@ where /// /// - `K`: The key type. /// - `E`: The element type. -pub trait Fields< K, E > +pub trait Fields< 'a, K, E > +where + E : Clone + 'a, { /// Returns an iterator over all fields of the specified type within the entity. - fn fields( &self ) -> impl IteratorTrait< Item = ( K, E ) >; + fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, std::borrow::Cow< 'a, E > ) >; } // /// Return number of fields convertible into a specified type withing an entity. diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 93edcad3d9..c9e7188bd5 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -10,6 +10,7 @@ use assistant:: use std:: { collections::HashMap, + borrow::Cow, }; /// Struct representing a test object with various fields. @@ -21,25 +22,38 @@ pub struct TestObject pub tools : Option< Vec< HashMap< String, String > > >, } -impl Fields< &'static str, String > for TestObject +impl< 'a > Fields< 'a, &'static str, String > for TestObject { - fn fields( &self ) -> impl IteratorTrait< Item = ( &'static str, String ) > + fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Cow< 'a, String > ) > { - let mut vec : Vec< ( &'static str, String ) > = Vec::new(); + let mut vec : Vec< ( &'static str, Cow< 'a, String > ) > = Vec::new(); - vec.push( ( "id", self.id.clone() ) ); - vec.push( ( "created_at", self.created_at.to_string() ) ); - vec.push( ( "file_ids", format!( "{:?}", self.file_ids ) ) ); + vec.push( ( "id", Cow::Borrowed( &self.id ) ) ); + vec.push( ( "created_at", Cow::Owned( self.created_at.to_string() ) ) ); + vec.push( ( "file_ids", Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ); if let Some( tools ) = &self.tools { - vec.push( ( "tools", format!( "{:?}", tools ) ) ); + vec.push( ( "tools", Cow::Owned( format!( "{:?}", tools ) ) ) ); } vec.into_iter() } } +// + +fn is_borrowed< 'a, T : Clone >( src : &Cow< 'a, T > ) -> bool +{ + match src + { + Cow::Borrowed( _ ) => true, + Cow::Owned( _ ) => false, + } +} + +// + #[ test ] fn basic() { @@ -60,11 +74,16 @@ fn basic() ), }; - let fields: Vec<( &'static str, String )> = test_object.fields().collect(); + let fields: Vec< _ > = test_object.fields().collect(); assert_eq!( fields.len(), 4 ); - assert_eq!( fields[ 0 ], ( "id", "12345".to_string() ) ); - assert_eq!( fields[ 1 ], ( "created_at", "1627845583".to_string() ) ); - assert_eq!( fields[ 2 ], ( "file_ids", "[\"file1\", \"file2\"]".to_string() ) ); + 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", Cow::Borrowed( &"12345".to_string() ) ) ); + assert_eq!( fields[ 1 ], ( "created_at", Cow::Owned( "1627845583".to_string() ) ) ); + assert_eq!( fields[ 2 ], ( "file_ids", Cow::Owned( "[\"file1\", \"file2\"]".to_string() ) ) ); assert_eq!( fields[ 3 ].0, "tools" ); -} \ No newline at end of file + +} diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 98780a2c63..88d6ea7afd 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -10,6 +10,7 @@ use assistant:: use std:: { collections::HashMap, + borrow::Cow, }; /// Struct representing a test object with various fields. @@ -21,19 +22,19 @@ pub struct TestObject pub tools : Option< Vec< HashMap< String, String > > >, } -impl Fields< &'static str, String > for TestObject +impl< 'a > Fields< 'a, &'static str, String > for TestObject { - fn fields( &self ) -> impl IteratorTrait< Item = ( &'static str, String ) > + fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Cow< 'a, String > ) > { - let mut vec : Vec< ( &'static str, String ) > = Vec::new(); + let mut vec : Vec< ( &'static str, Cow< 'a, String > ) > = Vec::new(); - vec.push( ( "id", self.id.clone() ) ); - vec.push( ( "created_at", self.created_at.to_string() ) ); - vec.push( ( "file_ids", format!( "{:?}", self.file_ids ) ) ); + vec.push( ( "id", Cow::Borrowed( &self.id ) ) ); + vec.push( ( "created_at", Cow::Owned( self.created_at.to_string() ) ) ); + vec.push( ( "file_ids", Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ); if let Some( tools ) = &self.tools { - vec.push( ( "tools", format!( "{:?}", tools ) ) ); + vec.push( ( "tools", Cow::Owned( format!( "{:?}", tools ) ) ) ); } vec.into_iter() @@ -48,9 +49,49 @@ impl Fields< &'static str, String > for TestObject // } // } +// + +fn is_borrowed< 'a, T : Clone >( src : &Cow< 'a, T > ) -> bool +{ + match src + { + Cow::Borrowed( _ ) => true, + Cow::Owned( _ ) => false, + } +} + +// + #[ test ] fn basic() { + let test_object = TestObject + { + id : "12345".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".to_string() ], + tools : Some + ( + vec! + [{ + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + }] + ), + }; + let fields: Vec< _ > = test_object.fields().collect(); -} \ No newline at end of file + assert_eq!( fields.len(), 4 ); + 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", Cow::Borrowed( &"12345".to_string() ) ) ); + assert_eq!( fields[ 1 ], ( "created_at", Cow::Owned( "1627845583".to_string() ) ) ); + assert_eq!( fields[ 2 ], ( "file_ids", Cow::Owned( "[\"file1\", \"file2\"]".to_string() ) ) ); + assert_eq!( fields[ 3 ].0, "tools" ); + +} From 56a7eab7f946f33fa10719b5c76a7c10a14ba483 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 00:17:06 +0300 Subject: [PATCH 022/143] experimenting --- module/move/assistant/src/print.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 320f979641..3a0f89f810 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -1,6 +1,7 @@ use super::*; use core::fmt; +use std::borrow::Cow; use former::Former; // == @@ -122,21 +123,20 @@ where // } // // } -// -// impl< 'a, Row, Key, Cell > Cells< Key, Cell > -// for Row -// where -// // Row : Clone + Cells< Key, Cell >, -// Row : Fields< 'a, Key, Cell >, -// Cell : fmt::Debug + Clone, -// { -// -// fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) > -// { -// self.fields() -// } -// -// } + +impl< Row, Key, Cell > Cells< Key, Cell > +for Row +where + Row : for< 'a > Fields< 'a, Key, Cell >, + Cell : fmt::Debug + Clone + 'static, +{ + + fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) > + { + self.fields().map( move | ( key, cell ) | ( key, cell.into_owned() ) ) + } + +} // == From 480dc34d93153ee2eb45376577605d46a14f2c66 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 00:24:16 +0300 Subject: [PATCH 023/143] experimenting --- module/move/assistant/src/print.rs | 43 ++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 3a0f89f810..85c409c5a7 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -27,6 +27,8 @@ where pub trait TableHeader< Key, Title > where Title : fmt::Debug, + // Title : 'a, + // Self : 'a, { /// Returns an iterator over all fields of the specified type within the entity. fn header( &self ) -> Option< impl IteratorTrait< Item = ( Key, Title ) > >; @@ -38,7 +40,12 @@ where Cell : fmt::Debug + Clone, { /// Returns an iterator over all cells of the row. - fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) >; + fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) > + // where + // Self : 'a, + // Cell : 'a, + // Key : 'static, + ; } // == @@ -94,7 +101,7 @@ where // } // // } -// + // impl< 'a, T, Row, Key, Cell, Title > TableHeader< Key, Title > // for AsTable< 'a, T, Row, Key, Cell, Title > // where @@ -138,6 +145,38 @@ where } +// /// A trait for iterating over all cells of a row. +// pub trait Cells2< 'a, Key, Cell > +// where +// Cell : fmt::Debug + Clone, +// { +// /// Returns an iterator over all cells of the row. +// fn cells( &'a self ) -> impl IteratorTrait< Item = ( Key, Cell ) > +// where +// // Self : 'a, +// // Cell : 'a, +// // Key : 'static, +// ; +// } +// +// impl< 'a, Row, Key, Cell > Cells2< 'a, Key, Cell > +// for Row +// where +// Row : Fields< 'a, Key, Cell >, +// Cell : fmt::Debug + Clone + 'static, +// { +// +// fn cells( &'a self ) -> impl IteratorTrait< Item = ( Key, Cell ) > +// where +// // Self : 'a, +// // Cell : 'a, +// // Key : 'static, +// { +// self.fields().map( move | ( key, cell ) | ( key, cell.into_owned() ) ) +// } +// +// } + // == /// Struct to hold options to print data as table. From e811daf3cb9333e0b39d764134a86ce73dc1f043 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 01:26:47 +0300 Subject: [PATCH 024/143] experimenting --- module/move/assistant/src/as_table.rs | 38 +++++++-------- module/move/assistant/src/print.rs | 66 +++++++++++++-------------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 1dc92aa606..aa86338e07 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -9,18 +9,18 @@ use core::fmt; #[ repr( transparent ) ] pub struct AsTable< 'a, T, Row, Key, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( Row, Key, Cell, Title, &'a () ) > ) where - T : TableRows< Row, Key, Cell >, - T : TableHeader< Key, Title >, + T : TableRows< 'a, Row, Key, Cell >, + T : TableHeader< 'a, Key, Title >, T : TableSize, - Row : 'a + Clone + Cells< Key, Cell >, + Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone, ; impl< 'a, T, Row, Key, Cell, Title > AsRef< T > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : 'a + Clone + Cells< Key, Cell >, + T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, + Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone { @@ -32,8 +32,8 @@ where impl< 'a, T, Row, Key, Cell, Title > AsMut< T > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : 'a + Clone + Cells< Key, Cell >, + T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, + Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone { @@ -45,8 +45,8 @@ where impl< 'a, T, Row, Key, Cell, Title > Deref for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : 'a + Clone + Cells< Key, Cell >, + T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, + Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone { @@ -60,8 +60,8 @@ where impl< 'a, T, Row, Key, Cell, Title > DerefMut for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : 'a + Clone + Cells< Key, Cell >, + T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, + Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone { @@ -73,8 +73,8 @@ where impl< 'a, T, Row, Key, Cell, Title > From< T > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : 'a + Clone + Cells< Key, Cell >, + T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, + Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone { @@ -86,8 +86,8 @@ where // impl< 'a, T, Row, Key, Cell, Title > From< AsTable< 'a, T, Row, Key, Cell, Title > > for T // where -// T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, -// Row : 'a + Clone + Cells< Key, Cell >, +// T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, +// Row : 'a + Clone + Cells< 'a, Key, Cell >, // Title : fmt::Debug, // Cell : fmt::Debug + Clone // { @@ -99,8 +99,8 @@ where impl< 'a, T, Row, Key, Cell, Title > Default for AsTable< 'a, T, Row, Key, Cell, Title > where - T : Default + TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize, - Row : 'a + Clone + Cells< Key, Cell >, + T : Default + TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, + Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone { @@ -112,8 +112,8 @@ where impl< 'a, T, Row, Key, Cell, Title > fmt::Debug for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell > + TableHeader< Key, Title > + TableSize + fmt::Debug, - Row : 'a + Clone + Cells< Key, Cell >, + T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize + fmt::Debug, + Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone { diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 85c409c5a7..09bf66b1bc 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -14,33 +14,33 @@ pub trait TableSize } /// A trait for iterating over all rows of a table. -pub trait TableRows< Row, Key, Cell > +pub trait TableRows< 'a, Row, Key, Cell > where - Row : Clone + Cells< Key, Cell >, + Row : Clone + Cells< 'a, Key, Cell >, Cell : fmt::Debug + Clone, { /// Returns an iterator over all rows of the table. - fn rows( &self ) -> impl IteratorTrait< Item = Row >; + fn rows( &'a self ) -> impl IteratorTrait< Item = Row >; } /// Trait returning headers of a table if any. -pub trait TableHeader< Key, Title > +pub trait TableHeader< 'a, Key, Title > where Title : fmt::Debug, // Title : 'a, // Self : 'a, { /// Returns an iterator over all fields of the specified type within the entity. - fn header( &self ) -> Option< impl IteratorTrait< Item = ( Key, Title ) > >; + fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( Key, Title ) > >; } /// A trait for iterating over all cells of a row. -pub trait Cells< Key, Cell > +pub trait Cells< 'a, Key, Cell > where Cell : fmt::Debug + Clone, { /// Returns an iterator over all cells of the row. - fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) > + fn cells( &'a self ) -> impl IteratorTrait< Item = ( Key, Cell ) > // where // Self : 'a, // Cell : 'a, @@ -53,10 +53,10 @@ where // impl< 'a, T, Row, Key, Cell, Title > TableSize // for AsTable< 'a, T, Row, Key, Cell, Title > // where -// T : TableRows< Row, Key, Cell >, -// T : TableHeader< Key, Title >, +// T : TableRows< 'a, Row, Key, Cell >, +// T : TableHeader< 'a, Key, Title >, // T : TableSize, -// Row : Clone + Cells< Key, Cell >, +// Row : Clone + Cells< 'a, Key, Cell >, // Title : fmt::Debug, // Cell : fmt::Debug + Clone, // { @@ -77,16 +77,16 @@ where // } // } // -// impl< 'a, T, Row, Key, Cell, Title > TableRows< Row, Key, Cell > +// impl< 'a, T, Row, Key, Cell, Title > TableRows< 'a, Row, Key, Cell > // for AsTable< 'a, T, Row, Key, Cell, Title > // where // Self : 'a, // // Self : 'static, -// T : TableRows< Row, Key, Cell >, -// T : TableHeader< Key, Title >, +// T : TableRows< 'a, Row, Key, Cell >, +// T : TableHeader< 'a, Key, Title >, // T : TableSize, // T : Fields< 'a, Key, Row >, -// Row : Clone + Cells< Key, Cell >, +// Row : Clone + Cells< 'a, Key, Cell >, // Row : 'static, // Title : fmt::Debug, // Cell : fmt::Debug + Clone, @@ -102,13 +102,13 @@ where // // } -// impl< 'a, T, Row, Key, Cell, Title > TableHeader< Key, Title > +// impl< 'a, T, Row, Key, Cell, Title > TableHeader< 'a, Key, Title > // for AsTable< 'a, T, Row, Key, Cell, Title > // where -// T : TableRows< Row, Key, Cell >, -// T : TableHeader< Key, Title >, +// T : TableRows< 'a, Row, Key, Cell >, +// T : TableHeader< 'a, Key, Title >, // T : TableSize, -// Row : Clone + Cells< Key, Cell >, +// Row : Clone + Cells< 'a, Key, Cell >, // Row : Fields< 'a, Key, Title >, // Key : Clone, // Title : fmt::Debug + Clone, @@ -131,14 +131,14 @@ where // // } -impl< Row, Key, Cell > Cells< Key, Cell > +impl< 'a, Row, Key, Cell > Cells< 'a, Key, Cell > for Row where - Row : for< 'a > Fields< 'a, Key, Cell >, - Cell : fmt::Debug + Clone + 'static, + Row : Fields< 'a, Key, Cell >, + Cell : fmt::Debug + Clone + 'a, // xxx { - fn cells( &self ) -> impl IteratorTrait< Item = ( Key, Cell ) > + fn cells( &'a self ) -> impl IteratorTrait< Item = ( Key, Cell ) > { self.fields().map( move | ( key, cell ) | ( key, cell.into_owned() ) ) } @@ -228,7 +228,7 @@ pub trait TableToString impl< T > TableToString for T where - T : TableFormatter + T : for< 'b > TableFormatter< 'b > { fn table_to_string( &self ) -> String { @@ -249,24 +249,25 @@ where /// to specify how a table should be formatted and displayed. /// -pub trait TableFormatter +pub trait TableFormatter< 'b > { /// Formats the table and writes the result to the given formatter. - fn fmt( &self, f : &mut Formatter< '_ > ) -> fmt::Result; + fn fmt( &'b self, f : &'b mut Formatter< '_ > ) -> fmt::Result; } /// A trait for formatting tables. -impl< 'a, T, Row, Key, Cell, Title > TableFormatter +impl< 'a, T, Row, Key, Cell, Title > TableFormatter< 'a > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< Row, Key, Cell >, - T : TableHeader< Key, Title >, + T : TableRows< 'a, Row, Key, Cell >, + T : TableHeader< 'a, Key, Title >, T : TableSize, - Row : Clone + Cells< Key, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone, + // 'b : 'a, { - fn fmt( &self, f : &mut Formatter< '_ > ) -> fmt::Result + fn fmt( &'a self, f : &'a mut Formatter< '_ > ) -> fmt::Result { let size = self.size(); let mut col_widths : Vec< usize > = vec![ 0 ; size[ 1 ] ]; @@ -298,10 +299,9 @@ where { let fields : Vec< String > = row .cells() - // .map( | ( key, value ) | format!( "{:?}: {:?}", key, value ) ) - .map( | ( _key, cell ) | format!( "{:?}", cell ) ) + .map( | ( _key, cell ) | format!( "{:?}", &cell ) ) .collect(); - all_rows.push( fields ); + // all_rows.push( fields ); } for row in &all_rows From 5c602888410bfaca6678ec7a6611ed3985b70018 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 01:27:03 +0300 Subject: [PATCH 025/143] experimenting --- module/move/assistant/src/print.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 09bf66b1bc..e1e9f7fc39 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -301,7 +301,7 @@ where .cells() .map( | ( _key, cell ) | format!( "{:?}", &cell ) ) .collect(); - // all_rows.push( fields ); + all_rows.push( fields ); } for row in &all_rows From 1b4f3f85168ec941fefb4cf1b3d0077c59079d55 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 01:47:17 +0300 Subject: [PATCH 026/143] experimenting --- module/move/assistant/src/as_table.rs | 18 +-- module/move/assistant/src/print.rs | 103 +++++++----------- module/move/assistant/src/reflect.rs | 3 +- module/move/assistant/tests/inc/print_test.rs | 15 +-- 4 files changed, 58 insertions(+), 81 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index aa86338e07..c4b100bbb8 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -14,7 +14,7 @@ where T : TableSize, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Clone, + Cell : fmt::Debug + Clone + 'static, ; impl< 'a, T, Row, Key, Cell, Title > AsRef< T > for AsTable< 'a, T, Row, Key, Cell, Title > @@ -22,7 +22,7 @@ where T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Clone + Cell : fmt::Debug + Clone + 'static, { fn as_ref( &self ) -> &T { @@ -35,7 +35,7 @@ where T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Clone + Cell : fmt::Debug + Clone + 'static, { fn as_mut( &mut self ) -> &mut T { @@ -48,7 +48,7 @@ where T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Clone + Cell : fmt::Debug + Clone + 'static, { type Target = T; @@ -63,7 +63,7 @@ where T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Clone + Cell : fmt::Debug + Clone + 'static, { fn deref_mut( &mut self ) -> &mut Self::Target { @@ -76,7 +76,7 @@ where T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Clone + Cell : fmt::Debug + Clone + 'static, { fn from( table : T ) -> Self { @@ -89,7 +89,7 @@ where // T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, // Row : 'a + Clone + Cells< 'a, Key, Cell >, // Title : fmt::Debug, -// Cell : fmt::Debug + Clone +// Cell : fmt::Debug + Clone + 'static, // { // fn from( as_table : AsTable< 'a, T, Row, Key, Cell, Title > ) -> Self // { @@ -102,7 +102,7 @@ where T : Default + TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Clone + Cell : fmt::Debug + Clone + 'static, { fn default() -> Self { @@ -115,7 +115,7 @@ where T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize + fmt::Debug, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Clone + Cell : fmt::Debug + Clone + 'static, { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index e1e9f7fc39..2689106d3c 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -17,7 +17,7 @@ pub trait TableSize pub trait TableRows< 'a, Row, Key, Cell > where Row : Clone + Cells< 'a, Key, Cell >, - Cell : fmt::Debug + Clone, + Cell : fmt::Debug + Clone + 'static, { /// Returns an iterator over all rows of the table. fn rows( &'a self ) -> impl IteratorTrait< Item = Row >; @@ -37,7 +37,7 @@ where /// A trait for iterating over all cells of a row. pub trait Cells< 'a, Key, Cell > where - Cell : fmt::Debug + Clone, + Cell : fmt::Debug + Clone + 'static, { /// Returns an iterator over all cells of the row. fn cells( &'a self ) -> impl IteratorTrait< Item = ( Key, Cell ) > @@ -102,40 +102,47 @@ where // // } -// impl< 'a, T, Row, Key, Cell, Title > TableHeader< 'a, Key, Title > -// for AsTable< 'a, T, Row, Key, Cell, Title > -// where -// T : TableRows< 'a, Row, Key, Cell >, -// T : TableHeader< 'a, Key, Title >, -// T : TableSize, -// Row : Clone + Cells< 'a, Key, Cell >, -// Row : Fields< 'a, Key, Title >, -// Key : Clone, -// Title : fmt::Debug + Clone, -// Cell : fmt::Debug + Clone, -// { -// -// fn header( &self ) -> Option< impl IteratorTrait< Item = ( Key, Title ) > > -// { -// let mut rows = self.rows(); -// let row = rows.next(); -// if let Some( row ) = row -// { -// Some( row.fields().collect::< Vec< _ > >().into_iter() ) -// } -// else -// { -// None -// } -// } -// -// } +impl< 'a, T, Row, Key, Cell, Title > TableHeader< 'a, Key, Title > +for AsTable< 'a, T, Row, Key, Cell, Title > +where + T : TableRows< 'a, Row, Key, Cell >, + T : TableHeader< 'a, Key, Title >, + T : TableSize, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell >, + Row : for< 'cell > Fields< 'cell, Key, Title >, + Key : Clone + 'static, + Title : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'static, +{ + + fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( Key, Title ) > > + { + let mut rows = self.rows(); + let row = rows.next(); + if let Some( row ) = row + { + Some + ( + row + .fields() + .map( | ( key, title ) | ( key, title.into_owned() ) ) + .collect::< Vec< _ > >() + .into_iter() + ) + } + else + { + None + } + } + +} impl< 'a, Row, Key, Cell > Cells< 'a, Key, Cell > for Row where Row : Fields< 'a, Key, Cell >, - Cell : fmt::Debug + Clone + 'a, // xxx + Cell : fmt::Debug + Clone + 'static, { fn cells( &'a self ) -> impl IteratorTrait< Item = ( Key, Cell ) > @@ -145,38 +152,6 @@ where } -// /// A trait for iterating over all cells of a row. -// pub trait Cells2< 'a, Key, Cell > -// where -// Cell : fmt::Debug + Clone, -// { -// /// Returns an iterator over all cells of the row. -// fn cells( &'a self ) -> impl IteratorTrait< Item = ( Key, Cell ) > -// where -// // Self : 'a, -// // Cell : 'a, -// // Key : 'static, -// ; -// } -// -// impl< 'a, Row, Key, Cell > Cells2< 'a, Key, Cell > -// for Row -// where -// Row : Fields< 'a, Key, Cell >, -// Cell : fmt::Debug + Clone + 'static, -// { -// -// fn cells( &'a self ) -> impl IteratorTrait< Item = ( Key, Cell ) > -// where -// // Self : 'a, -// // Cell : 'a, -// // Key : 'static, -// { -// self.fields().map( move | ( key, cell ) | ( key, cell.into_owned() ) ) -// } -// -// } - // == /// Struct to hold options to print data as table. @@ -264,7 +239,7 @@ where T : TableSize, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell >, Title : fmt::Debug, - Cell : fmt::Debug + Clone, + Cell : fmt::Debug + Clone + 'static, // 'b : 'a, { fn fmt( &'a self, f : &'a mut Formatter< '_ > ) -> fmt::Result diff --git a/module/move/assistant/src/reflect.rs b/module/move/assistant/src/reflect.rs index 271fcc34d3..47a1efe03e 100644 --- a/module/move/assistant/src/reflect.rs +++ b/module/move/assistant/src/reflect.rs @@ -36,7 +36,8 @@ where /// - `E`: The element type. pub trait Fields< 'a, K, E > where - E : Clone + 'a, + E : Clone + 'static, + // K : 'static, { /// Returns an iterator over all fields of the specified type within the entity. fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, std::borrow::Cow< 'a, E > ) >; diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 88d6ea7afd..8ae8f8c257 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -14,6 +14,7 @@ use std:: }; /// Struct representing a test object with various fields. +#[ derive( Clone ) ] pub struct TestObject { pub id : String, @@ -41,13 +42,13 @@ impl< 'a > Fields< 'a, &'static str, String > for TestObject } } -// impl< 'a > Fields< usize, &'a TestObject > for Vec< TestObject > -// { -// fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, &'a TestObject ) > -// { -// self.iter().enumerate() -// } -// } +impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > +{ + fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Cow< 'a, TestObject > ) > + { + self.iter().enumerate().map( | ( key, val ) | ( key, Cow::Borrowed( val ) ) ) + } +} // From 116d5f91a0d4e73efb5b4c2de2b1979693d17a58 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 01:55:20 +0300 Subject: [PATCH 027/143] experimenting --- module/move/assistant/src/as_table.rs | 18 +-- module/move/assistant/src/print.rs | 112 +++++++++--------- module/move/assistant/src/reflect.rs | 2 +- .../move/assistant/tests/inc/fields_test.rs | 9 ++ module/move/assistant/tests/inc/print_test.rs | 2 +- 5 files changed, 76 insertions(+), 67 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index c4b100bbb8..2f5087b0e7 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -11,7 +11,7 @@ pub struct AsTable< 'a, T, Row, Key, Cell, Title >( T, ::core::marker::PhantomDa where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, - T : TableSize, + T : TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -19,7 +19,7 @@ where impl< 'a, T, Row, Key, Cell, Title > AsRef< T > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, + T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -32,7 +32,7 @@ where impl< 'a, T, Row, Key, Cell, Title > AsMut< T > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, + T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -45,7 +45,7 @@ where impl< 'a, T, Row, Key, Cell, Title > Deref for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, + T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -60,7 +60,7 @@ where impl< 'a, T, Row, Key, Cell, Title > DerefMut for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, + T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -73,7 +73,7 @@ where impl< 'a, T, Row, Key, Cell, Title > From< T > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, + T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -86,7 +86,7 @@ where // impl< 'a, T, Row, Key, Cell, Title > From< AsTable< 'a, T, Row, Key, Cell, Title > > for T // where -// T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, +// T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, // Row : 'a + Clone + Cells< 'a, Key, Cell >, // Title : fmt::Debug, // Cell : fmt::Debug + Clone + 'static, @@ -99,7 +99,7 @@ where impl< 'a, T, Row, Key, Cell, Title > Default for AsTable< 'a, T, Row, Key, Cell, Title > where - T : Default + TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize, + T : Default + TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -112,7 +112,7 @@ where impl< 'a, T, Row, Key, Cell, Title > fmt::Debug for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize + fmt::Debug, + T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a > + fmt::Debug, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 2689106d3c..8fe3274167 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -1,16 +1,16 @@ use super::*; use core::fmt; -use std::borrow::Cow; +// use std::borrow::Cow; use former::Former; // == /// A trait for iterating over all rows of a table. -pub trait TableSize +pub trait TableSize< 'a > { /// Returns size of a table. - fn size( &self ) -> [ usize ; 2 ]; + fn size( &'a self ) -> [ usize ; 2 ]; } /// A trait for iterating over all rows of a table. @@ -50,64 +50,64 @@ where // == -// impl< 'a, T, Row, Key, Cell, Title > TableSize -// for AsTable< 'a, T, Row, Key, Cell, Title > -// where -// T : TableRows< 'a, Row, Key, Cell >, -// T : TableHeader< 'a, Key, Title >, -// T : TableSize, -// Row : Clone + Cells< 'a, Key, Cell >, -// Title : fmt::Debug, -// Cell : fmt::Debug + Clone, -// { -// fn size( &self ) -> [ usize ; 2 ] -// { -// let mut rows = self.rows(); -// let nrows = rows.len(); -// let row = rows.next(); -// if let Some( row ) = row -// { -// let ncells = row.cells().len(); -// [ nrows, ncells ] -// } -// else -// { -// [ 0, 0 ] -// } -// } -// } -// -// impl< 'a, T, Row, Key, Cell, Title > TableRows< 'a, Row, Key, Cell > -// for AsTable< 'a, T, Row, Key, Cell, Title > -// where -// Self : 'a, -// // Self : 'static, -// T : TableRows< 'a, Row, Key, Cell >, -// T : TableHeader< 'a, Key, Title >, -// T : TableSize, -// T : Fields< 'a, Key, Row >, -// Row : Clone + Cells< 'a, Key, Cell >, -// Row : 'static, -// Title : fmt::Debug, -// Cell : fmt::Debug + Clone, -// { -// -// fn rows( &self ) -> impl IteratorTrait< Item = Row > -// where -// // Self : 'a, -// // Self : 'static, -// { -// self.fields().map( move | ( _k, e ) | e.into_owned() ) -// } -// -// } +impl< 'a, T, Row, Key, Cell, Title > TableSize< 'a > +for AsTable< 'a, T, Row, Key, Cell, Title > +where + T : TableRows< 'a, Row, Key, Cell >, + T : TableHeader< 'a, Key, Title >, + T : TableSize< 'a >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell >, + Title : fmt::Debug, + Cell : fmt::Debug + Clone, +{ + fn size( &'a self ) -> [ usize ; 2 ] + { + let mut rows = self.rows(); + let nrows = rows.len(); + let row = rows.next(); + if let Some( row ) = row + { + let ncells = row.cells().len(); + [ nrows, ncells ] + } + else + { + [ 0, 0 ] + } + } +} + +impl< 'a, T, Row, Key, Cell, Title > TableRows< 'a, Row, Key, Cell > +for AsTable< 'a, T, Row, Key, Cell, Title > +where + // Self : 'a, + // Self : 'static, + T : TableRows< 'a, Row, Key, Cell >, + T : TableHeader< 'a, Key, Title >, + T : TableSize< 'a >, + T : Fields< 'a, Key, Row >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell >, + // Row : 'static, + Title : fmt::Debug, + Cell : fmt::Debug + Clone, +{ + + fn rows( &'a self ) -> impl IteratorTrait< Item = Row > + where + // Self : 'a, + // Self : 'static, + { + self.fields().map( move | ( _k, e ) | e.into_owned() ) + } + +} impl< 'a, T, Row, Key, Cell, Title > TableHeader< 'a, Key, Title > for AsTable< 'a, T, Row, Key, Cell, Title > where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, - T : TableSize, + T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell >, Row : for< 'cell > Fields< 'cell, Key, Title >, Key : Clone + 'static, @@ -236,7 +236,7 @@ for AsTable< 'a, T, Row, Key, Cell, Title > where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, - T : TableSize, + T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, diff --git a/module/move/assistant/src/reflect.rs b/module/move/assistant/src/reflect.rs index 47a1efe03e..85368aa236 100644 --- a/module/move/assistant/src/reflect.rs +++ b/module/move/assistant/src/reflect.rs @@ -36,7 +36,7 @@ where /// - `E`: The element type. pub trait Fields< 'a, K, E > where - E : Clone + 'static, + E : Clone + 'a, // K : 'static, { /// Returns an iterator over all fields of the specified type within the entity. diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index c9e7188bd5..61d2da3d4d 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -14,6 +14,7 @@ use std:: }; /// Struct representing a test object with various fields. +#[ derive( Clone, Debug ) ] pub struct TestObject { pub id : String, @@ -41,6 +42,14 @@ impl< 'a > Fields< 'a, &'static str, String > for TestObject } } +impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > +{ + fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Cow< 'a, TestObject > ) > + { + self.iter().enumerate().map( | ( key, val ) | ( key, Cow::Borrowed( val ) ) ) + } +} + // fn is_borrowed< 'a, T : Clone >( src : &Cow< 'a, T > ) -> bool diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 8ae8f8c257..61d2da3d4d 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -14,7 +14,7 @@ use std:: }; /// Struct representing a test object with various fields. -#[ derive( Clone ) ] +#[ derive( Clone, Debug ) ] pub struct TestObject { pub id : String, From 9ce86b6f984e6f64a723009b48d821e42bf6d959 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 01:56:57 +0300 Subject: [PATCH 028/143] experimenting --- .../move/assistant/tests/inc/fields_test.rs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 61d2da3d4d..e748e27a4a 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -96,3 +96,41 @@ fn basic() assert_eq!( fields[ 3 ].0, "tools" ); } + +// + +#[ test ] +fn test_vec_fields() +{ + let test_objects = vec! + [ + TestObject + { + id : "12345".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".to_string() ], + tools : Some + ( + vec! + [{ + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + }] + ), + }, + TestObject + { + id : "67890".to_string(), + created_at : 1627845584, + file_ids : vec![ "file3".to_string(), "file4".to_string() ], + tools : None, + } + ]; + + let fields: Vec< _ > = test_objects.fields().collect(); + assert_eq!( fields.len(), 2 ); + assert_eq!( fields[ 0 ].0, 0 ); + assert_eq!( fields[ 1 ].0, 1 ); +} From f1cdbcb4798b5665ddd5abbddacd5d3f5e93c1ea Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 02:05:46 +0300 Subject: [PATCH 029/143] experimenting --- module/move/assistant/tests/inc/print_test.rs | 78 +++++++++---------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 61d2da3d4d..f26b79337f 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -52,47 +52,45 @@ impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > // -fn is_borrowed< 'a, T : Clone >( src : &Cow< 'a, T > ) -> bool -{ - match src - { - Cow::Borrowed( _ ) => true, - Cow::Owned( _ ) => false, - } -} - -// - #[ test ] -fn basic() +fn test_table_to_string() { - let test_object = TestObject - { - id : "12345".to_string(), - created_at : 1627845583, - file_ids : vec![ "file1".to_string(), "file2".to_string() ], - tools : Some - ( - vec! - [{ - let mut map = HashMap::new(); - map.insert( "tool1".to_string(), "value1".to_string() ); - map.insert( "tool2".to_string(), "value2".to_string() ); - map - }] - ), - }; - - let fields: Vec< _ > = test_object.fields().collect(); + use the_module::TableToString; - assert_eq!( fields.len(), 4 ); - 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", Cow::Borrowed( &"12345".to_string() ) ) ); - assert_eq!( fields[ 1 ], ( "created_at", Cow::Owned( "1627845583".to_string() ) ) ); - assert_eq!( fields[ 2 ], ( "file_ids", Cow::Owned( "[\"file1\", \"file2\"]".to_string() ) ) ); - assert_eq!( fields[ 3 ].0, "tools" ); + let test_objects = vec! + [ + TestObject + { + id : "1".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".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 + } + ]), + }, + TestObject + { + id : "2".to_string(), + created_at : 1627845584, + file_ids : vec![ "file3".to_string(), "file4".to_string() ], + tools : None, + } + ]; -} + // let table_string = test_objects.table_to_string(); + // println!( "{}", table_string ); + // assert!( table_string.contains( "id" ) ); + // assert!( table_string.contains( "created_at" ) ); + // assert!( table_string.contains( "file_ids" ) ); + // assert!( table_string.contains( "tools" ) ); +} \ No newline at end of file From 38495a71ac5cdfcd936b4cbe0e0cf5d901ba7254 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 08:17:26 +0300 Subject: [PATCH 030/143] experimenting --- module/move/assistant/src/as_table.rs | 14 ++++++++++++++ module/move/assistant/tests/inc/print_test.rs | 12 ++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 2f5087b0e7..0f86e54193 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -17,6 +17,20 @@ where Cell : fmt::Debug + Clone + 'static, ; +impl< 'a, T, Row, Key, Cell, Title > AsTable< 'a, T, Row, Key, Cell, Title > +where + T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, + Row : 'a + Clone + Cells< 'a, Key, Cell >, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'static, +{ + /// Just a constructor. + pub fn new( src : T ) -> Self + { + Self( src, Default::default() ) + } +} + impl< 'a, T, Row, Key, Cell, Title > AsRef< T > for AsTable< 'a, T, Row, Key, Cell, Title > where T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index f26b79337f..74cb9ce3a0 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -5,6 +5,8 @@ use assistant:: { Fields, IteratorTrait, + AsTable, + Cells, }; use std:: @@ -87,10 +89,16 @@ fn test_table_to_string() } ]; - // let table_string = test_objects.table_to_string(); + let cells = Cells::< '_, &'static str, String >::cells( &test_objects[ 0 ] ); + assert_eq!( cells.len(), 4 ); + dbg!( cells.collect::< Vec< _ > >() ); + + // AsTable::new( test_objects ); + // let table_string = AsTable::new( test_objects ).table_to_string(); // println!( "{}", table_string ); // assert!( table_string.contains( "id" ) ); // assert!( table_string.contains( "created_at" ) ); // assert!( table_string.contains( "file_ids" ) ); // assert!( table_string.contains( "tools" ) ); -} \ No newline at end of file + +} From f32c01cc56eaa980cbe744906e112a06d71d83ba Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 08:18:48 +0300 Subject: [PATCH 031/143] experimenting --- module/move/assistant/src/as_table.rs | 34 ++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 0f86e54193..48c899b019 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -19,7 +19,9 @@ where impl< 'a, T, Row, Key, Cell, Title > AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, + T : TableRows< 'a, Row, Key, Cell >, + T : TableHeader< 'a, Key, Title >, + T : TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -33,7 +35,9 @@ where impl< 'a, T, Row, Key, Cell, Title > AsRef< T > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, + T : TableRows< 'a, Row, Key, Cell >, + T : TableHeader< 'a, Key, Title >, + T : TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -46,7 +50,9 @@ where impl< 'a, T, Row, Key, Cell, Title > AsMut< T > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, + T : TableRows< 'a, Row, Key, Cell >, + T : TableHeader< 'a, Key, Title >, + T : TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -59,7 +65,9 @@ where impl< 'a, T, Row, Key, Cell, Title > Deref for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, + T : TableRows< 'a, Row, Key, Cell >, + T : TableHeader< 'a, Key, Title >, + T : TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -74,7 +82,9 @@ where impl< 'a, T, Row, Key, Cell, Title > DerefMut for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, + T : TableRows< 'a, Row, Key, Cell >, + T : TableHeader< 'a, Key, Title >, + T : TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -87,7 +97,9 @@ where impl< 'a, T, Row, Key, Cell, Title > From< T > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, + T : TableRows< 'a, Row, Key, Cell >, + T : TableHeader< 'a, Key, Title >, + T : TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -113,7 +125,10 @@ where impl< 'a, T, Row, Key, Cell, Title > Default for AsTable< 'a, T, Row, Key, Cell, Title > where - T : Default + TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, + T : Default, + T : TableRows< 'a, Row, Key, Cell >, + T : TableHeader< 'a, Key, Title >, + T : TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, @@ -126,7 +141,10 @@ where impl< 'a, T, Row, Key, Cell, Title > fmt::Debug for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a > + fmt::Debug, + T : fmt::Debug, + T : TableRows< 'a, Row, Key, Cell >, + T : TableHeader< 'a, Key, Title >, + T : TableSize< 'a >, Row : 'a + Clone + Cells< 'a, Key, Cell >, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, From 06eecdc7c59f7589bbe05408b2f8a3714a362af1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 08:28:21 +0300 Subject: [PATCH 032/143] experimenting --- module/move/assistant/src/as_table.rs | 21 +++++++++++---------- module/move/assistant/src/print.rs | 25 ++++++++++++------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 48c899b019..d49eaa0a0b 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -12,17 +12,18 @@ where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, T : TableSize< 'a >, - Row : 'a + Clone + Cells< 'a, Key, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, ; +// xxx : use maybe ref inside impl< 'a, T, Row, Key, Cell, Title > AsTable< 'a, T, Row, Key, Cell, Title > where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, T : TableSize< 'a >, - Row : 'a + Clone + Cells< 'a, Key, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, { @@ -38,7 +39,7 @@ where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, T : TableSize< 'a >, - Row : 'a + Clone + Cells< 'a, Key, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, { @@ -53,7 +54,7 @@ where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, T : TableSize< 'a >, - Row : 'a + Clone + Cells< 'a, Key, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, { @@ -68,7 +69,7 @@ where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, T : TableSize< 'a >, - Row : 'a + Clone + Cells< 'a, Key, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, { @@ -85,7 +86,7 @@ where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, T : TableSize< 'a >, - Row : 'a + Clone + Cells< 'a, Key, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, { @@ -100,7 +101,7 @@ where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, T : TableSize< 'a >, - Row : 'a + Clone + Cells< 'a, Key, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, { @@ -113,7 +114,7 @@ where // impl< 'a, T, Row, Key, Cell, Title > From< AsTable< 'a, T, Row, Key, Cell, Title > > for T // where // T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, -// Row : 'a + Clone + Cells< 'a, Key, Cell >, +// Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, // Title : fmt::Debug, // Cell : fmt::Debug + Clone + 'static, // { @@ -129,7 +130,7 @@ where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, T : TableSize< 'a >, - Row : 'a + Clone + Cells< 'a, Key, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, { @@ -145,7 +146,7 @@ where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, T : TableSize< 'a >, - Row : 'a + Clone + Cells< 'a, Key, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, { diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 8fe3274167..380652e139 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -16,7 +16,7 @@ pub trait TableSize< 'a > /// A trait for iterating over all rows of a table. pub trait TableRows< 'a, Row, Key, Cell > where - Row : Clone + Cells< 'a, Key, Cell >, + Row : Clone + Cells< 'a, Key, Cell > + 'a, Cell : fmt::Debug + Clone + 'static, { /// Returns an iterator over all rows of the table. @@ -56,9 +56,9 @@ where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone, + Cell : fmt::Debug + Clone + 'static, { fn size( &'a self ) -> [ usize ; 2 ] { @@ -83,13 +83,12 @@ where // Self : 'a, // Self : 'static, T : TableRows< 'a, Row, Key, Cell >, + T : Fields< 'a, Key, Row >, T : TableHeader< 'a, Key, Title >, T : TableSize< 'a >, - T : Fields< 'a, Key, Row >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell >, - // Row : 'static, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone, + Cell : fmt::Debug + Clone + 'static, { fn rows( &'a self ) -> impl IteratorTrait< Item = Row > @@ -108,10 +107,10 @@ where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell >, - Row : for< 'cell > Fields< 'cell, Key, Title >, - Key : Clone + 'static, - Title : fmt::Debug + Clone + 'static, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + Row : for< 'cell > Fields< 'cell, Key, Title > + 'a, + Key : Clone, + Title : fmt::Debug + Clone, Cell : fmt::Debug + Clone + 'static, { @@ -141,7 +140,7 @@ where impl< 'a, Row, Key, Cell > Cells< 'a, Key, Cell > for Row where - Row : Fields< 'a, Key, Cell >, + Row : Fields< 'a, Key, Cell > + 'a, Cell : fmt::Debug + Clone + 'static, { @@ -237,7 +236,7 @@ where T : TableRows< 'a, Row, Key, Cell >, T : TableHeader< 'a, Key, Title >, T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, // 'b : 'a, From 1c52af4943e80015e568742fee58d3252ee92dde Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 08:31:09 +0300 Subject: [PATCH 033/143] experimenting --- module/move/assistant/src/print.rs | 8 ++++---- module/move/assistant/tests/inc/print_test.rs | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 380652e139..a085add243 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -10,7 +10,7 @@ use former::Former; pub trait TableSize< 'a > { /// Returns size of a table. - fn size( &'a self ) -> [ usize ; 2 ]; + fn table_size( &'a self ) -> [ usize ; 2 ]; } /// A trait for iterating over all rows of a table. @@ -60,7 +60,7 @@ where Title : fmt::Debug, Cell : fmt::Debug + Clone + 'static, { - fn size( &'a self ) -> [ usize ; 2 ] + fn table_size( &'a self ) -> [ usize ; 2 ] { let mut rows = self.rows(); let nrows = rows.len(); @@ -243,8 +243,8 @@ where { fn fmt( &'a self, f : &'a mut Formatter< '_ > ) -> fmt::Result { - let size = self.size(); - let mut col_widths : Vec< usize > = vec![ 0 ; size[ 1 ] ]; + let table_size = self.table_size(); + let mut col_widths : Vec< usize > = vec![ 0 ; table_size[ 1 ] ]; let separator = &f.styles.separator; // Write the header if provided diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 74cb9ce3a0..a8fedad984 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -7,6 +7,7 @@ use assistant:: IteratorTrait, AsTable, Cells, + TableSize, }; use std:: @@ -93,6 +94,9 @@ fn test_table_to_string() assert_eq!( cells.len(), 4 ); dbg!( cells.collect::< Vec< _ > >() ); + // let size = TableSize::< '_ >::table_size( &test_objects ); + // assert_eq!( size, [ 2, 4 ] ); + // AsTable::new( test_objects ); // let table_string = AsTable::new( test_objects ).table_to_string(); // println!( "{}", table_string ); From f1adf385e698f993eb62252b8bed4f8b5e4080f2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 08:33:13 +0300 Subject: [PATCH 034/143] experimenting --- module/move/assistant/src/as_table.rs | 20 ++++++++++---------- module/move/assistant/src/print.rs | 14 +++++++------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index d49eaa0a0b..724289a1d0 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -14,7 +14,7 @@ where T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, ; // xxx : use maybe ref inside @@ -25,7 +25,7 @@ where T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { /// Just a constructor. pub fn new( src : T ) -> Self @@ -41,7 +41,7 @@ where T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { fn as_ref( &self ) -> &T { @@ -56,7 +56,7 @@ where T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { fn as_mut( &mut self ) -> &mut T { @@ -71,7 +71,7 @@ where T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { type Target = T; @@ -88,7 +88,7 @@ where T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { fn deref_mut( &mut self ) -> &mut Self::Target { @@ -103,7 +103,7 @@ where T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { fn from( table : T ) -> Self { @@ -116,7 +116,7 @@ where // T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, // Title : fmt::Debug, -// Cell : fmt::Debug + Clone + 'static, +// Cell : fmt::Debug + Clone + 'a, // { // fn from( as_table : AsTable< 'a, T, Row, Key, Cell, Title > ) -> Self // { @@ -132,7 +132,7 @@ where T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { fn default() -> Self { @@ -148,7 +148,7 @@ where T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index a085add243..e16b4f3bb3 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -17,7 +17,7 @@ pub trait TableSize< 'a > pub trait TableRows< 'a, Row, Key, Cell > where Row : Clone + Cells< 'a, Key, Cell > + 'a, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { /// Returns an iterator over all rows of the table. fn rows( &'a self ) -> impl IteratorTrait< Item = Row >; @@ -37,7 +37,7 @@ where /// A trait for iterating over all cells of a row. pub trait Cells< 'a, Key, Cell > where - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { /// Returns an iterator over all cells of the row. fn cells( &'a self ) -> impl IteratorTrait< Item = ( Key, Cell ) > @@ -58,7 +58,7 @@ where T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { fn table_size( &'a self ) -> [ usize ; 2 ] { @@ -88,7 +88,7 @@ where T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { fn rows( &'a self ) -> impl IteratorTrait< Item = Row > @@ -111,7 +111,7 @@ where Row : for< 'cell > Fields< 'cell, Key, Title > + 'a, Key : Clone, Title : fmt::Debug + Clone, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( Key, Title ) > > @@ -141,7 +141,7 @@ impl< 'a, Row, Key, Cell > Cells< 'a, Key, Cell > for Row where Row : Fields< 'a, Key, Cell > + 'a, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, { fn cells( &'a self ) -> impl IteratorTrait< Item = ( Key, Cell ) > @@ -238,7 +238,7 @@ where T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'static, + Cell : fmt::Debug + Clone + 'a, // 'b : 'a, { fn fmt( &'a self, f : &'a mut Formatter< '_ > ) -> fmt::Result From 0f82968739358a84892506e57c61583db53f23c7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 08:48:34 +0300 Subject: [PATCH 035/143] experimenting --- module/move/assistant/src/as_table.rs | 108 +++++++++--------- module/move/assistant/src/print.rs | 48 ++++---- module/move/assistant/tests/inc/print_test.rs | 7 +- 3 files changed, 82 insertions(+), 81 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 724289a1d0..269dde5bf7 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -9,23 +9,23 @@ use core::fmt; #[ repr( transparent ) ] pub struct AsTable< 'a, T, Row, Key, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( Row, Key, Cell, Title, &'a () ) > ) where - T : TableRows< 'a, Row, Key, Cell >, - T : TableHeader< 'a, Key, Title >, - T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, + // T : TableRows< 'a, Row, Key, Cell >, + // T : TableHeader< 'a, Key, Title >, + // T : TableSize< 'a >, + // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, ; // xxx : use maybe ref inside impl< 'a, T, Row, Key, Cell, Title > AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell >, - T : TableHeader< 'a, Key, Title >, - T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, + // T : TableRows< 'a, Row, Key, Cell >, + // T : TableHeader< 'a, Key, Title >, + // T : TableSize< 'a >, + // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, { /// Just a constructor. pub fn new( src : T ) -> Self @@ -36,12 +36,12 @@ where impl< 'a, T, Row, Key, Cell, Title > AsRef< T > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell >, - T : TableHeader< 'a, Key, Title >, - T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, + // T : TableRows< 'a, Row, Key, Cell >, + // T : TableHeader< 'a, Key, Title >, + // T : TableSize< 'a >, + // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, { fn as_ref( &self ) -> &T { @@ -51,12 +51,12 @@ where impl< 'a, T, Row, Key, Cell, Title > AsMut< T > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell >, - T : TableHeader< 'a, Key, Title >, - T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, + // T : TableRows< 'a, Row, Key, Cell >, + // T : TableHeader< 'a, Key, Title >, + // T : TableSize< 'a >, + // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, { fn as_mut( &mut self ) -> &mut T { @@ -66,12 +66,12 @@ where impl< 'a, T, Row, Key, Cell, Title > Deref for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell >, - T : TableHeader< 'a, Key, Title >, - T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, + // T : TableRows< 'a, Row, Key, Cell >, + // T : TableHeader< 'a, Key, Title >, + // T : TableSize< 'a >, + // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, { type Target = T; @@ -83,12 +83,12 @@ where impl< 'a, T, Row, Key, Cell, Title > DerefMut for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell >, - T : TableHeader< 'a, Key, Title >, - T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, + // T : TableRows< 'a, Row, Key, Cell >, + // T : TableHeader< 'a, Key, Title >, + // T : TableSize< 'a >, + // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, { fn deref_mut( &mut self ) -> &mut Self::Target { @@ -98,12 +98,12 @@ where impl< 'a, T, Row, Key, Cell, Title > From< T > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell >, - T : TableHeader< 'a, Key, Title >, - T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, + // T : TableRows< 'a, Row, Key, Cell >, + // T : TableHeader< 'a, Key, Title >, + // T : TableSize< 'a >, + // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, { fn from( table : T ) -> Self { @@ -127,12 +127,12 @@ where impl< 'a, T, Row, Key, Cell, Title > Default for AsTable< 'a, T, Row, Key, Cell, Title > where T : Default, - T : TableRows< 'a, Row, Key, Cell >, - T : TableHeader< 'a, Key, Title >, - T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, + // T : TableRows< 'a, Row, Key, Cell >, + // T : TableHeader< 'a, Key, Title >, + // T : TableSize< 'a >, + // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, { fn default() -> Self { @@ -143,12 +143,12 @@ where impl< 'a, T, Row, Key, Cell, Title > fmt::Debug for AsTable< 'a, T, Row, Key, Cell, Title > where T : fmt::Debug, - T : TableRows< 'a, Row, Key, Cell >, - T : TableHeader< 'a, Key, Title >, - T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, + // T : TableRows< 'a, Row, Key, Cell >, + // T : TableHeader< 'a, Key, Title >, + // T : TableSize< 'a >, + // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index e16b4f3bb3..31663b4ff0 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -53,48 +53,44 @@ where impl< 'a, T, Row, Key, Cell, Title > TableSize< 'a > for AsTable< 'a, T, Row, Key, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell >, - T : TableHeader< 'a, Key, Title >, - T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, + // T : TableRows< 'a, Row, Key, Cell >, + // T : TableHeader< 'a, Key, Title >, + // T : TableSize< 'a >, + // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, { fn table_size( &'a self ) -> [ usize ; 2 ] { - let mut rows = self.rows(); - let nrows = rows.len(); - let row = rows.next(); - if let Some( row ) = row - { - let ncells = row.cells().len(); - [ nrows, ncells ] - } - else - { - [ 0, 0 ] - } + [ 0, 0 ] + // let mut rows = self.rows(); + // let nrows = rows.len(); + // let row = rows.next(); + // if let Some( row ) = row + // { + // let ncells = row.cells().len(); + // [ nrows, ncells ] + // } + // else + // { + // [ 0, 0 ] + // } } } impl< 'a, T, Row, Key, Cell, Title > TableRows< 'a, Row, Key, Cell > for AsTable< 'a, T, Row, Key, Cell, Title > where - // Self : 'a, - // Self : 'static, - T : TableRows< 'a, Row, Key, Cell >, + // T : TableRows< 'a, Row, Key, Cell >, T : Fields< 'a, Key, Row >, - T : TableHeader< 'a, Key, Title >, - T : TableSize< 'a >, + // T : TableHeader< 'a, Key, Title >, + // T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'a, { fn rows( &'a self ) -> impl IteratorTrait< Item = Row > - where - // Self : 'a, - // Self : 'static, { self.fields().map( move | ( _k, e ) | e.into_owned() ) } diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index a8fedad984..7f00b4aa62 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -8,6 +8,7 @@ use assistant:: AsTable, Cells, TableSize, + TableRows, }; use std:: @@ -94,8 +95,12 @@ fn test_table_to_string() assert_eq!( cells.len(), 4 ); dbg!( cells.collect::< Vec< _ > >() ); - // let size = TableSize::< '_ >::table_size( &test_objects ); + let as_table = AsTable::< Vec< TestObject >, TestObject, &'static str, String, &'static str >::new( test_objects ); + // let size = TableSize::< '_ >::table_size( &as_table ); // assert_eq!( size, [ 2, 4 ] ); + // let rows = TableRows::rows( &as_table ); + // assert_eq!( rows.len(), 2 ); + // dbg!( rows.collect::< Vec< _ > >() ); // AsTable::new( test_objects ); // let table_string = AsTable::new( test_objects ).table_to_string(); From 6b1bf32e963c6bc20ce84ccd193911a38e9ded9c Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 09:06:57 +0300 Subject: [PATCH 036/143] experimenting --- module/move/assistant/src/as_table.rs | 80 ++++++++-------- module/move/assistant/src/print.rs | 96 +++++++++---------- module/move/assistant/tests/inc/print_test.rs | 12 +-- 3 files changed, 94 insertions(+), 94 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 269dde5bf7..c3e15e271b 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -7,23 +7,23 @@ use core::fmt; /// Transparent wrapper for table-like structures. // #[ derive( Debug ) ] #[ repr( transparent ) ] -pub struct AsTable< 'a, T, Row, Key, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( Row, Key, Cell, Title, &'a () ) > ) +pub struct AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( RowKey, Row, CellKey, Cell, Title, &'a () ) > ) where - // T : TableRows< 'a, Row, Key, Cell >, - // T : TableHeader< 'a, Key, Title >, + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, // Title : fmt::Debug, // Cell : fmt::Debug + Clone + 'a, ; // xxx : use maybe ref inside -impl< 'a, T, Row, Key, Cell, Title > AsTable< 'a, T, Row, Key, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - // T : TableRows< 'a, Row, Key, Cell >, - // T : TableHeader< 'a, Key, Title >, + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, // Title : fmt::Debug, // Cell : fmt::Debug + Clone + 'a, { @@ -34,12 +34,12 @@ where } } -impl< 'a, T, Row, Key, Cell, Title > AsRef< T > for AsTable< 'a, T, Row, Key, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > AsRef< T > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - // T : TableRows< 'a, Row, Key, Cell >, - // T : TableHeader< 'a, Key, Title >, + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, // Title : fmt::Debug, // Cell : fmt::Debug + Clone + 'a, { @@ -49,12 +49,12 @@ where } } -impl< 'a, T, Row, Key, Cell, Title > AsMut< T > for AsTable< 'a, T, Row, Key, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > AsMut< T > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - // T : TableRows< 'a, Row, Key, Cell >, - // T : TableHeader< 'a, Key, Title >, + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, // Title : fmt::Debug, // Cell : fmt::Debug + Clone + 'a, { @@ -64,12 +64,12 @@ where } } -impl< 'a, T, Row, Key, Cell, Title > Deref for AsTable< 'a, T, Row, Key, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Deref for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - // T : TableRows< 'a, Row, Key, Cell >, - // T : TableHeader< 'a, Key, Title >, + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, // Title : fmt::Debug, // Cell : fmt::Debug + Clone + 'a, { @@ -81,12 +81,12 @@ where } } -impl< 'a, T, Row, Key, Cell, Title > DerefMut for AsTable< 'a, T, Row, Key, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > DerefMut for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - // T : TableRows< 'a, Row, Key, Cell >, - // T : TableHeader< 'a, Key, Title >, + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, // Title : fmt::Debug, // Cell : fmt::Debug + Clone + 'a, { @@ -96,12 +96,12 @@ where } } -impl< 'a, T, Row, Key, Cell, Title > From< T > for AsTable< 'a, T, Row, Key, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > From< T > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - // T : TableRows< 'a, Row, Key, Cell >, - // T : TableHeader< 'a, Key, Title >, + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, // Title : fmt::Debug, // Cell : fmt::Debug + Clone + 'a, { @@ -111,26 +111,26 @@ where } } -// impl< 'a, T, Row, Key, Cell, Title > From< AsTable< 'a, T, Row, Key, Cell, Title > > for T +// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > From< AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > > for T // where -// T : TableRows< 'a, Row, Key, Cell > + TableHeader< 'a, Key, Title > + TableSize< 'a >, -// Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, +// T : TableRows< 'a, RowKey, Row, CellKey, Cell > + TableHeader< 'a, CellKey, Title > + TableSize< 'a >, +// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, // Title : fmt::Debug, // Cell : fmt::Debug + Clone + 'a, // { -// fn from( as_table : AsTable< 'a, T, Row, Key, Cell, Title > ) -> Self +// fn from( as_table : AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > ) -> Self // { // as_table.0 // } // } -impl< 'a, T, Row, Key, Cell, Title > Default for AsTable< 'a, T, Row, Key, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Default for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where T : Default, - // T : TableRows< 'a, Row, Key, Cell >, - // T : TableHeader< 'a, Key, Title >, + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, // Title : fmt::Debug, // Cell : fmt::Debug + Clone + 'a, { @@ -140,13 +140,13 @@ where } } -impl< 'a, T, Row, Key, Cell, Title > fmt::Debug for AsTable< 'a, T, Row, Key, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > fmt::Debug for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where T : fmt::Debug, - // T : TableRows< 'a, Row, Key, Cell >, - // T : TableHeader< 'a, Key, Title >, + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, // Title : fmt::Debug, // Cell : fmt::Debug + Clone + 'a, { diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 31663b4ff0..09b8018ef9 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -14,9 +14,9 @@ pub trait TableSize< 'a > } /// A trait for iterating over all rows of a table. -pub trait TableRows< 'a, Row, Key, Cell > +pub trait TableRows< 'a, RowKey, Row, CellKey, Cell > where - Row : Clone + Cells< 'a, Key, Cell > + 'a, + Row : Clone + Cells< 'a, CellKey, Cell > + 'a, Cell : fmt::Debug + Clone + 'a, { /// Returns an iterator over all rows of the table. @@ -24,68 +24,68 @@ where } /// Trait returning headers of a table if any. -pub trait TableHeader< 'a, Key, Title > +pub trait TableHeader< 'a, CellKey, Title > where Title : fmt::Debug, // Title : 'a, // Self : 'a, { /// Returns an iterator over all fields of the specified type within the entity. - fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( Key, Title ) > >; + fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, Title ) > >; } /// A trait for iterating over all cells of a row. -pub trait Cells< 'a, Key, Cell > +pub trait Cells< 'a, CellKey, Cell > where Cell : fmt::Debug + Clone + 'a, { /// Returns an iterator over all cells of the row. - fn cells( &'a self ) -> impl IteratorTrait< Item = ( Key, Cell ) > + fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Cell ) > // where // Self : 'a, // Cell : 'a, - // Key : 'static, + // CellKey : 'static, ; } // == -impl< 'a, T, Row, Key, Cell, Title > TableSize< 'a > -for AsTable< 'a, T, Row, Key, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableSize< 'a > +for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - // T : TableRows< 'a, Row, Key, Cell >, - // T : TableHeader< 'a, Key, Title >, + Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, // Title : fmt::Debug, - // Cell : fmt::Debug + Clone + 'a, + Cell : fmt::Debug + Clone + 'a, { fn table_size( &'a self ) -> [ usize ; 2 ] { - [ 0, 0 ] - // let mut rows = self.rows(); - // let nrows = rows.len(); - // let row = rows.next(); - // if let Some( row ) = row - // { - // let ncells = row.cells().len(); - // [ nrows, ncells ] - // } - // else - // { - // [ 0, 0 ] - // } + // [ 0, 0 ] + let mut rows = self.rows(); + let nrows = rows.len(); + let row = rows.next(); + if let Some( row ) = row + { + let ncells = row.cells().len(); + [ nrows, ncells ] + } + else + { + [ 0, 0 ] + } } } -impl< 'a, T, Row, Key, Cell, Title > TableRows< 'a, Row, Key, Cell > -for AsTable< 'a, T, Row, Key, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableRows< 'a, RowKey, Row, CellKey, Cell > +for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - // T : TableRows< 'a, Row, Key, Cell >, - T : Fields< 'a, Key, Row >, - // T : TableHeader< 'a, Key, Title >, + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + T : Fields< 'a, RowKey, Row >, + // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'a, { @@ -97,20 +97,20 @@ where } -impl< 'a, T, Row, Key, Cell, Title > TableHeader< 'a, Key, Title > -for AsTable< 'a, T, Row, Key, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableHeader< 'a, CellKey, Title > +for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell >, - T : TableHeader< 'a, Key, Title >, + T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + T : TableHeader< 'a, CellKey, Title >, T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, - Row : for< 'cell > Fields< 'cell, Key, Title > + 'a, - Key : Clone, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Row : for< 'cell > Fields< 'cell, CellKey, Title > + 'a, + CellKey : Clone, Title : fmt::Debug + Clone, Cell : fmt::Debug + Clone + 'a, { - fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( Key, Title ) > > + fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, Title ) > > { let mut rows = self.rows(); let row = rows.next(); @@ -133,14 +133,14 @@ where } -impl< 'a, Row, Key, Cell > Cells< 'a, Key, Cell > +impl< 'a, Row, CellKey, Cell > Cells< 'a, CellKey, Cell > for Row where - Row : Fields< 'a, Key, Cell > + 'a, + Row : Fields< 'a, CellKey, Cell > + 'a, Cell : fmt::Debug + Clone + 'a, { - fn cells( &'a self ) -> impl IteratorTrait< Item = ( Key, Cell ) > + fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Cell ) > { self.fields().map( move | ( key, cell ) | ( key, cell.into_owned() ) ) } @@ -226,13 +226,13 @@ pub trait TableFormatter< 'b > } /// A trait for formatting tables. -impl< 'a, T, Row, Key, Cell, Title > TableFormatter< 'a > -for AsTable< 'a, T, Row, Key, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableFormatter< 'a > +for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - T : TableRows< 'a, Row, Key, Cell >, - T : TableHeader< 'a, Key, Title >, + T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + T : TableHeader< 'a, CellKey, Title >, T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, Key, Cell > + 'a, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'a, // 'b : 'a, diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 7f00b4aa62..3a9d331e15 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -95,12 +95,12 @@ fn test_table_to_string() assert_eq!( cells.len(), 4 ); dbg!( cells.collect::< Vec< _ > >() ); - let as_table = AsTable::< Vec< TestObject >, TestObject, &'static str, String, &'static str >::new( test_objects ); - // let size = TableSize::< '_ >::table_size( &as_table ); - // assert_eq!( size, [ 2, 4 ] ); - // let rows = TableRows::rows( &as_table ); - // assert_eq!( rows.len(), 2 ); - // dbg!( rows.collect::< Vec< _ > >() ); + let as_table = AsTable::< Vec< TestObject >, usize, TestObject, &'static str, String, &'static str >::new( test_objects ); + let size = TableSize::< '_ >::table_size( &as_table ); + assert_eq!( size, [ 2, 4 ] ); + let rows = TableRows::rows( &as_table ); + assert_eq!( rows.len(), 2 ); + dbg!( rows.collect::< Vec< _ > >() ); // AsTable::new( test_objects ); // let table_string = AsTable::new( test_objects ).table_to_string(); From 29dc632e718cbab225239e93df9bf71565874233 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 12:13:42 +0300 Subject: [PATCH 037/143] experimenting --- module/move/assistant/src/print.rs | 6 +++--- module/move/assistant/tests/inc/print_test.rs | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 09b8018ef9..8ecc761ccf 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -100,9 +100,9 @@ where impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableHeader< 'a, CellKey, Title > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - T : TableRows< 'a, RowKey, Row, CellKey, Cell >, - T : TableHeader< 'a, CellKey, Title >, - T : TableSize< 'a >, + Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, + // T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, Row : for< 'cell > Fields< 'cell, CellKey, Title > + 'a, CellKey : Clone, diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 3a9d331e15..27fbe29a47 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -9,6 +9,7 @@ use assistant:: Cells, TableSize, TableRows, + TableHeader, }; use std:: @@ -101,6 +102,9 @@ fn test_table_to_string() let rows = TableRows::rows( &as_table ); assert_eq!( rows.len(), 2 ); dbg!( rows.collect::< Vec< _ > >() ); + // let header = TableHeader::header( &as_table ); + // assert_eq!( header.len(), 2 ); + // dbg!( header.collect::< Vec< _ > >() ); // AsTable::new( test_objects ); // let table_string = AsTable::new( test_objects ).table_to_string(); From d1a9f6d9d32b5d97103fba7a70d20d3f043faee3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 12:24:16 +0300 Subject: [PATCH 038/143] experimenting --- module/move/assistant/src/print.rs | 14 +++++++------- module/move/assistant/tests/inc/print_test.rs | 7 +++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 8ecc761ccf..c5f304f126 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -97,20 +97,20 @@ where } -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableHeader< 'a, CellKey, Title > -for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell > TableHeader< 'a, CellKey, CellKey > +for AsTable< 'a, T, RowKey, Row, CellKey, Cell, CellKey > where Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Row : for< 'cell > Fields< 'cell, CellKey, Title > + 'a, + // Row : for< 'cell > Fields< 'cell, CellKey, Cell > + 'a, CellKey : Clone, - Title : fmt::Debug + Clone, + CellKey : fmt::Debug + Clone, Cell : fmt::Debug + Clone + 'a, { - fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, Title ) > > + fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, CellKey ) > > { let mut rows = self.rows(); let row = rows.next(); @@ -119,8 +119,8 @@ where Some ( row - .fields() - .map( | ( key, title ) | ( key, title.into_owned() ) ) + .cells() + .map( | ( key, _title ) | ( key.clone(), key ) ) .collect::< Vec< _ > >() .into_iter() ) diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 27fbe29a47..70ca26d93b 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -102,8 +102,11 @@ fn test_table_to_string() let rows = TableRows::rows( &as_table ); assert_eq!( rows.len(), 2 ); dbg!( rows.collect::< Vec< _ > >() ); - // let header = TableHeader::header( &as_table ); - // assert_eq!( header.len(), 2 ); + let header = TableHeader::header( &as_table ); + assert!( header.is_some() ); + let header = header.unwrap(); + assert_eq!( header.len(), 4 ); + assert_eq!( header.collect::< Vec< _ > >(), vec![ ( "id", "id" ), ( "created_at", "created_at" ), ( "file_ids", "file_ids" ), ( "tools", "tools" ) ] ); // dbg!( header.collect::< Vec< _ > >() ); // AsTable::new( test_objects ); From 277e2d8fb14d24658d1dcb5483ce8511d6d0330e Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 13:07:08 +0300 Subject: [PATCH 039/143] experimenting --- module/move/assistant/src/as_table.rs | 76 +++++++++---------- module/move/assistant/src/print.rs | 36 +++++---- module/move/assistant/tests/inc/print_test.rs | 18 +++-- 3 files changed, 69 insertions(+), 61 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index c3e15e271b..25b1f1b962 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -12,9 +12,10 @@ where // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - // Title : fmt::Debug, - // Cell : fmt::Debug + Clone + 'a, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, ; // xxx : use maybe ref inside @@ -23,9 +24,10 @@ where // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - // Title : fmt::Debug, - // Cell : fmt::Debug + Clone + 'a, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { /// Just a constructor. pub fn new( src : T ) -> Self @@ -39,9 +41,10 @@ where // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - // Title : fmt::Debug, - // Cell : fmt::Debug + Clone + 'a, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { fn as_ref( &self ) -> &T { @@ -54,9 +57,10 @@ where // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - // Title : fmt::Debug, - // Cell : fmt::Debug + Clone + 'a, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { fn as_mut( &mut self ) -> &mut T { @@ -69,9 +73,10 @@ where // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - // Title : fmt::Debug, - // Cell : fmt::Debug + Clone + 'a, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { type Target = T; @@ -86,9 +91,10 @@ where // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - // Title : fmt::Debug, - // Cell : fmt::Debug + Clone + 'a, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { fn deref_mut( &mut self ) -> &mut Self::Target { @@ -101,9 +107,10 @@ where // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - // Title : fmt::Debug, - // Cell : fmt::Debug + Clone + 'a, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { fn from( table : T ) -> Self { @@ -111,28 +118,16 @@ where } } -// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > From< AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > > for T -// where -// T : TableRows< 'a, RowKey, Row, CellKey, Cell > + TableHeader< 'a, CellKey, Title > + TableSize< 'a >, -// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, -// Title : fmt::Debug, -// Cell : fmt::Debug + Clone + 'a, -// { -// fn from( as_table : AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > ) -> Self -// { -// as_table.0 -// } -// } - impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Default for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where T : Default, // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - // Title : fmt::Debug, - // Cell : fmt::Debug + Clone + 'a, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { fn default() -> Self { @@ -146,9 +141,10 @@ where // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, - // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - // Title : fmt::Debug, - // Cell : fmt::Debug + Clone + 'a, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index c5f304f126..5eed52ca94 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -16,7 +16,7 @@ pub trait TableSize< 'a > /// A trait for iterating over all rows of a table. pub trait TableRows< 'a, RowKey, Row, CellKey, Cell > where - Row : Clone + Cells< 'a, CellKey, Cell > + 'a, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, Cell : fmt::Debug + Clone + 'a, { /// Returns an iterator over all rows of the table. @@ -57,8 +57,9 @@ where // T : TableHeader< 'a, CellKey, Title >, // T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - // Title : fmt::Debug, + Title : fmt::Debug, Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { fn table_size( &'a self ) -> [ usize ; 2 ] { @@ -88,6 +89,7 @@ where Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { fn rows( &'a self ) -> impl IteratorTrait< Item = Row > @@ -105,9 +107,10 @@ where // T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, // Row : for< 'cell > Fields< 'cell, CellKey, Cell > + 'a, - CellKey : Clone, + // CellKey : Clone, CellKey : fmt::Debug + Clone, Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, CellKey ) > > @@ -136,6 +139,7 @@ where impl< 'a, Row, CellKey, Cell > Cells< 'a, CellKey, Cell > for Row where + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, Row : Fields< 'a, CellKey, Cell > + 'a, Cell : fmt::Debug + Clone + 'a, { @@ -164,6 +168,15 @@ pub struct Formatter< 'a > styles : Styles, } +impl< 'a > Formatter< 'a > +{ + /// Just constructr. + pub fn new( buf : &'a mut dyn fmt::Write, styles : Styles ) -> Self + { + Self { buf, styles } + } +} + impl fmt::Debug for Formatter< '_ > { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result @@ -176,15 +189,6 @@ impl fmt::Debug for Formatter< '_ > } } -impl< 'a > Formatter< 'a > -{ - /// Creates a new `Formatter` with the given buffer and separator. - pub fn new( buf : &'a mut dyn fmt::Write, styles : Styles ) -> Self - { - Formatter { buf, styles } - } -} - /// A trait for converting tables to a string representation. pub trait TableToString { @@ -229,13 +233,13 @@ pub trait TableFormatter< 'b > impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableFormatter< 'a > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - T : TableRows< 'a, RowKey, Row, CellKey, Cell >, - T : TableHeader< 'a, CellKey, Title >, - T : TableSize< 'a >, + Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, + Self : TableHeader< 'a, CellKey, Title >, + Self : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'a, - // 'b : 'a, + CellKey : fmt::Debug + Clone, { fn fmt( &'a self, f : &'a mut Formatter< '_ > ) -> fmt::Result { diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 70ca26d93b..7a7b37662e 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -94,14 +94,15 @@ fn test_table_to_string() let cells = Cells::< '_, &'static str, String >::cells( &test_objects[ 0 ] ); assert_eq!( cells.len(), 4 ); - dbg!( cells.collect::< Vec< _ > >() ); + // dbg!( cells.collect::< Vec< _ > >() ); + drop( cells ); let as_table = AsTable::< Vec< TestObject >, usize, TestObject, &'static str, String, &'static str >::new( test_objects ); let size = TableSize::< '_ >::table_size( &as_table ); assert_eq!( size, [ 2, 4 ] ); let rows = TableRows::rows( &as_table ); assert_eq!( rows.len(), 2 ); - dbg!( rows.collect::< Vec< _ > >() ); + // dbg!( rows.collect::< Vec< _ > >() ); let header = TableHeader::header( &as_table ); assert!( header.is_some() ); let header = header.unwrap(); @@ -109,9 +110,16 @@ fn test_table_to_string() assert_eq!( header.collect::< Vec< _ > >(), vec![ ( "id", "id" ), ( "created_at", "created_at" ), ( "file_ids", "file_ids" ), ( "tools", "tools" ) ] ); // dbg!( header.collect::< Vec< _ > >() ); - // AsTable::new( test_objects ); - // let table_string = AsTable::new( test_objects ).table_to_string(); - // println!( "{}", table_string ); + // let mut output = String::new(); + // let mut formatter = the_module::Formatter::new( &mut output, Default::default() ); + // let got = the_module::TableFormatter::fmt( &as_table, &mut formatter ); + // assert!( got.is_ok() ); + // println!( "{}", &output ); + + // // AsTable::new( test_objects ); + // // // let table_string = AsTable::new( test_objects ).table_to_string(); + // let table_string = as_table.table_to_string(); + // // println!( "{}", table_string ); // assert!( table_string.contains( "id" ) ); // assert!( table_string.contains( "created_at" ) ); // assert!( table_string.contains( "file_ids" ) ); From 8bfaac26f85a49c041aa49bd529bfeebd5e8398b Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 15:00:11 +0300 Subject: [PATCH 040/143] experimenting --- module/move/assistant/src/print.rs | 6 ++-- module/move/assistant/tests/inc/print_test.rs | 34 +++++++++++-------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 5eed52ca94..06cc5d4569 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -202,7 +202,7 @@ pub trait TableToString impl< T > TableToString for T where - T : for< 'b > TableFormatter< 'b > + T : for< 'b > TableFormatter< 'b >, { fn table_to_string( &self ) -> String { @@ -226,7 +226,7 @@ where pub trait TableFormatter< 'b > { /// Formats the table and writes the result to the given formatter. - fn fmt( &'b self, f : &'b mut Formatter< '_ > ) -> fmt::Result; + fn fmt( &'b self, f : &'b mut Formatter< 'b > ) -> fmt::Result; } /// A trait for formatting tables. @@ -241,7 +241,7 @@ where Cell : fmt::Debug + Clone + 'a, CellKey : fmt::Debug + Clone, { - fn fmt( &'a self, f : &'a mut Formatter< '_ > ) -> fmt::Result + fn fmt( &'a self, f : &'a mut Formatter< 'a > ) -> fmt::Result { let table_size = self.table_size(); let mut col_widths : Vec< usize > = vec![ 0 ; table_size[ 1 ] ]; diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 7a7b37662e..bac869a039 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -10,6 +10,7 @@ use assistant:: TableSize, TableRows, TableHeader, + TableFormatter, }; use std:: @@ -59,6 +60,8 @@ impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > #[ test ] fn test_table_to_string() +// where + // Vec< TestObject > : for< 'a > TableFormatter< 'a >, { use the_module::TableToString; @@ -97,7 +100,7 @@ fn test_table_to_string() // dbg!( cells.collect::< Vec< _ > >() ); drop( cells ); - let as_table = AsTable::< Vec< TestObject >, usize, TestObject, &'static str, String, &'static str >::new( test_objects ); + let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, String, &str > = AsTable::new( test_objects ); let size = TableSize::< '_ >::table_size( &as_table ); assert_eq!( size, [ 2, 4 ] ); let rows = TableRows::rows( &as_table ); @@ -110,19 +113,20 @@ fn test_table_to_string() assert_eq!( header.collect::< Vec< _ > >(), vec![ ( "id", "id" ), ( "created_at", "created_at" ), ( "file_ids", "file_ids" ), ( "tools", "tools" ) ] ); // dbg!( header.collect::< Vec< _ > >() ); - // let mut output = String::new(); - // let mut formatter = the_module::Formatter::new( &mut output, Default::default() ); - // let got = the_module::TableFormatter::fmt( &as_table, &mut formatter ); - // assert!( got.is_ok() ); - // println!( "{}", &output ); - - // // AsTable::new( test_objects ); - // // // let table_string = AsTable::new( test_objects ).table_to_string(); - // let table_string = as_table.table_to_string(); - // // println!( "{}", table_string ); - // assert!( table_string.contains( "id" ) ); - // assert!( table_string.contains( "created_at" ) ); - // assert!( table_string.contains( "file_ids" ) ); - // assert!( table_string.contains( "tools" ) ); + let mut output = String::new(); + let mut formatter = the_module::Formatter::new( &mut output, Default::default() ); + let got = the_module::TableFormatter::fmt( &as_table, &mut formatter ); + assert!( got.is_ok() ); + println!( "{}", &output ); + + // use the_module::{ TableFormatter, TableToString }; + // AsTable::new( test_objects ); + // // let table_string = AsTable::new( test_objects ).table_to_string(); + let table_string = as_table.table_to_string(); + // println!( "{}", table_string ); + assert!( table_string.contains( "id" ) ); + assert!( table_string.contains( "created_at" ) ); + assert!( table_string.contains( "file_ids" ) ); + assert!( table_string.contains( "tools" ) ); } From f6eb21cda8328fa0a9d06f5a4da157d790b1b704 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 16:13:28 +0300 Subject: [PATCH 041/143] experimenting --- module/move/assistant/src/as_table.rs | 68 ++++++++++--------- module/move/assistant/src/print.rs | 8 +-- module/move/assistant/tests/inc/experiment.rs | 0 module/move/assistant/tests/inc/mod.rs | 1 + module/move/assistant/tests/inc/print_test.rs | 22 +++--- 5 files changed, 51 insertions(+), 48 deletions(-) create mode 100644 module/move/assistant/tests/inc/experiment.rs diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 25b1f1b962..15f5363a40 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -7,7 +7,7 @@ use core::fmt; /// Transparent wrapper for table-like structures. // #[ derive( Debug ) ] #[ repr( transparent ) ] -pub struct AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title >( T, ::core::marker::PhantomData< fn () -> ( RowKey, Row, CellKey, Cell, Title, &'a () ) > ) +pub struct AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title >( T, ::core::marker::PhantomData< ( &'a (), fn () -> ( RowKey, Row, CellKey, Cell, Title ) ) > ) where // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, // T : TableHeader< 'a, CellKey, Title >, @@ -68,39 +68,41 @@ where } } -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Deref for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ - type Target = T; - - fn deref( &self ) -> &Self::Target - { - &self.0 - } -} +// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Deref for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > +// where +// // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, +// // T : TableHeader< 'a, CellKey, Title >, +// // T : TableSize< 'a >, +// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, +// Title : fmt::Debug, +// Cell : fmt::Debug + Clone + 'a, +// CellKey : fmt::Debug + Clone, +// { +// type Target = T; +// +// fn deref( &self ) -> &Self::Target +// { +// &self.0 +// } +// } +// +// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > DerefMut for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > +// where +// // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, +// // T : TableHeader< 'a, CellKey, Title >, +// // T : TableSize< 'a >, +// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, +// Title : fmt::Debug, +// Cell : fmt::Debug + Clone + 'a, +// CellKey : fmt::Debug + Clone, +// { +// fn deref_mut( &mut self ) -> &mut Self::Target +// { +// &mut self.0 +// } +// } -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > DerefMut for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ - fn deref_mut( &mut self ) -> &mut Self::Target - { - &mut self.0 - } -} +// xxx impl< 'a, T, RowKey, Row, CellKey, Cell, Title > From< T > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 06cc5d4569..11c4bcd82d 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -94,7 +94,7 @@ where fn rows( &'a self ) -> impl IteratorTrait< Item = Row > { - self.fields().map( move | ( _k, e ) | e.into_owned() ) + self.as_ref().fields().map( move | ( _k, e ) | e.into_owned() ) } } @@ -202,7 +202,7 @@ pub trait TableToString impl< T > TableToString for T where - T : for< 'b > TableFormatter< 'b >, + T : for< 'b > TableFormatter< 'b > { fn table_to_string( &self ) -> String { @@ -226,7 +226,7 @@ where pub trait TableFormatter< 'b > { /// Formats the table and writes the result to the given formatter. - fn fmt( &'b self, f : &'b mut Formatter< 'b > ) -> fmt::Result; + fn fmt( &'b self, f : &'b mut Formatter< '_ > ) -> fmt::Result; } /// A trait for formatting tables. @@ -241,7 +241,7 @@ where Cell : fmt::Debug + Clone + 'a, CellKey : fmt::Debug + Clone, { - fn fmt( &'a self, f : &'a mut Formatter< 'a > ) -> fmt::Result + fn fmt( &'a self, f : &'a mut Formatter< '_ > ) -> fmt::Result { let table_size = self.table_size(); let mut col_widths : Vec< usize > = vec![ 0 ; table_size[ 1 ] ]; diff --git a/module/move/assistant/tests/inc/experiment.rs b/module/move/assistant/tests/inc/experiment.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/module/move/assistant/tests/inc/mod.rs b/module/move/assistant/tests/inc/mod.rs index 707889e650..bd9f33110b 100644 --- a/module/move/assistant/tests/inc/mod.rs +++ b/module/move/assistant/tests/inc/mod.rs @@ -4,3 +4,4 @@ use super::*; mod fields_test; mod print_test; +mod experiment; diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index bac869a039..4389eb64f0 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -60,8 +60,8 @@ impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > #[ test ] fn test_table_to_string() -// where - // Vec< TestObject > : for< 'a > TableFormatter< 'a >, +where + for< 'a > AsTable< 'a, Vec< TestObject >, usize, TestObject, &'static str, String, &'static str > : TableFormatter< 'a >, { use the_module::TableToString; @@ -119,14 +119,14 @@ fn test_table_to_string() assert!( got.is_ok() ); println!( "{}", &output ); - // use the_module::{ TableFormatter, TableToString }; - // AsTable::new( test_objects ); - // // let table_string = AsTable::new( test_objects ).table_to_string(); - let table_string = as_table.table_to_string(); - // println!( "{}", table_string ); - assert!( table_string.contains( "id" ) ); - assert!( table_string.contains( "created_at" ) ); - assert!( table_string.contains( "file_ids" ) ); - assert!( table_string.contains( "tools" ) ); + // // use the_module::{ TableFormatter, TableToString }; + // // AsTable::new( test_objects ); + // // // let table_string = AsTable::new( test_objects ).table_to_string(); + // let table_string = as_table.table_to_string(); + // // println!( "{}", table_string ); + // assert!( table_string.contains( "id" ) ); + // assert!( table_string.contains( "created_at" ) ); + // assert!( table_string.contains( "file_ids" ) ); + // assert!( table_string.contains( "tools" ) ); } From fb7b3bc20244fac2458a9d06436f349b0e6e507f Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 16:46:56 +0300 Subject: [PATCH 042/143] experimenting --- module/move/assistant/src/print.rs | 121 +++++++++++++++++- module/move/assistant/tests/inc/print_test.rs | 18 +-- 2 files changed, 123 insertions(+), 16 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 11c4bcd82d..7791bf4aaa 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -190,21 +190,21 @@ impl fmt::Debug for Formatter< '_ > } /// A trait for converting tables to a string representation. -pub trait TableToString +pub trait TableToString< 'a > { /// Converts the table to a string representation. /// /// # Returns /// /// A `String` containing the formatted table. - fn table_to_string( &self ) -> String; + fn table_to_string( &'a self ) -> String; } -impl< T > TableToString for T +impl< 'a, T > TableToString< 'a > for T where - T : for< 'b > TableFormatter< 'b > + T : TableFormatter< 'a > { - fn table_to_string( &self ) -> String + fn table_to_string( &'a self ) -> String { let mut output = String::new(); let mut formatter = Formatter @@ -226,7 +226,7 @@ where pub trait TableFormatter< 'b > { /// Formats the table and writes the result to the given formatter. - fn fmt( &'b self, f : &'b mut Formatter< '_ > ) -> fmt::Result; + fn fmt( &'b self, f : &mut Formatter< '_ > ) -> fmt::Result; } /// A trait for formatting tables. @@ -241,7 +241,7 @@ where Cell : fmt::Debug + Clone + 'a, CellKey : fmt::Debug + Clone, { - fn fmt( &'a self, f : &'a mut Formatter< '_ > ) -> fmt::Result + fn fmt( &'a self, f : &mut Formatter< '_ > ) -> fmt::Result { let table_size = self.table_size(); let mut col_widths : Vec< usize > = vec![ 0 ; table_size[ 1 ] ]; @@ -307,3 +307,110 @@ where Ok(()) } } + +// = xxx + +// /// Struct for formatting tables. +// pub struct Formatter2<'a> +// { +// buf: &'a mut dyn fmt::Write, +// } +// +// impl<'a> Formatter2<'a> +// { +// /// Just constructr. +// pub fn new(buf: &'a mut dyn fmt::Write) -> Self +// { +// Self { buf } +// } +// } +// +// /// A trait for converting tables to a string representation. +// pub trait TableToString2<'b> +// { +// /// Converts the table to a string representation. +// /// +// /// # Returns +// /// +// /// A `String` containing the formatted table. +// fn table_to_string(&'b self) -> String; +// } +// +// impl<'b, T> TableToString2<'b> for T +// where +// T: TableFormatter2<'b>, +// { +// fn table_to_string(&'b self) -> String +// { +// let mut output = String::new(); +// { +// let mut formatter = Formatter2 +// { +// buf : &mut output, +// }; +// T::fmt(self, &mut formatter).expect("Formatting failed"); +// } +// output +// } +// } +// +// pub trait TableFormatter2<'b> +// { +// /// Formats the table and writes the result to the given formatter. +// fn fmt(&'b self, f: &mut Formatter2<'_>) -> fmt::Result; +// } + +// = xxx + +// /// Struct for formatting tables. +// pub struct Formatter2< 'a > +// { +// buf : &'a mut dyn fmt::Write, +// } +// +// impl< 'a > Formatter2< 'a > +// { +// /// Just constructr. +// pub fn new( buf : &'a mut dyn fmt::Write ) -> Self +// { +// Self { buf } +// } +// } +// +// /// A trait for converting tables to a string representation. +// pub trait TableToString2< 'b > +// { +// /// Converts the table to a string representation. +// /// +// /// # Returns +// /// +// /// A `String` containing the formatted table. +// fn table_to_string( &'b self ) -> String; +// } +// +// impl< 'b, T > TableToString2< 'b > for T +// where +// T : TableFormatter2< 'b >, +// // Self : 'static, +// { +// fn table_to_string( &'b self ) -> String +// { +// let mut output = String::new(); +// { +// let mut formatter = Formatter2 +// { +// buf : &mut output, +// }; +// T::fmt( self, &mut formatter ).expect( "Formatting failed" ); +// } +// output +// } +// } +// +// pub trait TableFormatter2< 'b > +// { +// /// Formats the table and writes the result to the given formatter. +// fn fmt( &'b self, f : &'b mut Formatter2< '_ > ) -> fmt::Result; +// } + +// = xxx diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 4389eb64f0..bdbed71e07 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -119,14 +119,14 @@ where assert!( got.is_ok() ); println!( "{}", &output ); - // // use the_module::{ TableFormatter, TableToString }; - // // AsTable::new( test_objects ); - // // // let table_string = AsTable::new( test_objects ).table_to_string(); - // let table_string = as_table.table_to_string(); - // // println!( "{}", table_string ); - // assert!( table_string.contains( "id" ) ); - // assert!( table_string.contains( "created_at" ) ); - // assert!( table_string.contains( "file_ids" ) ); - // assert!( table_string.contains( "tools" ) ); + // use the_module::{ TableFormatter, TableToString }; + // AsTable::new( test_objects ); + // // let table_string = AsTable::new( test_objects ).table_to_string(); + let table_string = as_table.table_to_string(); + // println!( "{}", table_string ); + assert!( table_string.contains( "id" ) ); + assert!( table_string.contains( "created_at" ) ); + assert!( table_string.contains( "file_ids" ) ); + assert!( table_string.contains( "tools" ) ); } From 6c15239c91246959b32a0d4a90a0d518e99e7c19 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 19:18:34 +0300 Subject: [PATCH 043/143] experimenting --- module/move/assistant/src/print.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 7791bf4aaa..ad15de7574 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -226,7 +226,7 @@ where pub trait TableFormatter< 'b > { /// Formats the table and writes the result to the given formatter. - fn fmt( &'b self, f : &mut Formatter< '_ > ) -> fmt::Result; + fn fmt< 'a >( &'b self, f : &mut Formatter< 'a > ) -> fmt::Result; } /// A trait for formatting tables. From 2f4a7ad5b1284e9743585b5aa2d6c1a1a40e0ce1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 5 Jun 2024 23:57:22 +0300 Subject: [PATCH 044/143] experimenting --- module/move/assistant/src/as_table.rs | 67 +++++++------- module/move/assistant/src/print.rs | 125 -------------------------- 2 files changed, 32 insertions(+), 160 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 15f5363a40..8c3f96259c 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -5,7 +5,6 @@ use core::marker::PhantomData; use core::fmt; /// Transparent wrapper for table-like structures. -// #[ derive( Debug ) ] #[ repr( transparent ) ] pub struct AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title >( T, ::core::marker::PhantomData< ( &'a (), fn () -> ( RowKey, Row, CellKey, Cell, Title ) ) > ) where @@ -68,41 +67,39 @@ where } } -// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Deref for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -// where -// // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, -// // T : TableHeader< 'a, CellKey, Title >, -// // T : TableSize< 'a >, -// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, -// Title : fmt::Debug, -// Cell : fmt::Debug + Clone + 'a, -// CellKey : fmt::Debug + Clone, -// { -// type Target = T; -// -// fn deref( &self ) -> &Self::Target -// { -// &self.0 -// } -// } -// -// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > DerefMut for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -// where -// // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, -// // T : TableHeader< 'a, CellKey, Title >, -// // T : TableSize< 'a >, -// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, -// Title : fmt::Debug, -// Cell : fmt::Debug + Clone + 'a, -// CellKey : fmt::Debug + Clone, -// { -// fn deref_mut( &mut self ) -> &mut Self::Target -// { -// &mut self.0 -// } -// } +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Deref for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > +where + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, + // T : TableSize< 'a >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, +{ + type Target = T; + + fn deref( &self ) -> &Self::Target + { + &self.0 + } +} -// xxx +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > DerefMut for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > +where + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, + // T : TableSize< 'a >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, +{ + fn deref_mut( &mut self ) -> &mut Self::Target + { + &mut self.0 + } +} impl< 'a, T, RowKey, Row, CellKey, Cell, Title > From< T > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index ad15de7574..b7bbd9ce9b 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -1,7 +1,6 @@ use super::*; use core::fmt; -// use std::borrow::Cow; use former::Former; // == @@ -27,8 +26,6 @@ where pub trait TableHeader< 'a, CellKey, Title > where Title : fmt::Debug, - // Title : 'a, - // Self : 'a, { /// Returns an iterator over all fields of the specified type within the entity. fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, Title ) > >; @@ -41,10 +38,6 @@ where { /// Returns an iterator over all cells of the row. fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Cell ) > - // where - // Self : 'a, - // Cell : 'a, - // CellKey : 'static, ; } @@ -54,8 +47,6 @@ impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableSize< 'a > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'a, @@ -63,7 +54,6 @@ where { fn table_size( &'a self ) -> [ usize ; 2 ] { - // [ 0, 0 ] let mut rows = self.rows(); let nrows = rows.len(); let row = rows.next(); @@ -82,10 +72,7 @@ where impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableRows< 'a, RowKey, Row, CellKey, Cell > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, T : Fields< 'a, RowKey, Row >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'a, @@ -103,11 +90,7 @@ impl< 'a, T, RowKey, Row, CellKey, Cell > TableHeader< 'a, CellKey, CellKey > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, CellKey > where Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - // Row : for< 'cell > Fields< 'cell, CellKey, Cell > + 'a, - // CellKey : Clone, CellKey : fmt::Debug + Clone, Cell : fmt::Debug + Clone + 'a, CellKey : fmt::Debug + Clone, @@ -139,7 +122,6 @@ where impl< 'a, Row, CellKey, Cell > Cells< 'a, CellKey, Cell > for Row where - // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, Row : Fields< 'a, CellKey, Cell > + 'a, Cell : fmt::Debug + Clone + 'a, { @@ -307,110 +289,3 @@ where Ok(()) } } - -// = xxx - -// /// Struct for formatting tables. -// pub struct Formatter2<'a> -// { -// buf: &'a mut dyn fmt::Write, -// } -// -// impl<'a> Formatter2<'a> -// { -// /// Just constructr. -// pub fn new(buf: &'a mut dyn fmt::Write) -> Self -// { -// Self { buf } -// } -// } -// -// /// A trait for converting tables to a string representation. -// pub trait TableToString2<'b> -// { -// /// Converts the table to a string representation. -// /// -// /// # Returns -// /// -// /// A `String` containing the formatted table. -// fn table_to_string(&'b self) -> String; -// } -// -// impl<'b, T> TableToString2<'b> for T -// where -// T: TableFormatter2<'b>, -// { -// fn table_to_string(&'b self) -> String -// { -// let mut output = String::new(); -// { -// let mut formatter = Formatter2 -// { -// buf : &mut output, -// }; -// T::fmt(self, &mut formatter).expect("Formatting failed"); -// } -// output -// } -// } -// -// pub trait TableFormatter2<'b> -// { -// /// Formats the table and writes the result to the given formatter. -// fn fmt(&'b self, f: &mut Formatter2<'_>) -> fmt::Result; -// } - -// = xxx - -// /// Struct for formatting tables. -// pub struct Formatter2< 'a > -// { -// buf : &'a mut dyn fmt::Write, -// } -// -// impl< 'a > Formatter2< 'a > -// { -// /// Just constructr. -// pub fn new( buf : &'a mut dyn fmt::Write ) -> Self -// { -// Self { buf } -// } -// } -// -// /// A trait for converting tables to a string representation. -// pub trait TableToString2< 'b > -// { -// /// Converts the table to a string representation. -// /// -// /// # Returns -// /// -// /// A `String` containing the formatted table. -// fn table_to_string( &'b self ) -> String; -// } -// -// impl< 'b, T > TableToString2< 'b > for T -// where -// T : TableFormatter2< 'b >, -// // Self : 'static, -// { -// fn table_to_string( &'b self ) -> String -// { -// let mut output = String::new(); -// { -// let mut formatter = Formatter2 -// { -// buf : &mut output, -// }; -// T::fmt( self, &mut formatter ).expect( "Formatting failed" ); -// } -// output -// } -// } -// -// pub trait TableFormatter2< 'b > -// { -// /// Formats the table and writes the result to the given formatter. -// fn fmt( &'b self, f : &'b mut Formatter2< '_ > ) -> fmt::Result; -// } - -// = xxx From 4494cf415ae23973c63ddf889333c9c841494764 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 6 Jun 2024 00:06:00 +0300 Subject: [PATCH 045/143] experimenting --- module/move/assistant/src/as_table.rs | 110 ++++++++++-------- module/move/assistant/tests/inc/print_test.rs | 2 +- 2 files changed, 60 insertions(+), 52 deletions(-) diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 8c3f96259c..100fc72e6e 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -1,12 +1,17 @@ use super::*; -use core::ops::{ Deref, DerefMut }; +use core::ops::{ Deref }; use core::marker::PhantomData; use core::fmt; /// Transparent wrapper for table-like structures. #[ repr( transparent ) ] -pub struct AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title >( T, ::core::marker::PhantomData< ( &'a (), fn () -> ( RowKey, Row, CellKey, Cell, Title ) ) > ) +#[ derive( Clone, Copy ) ] +pub struct AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > +( + &'a T, + ::core::marker::PhantomData< ( &'a (), fn () -> ( RowKey, Row, CellKey, Cell, Title ) ) >, +) where // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, // T : TableHeader< 'a, CellKey, Title >, @@ -29,7 +34,7 @@ where CellKey : fmt::Debug + Clone, { /// Just a constructor. - pub fn new( src : T ) -> Self + pub fn new( src : &'a T ) -> Self { Self( src, Default::default() ) } @@ -51,21 +56,22 @@ where } } -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > AsMut< T > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ - fn as_mut( &mut self ) -> &mut T - { - &mut self.0 - } -} +// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > AsMut< T > +// for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > +// where +// // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, +// // T : TableHeader< 'a, CellKey, Title >, +// // T : TableSize< 'a >, +// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, +// Title : fmt::Debug, +// Cell : fmt::Debug + Clone + 'a, +// CellKey : fmt::Debug + Clone, +// { +// fn as_mut( &mut self ) -> &mut T +// { +// &mut self.0 +// } +// } impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Deref for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where @@ -85,23 +91,25 @@ where } } -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > DerefMut for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ - fn deref_mut( &mut self ) -> &mut Self::Target - { - &mut self.0 - } -} +// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > DerefMut +// for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > +// where +// // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, +// // T : TableHeader< 'a, CellKey, Title >, +// // T : TableSize< 'a >, +// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, +// Title : fmt::Debug, +// Cell : fmt::Debug + Clone + 'a, +// CellKey : fmt::Debug + Clone, +// { +// fn deref_mut( &mut self ) -> &mut Self::Target +// { +// &mut self.0 +// } +// } -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > From< T > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > From< &'a T > +for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, // T : TableHeader< 'a, CellKey, Title >, @@ -111,28 +119,28 @@ where Cell : fmt::Debug + Clone + 'a, CellKey : fmt::Debug + Clone, { - fn from( table : T ) -> Self + fn from( table : &'a T ) -> Self { AsTable( table, PhantomData ) } } -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Default for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - T : Default, - // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ - fn default() -> Self - { - AsTable( T::default(), PhantomData ) - } -} +// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Default for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > +// where +// T : Default, +// // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, +// // T : TableHeader< 'a, CellKey, Title >, +// // T : TableSize< 'a >, +// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, +// Title : fmt::Debug, +// Cell : fmt::Debug + Clone + 'a, +// CellKey : fmt::Debug + Clone, +// { +// fn default() -> Self +// { +// AsTable( T::default(), PhantomData ) +// } +// } impl< 'a, T, RowKey, Row, CellKey, Cell, Title > fmt::Debug for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index bdbed71e07..3de77e2cbf 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -100,7 +100,7 @@ where // dbg!( cells.collect::< Vec< _ > >() ); drop( cells ); - let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, String, &str > = AsTable::new( test_objects ); + let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, String, &str > = AsTable::new( &test_objects ); let size = TableSize::< '_ >::table_size( &as_table ); assert_eq!( size, [ 2, 4 ] ); let rows = TableRows::rows( &as_table ); From bb23988163d83dda7dbccc66e33cdec7b0ee5e58 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 6 Jun 2024 00:12:45 +0300 Subject: [PATCH 046/143] experimenting --- module/move/assistant/src/lib.rs | 3 + module/move/assistant/src/print.rs | 146 +----------------- module/move/assistant/src/table.rs | 135 ++++++++++++++++ module/move/assistant/tests/inc/print_test.rs | 8 +- 4 files changed, 149 insertions(+), 143 deletions(-) create mode 100644 module/move/assistant/src/table.rs diff --git a/module/move/assistant/src/lib.rs b/module/move/assistant/src/lib.rs index a3b1b213e0..a3d94a448e 100644 --- a/module/move/assistant/src/lib.rs +++ b/module/move/assistant/src/lib.rs @@ -27,6 +27,9 @@ pub use print::*; /// Nice print's wrapper. pub mod as_table; pub use as_table::*; +/// Table interface. +pub mod table; +pub use table::*; /// Options for configuring the OpenAI API client. #[ derive( Former, Debug ) ] diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index b7bbd9ce9b..99ad10f833 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -3,137 +3,7 @@ use super::*; use core::fmt; use former::Former; -// == - -/// A trait for iterating over all rows of a table. -pub trait TableSize< 'a > -{ - /// Returns size of a table. - fn table_size( &'a self ) -> [ usize ; 2 ]; -} - -/// A trait for iterating over all rows of a table. -pub trait TableRows< 'a, RowKey, Row, CellKey, Cell > -where - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Cell : fmt::Debug + Clone + 'a, -{ - /// Returns an iterator over all rows of the table. - fn rows( &'a self ) -> impl IteratorTrait< Item = Row >; -} - -/// Trait returning headers of a table if any. -pub trait TableHeader< 'a, CellKey, Title > -where - Title : fmt::Debug, -{ - /// Returns an iterator over all fields of the specified type within the entity. - fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, Title ) > >; -} - -/// A trait for iterating over all cells of a row. -pub trait Cells< 'a, CellKey, Cell > -where - Cell : fmt::Debug + Clone + 'a, -{ - /// Returns an iterator over all cells of the row. - fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Cell ) > - ; -} - -// == - -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableSize< 'a > -for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ - fn table_size( &'a self ) -> [ usize ; 2 ] - { - let mut rows = self.rows(); - let nrows = rows.len(); - let row = rows.next(); - if let Some( row ) = row - { - let ncells = row.cells().len(); - [ nrows, ncells ] - } - else - { - [ 0, 0 ] - } - } -} - -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableRows< 'a, RowKey, Row, CellKey, Cell > -for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - T : Fields< 'a, RowKey, Row >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ - - fn rows( &'a self ) -> impl IteratorTrait< Item = Row > - { - self.as_ref().fields().map( move | ( _k, e ) | e.into_owned() ) - } - -} - -impl< 'a, T, RowKey, Row, CellKey, Cell > TableHeader< 'a, CellKey, CellKey > -for AsTable< 'a, T, RowKey, Row, CellKey, Cell, CellKey > -where - Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - CellKey : fmt::Debug + Clone, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ - - fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, CellKey ) > > - { - let mut rows = self.rows(); - let row = rows.next(); - if let Some( row ) = row - { - Some - ( - row - .cells() - .map( | ( key, _title ) | ( key.clone(), key ) ) - .collect::< Vec< _ > >() - .into_iter() - ) - } - else - { - None - } - } - -} - -impl< 'a, Row, CellKey, Cell > Cells< 'a, CellKey, Cell > -for Row -where - Row : Fields< 'a, CellKey, Cell > + 'a, - Cell : fmt::Debug + Clone + 'a, -{ - - fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Cell ) > - { - self.fields().map( move | ( key, cell ) | ( key, cell.into_owned() ) ) - } - -} - -// == +//= /// Struct to hold options to print data as table. #[ derive( Debug, Default, Former ) ] @@ -144,13 +14,13 @@ pub struct Styles } /// Struct for formatting tables. -pub struct Formatter< 'a > +pub struct Context< 'a > { buf : &'a mut dyn fmt::Write, styles : Styles, } -impl< 'a > Formatter< 'a > +impl< 'a > Context< 'a > { /// Just constructr. pub fn new( buf : &'a mut dyn fmt::Write, styles : Styles ) -> Self @@ -159,12 +29,12 @@ impl< 'a > Formatter< 'a > } } -impl fmt::Debug for Formatter< '_ > +impl fmt::Debug for Context< '_ > { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { f - .debug_struct( "Formatter" ) + .debug_struct( "Context" ) .field( "buf", &"dyn fmt::Write" ) .field( "styles", &self.styles ) .finish() @@ -189,7 +59,7 @@ where fn table_to_string( &'a self ) -> String { let mut output = String::new(); - let mut formatter = Formatter + let mut formatter = Context { buf : &mut output, styles : Styles::default(), @@ -208,7 +78,7 @@ where pub trait TableFormatter< 'b > { /// Formats the table and writes the result to the given formatter. - fn fmt< 'a >( &'b self, f : &mut Formatter< 'a > ) -> fmt::Result; + fn fmt< 'a >( &'b self, f : &mut Context< 'a > ) -> fmt::Result; } /// A trait for formatting tables. @@ -223,7 +93,7 @@ where Cell : fmt::Debug + Clone + 'a, CellKey : fmt::Debug + Clone, { - fn fmt( &'a self, f : &mut Formatter< '_ > ) -> fmt::Result + fn fmt( &'a self, f : &mut Context< '_ > ) -> fmt::Result { let table_size = self.table_size(); let mut col_widths : Vec< usize > = vec![ 0 ; table_size[ 1 ] ]; diff --git a/module/move/assistant/src/table.rs b/module/move/assistant/src/table.rs new file mode 100644 index 0000000000..54c0bda45b --- /dev/null +++ b/module/move/assistant/src/table.rs @@ -0,0 +1,135 @@ + +use super::*; +use core::fmt; + +// == + +/// A trait for iterating over all rows of a table. +pub trait TableSize< 'a > +{ + /// Returns size of a table. + fn table_size( &'a self ) -> [ usize ; 2 ]; +} + +/// A trait for iterating over all rows of a table. +pub trait TableRows< 'a, RowKey, Row, CellKey, Cell > +where + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Cell : fmt::Debug + Clone + 'a, +{ + /// Returns an iterator over all rows of the table. + fn rows( &'a self ) -> impl IteratorTrait< Item = Row >; +} + +/// Trait returning headers of a table if any. +pub trait TableHeader< 'a, CellKey, Title > +where + Title : fmt::Debug, +{ + /// Returns an iterator over all fields of the specified type within the entity. + fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, Title ) > >; +} + +/// A trait for iterating over all cells of a row. +pub trait Cells< 'a, CellKey, Cell > +where + Cell : fmt::Debug + Clone + 'a, +{ + /// Returns an iterator over all cells of the row. + fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Cell ) > + ; +} + +// == + +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableSize< 'a > +for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > +where + Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, +{ + fn table_size( &'a self ) -> [ usize ; 2 ] + { + let mut rows = self.rows(); + let nrows = rows.len(); + let row = rows.next(); + if let Some( row ) = row + { + let ncells = row.cells().len(); + [ nrows, ncells ] + } + else + { + [ 0, 0 ] + } + } +} + +impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableRows< 'a, RowKey, Row, CellKey, Cell > +for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > +where + T : Fields< 'a, RowKey, Row >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, +{ + + fn rows( &'a self ) -> impl IteratorTrait< Item = Row > + { + self.as_ref().fields().map( move | ( _k, e ) | e.into_owned() ) + } + +} + +impl< 'a, T, RowKey, Row, CellKey, Cell > TableHeader< 'a, CellKey, CellKey > +for AsTable< 'a, T, RowKey, Row, CellKey, Cell, CellKey > +where + Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + CellKey : fmt::Debug + Clone, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, +{ + + fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, CellKey ) > > + { + let mut rows = self.rows(); + let row = rows.next(); + if let Some( row ) = row + { + Some + ( + row + .cells() + .map( | ( key, _title ) | ( key.clone(), key ) ) + .collect::< Vec< _ > >() + .into_iter() + ) + } + else + { + None + } + } + +} + +impl< 'a, Row, CellKey, Cell > Cells< 'a, CellKey, Cell > +for Row +where + Row : Fields< 'a, CellKey, Cell > + 'a, + Cell : fmt::Debug + Clone + 'a, +{ + + fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Cell ) > + { + self.fields().map( move | ( key, cell ) | ( key, cell.into_owned() ) ) + } + +} + +// == diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 3de77e2cbf..9bdfc981f2 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -11,6 +11,7 @@ use assistant:: TableRows, TableHeader, TableFormatter, + Context, }; use std:: @@ -114,16 +115,13 @@ where // dbg!( header.collect::< Vec< _ > >() ); let mut output = String::new(); - let mut formatter = the_module::Formatter::new( &mut output, Default::default() ); + let mut formatter = Context::new( &mut output, Default::default() ); let got = the_module::TableFormatter::fmt( &as_table, &mut formatter ); assert!( got.is_ok() ); println!( "{}", &output ); - // use the_module::{ TableFormatter, TableToString }; - // AsTable::new( test_objects ); - // // let table_string = AsTable::new( test_objects ).table_to_string(); + let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, String, &str > = AsTable::new( &test_objects ); let table_string = as_table.table_to_string(); - // println!( "{}", table_string ); assert!( table_string.contains( "id" ) ); assert!( table_string.contains( "created_at" ) ); assert!( table_string.contains( "file_ids" ) ); From 17240d9f1a02ed8faa7ed40ef41940eaa1fd102f Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 6 Jun 2024 00:15:56 +0300 Subject: [PATCH 047/143] experimenting --- module/move/assistant/src/print.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 99ad10f833..7e90497fac 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -6,13 +6,22 @@ use former::Former; //= /// Struct to hold options to print data as table. -#[ derive( Debug, Default, Former ) ] +#[ derive( Debug, Former ) ] pub struct Styles { /// Delimiter for separating table columns. pub separator : String, } +impl Default for Styles +{ + fn default() -> Self + { + let separator = "|".to_string(); + Styles { separator } + } +} + /// Struct for formatting tables. pub struct Context< 'a > { From b4ed166b6fcd8825e1457de35eea4664e25cdb5d Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 6 Jun 2024 00:57:12 +0300 Subject: [PATCH 048/143] experimenting --- module/move/assistant/src/print.rs | 64 ++++++++++++++----- .../move/assistant/tests/inc/fields_test.rs | 2 +- module/move/assistant/tests/inc/print_test.rs | 37 ++++++----- 3 files changed, 69 insertions(+), 34 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 7e90497fac..94edc868a9 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -17,7 +17,7 @@ impl Default for Styles { fn default() -> Self { - let separator = "|".to_string(); + let separator = " | ".to_string(); Styles { separator } } } @@ -108,26 +108,21 @@ where let mut col_widths : Vec< usize > = vec![ 0 ; table_size[ 1 ] ]; let separator = &f.styles.separator; - // Write the header if provided + // println!( "{}", self.header().is_some() ); + if let Some( header ) = self.header() { - let mut first = true; let mut i = 0; for ( _key, title ) in header { - if !first - { - write!( f.buf, "{}", separator )?; - } col_widths[ i ] = format!( "{:?}", title ).len(); - // zzz : avoid extra allocation of memory - write!( f.buf, "{:?}", title )?; - first = false; i += 1; } writeln!( f.buf )?; } + // dbg!( &col_widths ); + // Collect rows let mut all_rows : Vec< Vec< String > > = Vec::new(); for row in self.rows() @@ -154,17 +149,52 @@ where } } + // Write the header if provided + if let Some( header ) = self.header() + { + let mut i = 0; + for ( _key, title ) in header + { + if i > 0 + { + write!( f.buf, "{}", separator )?; + } + write!( f.buf, "{:^width$}", format!( "{:?}", title ), width = col_widths[ i ] )?; + // write!( f.buf, "{:?}", title )?; + i += 1; + } + writeln!( f.buf )?; + } + + // dbg!( &col_widths ); + // Write rows with proper alignment - for row in all_rows + for row in &all_rows { - let formatted_row : Vec< String > = row - .iter() - .enumerate() - .map( | ( i, cell ) | format!( "{:width$}", cell, width = col_widths[ i ] ) ) - .collect(); - writeln!( f.buf, "{}", formatted_row.join( separator ) )?; + let mut i = 0; + for cell in row + { + if i > 0 + { + write!( f.buf, "{}", separator )?; + } + write!( f.buf, "{:^width$}", format!( "{:?}", cell ), width = col_widths[ i ] )?; + i += 1; + } + writeln!( f.buf )?; } + // // Write rows with proper alignment + // for row in all_rows + // { + // let formatted_row : Vec< String > = row + // .iter() + // .enumerate() + // .map( | ( i, cell ) | format!( "{:?^width$}", cell, width = col_widths[ i ] ) ) + // .collect(); + // writeln!( f.buf, "{}", formatted_row.join( separator ) )?; + // } + Ok(()) } } diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index e748e27a4a..3ba06ea324 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -123,7 +123,7 @@ fn test_vec_fields() TestObject { id : "67890".to_string(), - created_at : 1627845584, + created_at : 13, file_ids : vec![ "file3".to_string(), "file4".to_string() ], tools : None, } diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 9bdfc981f2..7a623e800b 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -73,31 +73,36 @@ where id : "1".to_string(), created_at : 1627845583, file_ids : vec![ "file1".to_string(), "file2".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 - } - ]), + tools : None }, TestObject { id : "2".to_string(), - created_at : 1627845584, + created_at : 13, file_ids : vec![ "file3".to_string(), "file4".to_string() ], - tools : None, - } + 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 + } + ] + ), + }, ]; let cells = Cells::< '_, &'static str, String >::cells( &test_objects[ 0 ] ); assert_eq!( cells.len(), 4 ); + let cells = Cells::< '_, &'static str, String >::cells( &test_objects[ 1 ] ); + assert_eq!( cells.len(), 4 ); // dbg!( cells.collect::< Vec< _ > >() ); drop( cells ); From 2f3c9f2e5d4246f88264e1c4103c5a6dcb4d79de Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 6 Jun 2024 08:23:51 +0300 Subject: [PATCH 049/143] experimenting --- module/move/assistant/src/reflect.rs | 8 +++--- module/move/assistant/src/table.rs | 25 ++++++++++++++++--- .../move/assistant/tests/inc/fields_test.rs | 18 +++++++------ module/move/assistant/tests/inc/print_test.rs | 18 +++++++------ 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/module/move/assistant/src/reflect.rs b/module/move/assistant/src/reflect.rs index 85368aa236..037cb64269 100644 --- a/module/move/assistant/src/reflect.rs +++ b/module/move/assistant/src/reflect.rs @@ -1,17 +1,17 @@ - // use core::fmt; +use std::borrow::Cow; /// A trait for iterators that are also `ExactSizeIterator`. pub trait _IteratorTrait where - Self : core::iter::Iterator + ExactSizeIterator + Self : core::iter::Iterator + ExactSizeIterator + DoubleEndedIterator { } impl< T > _IteratorTrait for T where - Self : core::iter::Iterator + ExactSizeIterator + Self : core::iter::Iterator + ExactSizeIterator + DoubleEndedIterator { } @@ -40,7 +40,7 @@ where // K : 'static, { /// Returns an iterator over all fields of the specified type within the entity. - fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, std::borrow::Cow< 'a, E > ) >; + fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, Option< Cow< 'a, E > > ) >; } // /// Return number of fields convertible into a specified type withing an entity. diff --git a/module/move/assistant/src/table.rs b/module/move/assistant/src/table.rs index 54c0bda45b..e25cec3298 100644 --- a/module/move/assistant/src/table.rs +++ b/module/move/assistant/src/table.rs @@ -36,7 +36,7 @@ where Cell : fmt::Debug + Clone + 'a, { /// Returns an iterator over all cells of the row. - fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Cell ) > + fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Option< Cell > ) > ; } @@ -80,7 +80,14 @@ where fn rows( &'a self ) -> impl IteratorTrait< Item = Row > { - self.as_ref().fields().map( move | ( _k, e ) | e.into_owned() ) + self.as_ref().fields().filter_map( move | ( _k, e ) | + { + match e + { + Some( e ) => Some( e.into_owned() ), + None => None, + } + }).collect::< Vec< _ > >().into_iter() } } @@ -125,9 +132,19 @@ where Cell : fmt::Debug + Clone + 'a, { - fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Cell ) > + fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Option< Cell > ) > { - self.fields().map( move | ( key, cell ) | ( key, cell.into_owned() ) ) + self.fields().filter + ( + move | ( key, cell ) | + { + match cell + { + Some( cell ) => ( key, Some( cell.into_owned() ) ), + None => ( key, None ) + } + } + ) } } diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 3ba06ea324..1570ba7116 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -25,17 +25,21 @@ pub struct TestObject impl< 'a > Fields< 'a, &'static str, String > for TestObject { - fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Cow< 'a, String > ) > + fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, String > > ) > { - let mut vec : Vec< ( &'static str, Cow< 'a, String > ) > = Vec::new(); + let mut vec : Vec< ( &'static str, Option< Cow< 'a, String > > ) > = Vec::new(); - vec.push( ( "id", Cow::Borrowed( &self.id ) ) ); - vec.push( ( "created_at", Cow::Owned( self.created_at.to_string() ) ) ); - vec.push( ( "file_ids", Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ); + vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ) ); + vec.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); + vec.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); if let Some( tools ) = &self.tools { - vec.push( ( "tools", Cow::Owned( format!( "{:?}", tools ) ) ) ); + vec.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ) ) ); + } + else + { + vec.push( None ) } vec.into_iter() @@ -46,7 +50,7 @@ impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > { fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Cow< 'a, TestObject > ) > { - self.iter().enumerate().map( | ( key, val ) | ( key, Cow::Borrowed( val ) ) ) + self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) } } diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 7a623e800b..51e5534fc4 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -32,17 +32,21 @@ pub struct TestObject impl< 'a > Fields< 'a, &'static str, String > for TestObject { - fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Cow< 'a, String > ) > + fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, String > > ) > { - let mut vec : Vec< ( &'static str, Cow< 'a, String > ) > = Vec::new(); + let mut vec : Vec< ( &'static str, Option< Cow< 'a, String > > ) > = Vec::new(); - vec.push( ( "id", Cow::Borrowed( &self.id ) ) ); - vec.push( ( "created_at", Cow::Owned( self.created_at.to_string() ) ) ); - vec.push( ( "file_ids", Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ); + vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ) ); + vec.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); + vec.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); if let Some( tools ) = &self.tools { - vec.push( ( "tools", Cow::Owned( format!( "{:?}", tools ) ) ) ); + vec.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ) ) ); + } + else + { + vec.push( None ) } vec.into_iter() @@ -53,7 +57,7 @@ impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > { fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Cow< 'a, TestObject > ) > { - self.iter().enumerate().map( | ( key, val ) | ( key, Cow::Borrowed( val ) ) ) + self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) } } From 68474ddaae6ae676834f0c88b97bf2b83e52a4e3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 7 Jun 2024 00:20:05 +0300 Subject: [PATCH 050/143] experimenting --- module/move/assistant/src/table.rs | 2 +- module/move/assistant/tests/inc/fields_test.rs | 2 +- module/move/assistant/tests/inc/print_test.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/module/move/assistant/src/table.rs b/module/move/assistant/src/table.rs index e25cec3298..a0bfeeacc9 100644 --- a/module/move/assistant/src/table.rs +++ b/module/move/assistant/src/table.rs @@ -134,7 +134,7 @@ where fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Option< Cell > ) > { - self.fields().filter + self.fields().map ( move | ( key, cell ) | { diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 1570ba7116..25a7d830b2 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -29,7 +29,7 @@ impl< 'a > Fields< 'a, &'static str, String > for TestObject { let mut vec : Vec< ( &'static str, Option< Cow< 'a, String > > ) > = Vec::new(); - vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ) ); + vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ); vec.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); vec.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 51e5534fc4..7d0429f368 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -36,7 +36,7 @@ impl< 'a > Fields< 'a, &'static str, String > for TestObject { let mut vec : Vec< ( &'static str, Option< Cow< 'a, String > > ) > = Vec::new(); - vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ) ); + vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ); vec.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); vec.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); From c12238e20b721e053ecac1d2ea45e894c4207a32 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 7 Jun 2024 00:31:40 +0300 Subject: [PATCH 051/143] experimenting --- .../move/assistant/tests/inc/fields_test.rs | 18 +- module/move/assistant/tests/inc/print_test.rs | 278 +++++++++--------- 2 files changed, 150 insertions(+), 146 deletions(-) diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 25a7d830b2..643497cc84 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -39,7 +39,7 @@ impl< 'a > Fields< 'a, &'static str, String > for TestObject } else { - vec.push( None ) + vec.push( ( "tools", None ) ); } vec.into_iter() @@ -48,7 +48,7 @@ impl< 'a > Fields< 'a, &'static str, String > for TestObject impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > { - fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Cow< 'a, TestObject > ) > + fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Option< Cow< 'a, TestObject > > ) > { self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) } @@ -56,9 +56,13 @@ impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > // -fn is_borrowed< 'a, T : Clone >( src : &Cow< 'a, T > ) -> bool +fn is_borrowed< 'a, T : Clone >( src : &Option< Cow< 'a, T > > ) -> bool { - match src + if src.is_none() + { + return false; + } + match src.as_ref().unwrap() { Cow::Borrowed( _ ) => true, Cow::Owned( _ ) => false, @@ -94,9 +98,9 @@ fn basic() assert!( !is_borrowed( &fields[ 1 ].1 ) ); assert!( !is_borrowed( &fields[ 2 ].1 ) ); assert!( !is_borrowed( &fields[ 3 ].1 ) ); - assert_eq!( fields[ 0 ], ( "id", Cow::Borrowed( &"12345".to_string() ) ) ); - assert_eq!( fields[ 1 ], ( "created_at", Cow::Owned( "1627845583".to_string() ) ) ); - assert_eq!( fields[ 2 ], ( "file_ids", Cow::Owned( "[\"file1\", \"file2\"]".to_string() ) ) ); + assert_eq!( fields[ 0 ], ( "id", Some( Cow::Borrowed( &"12345".to_string() ) ) ) ); + assert_eq!( fields[ 1 ], ( "created_at", Some( Cow::Owned( "1627845583".to_string() ) ) ) ); + assert_eq!( fields[ 2 ], ( "file_ids", Some( Cow::Owned( "[\"file1\", \"file2\"]".to_string() ) ) ) ); assert_eq!( fields[ 3 ].0, "tools" ); } diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 7d0429f368..64416e6679 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -1,139 +1,139 @@ -#[ allow( unused_imports ) ] -use super::*; - -use assistant:: -{ - Fields, - IteratorTrait, - AsTable, - Cells, - TableSize, - TableRows, - TableHeader, - TableFormatter, - Context, -}; - -use std:: -{ - collections::HashMap, - borrow::Cow, -}; - -/// Struct representing a test object with various fields. -#[ derive( Clone, Debug ) ] -pub struct TestObject -{ - pub id : String, - pub created_at : i64, - pub file_ids : Vec< String >, - pub tools : Option< Vec< HashMap< String, String > > >, -} - -impl< 'a > Fields< 'a, &'static str, String > for TestObject -{ - fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, String > > ) > - { - let mut vec : Vec< ( &'static str, Option< Cow< 'a, String > > ) > = Vec::new(); - - vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ); - vec.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); - vec.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); - - if let Some( tools ) = &self.tools - { - vec.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ) ) ); - } - else - { - vec.push( None ) - } - - vec.into_iter() - } -} - -impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > -{ - fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Cow< 'a, TestObject > ) > - { - self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) - } -} - -// - -#[ test ] -fn test_table_to_string() -where - for< 'a > AsTable< 'a, Vec< TestObject >, usize, TestObject, &'static str, String, &'static str > : TableFormatter< 'a >, -{ - use the_module::TableToString; - - let test_objects = vec! - [ - TestObject - { - id : "1".to_string(), - created_at : 1627845583, - file_ids : vec![ "file1".to_string(), "file2".to_string() ], - tools : None - }, - TestObject - { - id : "2".to_string(), - created_at : 13, - file_ids : vec![ "file3".to_string(), "file4".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 - } - ] - ), - }, - ]; - - let cells = Cells::< '_, &'static str, String >::cells( &test_objects[ 0 ] ); - assert_eq!( cells.len(), 4 ); - let cells = Cells::< '_, &'static str, String >::cells( &test_objects[ 1 ] ); - assert_eq!( cells.len(), 4 ); - // dbg!( cells.collect::< Vec< _ > >() ); - drop( cells ); - - let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, String, &str > = AsTable::new( &test_objects ); - let size = TableSize::< '_ >::table_size( &as_table ); - assert_eq!( size, [ 2, 4 ] ); - let rows = TableRows::rows( &as_table ); - assert_eq!( rows.len(), 2 ); - // dbg!( rows.collect::< Vec< _ > >() ); - let header = TableHeader::header( &as_table ); - assert!( header.is_some() ); - let header = header.unwrap(); - assert_eq!( header.len(), 4 ); - assert_eq!( header.collect::< Vec< _ > >(), vec![ ( "id", "id" ), ( "created_at", "created_at" ), ( "file_ids", "file_ids" ), ( "tools", "tools" ) ] ); - // dbg!( header.collect::< Vec< _ > >() ); - - let mut output = String::new(); - let mut formatter = Context::new( &mut output, Default::default() ); - let got = the_module::TableFormatter::fmt( &as_table, &mut formatter ); - assert!( got.is_ok() ); - println!( "{}", &output ); - - let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, String, &str > = AsTable::new( &test_objects ); - let table_string = as_table.table_to_string(); - assert!( table_string.contains( "id" ) ); - assert!( table_string.contains( "created_at" ) ); - assert!( table_string.contains( "file_ids" ) ); - assert!( table_string.contains( "tools" ) ); - -} +// #[ allow( unused_imports ) ] +// use super::*; +// +// use assistant:: +// { +// Fields, +// IteratorTrait, +// AsTable, +// Cells, +// TableSize, +// TableRows, +// TableHeader, +// TableFormatter, +// Context, +// }; +// +// use std:: +// { +// collections::HashMap, +// borrow::Cow, +// }; +// +// /// Struct representing a test object with various fields. +// #[ derive( Clone, Debug ) ] +// pub struct TestObject +// { +// pub id : String, +// pub created_at : i64, +// pub file_ids : Vec< String >, +// pub tools : Option< Vec< HashMap< String, String > > >, +// } +// +// impl< 'a > Fields< 'a, &'static str, String > for TestObject +// { +// fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, String > > ) > +// { +// let mut vec : Vec< ( &'static str, Option< Cow< 'a, String > > ) > = Vec::new(); +// +// vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ); +// vec.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); +// vec.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); +// +// if let Some( tools ) = &self.tools +// { +// vec.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ) ) ); +// } +// else +// { +// vec.push( None ) +// } +// +// vec.into_iter() +// } +// } +// +// impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > +// { +// fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Cow< 'a, TestObject > ) > +// { +// self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) +// } +// } +// +// // +// +// #[ test ] +// fn test_table_to_string() +// where +// for< 'a > AsTable< 'a, Vec< TestObject >, usize, TestObject, &'static str, String, &'static str > : TableFormatter< 'a >, +// { +// use the_module::TableToString; +// +// let test_objects = vec! +// [ +// TestObject +// { +// id : "1".to_string(), +// created_at : 1627845583, +// file_ids : vec![ "file1".to_string(), "file2".to_string() ], +// tools : None +// }, +// TestObject +// { +// id : "2".to_string(), +// created_at : 13, +// file_ids : vec![ "file3".to_string(), "file4".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 +// } +// ] +// ), +// }, +// ]; +// +// let cells = Cells::< '_, &'static str, String >::cells( &test_objects[ 0 ] ); +// assert_eq!( cells.len(), 4 ); +// let cells = Cells::< '_, &'static str, String >::cells( &test_objects[ 1 ] ); +// assert_eq!( cells.len(), 4 ); +// // dbg!( cells.collect::< Vec< _ > >() ); +// drop( cells ); +// +// let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, String, &str > = AsTable::new( &test_objects ); +// let size = TableSize::< '_ >::table_size( &as_table ); +// assert_eq!( size, [ 2, 4 ] ); +// let rows = TableRows::rows( &as_table ); +// assert_eq!( rows.len(), 2 ); +// // dbg!( rows.collect::< Vec< _ > >() ); +// let header = TableHeader::header( &as_table ); +// assert!( header.is_some() ); +// let header = header.unwrap(); +// assert_eq!( header.len(), 4 ); +// assert_eq!( header.collect::< Vec< _ > >(), vec![ ( "id", "id" ), ( "created_at", "created_at" ), ( "file_ids", "file_ids" ), ( "tools", "tools" ) ] ); +// // dbg!( header.collect::< Vec< _ > >() ); +// +// let mut output = String::new(); +// let mut formatter = Context::new( &mut output, Default::default() ); +// let got = the_module::TableFormatter::fmt( &as_table, &mut formatter ); +// assert!( got.is_ok() ); +// println!( "{}", &output ); +// +// let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, String, &str > = AsTable::new( &test_objects ); +// let table_string = as_table.table_to_string(); +// assert!( table_string.contains( "id" ) ); +// assert!( table_string.contains( "created_at" ) ); +// assert!( table_string.contains( "file_ids" ) ); +// assert!( table_string.contains( "tools" ) ); +// +// } From b867baac4d60ae8a96f2657f512b211ffe00f887 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 7 Jun 2024 00:38:56 +0300 Subject: [PATCH 052/143] experimenting --- module/move/assistant/tests/inc/print_test.rs | 278 +++++++++--------- 1 file changed, 139 insertions(+), 139 deletions(-) diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 64416e6679..b9988a6c25 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -1,139 +1,139 @@ -// #[ allow( unused_imports ) ] -// use super::*; -// -// use assistant:: -// { -// Fields, -// IteratorTrait, -// AsTable, -// Cells, -// TableSize, -// TableRows, -// TableHeader, -// TableFormatter, -// Context, -// }; -// -// use std:: -// { -// collections::HashMap, -// borrow::Cow, -// }; -// -// /// Struct representing a test object with various fields. -// #[ derive( Clone, Debug ) ] -// pub struct TestObject -// { -// pub id : String, -// pub created_at : i64, -// pub file_ids : Vec< String >, -// pub tools : Option< Vec< HashMap< String, String > > >, -// } -// -// impl< 'a > Fields< 'a, &'static str, String > for TestObject -// { -// fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, String > > ) > -// { -// let mut vec : Vec< ( &'static str, Option< Cow< 'a, String > > ) > = Vec::new(); -// -// vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ); -// vec.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); -// vec.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); -// -// if let Some( tools ) = &self.tools -// { -// vec.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ) ) ); -// } -// else -// { -// vec.push( None ) -// } -// -// vec.into_iter() -// } -// } -// -// impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > -// { -// fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Cow< 'a, TestObject > ) > -// { -// self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) -// } -// } -// -// // -// -// #[ test ] -// fn test_table_to_string() -// where -// for< 'a > AsTable< 'a, Vec< TestObject >, usize, TestObject, &'static str, String, &'static str > : TableFormatter< 'a >, -// { -// use the_module::TableToString; -// -// let test_objects = vec! -// [ -// TestObject -// { -// id : "1".to_string(), -// created_at : 1627845583, -// file_ids : vec![ "file1".to_string(), "file2".to_string() ], -// tools : None -// }, -// TestObject -// { -// id : "2".to_string(), -// created_at : 13, -// file_ids : vec![ "file3".to_string(), "file4".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 -// } -// ] -// ), -// }, -// ]; -// -// let cells = Cells::< '_, &'static str, String >::cells( &test_objects[ 0 ] ); -// assert_eq!( cells.len(), 4 ); -// let cells = Cells::< '_, &'static str, String >::cells( &test_objects[ 1 ] ); -// assert_eq!( cells.len(), 4 ); -// // dbg!( cells.collect::< Vec< _ > >() ); -// drop( cells ); -// -// let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, String, &str > = AsTable::new( &test_objects ); -// let size = TableSize::< '_ >::table_size( &as_table ); -// assert_eq!( size, [ 2, 4 ] ); -// let rows = TableRows::rows( &as_table ); -// assert_eq!( rows.len(), 2 ); -// // dbg!( rows.collect::< Vec< _ > >() ); -// let header = TableHeader::header( &as_table ); -// assert!( header.is_some() ); -// let header = header.unwrap(); -// assert_eq!( header.len(), 4 ); -// assert_eq!( header.collect::< Vec< _ > >(), vec![ ( "id", "id" ), ( "created_at", "created_at" ), ( "file_ids", "file_ids" ), ( "tools", "tools" ) ] ); -// // dbg!( header.collect::< Vec< _ > >() ); -// -// let mut output = String::new(); -// let mut formatter = Context::new( &mut output, Default::default() ); -// let got = the_module::TableFormatter::fmt( &as_table, &mut formatter ); -// assert!( got.is_ok() ); -// println!( "{}", &output ); -// -// let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, String, &str > = AsTable::new( &test_objects ); -// let table_string = as_table.table_to_string(); -// assert!( table_string.contains( "id" ) ); -// assert!( table_string.contains( "created_at" ) ); -// assert!( table_string.contains( "file_ids" ) ); -// assert!( table_string.contains( "tools" ) ); -// -// } +#[ allow( unused_imports ) ] +use super::*; + +use assistant:: +{ + Fields, + IteratorTrait, + AsTable, + Cells, + TableSize, + TableRows, + TableHeader, + TableFormatter, + Context, +}; + +use std:: +{ + collections::HashMap, + borrow::Cow, +}; + +/// Struct representing a test object with various fields. +#[ derive( Clone, Debug ) ] +pub struct TestObject +{ + pub id : String, + pub created_at : i64, + pub file_ids : Vec< String >, + pub tools : Option< Vec< HashMap< String, String > > >, +} + +impl< 'a > Fields< 'a, &'static str, String > for TestObject +{ + fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, String > > ) > + { + let mut vec : Vec< ( &'static str, Option< Cow< 'a, String > > ) > = Vec::new(); + + vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ); + vec.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); + vec.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); + + if let Some( tools ) = &self.tools + { + vec.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ) ) ); + } + else + { + vec.push( ( "tools", None ) ); + } + + vec.into_iter() + } +} + +impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > +{ + fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Option< Cow< 'a, TestObject > > ) > + { + self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) + } +} + +// + +#[ test ] +fn test_table_to_string() +where + for< 'a > AsTable< 'a, Vec< TestObject >, usize, TestObject, &'static str, String, &'static str > : TableFormatter< 'a >, +{ + use the_module::TableToString; + + let test_objects = vec! + [ + TestObject + { + id : "1".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".to_string() ], + tools : None + }, + TestObject + { + id : "2".to_string(), + created_at : 13, + file_ids : vec![ "file3".to_string(), "file4".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 + } + ] + ), + }, + ]; + + let cells = Cells::< '_, &'static str, String >::cells( &test_objects[ 0 ] ); + assert_eq!( cells.len(), 4 ); + let cells = Cells::< '_, &'static str, String >::cells( &test_objects[ 1 ] ); + assert_eq!( cells.len(), 4 ); + // dbg!( cells.collect::< Vec< _ > >() ); + drop( cells ); + + let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, String, &str > = AsTable::new( &test_objects ); + let size = TableSize::< '_ >::table_size( &as_table ); + assert_eq!( size, [ 2, 4 ] ); + let rows = TableRows::rows( &as_table ); + assert_eq!( rows.len(), 2 ); + // dbg!( rows.collect::< Vec< _ > >() ); + let header = TableHeader::header( &as_table ); + assert!( header.is_some() ); + let header = header.unwrap(); + assert_eq!( header.len(), 4 ); + assert_eq!( header.collect::< Vec< _ > >(), vec![ ( "id", "id" ), ( "created_at", "created_at" ), ( "file_ids", "file_ids" ), ( "tools", "tools" ) ] ); + // dbg!( header.collect::< Vec< _ > >() ); + + let mut output = String::new(); + let mut formatter = Context::new( &mut output, Default::default() ); + let got = the_module::TableFormatter::fmt( &as_table, &mut formatter ); + assert!( got.is_ok() ); + println!( "{}", &output ); + + let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, String, &str > = AsTable::new( &test_objects ); + let table_string = as_table.table_to_string(); + assert!( table_string.contains( "id" ) ); + assert!( table_string.contains( "created_at" ) ); + assert!( table_string.contains( "file_ids" ) ); + assert!( table_string.contains( "tools" ) ); + +} From 7630513c3de36e6c2a7271b2890a933a0ff71607 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 7 Jun 2024 00:49:08 +0300 Subject: [PATCH 053/143] experimenting --- module/move/assistant/src/print.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index 94edc868a9..d4c3a7018c 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -129,7 +129,17 @@ where { let fields : Vec< String > = row .cells() - .map( | ( _key, cell ) | format!( "{:?}", &cell ) ) + .map + ( + | ( _key, cell ) | + { + match cell + { + Some( cell ) => format!( "{:?}", &cell ), + None => "".to_string(), + } + } + ) .collect(); all_rows.push( fields ); } @@ -178,7 +188,7 @@ where { write!( f.buf, "{}", separator )?; } - write!( f.buf, "{:^width$}", format!( "{:?}", cell ), width = col_widths[ i ] )?; + write!( f.buf, "{:^width$}", cell, width = col_widths[ i ] )?; i += 1; } writeln!( f.buf )?; From f77cae25548662ec02239ce295270dc852b928be Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 7 Jun 2024 08:29:26 +0300 Subject: [PATCH 054/143] reflect: experimenting --- module/move/assistant/src/as_table.rs | 18 ++++- module/move/assistant/src/as_wrapper.rs | 77 +++++++++++++++++++ module/move/assistant/src/lib.rs | 4 + module/move/assistant/src/reflect.rs | 1 - .../move/assistant/tests/inc/fields_test.rs | 28 ++++++- 5 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 module/move/assistant/src/as_wrapper.rs diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 100fc72e6e..3de5a57dc4 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -21,7 +21,6 @@ where Cell : fmt::Debug + Clone + 'a, CellKey : fmt::Debug + Clone, ; -// xxx : use maybe ref inside impl< 'a, T, RowKey, Row, CellKey, Cell, Title > AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where @@ -125,7 +124,22 @@ where } } -// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Default for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > +// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > From< AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > > +// for &'a T +// where +// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, +// Title : fmt::Debug, +// Cell : fmt::Debug + Clone + 'a, +// CellKey : fmt::Debug + Clone, +// { +// fn from( wrapper : AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > ) -> &'a T +// { +// wrapper.0 +// } +// } + +// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Default +// for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > // where // T : Default, // // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, diff --git a/module/move/assistant/src/as_wrapper.rs b/module/move/assistant/src/as_wrapper.rs new file mode 100644 index 0000000000..9f653e604e --- /dev/null +++ b/module/move/assistant/src/as_wrapper.rs @@ -0,0 +1,77 @@ +use core::fmt; +use core::ops::{ Deref }; + +/// Transparent wrapper to emphasizing a specific aspect of identity of its internal type. +#[ repr( transparent ) ] +#[ derive( Clone, Copy ) ] +pub struct As< 'a, T >( &'a T ); + +impl< 'a, T > As< 'a, T > +{ + /// Just a constructor. + pub fn new( src : &'a T ) -> Self + { + Self( src ) + } + /// Just a constructor. + pub fn inner( self ) -> &'a T + { + self.0 + } + +} + +impl< 'a, T > AsRef< T > for As< 'a, T > +{ + fn as_ref( &self ) -> &T + { + &self.0 + } +} + +impl< 'a, T > Deref for As< 'a, T > +{ + type Target = T; + fn deref( &self ) -> &Self::Target + { + &self.0 + } +} + +impl< 'a, T > From< &'a T > for As< 'a, T > +{ + fn from( table : &'a T ) -> Self + { + As( table ) + } +} + +// impl< 'a, T > From< As< 'a, T > > for &'a T +// { +// fn from( wrapper : As< 'a, T > ) -> &'a T +// { +// wrapper.0 +// } +// } + +// impl< 'a, T > Default for As< 'a, T > +// where +// T : Default, +// { +// fn default() -> Self +// { +// As( &T::default() ) +// } +// } + +impl< 'a, T > fmt::Debug for As< 'a, T > +where + T : fmt::Debug, +{ + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f.debug_struct( "As" ) + .field( "0", &self.0 ) + .finish() + } +} diff --git a/module/move/assistant/src/lib.rs b/module/move/assistant/src/lib.rs index a3d94a448e..495b74e87e 100644 --- a/module/move/assistant/src/lib.rs +++ b/module/move/assistant/src/lib.rs @@ -21,6 +21,10 @@ use former::Former; /// Reflections. pub mod reflect; pub use reflect::*; +/// Universal wrapper. +pub mod as_wrapper; +pub use as_wrapper::*; + /// Nice print. pub mod print; pub use print::*; diff --git a/module/move/assistant/src/reflect.rs b/module/move/assistant/src/reflect.rs index 037cb64269..b3d2370eb8 100644 --- a/module/move/assistant/src/reflect.rs +++ b/module/move/assistant/src/reflect.rs @@ -37,7 +37,6 @@ where pub trait Fields< 'a, K, E > where E : Clone + 'a, - // K : 'static, { /// Returns an iterator over all fields of the specified type within the entity. fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, Option< Cow< 'a, E > > ) >; diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 643497cc84..b71ecfabca 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -46,6 +46,30 @@ impl< 'a > Fields< 'a, &'static str, String > for TestObject } } +// impl< 'a, V > Fields< 'a, &'static str, V > +// for TestObject +// { +// fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, V > > ) > +// { +// let mut vec : Vec< ( &'static str, Option< Cow< 'a, V > > ) > = Vec::new(); +// +// vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ); +// vec.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); +// vec.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); +// +// if let Some( tools ) = &self.tools +// { +// vec.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ) ) ); +// } +// else +// { +// vec.push( ( "tools", None ) ); +// } +// +// vec.into_iter() +// } +// } + impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > { fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Option< Cow< 'a, TestObject > > ) > @@ -134,10 +158,10 @@ fn test_vec_fields() created_at : 13, file_ids : vec![ "file3".to_string(), "file4".to_string() ], tools : None, - } + }, ]; - let fields: Vec< _ > = test_objects.fields().collect(); + let fields : Vec< _ > = test_objects.fields().collect(); assert_eq!( fields.len(), 2 ); assert_eq!( fields[ 0 ].0, 0 ); assert_eq!( fields[ 1 ].0, 1 ); From 9430ddd59da367ede1d898509d400096ac987898 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 7 Jun 2024 08:43:50 +0300 Subject: [PATCH 055/143] reflect: experimenting --- module/move/assistant/src/lib.rs | 4 +- module/move/assistant/src/wrapper_cow.rs | 81 +++++++++++++++++++ .../src/{as_wrapper.rs => wrapper_ref.rs} | 30 ++++--- 3 files changed, 100 insertions(+), 15 deletions(-) create mode 100644 module/move/assistant/src/wrapper_cow.rs rename module/move/assistant/src/{as_wrapper.rs => wrapper_ref.rs} (54%) diff --git a/module/move/assistant/src/lib.rs b/module/move/assistant/src/lib.rs index 495b74e87e..23fd65c382 100644 --- a/module/move/assistant/src/lib.rs +++ b/module/move/assistant/src/lib.rs @@ -22,8 +22,8 @@ use former::Former; pub mod reflect; pub use reflect::*; /// Universal wrapper. -pub mod as_wrapper; -pub use as_wrapper::*; +pub mod wrapper_ref; +pub use wrapper_ref::*; /// Nice print. pub mod print; diff --git a/module/move/assistant/src/wrapper_cow.rs b/module/move/assistant/src/wrapper_cow.rs new file mode 100644 index 0000000000..c8be453726 --- /dev/null +++ b/module/move/assistant/src/wrapper_cow.rs @@ -0,0 +1,81 @@ +use core::fmt; +use core::ops::{ Deref }; + +/// Transparent reference wrapper to emphasizing a specific aspect of identity of its internal type. +#[ repr( transparent ) ] +#[ derive( Clone, Copy ) ] +pub struct AsCow< 'a, T >( &'a T ); + +impl< 'a, T > AsCow< 'a, T > +{ + + /// Just a constructor. + #[ inline( always ) ] + pub fn new( src : &'a T ) -> Self + { + Self( src ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn inner( self ) -> &'a T + { + self.0 + } + +} + +impl< 'a, T > AsRef< T > for AsCow< 'a, T > +{ + fn as_ref( &self ) -> &T + { + &self.0 + } +} + +impl< 'a, T > Deref for AsCow< 'a, T > +{ + type Target = T; + fn deref( &self ) -> &Self::Target + { + &self.0 + } +} + +impl< 'a, T > From< &'a T > for AsCow< 'a, T > +{ + fn from( table : &'a T ) -> Self + { + AsCow( table ) + } +} + +// impl< 'a, T > From< AsCow< 'a, T > > for &'a T +// { +// fn from( wrapper : AsCow< 'a, T > ) -> &'a T +// { +// wrapper.0 +// } +// } + +// impl< 'a, T > Default for AsCow< 'a, T > +// where +// T : Default, +// { +// fn default() -> Self +// { +// AsCow( &T::default() ) +// } +// } + +impl< 'a, T > fmt::Debug for AsCow< 'a, T > +where + T : fmt::Debug, +{ + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f.debug_struct( "AsCow" ) + .field( "0", &self.0 ) + .finish() + } +} diff --git a/module/move/assistant/src/as_wrapper.rs b/module/move/assistant/src/wrapper_ref.rs similarity index 54% rename from module/move/assistant/src/as_wrapper.rs rename to module/move/assistant/src/wrapper_ref.rs index 9f653e604e..4fedb5e239 100644 --- a/module/move/assistant/src/as_wrapper.rs +++ b/module/move/assistant/src/wrapper_ref.rs @@ -1,19 +1,23 @@ use core::fmt; use core::ops::{ Deref }; -/// Transparent wrapper to emphasizing a specific aspect of identity of its internal type. +/// Transparent reference wrapper to emphasizing a specific aspect of identity of its internal type. #[ repr( transparent ) ] #[ derive( Clone, Copy ) ] -pub struct As< 'a, T >( &'a T ); +pub struct Ref< 'a, T >( &'a T ); -impl< 'a, T > As< 'a, T > +impl< 'a, T > Ref< 'a, T > { + /// Just a constructor. + #[ inline( always ) ] pub fn new( src : &'a T ) -> Self { Self( src ) } + /// Just a constructor. + #[ inline( always ) ] pub fn inner( self ) -> &'a T { self.0 @@ -21,7 +25,7 @@ impl< 'a, T > As< 'a, T > } -impl< 'a, T > AsRef< T > for As< 'a, T > +impl< 'a, T > AsRef< T > for Ref< 'a, T > { fn as_ref( &self ) -> &T { @@ -29,7 +33,7 @@ impl< 'a, T > AsRef< T > for As< 'a, T > } } -impl< 'a, T > Deref for As< 'a, T > +impl< 'a, T > Deref for Ref< 'a, T > { type Target = T; fn deref( &self ) -> &Self::Target @@ -38,39 +42,39 @@ impl< 'a, T > Deref for As< 'a, T > } } -impl< 'a, T > From< &'a T > for As< 'a, T > +impl< 'a, T > From< &'a T > for Ref< 'a, T > { fn from( table : &'a T ) -> Self { - As( table ) + Ref( table ) } } -// impl< 'a, T > From< As< 'a, T > > for &'a T +// impl< 'a, T > From< Ref< 'a, T > > for &'a T // { -// fn from( wrapper : As< 'a, T > ) -> &'a T +// fn from( wrapper : Ref< 'a, T > ) -> &'a T // { // wrapper.0 // } // } -// impl< 'a, T > Default for As< 'a, T > +// impl< 'a, T > Default for Ref< 'a, T > // where // T : Default, // { // fn default() -> Self // { -// As( &T::default() ) +// Ref( &T::default() ) // } // } -impl< 'a, T > fmt::Debug for As< 'a, T > +impl< 'a, T > fmt::Debug for Ref< 'a, T > where T : fmt::Debug, { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { - f.debug_struct( "As" ) + f.debug_struct( "Ref" ) .field( "0", &self.0 ) .finish() } From 06254623204510f9a1af85895c3197ab875232a8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 7 Jun 2024 08:44:47 +0300 Subject: [PATCH 056/143] reflect: experimenting --- module/move/assistant/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module/move/assistant/src/lib.rs b/module/move/assistant/src/lib.rs index 23fd65c382..a5cebd74f4 100644 --- a/module/move/assistant/src/lib.rs +++ b/module/move/assistant/src/lib.rs @@ -24,6 +24,9 @@ pub use reflect::*; /// Universal wrapper. pub mod wrapper_ref; pub use wrapper_ref::*; +/// Universal wrapper. +pub mod wrapper_cow; +pub use wrapper_cow::*; /// Nice print. pub mod print; From 02635d944f94864bccee5991716a7f1c450be563 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 7 Jun 2024 20:06:31 +0300 Subject: [PATCH 057/143] experimenting --- .../{wrapper_cow.rs => wrapper_option_cow.rs} | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) rename module/move/assistant/src/{wrapper_cow.rs => wrapper_option_cow.rs} (61%) diff --git a/module/move/assistant/src/wrapper_cow.rs b/module/move/assistant/src/wrapper_option_cow.rs similarity index 61% rename from module/move/assistant/src/wrapper_cow.rs rename to module/move/assistant/src/wrapper_option_cow.rs index c8be453726..ae0daa3ed8 100644 --- a/module/move/assistant/src/wrapper_cow.rs +++ b/module/move/assistant/src/wrapper_option_cow.rs @@ -4,9 +4,9 @@ use core::ops::{ Deref }; /// Transparent reference wrapper to emphasizing a specific aspect of identity of its internal type. #[ repr( transparent ) ] #[ derive( Clone, Copy ) ] -pub struct AsCow< 'a, T >( &'a T ); +pub struct AsOptionCow< 'a, T >( &'a T ); -impl< 'a, T > AsCow< 'a, T > +impl< 'a, T > AsOptionCow< 'a, T > { /// Just a constructor. @@ -25,7 +25,7 @@ impl< 'a, T > AsCow< 'a, T > } -impl< 'a, T > AsRef< T > for AsCow< 'a, T > +impl< 'a, T > AsRef< T > for AsOptionCow< 'a, T > { fn as_ref( &self ) -> &T { @@ -33,7 +33,7 @@ impl< 'a, T > AsRef< T > for AsCow< 'a, T > } } -impl< 'a, T > Deref for AsCow< 'a, T > +impl< 'a, T > Deref for AsOptionCow< 'a, T > { type Target = T; fn deref( &self ) -> &Self::Target @@ -42,39 +42,39 @@ impl< 'a, T > Deref for AsCow< 'a, T > } } -impl< 'a, T > From< &'a T > for AsCow< 'a, T > +impl< 'a, T > From< &'a T > for AsOptionCow< 'a, T > { fn from( table : &'a T ) -> Self { - AsCow( table ) + AsOptionCow( table ) } } -// impl< 'a, T > From< AsCow< 'a, T > > for &'a T +// impl< 'a, T > From< AsOptionCow< 'a, T > > for &'a T // { -// fn from( wrapper : AsCow< 'a, T > ) -> &'a T +// fn from( wrapper : AsOptionCow< 'a, T > ) -> &'a T // { // wrapper.0 // } // } -// impl< 'a, T > Default for AsCow< 'a, T > +// impl< 'a, T > Default for AsOptionCow< 'a, T > // where // T : Default, // { // fn default() -> Self // { -// AsCow( &T::default() ) +// AsOptionCow( &T::default() ) // } // } -impl< 'a, T > fmt::Debug for AsCow< 'a, T > +impl< 'a, T > fmt::Debug for AsOptionCow< 'a, T > where T : fmt::Debug, { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { - f.debug_struct( "AsCow" ) + f.debug_struct( "AsOptionCow" ) .field( "0", &self.0 ) .finish() } From 958597286b8f76672b6a1cf954851e64f7fdd08a Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 07:20:08 +0300 Subject: [PATCH 058/143] reflect: MaybeAs experimenting --- module/move/assistant/src/lib.rs | 4 +- .../move/assistant/src/wrapper_option_cow.rs | 81 -------- .../assistant/src/wrapper_option_cow_ref.rs | 181 ++++++++++++++++++ module/move/assistant/src/wrapper_ref.rs | 18 +- 4 files changed, 200 insertions(+), 84 deletions(-) delete mode 100644 module/move/assistant/src/wrapper_option_cow.rs create mode 100644 module/move/assistant/src/wrapper_option_cow_ref.rs diff --git a/module/move/assistant/src/lib.rs b/module/move/assistant/src/lib.rs index a5cebd74f4..270c34b907 100644 --- a/module/move/assistant/src/lib.rs +++ b/module/move/assistant/src/lib.rs @@ -25,8 +25,8 @@ pub use reflect::*; pub mod wrapper_ref; pub use wrapper_ref::*; /// Universal wrapper. -pub mod wrapper_cow; -pub use wrapper_cow::*; +pub mod wrapper_option_cow_ref; +pub use wrapper_option_cow_ref::*; /// Nice print. pub mod print; diff --git a/module/move/assistant/src/wrapper_option_cow.rs b/module/move/assistant/src/wrapper_option_cow.rs deleted file mode 100644 index ae0daa3ed8..0000000000 --- a/module/move/assistant/src/wrapper_option_cow.rs +++ /dev/null @@ -1,81 +0,0 @@ -use core::fmt; -use core::ops::{ Deref }; - -/// Transparent reference wrapper to emphasizing a specific aspect of identity of its internal type. -#[ repr( transparent ) ] -#[ derive( Clone, Copy ) ] -pub struct AsOptionCow< 'a, T >( &'a T ); - -impl< 'a, T > AsOptionCow< 'a, T > -{ - - /// Just a constructor. - #[ inline( always ) ] - pub fn new( src : &'a T ) -> Self - { - Self( src ) - } - - /// Just a constructor. - #[ inline( always ) ] - pub fn inner( self ) -> &'a T - { - self.0 - } - -} - -impl< 'a, T > AsRef< T > for AsOptionCow< 'a, T > -{ - fn as_ref( &self ) -> &T - { - &self.0 - } -} - -impl< 'a, T > Deref for AsOptionCow< 'a, T > -{ - type Target = T; - fn deref( &self ) -> &Self::Target - { - &self.0 - } -} - -impl< 'a, T > From< &'a T > for AsOptionCow< 'a, T > -{ - fn from( table : &'a T ) -> Self - { - AsOptionCow( table ) - } -} - -// impl< 'a, T > From< AsOptionCow< 'a, T > > for &'a T -// { -// fn from( wrapper : AsOptionCow< 'a, T > ) -> &'a T -// { -// wrapper.0 -// } -// } - -// impl< 'a, T > Default for AsOptionCow< 'a, T > -// where -// T : Default, -// { -// fn default() -> Self -// { -// AsOptionCow( &T::default() ) -// } -// } - -impl< 'a, T > fmt::Debug for AsOptionCow< 'a, T > -where - T : fmt::Debug, -{ - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result - { - f.debug_struct( "AsOptionCow" ) - .field( "0", &self.0 ) - .finish() - } -} diff --git a/module/move/assistant/src/wrapper_option_cow_ref.rs b/module/move/assistant/src/wrapper_option_cow_ref.rs new file mode 100644 index 0000000000..47a9e5683f --- /dev/null +++ b/module/move/assistant/src/wrapper_option_cow_ref.rs @@ -0,0 +1,181 @@ +use core::fmt; +use std::borrow::Cow; +use core::ops::{ Deref }; + +/// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. +pub trait IntoOptionCow< 'a, T > +where + T : Clone, +{ + /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. + fn into_option_cow( self ) -> MaybeAs< 'a, T >; +} + +impl< 'a, T > IntoOptionCow< 'a, T > for T +where + T : Clone, +{ + #[ inline( always ) ] + fn into_option_cow( self ) -> MaybeAs< 'a, T > + { + MaybeAs::< 'a, T >( Some( Cow::Owned( self ) ) ) + } +} + +impl< 'a, T > IntoOptionCow< 'a, T > for &'a T +where + T : Clone, +{ + #[ inline( always ) ] + fn into_option_cow( self ) -> MaybeAs< 'a, T > + { + MaybeAs::< 'a, T >( Some( Cow::Borrowed( self ) ) ) + } +} + +// xxx +// impl< 'a, T > IntoOptionCow< 'a, T > for () +// where +// T : Clone, +// { +// #[ inline( always ) ] +// fn into_option_cow( self ) -> MaybeAs< 'a, T > +// { +// MaybeAs::< 'a, T >( None ) +// } +// } + +/// Universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. +#[ repr( transparent ) ] +#[ derive( Clone ) ] +pub struct MaybeAs< 'a, T >( pub Option< Cow< 'a, T > > ) +where + T : Clone, +; + +impl< 'a, T > MaybeAs< 'a, T > +where + T : Clone, +{ + + /// Just a constructor. + #[ inline( always ) ] + pub fn new( src : T ) -> Self + { + Self( Some( Cow::Owned( src ) ) ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn new_with_ref( src : &'a T ) -> Self + { + Self( Some( Cow::Borrowed( src ) ) ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn inner( self ) -> Option< Cow< 'a, T > > + { + self.0 + } + +} + +// impl< 'a, T > AsRef< T > for MaybeAs< 'a, T > +// where +// T : Clone, +// Self : 'a, +// { +// fn as_ref( &self ) -> &'a T +// { +// match &self.0 +// { +// Some( src ) => +// { +// match src +// { +// Cow::Borrowed( src ) => src, +// Cow::Owned( src ) => &src, +// } +// }, +// None => panic!( "MaybeAs is None" ), +// } +// } +// } +// +// impl< 'a, T > Deref for MaybeAs< 'a, T > +// where +// T : Clone, +// { +// type Target = T; +// fn deref( &self ) -> &'a T +// { +// self.as_ref() +// } +// } + +impl< 'a, T > From< T > for MaybeAs< 'a, T > +where + T : Clone, +{ + fn from( table : T ) -> Self + { + MaybeAs( Some( Cow::Owned( table ) ) ) + } +} + +impl< 'a, T > From< &'a T > for MaybeAs< 'a, T > +where + T : Clone, +{ + fn from( table : &'a T ) -> Self + { + MaybeAs( Some( Cow::Borrowed( table ) ) ) + } +} + +// impl< 'a, T > From< () > for MaybeAs< 'a, T > +// where +// T : (), +// { +// fn from( table : &'a T ) -> Self +// { +// MaybeAs( None ) +// } +// } + +// xxx : more from + +// impl< 'a, T > From< MaybeAs< 'a, T > > for &'a T +// where +// T : Clone, +// { +// fn from( wrapper : MaybeAs< 'a, T > ) -> &'a T +// { +// wrapper.0 +// } +// } + +impl< 'a, T > Default for MaybeAs< 'a, T > +where + T : Clone, + T : Default, +{ + fn default() -> Self + { + MaybeAs( Some( Cow::Owned( T::default() ) ) ) + } +} + +impl< 'a, T > fmt::Debug for MaybeAs< 'a, T > +where + T : fmt::Debug, + T : Clone, +{ + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f.debug_struct( "MaybeAs" ) + .field( "0", &self.0 ) + .finish() + } +} diff --git a/module/move/assistant/src/wrapper_ref.rs b/module/move/assistant/src/wrapper_ref.rs index 4fedb5e239..c369c6503b 100644 --- a/module/move/assistant/src/wrapper_ref.rs +++ b/module/move/assistant/src/wrapper_ref.rs @@ -1,7 +1,23 @@ use core::fmt; use core::ops::{ Deref }; -/// Transparent reference wrapper to emphasizing a specific aspect of identity of its internal type. +/// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. +pub trait IntoRef< 'a, T > +{ + /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. + fn into_option_cow( self ) -> Ref< 'a, T >; +} + +impl< 'a, T > IntoRef< 'a, T > for &'a T +{ + #[ inline( always ) ] + fn into_option_cow( self ) -> Ref< 'a, T > + { + Ref::< 'a, T >( self ) + } +} + +/// Transparent reference wrapper emphasizing a specific aspect of identity of its internal type. #[ repr( transparent ) ] #[ derive( Clone, Copy ) ] pub struct Ref< 'a, T >( &'a T ); From b01327fd56036e6531cdab08ccd9aa39807f65ef Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 07:35:24 +0300 Subject: [PATCH 059/143] reflect: MaybeAs experimenting --- module/move/assistant/tests/inc/fields_test.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index b71ecfabca..5746140214 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -9,6 +9,7 @@ use assistant:: use std:: { + fmt, collections::HashMap, borrow::Cow, }; @@ -46,6 +47,21 @@ impl< 'a > Fields< 'a, &'static str, String > for TestObject } } +pub trait DebugToString< 'a > +{ + fn debug_to_string( &'a self ) -> Cow< 'a, String >; +} + +impl< 'a, T > DebugToString< 'a > for T +where + T : fmt::Debug, +{ + fn debug_to_string( &'a self ) -> Cow< 'a, String > + { + Cow::Owned( format!( "{:?}", self ) ) + } +} + // impl< 'a, V > Fields< 'a, &'static str, V > // for TestObject // { From 3eb52d848282ca176da32a43ffb92f4153fdf26e Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 07:52:29 +0300 Subject: [PATCH 060/143] reflect: MaybeAs experimenting --- module/move/assistant/tests/inc/fields_test.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 5746140214..ecde2b2cd4 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -5,6 +5,7 @@ use assistant:: { Fields, IteratorTrait, + MaybeAs, }; use std:: @@ -62,6 +63,8 @@ where } } +// pub type Wrap< 'a, T : DebugToString< 'a > > = MaybeAs< 'a, T >; + // impl< 'a, V > Fields< 'a, &'static str, V > // for TestObject // { From 09e2aa5064df6ae4a6234e03ddee94c58b73ded5 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 09:54:48 +0300 Subject: [PATCH 061/143] reflect: MaybeAs experimenting --- .../assistant/src/wrapper_option_cow_ref.rs | 48 +++++++++---------- .../move/assistant/tests/inc/fields_test.rs | 15 +++--- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/module/move/assistant/src/wrapper_option_cow_ref.rs b/module/move/assistant/src/wrapper_option_cow_ref.rs index 47a9e5683f..677e0802e5 100644 --- a/module/move/assistant/src/wrapper_option_cow_ref.rs +++ b/module/move/assistant/src/wrapper_option_cow_ref.rs @@ -3,57 +3,57 @@ use std::borrow::Cow; use core::ops::{ Deref }; /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. -pub trait IntoOptionCow< 'a, T > +pub trait IntoOptionCow< 'a, T, Marker > where T : Clone, { /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. - fn into_option_cow( self ) -> MaybeAs< 'a, T >; + fn into_option_cow( self ) -> MaybeAs< 'a, T, Marker >; } -impl< 'a, T > IntoOptionCow< 'a, T > for T +impl< 'a, T, Marker > IntoOptionCow< 'a, T, Marker > for T where T : Clone, { #[ inline( always ) ] - fn into_option_cow( self ) -> MaybeAs< 'a, T > + fn into_option_cow( self ) -> MaybeAs< 'a, T, Marker > { - MaybeAs::< 'a, T >( Some( Cow::Owned( self ) ) ) + MaybeAs::< 'a, T, Marker >::new( self ) } } -impl< 'a, T > IntoOptionCow< 'a, T > for &'a T +impl< 'a, T, Marker > IntoOptionCow< 'a, T, Marker > for &'a T where T : Clone, { #[ inline( always ) ] - fn into_option_cow( self ) -> MaybeAs< 'a, T > + fn into_option_cow( self ) -> MaybeAs< 'a, T, Marker > { - MaybeAs::< 'a, T >( Some( Cow::Borrowed( self ) ) ) + MaybeAs::< 'a, T, Marker >::new_with_ref( self ) } } // xxx -// impl< 'a, T > IntoOptionCow< 'a, T > for () +// impl< 'a, T, Marker > IntoOptionCow< 'a, T, Marker > for () // where // T : Clone, // { // #[ inline( always ) ] -// fn into_option_cow( self ) -> MaybeAs< 'a, T > +// fn into_option_cow( self ) -> MaybeAs< 'a, T, Marker > // { -// MaybeAs::< 'a, T >( None ) +// MaybeAs::< 'a, T, Marker >( None ) // } // } /// Universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. #[ repr( transparent ) ] #[ derive( Clone ) ] -pub struct MaybeAs< 'a, T >( pub Option< Cow< 'a, T > > ) +pub struct MaybeAs< 'a, T, Marker >( pub Option< Cow< 'a, T > >, ::core::marker::PhantomData< fn() -> Marker > ) where T : Clone, ; -impl< 'a, T > MaybeAs< 'a, T > +impl< 'a, T, Marker > MaybeAs< 'a, T, Marker > where T : Clone, { @@ -62,14 +62,14 @@ where #[ inline( always ) ] pub fn new( src : T ) -> Self { - Self( Some( Cow::Owned( src ) ) ) + Self( Some( Cow::Owned( src ) ), ::core::marker::PhantomData ) } /// Just a constructor. #[ inline( always ) ] pub fn new_with_ref( src : &'a T ) -> Self { - Self( Some( Cow::Borrowed( src ) ) ) + Self( Some( Cow::Borrowed( src ) ), ::core::marker::PhantomData ) } /// Just a constructor. @@ -81,7 +81,7 @@ where } -// impl< 'a, T > AsRef< T > for MaybeAs< 'a, T > +// impl< 'a, T, Marker > AsRef< T > for MaybeAs< 'a, T, Marker > // where // T : Clone, // Self : 'a, @@ -103,7 +103,7 @@ where // } // } // -// impl< 'a, T > Deref for MaybeAs< 'a, T > +// impl< 'a, T, Marker > Deref for MaybeAs< 'a, T, Marker > // where // T : Clone, // { @@ -114,7 +114,7 @@ where // } // } -impl< 'a, T > From< T > for MaybeAs< 'a, T > +impl< 'a, T, Marker > From< T > for MaybeAs< 'a, T, Marker > where T : Clone, { @@ -124,7 +124,7 @@ where } } -impl< 'a, T > From< &'a T > for MaybeAs< 'a, T > +impl< 'a, T, Marker > From< &'a T > for MaybeAs< 'a, T, Marker > where T : Clone, { @@ -134,7 +134,7 @@ where } } -// impl< 'a, T > From< () > for MaybeAs< 'a, T > +// impl< 'a, T, Marker > From< () > for MaybeAs< 'a, T, Marker > // where // T : (), // { @@ -146,17 +146,17 @@ where // xxx : more from -// impl< 'a, T > From< MaybeAs< 'a, T > > for &'a T +// impl< 'a, T, Marker > From< MaybeAs< 'a, T, Marker > > for &'a T // where // T : Clone, // { -// fn from( wrapper : MaybeAs< 'a, T > ) -> &'a T +// fn from( wrapper : MaybeAs< 'a, T, Marker > ) -> &'a T // { // wrapper.0 // } // } -impl< 'a, T > Default for MaybeAs< 'a, T > +impl< 'a, T, Marker > Default for MaybeAs< 'a, T, Marker > where T : Clone, T : Default, @@ -167,7 +167,7 @@ where } } -impl< 'a, T > fmt::Debug for MaybeAs< 'a, T > +impl< 'a, T, Marker > fmt::Debug for MaybeAs< 'a, T, Marker > where T : fmt::Debug, T : Clone, diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index ecde2b2cd4..fa3ab63196 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -25,7 +25,8 @@ pub struct TestObject pub tools : Option< Vec< HashMap< String, String > > >, } -impl< 'a > Fields< 'a, &'static str, String > for TestObject +impl< 'a > Fields< 'a, &'static str, String > +for TestObject { fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, String > > ) > { @@ -63,22 +64,22 @@ where } } -// pub type Wrap< 'a, T : DebugToString< 'a > > = MaybeAs< 'a, T >; - // impl< 'a, V > Fields< 'a, &'static str, V > // for TestObject +// where +// V : DebugToString< 'a > + Clone + 'a, // { // fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, V > > ) > // { // let mut vec : Vec< ( &'static str, Option< Cow< 'a, V > > ) > = Vec::new(); // -// vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ); -// vec.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); -// vec.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); +// vec.push( ( "id", Some( self.id.debug_to_string() ) ) ); +// vec.push( ( "created_at", Some( self.created_at.debug_to_string() ) ) ); +// vec.push( ( "file_ids", Some( self.file_ids.debug_to_string() ) ) ); // // if let Some( tools ) = &self.tools // { -// vec.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ) ) ); +// vec.push( ( "tools", Some( self.tools.debug_to_string() ) ) ); // } // else // { From fa446b9579cd0fae28b1d32c91ec4543e3293c90 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 09:56:20 +0300 Subject: [PATCH 062/143] reflect: MaybeAs experimenting --- .../assistant/src/wrapper_option_cow_ref.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/module/move/assistant/src/wrapper_option_cow_ref.rs b/module/move/assistant/src/wrapper_option_cow_ref.rs index 677e0802e5..afc0a4ee6d 100644 --- a/module/move/assistant/src/wrapper_option_cow_ref.rs +++ b/module/move/assistant/src/wrapper_option_cow_ref.rs @@ -114,23 +114,25 @@ where // } // } -impl< 'a, T, Marker > From< T > for MaybeAs< 'a, T, Marker > +impl< 'a, T, Marker > From< T > +for MaybeAs< 'a, T, Marker > where T : Clone, { - fn from( table : T ) -> Self + fn from( src : T ) -> Self { - MaybeAs( Some( Cow::Owned( table ) ) ) + MaybeAs::new( src ) } } -impl< 'a, T, Marker > From< &'a T > for MaybeAs< 'a, T, Marker > +impl< 'a, T, Marker > From< &'a T > +for MaybeAs< 'a, T, Marker > where T : Clone, { - fn from( table : &'a T ) -> Self + fn from( src : &'a T ) -> Self { - MaybeAs( Some( Cow::Borrowed( table ) ) ) + MaybeAs::new_with_ref( src ) } } @@ -138,7 +140,7 @@ where // where // T : (), // { -// fn from( table : &'a T ) -> Self +// fn from( src : &'a T ) -> Self // { // MaybeAs( None ) // } @@ -163,7 +165,7 @@ where { fn default() -> Self { - MaybeAs( Some( Cow::Owned( T::default() ) ) ) + MaybeAs::new( T::default() ) } } From ed5a008286e032cc306c0670a78baec23c69d76c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 10:44:58 +0300 Subject: [PATCH 063/143] reflect: MaybeAs experimenting --- module/move/assistant/src/reflect.rs | 17 ++++++++++++++- module/move/assistant/src/table.rs | 5 +++-- .../move/assistant/tests/inc/fields_test.rs | 16 +++++++------- module/move/assistant/tests/inc/print_test.rs | 21 ++++++++++--------- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/module/move/assistant/src/reflect.rs b/module/move/assistant/src/reflect.rs index b3d2370eb8..26291bb04b 100644 --- a/module/move/assistant/src/reflect.rs +++ b/module/move/assistant/src/reflect.rs @@ -39,7 +39,8 @@ where E : Clone + 'a, { /// Returns an iterator over all fields of the specified type within the entity. - fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, Option< Cow< 'a, E > > ) >; + fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, E ) >; + // fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, Option< Cow< 'a, E > > ) >; } // /// Return number of fields convertible into a specified type withing an entity. @@ -71,3 +72,17 @@ where ::core::any::type_name_of_val( self ) } } + +// == implementations for collections + +impl< 'a, T > Fields< 'a, usize, Option< Cow< 'a, T > > > for Vec< T > +where + T : Clone +{ + fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Option< Cow< 'a, T > > ) > + { + self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) + } +} + +// == \ No newline at end of file diff --git a/module/move/assistant/src/table.rs b/module/move/assistant/src/table.rs index a0bfeeacc9..62a0e4e5ac 100644 --- a/module/move/assistant/src/table.rs +++ b/module/move/assistant/src/table.rs @@ -1,6 +1,7 @@ use super::*; use core::fmt; +use std::borrow::Cow; // == @@ -71,7 +72,7 @@ where impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableRows< 'a, RowKey, Row, CellKey, Cell > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > where - T : Fields< 'a, RowKey, Row >, + T : Fields< 'a, RowKey, Option< Cow< 'a, Row > > >, Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, Title : fmt::Debug, Cell : fmt::Debug + Clone + 'a, @@ -128,7 +129,7 @@ where impl< 'a, Row, CellKey, Cell > Cells< 'a, CellKey, Cell > for Row where - Row : Fields< 'a, CellKey, Cell > + 'a, + Row : Fields< 'a, CellKey, Option< Cow< 'a, Cell > > > + 'a, Cell : fmt::Debug + Clone + 'a, { diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index fa3ab63196..e7256b7727 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -25,7 +25,7 @@ pub struct TestObject pub tools : Option< Vec< HashMap< String, String > > >, } -impl< 'a > Fields< 'a, &'static str, String > +impl< 'a > Fields< 'a, &'static str, Option< Cow< 'a, String > > > for TestObject { fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, String > > ) > @@ -90,13 +90,13 @@ where // } // } -impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > -{ - fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Option< Cow< 'a, TestObject > > ) > - { - self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) - } -} +// impl< 'a > Fields< 'a, usize, Option< Cow< 'a, TestObject > > > for Vec< TestObject > +// { +// fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Option< Cow< 'a, TestObject > > ) > +// { +// self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) +// } +// } // diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index b9988a6c25..4436e928a2 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -30,7 +30,8 @@ pub struct TestObject pub tools : Option< Vec< HashMap< String, String > > >, } -impl< 'a > Fields< 'a, &'static str, String > for TestObject +impl< 'a > Fields< 'a, &'static str, Option< Cow< 'a, String > > > +for TestObject { fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, String > > ) > { @@ -53,20 +54,20 @@ impl< 'a > Fields< 'a, &'static str, String > for TestObject } } -impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > -{ - fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Option< Cow< 'a, TestObject > > ) > - { - self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) - } -} +// impl< 'a > Fields< 'a, usize, TestObject > for Vec< TestObject > +// { +// fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Option< Cow< 'a, TestObject > > ) > +// { +// self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) +// } +// } // #[ test ] fn test_table_to_string() -where - for< 'a > AsTable< 'a, Vec< TestObject >, usize, TestObject, &'static str, String, &'static str > : TableFormatter< 'a >, +// where + // for< 'a > AsTable< 'a, Vec< TestObject >, usize, TestObject, &'static str, String, &'static str > : TableFormatter< 'a >, { use the_module::TableToString; From 1fb0287bb7b72aacdaceafe757b195a9561b7a09 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 10:48:02 +0300 Subject: [PATCH 064/143] reflect: MaybeAs experimenting --- module/move/assistant/tests/inc/fields_test.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index e7256b7727..3d9d7c41c1 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -49,22 +49,24 @@ for TestObject } } +pub struct StringFromDebug; + pub trait DebugToString< 'a > { - fn debug_to_string( &'a self ) -> Cow< 'a, String >; + fn debug_to_string( &'a self ) -> MaybeAs< 'a, String, StringFromDebug >; } impl< 'a, T > DebugToString< 'a > for T where T : fmt::Debug, { - fn debug_to_string( &'a self ) -> Cow< 'a, String > + fn debug_to_string( &'a self ) -> MaybeAs< 'a, String, StringFromDebug > { - Cow::Owned( format!( "{:?}", self ) ) + MaybeAs::from( format!( "{:?}", self ) ) } } -// impl< 'a, V > Fields< 'a, &'static str, V > +// impl< 'a, V > Fields< 'a, &'static str, Option< Cow< 'a, V > > > // for TestObject // where // V : DebugToString< 'a > + Clone + 'a, From cfb3a7ef1034787fc87730b0c73e0642e0f764af Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 11:08:04 +0300 Subject: [PATCH 065/143] reflect: MaybeAs experimenting --- .../assistant/src/wrapper_option_cow_ref.rs | 7 +++ .../move/assistant/tests/inc/fields_test.rs | 61 ++++++++++--------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/module/move/assistant/src/wrapper_option_cow_ref.rs b/module/move/assistant/src/wrapper_option_cow_ref.rs index afc0a4ee6d..c59cc5dcc0 100644 --- a/module/move/assistant/src/wrapper_option_cow_ref.rs +++ b/module/move/assistant/src/wrapper_option_cow_ref.rs @@ -58,6 +58,13 @@ where T : Clone, { + /// Just a constructor. + #[ inline( always ) ] + pub fn none() -> Self + { + Self( None, ::core::marker::PhantomData ) + } + /// Just a constructor. #[ inline( always ) ] pub fn new( src : T ) -> Self diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 3d9d7c41c1..7f34c064c8 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -49,57 +49,61 @@ for TestObject } } -pub struct StringFromDebug; +// = -pub trait DebugToString< 'a > +#[ derive( Debug, Default, Clone, Copy ) ] +pub struct WithDebug; + +#[ derive( Debug, Default, Clone, Copy ) ] +pub struct WithDisplay; + +#[ derive( Debug, Default, Clone, Copy ) ] +pub struct WithWell; + +pub trait ToStringWith< 'a, How > { - fn debug_to_string( &'a self ) -> MaybeAs< 'a, String, StringFromDebug >; + // fn debug_to_string( &'a self ) -> MaybeAs< 'a, String, StringFromDebug >; + fn to_string_with( &'a self ) -> String; } -impl< 'a, T > DebugToString< 'a > for T +impl< 'a, T > ToStringWith< 'a, WithDebug > for T where T : fmt::Debug, { - fn debug_to_string( &'a self ) -> MaybeAs< 'a, String, StringFromDebug > + // fn to_string_with( &'a self ) -> MaybeAs< 'a, String, StringFromDebug > + fn to_string_with( &'a self ) -> String { - MaybeAs::from( format!( "{:?}", self ) ) + format!( "{:?}", self ) + // MaybeAs::from( format!( "{:?}", self ) ) } } -// impl< 'a, V > Fields< 'a, &'static str, Option< Cow< 'a, V > > > +// impl< 'a > Fields< 'a, &'static str, MaybeAs< 'a, String, StringFromDebug > > // for TestObject -// where -// V : DebugToString< 'a > + Clone + 'a, +// // where +// // V : ToStringWith< 'a > + Clone + 'a, // { -// fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, V > > ) > +// fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, StringFromDebug > ) > // { -// let mut vec : Vec< ( &'static str, Option< Cow< 'a, V > > ) > = Vec::new(); +// let mut vec : Vec< ( &'static str, MaybeAs< 'a, String, StringFromDebug > ) > = Vec::new(); // -// vec.push( ( "id", Some( self.id.debug_to_string() ) ) ); -// vec.push( ( "created_at", Some( self.created_at.debug_to_string() ) ) ); -// vec.push( ( "file_ids", Some( self.file_ids.debug_to_string() ) ) ); +// vec.push( ( "id", self.id.debug_to_string() ) ); +// vec.push( ( "created_at", self.created_at.debug_to_string() ) ); +// vec.push( ( "file_ids", self.file_ids.debug_to_string() ) ); // // if let Some( tools ) = &self.tools // { -// vec.push( ( "tools", Some( self.tools.debug_to_string() ) ) ); +// vec.push( ( "tools", self.tools.debug_to_string() ) ); // } // else // { -// vec.push( ( "tools", None ) ); +// vec.push( ( "tools", MaybeAs::none() ) ); // } // // vec.into_iter() // } // } -// impl< 'a > Fields< 'a, usize, Option< Cow< 'a, TestObject > > > for Vec< TestObject > -// { -// fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Option< Cow< 'a, TestObject > > ) > -// { -// self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) -// } -// } - // fn is_borrowed< 'a, T : Clone >( src : &Option< Cow< 'a, T > > ) -> bool @@ -140,10 +144,11 @@ fn basic() let fields: Vec< _ > = test_object.fields().collect(); assert_eq!( fields.len(), 4 ); - 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!( is_borrowed( &fields[ 0 ].1 ) ); + // assert!( !is_borrowed( &fields[ 1 ].1 ) ); + // assert!( !is_borrowed( &fields[ 2 ].1 ) ); + // assert!( !is_borrowed( &fields[ 3 ].1 ) ); + // xxx assert_eq!( fields[ 0 ], ( "id", Some( Cow::Borrowed( &"12345".to_string() ) ) ) ); assert_eq!( fields[ 1 ], ( "created_at", Some( Cow::Owned( "1627845583".to_string() ) ) ) ); assert_eq!( fields[ 2 ], ( "file_ids", Some( Cow::Owned( "[\"file1\", \"file2\"]".to_string() ) ) ) ); From 488ed7c7ed7d2e58978b4211bd2b8eda1e90112f Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 11:16:10 +0300 Subject: [PATCH 066/143] reflect: MaybeAs experimenting --- .../move/assistant/tests/inc/fields_test.rs | 108 +++++++++--------- 1 file changed, 57 insertions(+), 51 deletions(-) diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 7f34c064c8..674d8fd321 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -25,29 +25,29 @@ pub struct TestObject pub tools : Option< Vec< HashMap< String, String > > >, } -impl< 'a > Fields< 'a, &'static str, Option< Cow< 'a, String > > > -for TestObject -{ - fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, String > > ) > - { - let mut vec : Vec< ( &'static str, Option< Cow< 'a, String > > ) > = Vec::new(); - - vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ); - vec.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); - vec.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); - - if let Some( tools ) = &self.tools - { - vec.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ) ) ); - } - else - { - vec.push( ( "tools", None ) ); - } - - vec.into_iter() - } -} +// impl< 'a > Fields< 'a, &'static str, Option< Cow< 'a, String > > > +// for TestObject +// { +// fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, String > > ) > +// { +// let mut vec : Vec< ( &'static str, Option< Cow< 'a, String > > ) > = Vec::new(); +// +// vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ); +// vec.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); +// vec.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); +// +// if let Some( tools ) = &self.tools +// { +// vec.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ) ) ); +// } +// else +// { +// vec.push( ( "tools", None ) ); +// } +// +// vec.into_iter() +// } +// } // = @@ -62,7 +62,7 @@ pub struct WithWell; pub trait ToStringWith< 'a, How > { - // fn debug_to_string( &'a self ) -> MaybeAs< 'a, String, StringFromDebug >; + // fn to_string_with( &'a self ) -> MaybeAs< 'a, String, StringFromDebug >; fn to_string_with( &'a self ) -> String; } @@ -79,30 +79,36 @@ where } // impl< 'a > Fields< 'a, &'static str, MaybeAs< 'a, String, StringFromDebug > > -// for TestObject -// // where -// // V : ToStringWith< 'a > + Clone + 'a, -// { -// fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, StringFromDebug > ) > -// { -// let mut vec : Vec< ( &'static str, MaybeAs< 'a, String, StringFromDebug > ) > = Vec::new(); -// -// vec.push( ( "id", self.id.debug_to_string() ) ); -// vec.push( ( "created_at", self.created_at.debug_to_string() ) ); -// vec.push( ( "file_ids", self.file_ids.debug_to_string() ) ); -// -// if let Some( tools ) = &self.tools -// { -// vec.push( ( "tools", self.tools.debug_to_string() ) ); -// } -// else -// { -// vec.push( ( "tools", MaybeAs::none() ) ); -// } -// -// vec.into_iter() -// } -// } +impl< 'a, V > Fields< 'a, &'static str, MaybeAs< 'a, V, WithDebug > > +for TestObject +where + V : ToStringWith< 'a, WithDebug > + Clone + 'a, + // MaybeAs< 'a, V, WithDebug > : From< String >, + String : Into< MaybeAs< 'a, V, WithDebug > >, +{ + // fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, StringFromDebug > ) > + fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, V, WithDebug > ) > + { + // let mut vec : Vec< ( &'static str, MaybeAs< 'a, String, StringFromDebug > ) > = Vec::new(); + let mut vec : Vec< ( &'static str, MaybeAs< 'a, V, WithDebug > ) > = Vec::new(); + + // vec.push( ( "id", MaybeAs::< 'a, V, WithDebug >::from( self.id.to_string_with() ) ) ); + vec.push( ( "id", self.id.to_string_with().into() ) ); + vec.push( ( "created_at", self.created_at.to_string_with().into() ) ); + vec.push( ( "file_ids", self.file_ids.to_string_with().into() ) ); + + if let Some( tools ) = &self.tools + { + vec.push( ( "tools", self.tools.to_string_with().into() ) ); + } + else + { + vec.push( ( "tools", MaybeAs::none() ) ); + } + + vec.into_iter() + } +} // @@ -149,9 +155,9 @@ fn basic() // assert!( !is_borrowed( &fields[ 2 ].1 ) ); // assert!( !is_borrowed( &fields[ 3 ].1 ) ); // xxx - assert_eq!( fields[ 0 ], ( "id", Some( Cow::Borrowed( &"12345".to_string() ) ) ) ); - assert_eq!( fields[ 1 ], ( "created_at", Some( Cow::Owned( "1627845583".to_string() ) ) ) ); - assert_eq!( fields[ 2 ], ( "file_ids", Some( Cow::Owned( "[\"file1\", \"file2\"]".to_string() ) ) ) ); + // assert_eq!( fields[ 0 ], ( "id", Some( Cow::Borrowed( &"12345".to_string() ) ).into() ) ); + // assert_eq!( fields[ 1 ], ( "created_at", Some( Cow::Owned( "1627845583".to_string() ) ).into() ) ); + // assert_eq!( fields[ 2 ], ( "file_ids", Some( Cow::Owned( "[\"file1\", \"file2\"]".to_string() ) ).into() ) ); assert_eq!( fields[ 3 ].0, "tools" ); } From cd965825c930c90dca7d38e91a4ffa19ca0f8150 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 11:31:06 +0300 Subject: [PATCH 067/143] reflect: MaybeAs experimenting --- .../assistant/src/wrapper_option_cow_ref.rs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/module/move/assistant/src/wrapper_option_cow_ref.rs b/module/move/assistant/src/wrapper_option_cow_ref.rs index c59cc5dcc0..0a1d7a0ff5 100644 --- a/module/move/assistant/src/wrapper_option_cow_ref.rs +++ b/module/move/assistant/src/wrapper_option_cow_ref.rs @@ -79,6 +79,13 @@ where Self( Some( Cow::Borrowed( src ) ), ::core::marker::PhantomData ) } + /// Just a constructor. + #[ inline( always ) ] + pub fn new_with_inner( src : Option< Cow< 'a, T > > ) -> Self + { + Self( src, ::core::marker::PhantomData ) + } + /// Just a constructor. #[ inline( always ) ] pub fn inner( self ) -> Option< Cow< 'a, T > > @@ -88,6 +95,29 @@ where } +impl< 'a, T, Marker > AsRef< Option< Cow< 'a, T > > > for MaybeAs< 'a, T, Marker > +where + T : Clone, + Self : 'a, +{ + fn as_ref( &self ) -> &Option< Cow< 'a, T > > + { + &self.0 + } +} + +impl< 'a, T, Marker > Deref for MaybeAs< 'a, T, Marker > +where + T : Clone, + Marker : 'static, +{ + type Target = Option< Cow< 'a, T > >; + fn deref( &self ) -> &Option< Cow< 'a, T > > + { + self.as_ref() + } +} + // impl< 'a, T, Marker > AsRef< T > for MaybeAs< 'a, T, Marker > // where // T : Clone, @@ -132,6 +162,17 @@ where } } +impl< 'a, T, Marker > From< Option< Cow< 'a, T > > > +for MaybeAs< 'a, T, Marker > +where + T : Clone, +{ + fn from( src : Option< Cow< 'a, T > > ) -> Self + { + MaybeAs::new_with_inner( src ) + } +} + impl< 'a, T, Marker > From< &'a T > for MaybeAs< 'a, T, Marker > where @@ -188,3 +229,19 @@ where .finish() } } + +impl< 'a, T, Marker > PartialEq for MaybeAs< 'a, T, Marker > +where + T : Clone + PartialEq, +{ + fn eq( &self, other : &Self ) -> bool + { + self.as_ref() == other.as_ref() + } +} + +impl< 'a, T, Marker > Eq for MaybeAs< 'a, T, Marker > +where + T : Clone + Eq, +{ +} From 2ef3d1d900dd9e7154c5ed0f423063568956dbf9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 11:44:35 +0300 Subject: [PATCH 068/143] reflect: MaybeAs experimenting --- module/move/assistant/tests/inc/fields_test.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 674d8fd321..345dbecf0e 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -155,9 +155,9 @@ fn basic() // assert!( !is_borrowed( &fields[ 2 ].1 ) ); // assert!( !is_borrowed( &fields[ 3 ].1 ) ); // xxx - // assert_eq!( fields[ 0 ], ( "id", Some( Cow::Borrowed( &"12345".to_string() ) ).into() ) ); - // assert_eq!( fields[ 1 ], ( "created_at", Some( Cow::Owned( "1627845583".to_string() ) ).into() ) ); - // assert_eq!( fields[ 2 ], ( "file_ids", Some( Cow::Owned( "[\"file1\", \"file2\"]".to_string() ) ).into() ) ); + assert_eq!( fields[ 0 ], ( "id", Some( Cow::Borrowed( &"\"12345\"".to_string() ) ).into() ) ); + assert_eq!( fields[ 1 ], ( "created_at", Some( Cow::Owned( "1627845583".to_string() ) ).into() ) ); + assert_eq!( fields[ 2 ], ( "file_ids", Some( Cow::Owned( "[\"file1\", \"file2\"]".to_string() ) ).into() ) ); assert_eq!( fields[ 3 ].0, "tools" ); } From 49eccdac298c66b748dee36a5a6af4aa3a734331 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 13:41:14 +0300 Subject: [PATCH 069/143] reflect: MaybeAs experimenting --- .../move/assistant/tests/inc/fields_test.rs | 62 +++++++++++++------ 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 345dbecf0e..678f3a5e5b 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -78,33 +78,55 @@ where } } +impl< 'a, T > ToStringWith< 'a, WithDisplay > for T +where + T : fmt::Display, +{ + fn to_string_with( &'a self ) -> String + { + format!( "{}", self ) + } +} + // impl< 'a > Fields< 'a, &'static str, MaybeAs< 'a, String, StringFromDebug > > -impl< 'a, V > Fields< 'a, &'static str, MaybeAs< 'a, V, WithDebug > > +impl< 'a, V, How > Fields< 'a, &'static str, MaybeAs< 'a, V, How > > for TestObject where - V : ToStringWith< 'a, WithDebug > + Clone + 'a, + V : ToStringWith< 'a, How > + Clone + 'a, // MaybeAs< 'a, V, WithDebug > : From< String >, - String : Into< MaybeAs< 'a, V, WithDebug > >, + // String : Into< MaybeAs< 'a, V, How > >, + MaybeAs< 'a, V, How > : From< String >, + How : Clone + Copy + 'static, + String : ToStringWith< 'a, How >, { // fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, StringFromDebug > ) > - fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, V, WithDebug > ) > + fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, V, How > ) > { // let mut vec : Vec< ( &'static str, MaybeAs< 'a, String, StringFromDebug > ) > = Vec::new(); - let mut vec : Vec< ( &'static str, MaybeAs< 'a, V, WithDebug > ) > = Vec::new(); - - // vec.push( ( "id", MaybeAs::< 'a, V, WithDebug >::from( self.id.to_string_with() ) ) ); - vec.push( ( "id", self.id.to_string_with().into() ) ); - vec.push( ( "created_at", self.created_at.to_string_with().into() ) ); - vec.push( ( "file_ids", self.file_ids.to_string_with().into() ) ); - - if let Some( tools ) = &self.tools - { - vec.push( ( "tools", self.tools.to_string_with().into() ) ); - } - else - { - vec.push( ( "tools", MaybeAs::none() ) ); - } + let mut vec : Vec< ( &'static str, MaybeAs< 'a, V, How > ) > = Vec::new(); + + // fn into< 'a, V, How >( src : &'a V ) -> MaybeAs< 'a, V, How > + // where + // V : ToStringWith< 'a, How > + Clone + 'a, + // How : Clone + Copy + 'static, + // String : Into< MaybeAs< 'a, V, How > >, + // { + // ToStringWith::< '_, How >::to_string_with( src ).into() + // } + + vec.push( ( "id", MaybeAs::< 'a, V, How >::from( < String as ToStringWith< '_, How > >::to_string_with( &self.id ) ) ) ); +// vec.push( ( "id", into( &self.id ) ) ); +// vec.push( ( "created_at", self.created_at.to_string_with().into() ) ); +// vec.push( ( "file_ids", self.file_ids.to_string_with().into() ) ); +// +// if let Some( tools ) = &self.tools +// { +// vec.push( ( "tools", self.tools.to_string_with().into() ) ); +// } +// else +// { +// vec.push( ( "tools", MaybeAs::none() ) ); +// } vec.into_iter() } @@ -147,7 +169,7 @@ fn basic() ), }; - let fields: Vec< _ > = test_object.fields().collect(); + let fields : Vec< ( &str, MaybeAs< '_, String, WithDebug > ) > = test_object.fields().collect(); assert_eq!( fields.len(), 4 ); // assert!( is_borrowed( &fields[ 0 ].1 ) ); From 2cfb436725d5a3d77f4133a1dbab2efdf27bac41 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 13:43:28 +0300 Subject: [PATCH 070/143] reflect: MaybeAs experimenting --- module/move/assistant/tests/inc/fields_test.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 678f3a5e5b..641221e9a8 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -89,32 +89,32 @@ where } // impl< 'a > Fields< 'a, &'static str, MaybeAs< 'a, String, StringFromDebug > > -impl< 'a, V, How > Fields< 'a, &'static str, MaybeAs< 'a, V, How > > +impl< 'a, How > Fields< 'a, &'static str, MaybeAs< 'a, String, How > > for TestObject where - V : ToStringWith< 'a, How > + Clone + 'a, + // V : ToStringWith< 'a, How > + Clone + 'a, // MaybeAs< 'a, V, WithDebug > : From< String >, // String : Into< MaybeAs< 'a, V, How > >, - MaybeAs< 'a, V, How > : From< String >, + MaybeAs< 'a, String, How > : From< String >, How : Clone + Copy + 'static, String : ToStringWith< 'a, How >, { // fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, StringFromDebug > ) > - fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, V, How > ) > + fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, How > ) > { // let mut vec : Vec< ( &'static str, MaybeAs< 'a, String, StringFromDebug > ) > = Vec::new(); - let mut vec : Vec< ( &'static str, MaybeAs< 'a, V, How > ) > = Vec::new(); + let mut vec : Vec< ( &'static str, MaybeAs< 'a, String, How > ) > = Vec::new(); - // fn into< 'a, V, How >( src : &'a V ) -> MaybeAs< 'a, V, How > + // fn into< 'a, String, How >( src : &'a String ) -> MaybeAs< 'a, String, How > // where - // V : ToStringWith< 'a, How > + Clone + 'a, + // String : ToStringWith< 'a, How > + Clone + 'a, // How : Clone + Copy + 'static, - // String : Into< MaybeAs< 'a, V, How > >, + // String : Into< MaybeAs< 'a, String, How > >, // { // ToStringWith::< '_, How >::to_string_with( src ).into() // } - vec.push( ( "id", MaybeAs::< 'a, V, How >::from( < String as ToStringWith< '_, How > >::to_string_with( &self.id ) ) ) ); + vec.push( ( "id", MaybeAs::< 'a, String, How >::from( < String as ToStringWith< '_, How > >::to_string_with( &self.id ) ) ) ); // vec.push( ( "id", into( &self.id ) ) ); // vec.push( ( "created_at", self.created_at.to_string_with().into() ) ); // vec.push( ( "file_ids", self.file_ids.to_string_with().into() ) ); From cce6bf4b3f74098d1a03688a17381fa220df2761 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 13:52:38 +0300 Subject: [PATCH 071/143] reflect: MaybeAs experimenting --- .../move/assistant/tests/inc/fields_test.rs | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 641221e9a8..34ec21353f 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -95,7 +95,7 @@ where // V : ToStringWith< 'a, How > + Clone + 'a, // MaybeAs< 'a, V, WithDebug > : From< String >, // String : Into< MaybeAs< 'a, V, How > >, - MaybeAs< 'a, String, How > : From< String >, + // MaybeAs< 'a, String, How > : From< String >, How : Clone + Copy + 'static, String : ToStringWith< 'a, How >, { @@ -105,17 +105,28 @@ where // let mut vec : Vec< ( &'static str, MaybeAs< 'a, String, StringFromDebug > ) > = Vec::new(); let mut vec : Vec< ( &'static str, MaybeAs< 'a, String, How > ) > = Vec::new(); - // fn into< 'a, String, How >( src : &'a String ) -> MaybeAs< 'a, String, How > - // where - // String : ToStringWith< 'a, How > + Clone + 'a, - // How : Clone + Copy + 'static, - // String : Into< MaybeAs< 'a, String, How > >, - // { - // ToStringWith::< '_, How >::to_string_with( src ).into() - // } - - vec.push( ( "id", MaybeAs::< 'a, String, How >::from( < String as ToStringWith< '_, How > >::to_string_with( &self.id ) ) ) ); -// vec.push( ( "id", into( &self.id ) ) ); + fn into< 'a, V, How >( src : &'a V ) -> MaybeAs< 'a, String, How > + where + + V : ToStringWith< 'a, How > + 'a, + // How : Clone + Copy + 'static, + // // String : Into< MaybeAs< 'a, V, How > >, + // String : ToStringWith< 'a, How >, + + // MaybeAs< 'a, String, How > : From< String >, + How : Clone + Copy + 'static, + V : ToStringWith< 'a, How >, + + { + MaybeAs::< 'a, String, How >::from + ( + < V as ToStringWith< '_, How > >::to_string_with( src ) + ) + // ToStringWith::< '_, How >::to_string_with( src ).into() + } + + // vec.push( ( "id", MaybeAs::< 'a, String, How >::from( < String as ToStringWith< '_, How > >::to_string_with( &self.id ) ) ) ); + vec.push( ( "id", into( &self.id ) ) ); // vec.push( ( "created_at", self.created_at.to_string_with().into() ) ); // vec.push( ( "file_ids", self.file_ids.to_string_with().into() ) ); // From e1eb45ba909a3e551e62fc5559f592943a705571 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 14:02:42 +0300 Subject: [PATCH 072/143] reflect: MaybeAs experimenting --- .../move/assistant/tests/inc/fields_test.rs | 65 ++++++++++++++----- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 34ec21353f..e518b01713 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -88,45 +88,74 @@ where } } -// impl< 'a > Fields< 'a, &'static str, MaybeAs< 'a, String, StringFromDebug > > impl< 'a, How > Fields< 'a, &'static str, MaybeAs< 'a, String, How > > for TestObject where - // V : ToStringWith< 'a, How > + Clone + 'a, - // MaybeAs< 'a, V, WithDebug > : From< String >, - // String : Into< MaybeAs< 'a, V, How > >, - // MaybeAs< 'a, String, How > : From< String >, How : Clone + Copy + 'static, String : ToStringWith< 'a, How >, + i64 : ToStringWith< 'a, How >, + Vec< String > : ToStringWith< 'a, How >, + Option< Vec< HashMap< String, String > > > : ToStringWith< 'a, How >, { - // fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, StringFromDebug > ) > fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, How > ) > { - // let mut vec : Vec< ( &'static str, MaybeAs< 'a, String, StringFromDebug > ) > = Vec::new(); let mut vec : Vec< ( &'static str, MaybeAs< 'a, String, How > ) > = Vec::new(); fn into< 'a, V, How >( src : &'a V ) -> MaybeAs< 'a, String, How > where - - V : ToStringWith< 'a, How > + 'a, - // How : Clone + Copy + 'static, - // // String : Into< MaybeAs< 'a, V, How > >, - // String : ToStringWith< 'a, How >, - - // MaybeAs< 'a, String, How > : From< String >, How : Clone + Copy + 'static, - V : ToStringWith< 'a, How >, - + V : ToStringWith< 'a, How > + 'a, { MaybeAs::< 'a, String, How >::from ( < V as ToStringWith< '_, How > >::to_string_with( src ) ) - // ToStringWith::< '_, How >::to_string_with( src ).into() } + fn add< 'a, V, How > + ( + dst : &mut Vec< ( &'static str, MaybeAs< 'a, String, How > ) >, + key : &'static str, + src : &'a V + ) + where + How : Clone + Copy + 'static, + V : ToStringWith< 'a, How > + 'a, + { + let val = MaybeAs::< 'a, String, How >::from + ( + < V as ToStringWith< '_, How > >::to_string_with( src ) + ); + dst.push( ( key, val ) ); + } + + add( &mut vec, "id", &self.id ); + add( &mut vec, "created_at", &self.created_at ); + add( &mut vec, "file_ids", &self.file_ids ); + + if let Some( tools ) = &self.tools + { + add( &mut vec, "tools", &self.tools ); + } + else + { + vec.push( ( "tools", MaybeAs::none() ) ); + } + +// vec.push( ( "id", into( &self.id ) ) ); +// vec.push( ( "created_at", into( &self.created_at ) ) ); +// vec.push( ( "file_ids", into( &self.file_ids ) ) ); +// +// if let Some( tools ) = &self.tools +// { +// vec.push( ( "tools", into( &self.tools ) ) ); +// } +// else +// { +// vec.push( ( "tools", MaybeAs::none() ) ); +// } + // vec.push( ( "id", MaybeAs::< 'a, String, How >::from( < String as ToStringWith< '_, How > >::to_string_with( &self.id ) ) ) ); - vec.push( ( "id", into( &self.id ) ) ); // vec.push( ( "created_at", self.created_at.to_string_with().into() ) ); // vec.push( ( "file_ids", self.file_ids.to_string_with().into() ) ); // From 6cb26204b294fc1e87e831e5f5efaf3ad483859d Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 14:57:57 +0300 Subject: [PATCH 073/143] reflect: MaybeAs experimenting --- .../move/assistant/tests/inc/fields_test.rs | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index e518b01713..1243347ade 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -30,22 +30,22 @@ pub struct TestObject // { // fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, String > > ) > // { -// let mut vec : Vec< ( &'static str, Option< Cow< 'a, String > > ) > = Vec::new(); +// let mut dst : Vec< ( &'static str, Option< Cow< 'a, String > > ) > = Vec::new(); // -// vec.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ); -// vec.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); -// vec.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); +// dst.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ); +// dst.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); +// dst.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); // // if let Some( tools ) = &self.tools // { -// vec.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ) ) ); +// dst.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ) ) ); // } // else // { -// vec.push( ( "tools", None ) ); +// dst.push( ( "tools", None ) ); // } // -// vec.into_iter() +// dst.into_iter() // } // } @@ -99,7 +99,7 @@ where { fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, How > ) > { - let mut vec : Vec< ( &'static str, MaybeAs< 'a, String, How > ) > = Vec::new(); + let mut dst : Vec< ( &'static str, MaybeAs< 'a, String, How > ) > = Vec::new(); fn into< 'a, V, How >( src : &'a V ) -> MaybeAs< 'a, String, How > where @@ -129,46 +129,47 @@ where dst.push( ( key, val ) ); } - add( &mut vec, "id", &self.id ); - add( &mut vec, "created_at", &self.created_at ); - add( &mut vec, "file_ids", &self.file_ids ); + // dst.push( ( "id", MaybeAs::< 'a, String, How >::from( &self.id ) ) ); + add( &mut dst, "id", &self.id ); + add( &mut dst, "created_at", &self.created_at ); + add( &mut dst, "file_ids", &self.file_ids ); if let Some( tools ) = &self.tools { - add( &mut vec, "tools", &self.tools ); + add( &mut dst, "tools", &self.tools ); } else { - vec.push( ( "tools", MaybeAs::none() ) ); + dst.push( ( "tools", MaybeAs::none() ) ); } -// vec.push( ( "id", into( &self.id ) ) ); -// vec.push( ( "created_at", into( &self.created_at ) ) ); -// vec.push( ( "file_ids", into( &self.file_ids ) ) ); +// dst.push( ( "id", into( &self.id ) ) ); +// dst.push( ( "created_at", into( &self.created_at ) ) ); +// dst.push( ( "file_ids", into( &self.file_ids ) ) ); // // if let Some( tools ) = &self.tools // { -// vec.push( ( "tools", into( &self.tools ) ) ); +// dst.push( ( "tools", into( &self.tools ) ) ); // } // else // { -// vec.push( ( "tools", MaybeAs::none() ) ); +// dst.push( ( "tools", MaybeAs::none() ) ); // } - // vec.push( ( "id", MaybeAs::< 'a, String, How >::from( < String as ToStringWith< '_, How > >::to_string_with( &self.id ) ) ) ); -// vec.push( ( "created_at", self.created_at.to_string_with().into() ) ); -// vec.push( ( "file_ids", self.file_ids.to_string_with().into() ) ); + // dst.push( ( "id", MaybeAs::< 'a, String, How >::from( < String as ToStringWith< '_, How > >::to_string_with( &self.id ) ) ) ); +// dst.push( ( "created_at", self.created_at.to_string_with().into() ) ); +// dst.push( ( "file_ids", self.file_ids.to_string_with().into() ) ); // // if let Some( tools ) = &self.tools // { -// vec.push( ( "tools", self.tools.to_string_with().into() ) ); +// dst.push( ( "tools", self.tools.to_string_with().into() ) ); // } // else // { -// vec.push( ( "tools", MaybeAs::none() ) ); +// dst.push( ( "tools", MaybeAs::none() ) ); // } - vec.into_iter() + dst.into_iter() } } From 47b4b470fe4a1ef4e09891613413455060c65f67 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 15:05:10 +0300 Subject: [PATCH 074/143] reflect: MaybeAs experimenting --- .../tests/inc/former_tests/parametrized_slice_manual.rs | 4 ++-- module/move/assistant/tests/inc/fields_test.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/parametrized_slice_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_slice_manual.rs index 6b9632f366..25e943e2b5 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_slice_manual.rs @@ -128,14 +128,14 @@ impl< 'a > former::StoragePreform for Struct1FormerStorage< 'a > } } - impl< T > MaybeDefault< T > for & ::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > where T : ::core::default::Default, { fn maybe_default( self : & Self ) -> T { T::default() } } - (& ::core::marker::PhantomData::< &'a str >).maybe_default() + ( &::core::marker::PhantomData::< &'a str > ).maybe_default() } }; let result = Struct1 { string_slice_1, }; diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 1243347ade..ce62640121 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -88,6 +88,14 @@ where } } +// impl< 'a > ToStringWith< 'a, WithDisplay > for String +// { +// fn to_string_with( &'a self ) -> String +// { +// format!( "String : {}", self ) +// } +// } + impl< 'a, How > Fields< 'a, &'static str, MaybeAs< 'a, String, How > > for TestObject where From a3871b4e18196ef997b74e00b772d6e8d5898dba Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 15:13:54 +0300 Subject: [PATCH 075/143] reflect: ToStringWithFallback --- .../former_tests/parametrized_slice_manual.rs | 4 +-- .../move/assistant/tests/inc/fields_test.rs | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/parametrized_slice_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_slice_manual.rs index 25e943e2b5..e0195c4433 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_slice_manual.rs @@ -122,7 +122,7 @@ impl< 'a > former::StoragePreform for Struct1FormerStorage< 'a > { trait MaybeDefault< T > { - fn maybe_default( self : & Self ) -> T + fn maybe_default( self : &Self ) -> T { panic!( "Field 'string_slice_1' isn't initialized" ) } @@ -132,7 +132,7 @@ impl< 'a > former::StoragePreform for Struct1FormerStorage< 'a > impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > where T : ::core::default::Default, { - fn maybe_default( self : & Self ) -> T { T::default() } + fn maybe_default( self : &Self ) -> T { T::default() } } ( &::core::marker::PhantomData::< &'a str > ).maybe_default() diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index ce62640121..f8d02b8ece 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -60,6 +60,31 @@ pub struct WithDisplay; #[ derive( Debug, Default, Clone, Copy ) ] pub struct WithWell; +pub trait ToStringWithFallback< 'a, How, Fallback > +{ + fn to_string_with_fallback( &'a self ) -> String; +} + +impl< 'a, T, How, Fallback > ToStringWithFallback< 'a, How, Fallback > for ( &T, ) +where + T : ToStringWith< 'a, How >, +{ + fn to_string_with_fallback( &'a self ) -> String + { + < T as ToStringWith< 'a, How > >::to_string_with( self.0 ) + } +} + +impl< 'a, T, How, Fallback > ToStringWithFallback< 'a, How, Fallback > for &( &T, ) +where + T : ToStringWith< 'a, Fallback >, +{ + fn to_string_with_fallback( &'a self ) -> String + { + < T as ToStringWith< 'a, Fallback > >::to_string_with( self.0 ) + } +} + pub trait ToStringWith< 'a, How > { // fn to_string_with( &'a self ) -> MaybeAs< 'a, String, StringFromDebug >; From 3a9eefe86154a0f5c1fffa014180f583387d2eed Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 15:51:11 +0300 Subject: [PATCH 076/143] reflect: ToStringWithFallback --- module/move/assistant/src/lib.rs | 3 + module/move/assistant/src/to_string.rs | 70 ++++++++++++++++++ .../move/assistant/tests/inc/fields_test.rs | 74 +------------------ 3 files changed, 75 insertions(+), 72 deletions(-) create mode 100644 module/move/assistant/src/to_string.rs diff --git a/module/move/assistant/src/lib.rs b/module/move/assistant/src/lib.rs index 270c34b907..0a07d15add 100644 --- a/module/move/assistant/src/lib.rs +++ b/module/move/assistant/src/lib.rs @@ -27,6 +27,9 @@ pub use wrapper_ref::*; /// Universal wrapper. pub mod wrapper_option_cow_ref; pub use wrapper_option_cow_ref::*; +/// Conversion to string. +pub mod to_string; +pub use to_string::*; /// Nice print. pub mod print; diff --git a/module/move/assistant/src/to_string.rs b/module/move/assistant/src/to_string.rs new file mode 100644 index 0000000000..5158cc172f --- /dev/null +++ b/module/move/assistant/src/to_string.rs @@ -0,0 +1,70 @@ +#[ allow( unused_imports ) ] +use super::*; + +use std:: +{ + fmt, + // collections::HashMap, + // borrow::Cow, +}; + +// = + +#[ derive( Debug, Default, Clone, Copy ) ] +pub struct WithDebug; + +#[ derive( Debug, Default, Clone, Copy ) ] +pub struct WithDisplay; + +#[ derive( Debug, Default, Clone, Copy ) ] +pub struct WithWell; + +pub trait ToStringWithFallback< 'a, How, Fallback > +{ + fn to_string_with_fallback( &'a self ) -> String; +} + +impl< 'a, T, How, Fallback > ToStringWithFallback< 'a, How, Fallback > for ( &T, ) +where + T : ToStringWith< 'a, How >, +{ + fn to_string_with_fallback( &'a self ) -> String + { + < T as ToStringWith< 'a, How > >::to_string_with( self.0 ) + } +} + +impl< 'a, T, How, Fallback > ToStringWithFallback< 'a, How, Fallback > for &( &T, ) +where + T : ToStringWith< 'a, Fallback >, +{ + fn to_string_with_fallback( &'a self ) -> String + { + < T as ToStringWith< 'a, Fallback > >::to_string_with( self.0 ) + } +} + +pub trait ToStringWith< 'a, How > +{ + fn to_string_with( &'a self ) -> String; +} + +impl< 'a, T > ToStringWith< 'a, WithDebug > for T +where + T : fmt::Debug, +{ + fn to_string_with( &'a self ) -> String + { + format!( "{:?}", self ) + } +} + +impl< 'a, T > ToStringWith< 'a, WithDisplay > for T +where + T : fmt::Display, +{ + fn to_string_with( &'a self ) -> String + { + format!( "{}", self ) + } +} diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index f8d02b8ece..3382f6fd15 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -6,6 +6,8 @@ use assistant:: Fields, IteratorTrait, MaybeAs, + ToStringWith, + WithDebug, }; use std:: @@ -49,78 +51,6 @@ pub struct TestObject // } // } -// = - -#[ derive( Debug, Default, Clone, Copy ) ] -pub struct WithDebug; - -#[ derive( Debug, Default, Clone, Copy ) ] -pub struct WithDisplay; - -#[ derive( Debug, Default, Clone, Copy ) ] -pub struct WithWell; - -pub trait ToStringWithFallback< 'a, How, Fallback > -{ - fn to_string_with_fallback( &'a self ) -> String; -} - -impl< 'a, T, How, Fallback > ToStringWithFallback< 'a, How, Fallback > for ( &T, ) -where - T : ToStringWith< 'a, How >, -{ - fn to_string_with_fallback( &'a self ) -> String - { - < T as ToStringWith< 'a, How > >::to_string_with( self.0 ) - } -} - -impl< 'a, T, How, Fallback > ToStringWithFallback< 'a, How, Fallback > for &( &T, ) -where - T : ToStringWith< 'a, Fallback >, -{ - fn to_string_with_fallback( &'a self ) -> String - { - < T as ToStringWith< 'a, Fallback > >::to_string_with( self.0 ) - } -} - -pub trait ToStringWith< 'a, How > -{ - // fn to_string_with( &'a self ) -> MaybeAs< 'a, String, StringFromDebug >; - fn to_string_with( &'a self ) -> String; -} - -impl< 'a, T > ToStringWith< 'a, WithDebug > for T -where - T : fmt::Debug, -{ - // fn to_string_with( &'a self ) -> MaybeAs< 'a, String, StringFromDebug > - fn to_string_with( &'a self ) -> String - { - format!( "{:?}", self ) - // MaybeAs::from( format!( "{:?}", self ) ) - } -} - -impl< 'a, T > ToStringWith< 'a, WithDisplay > for T -where - T : fmt::Display, -{ - fn to_string_with( &'a self ) -> String - { - format!( "{}", self ) - } -} - -// impl< 'a > ToStringWith< 'a, WithDisplay > for String -// { -// fn to_string_with( &'a self ) -> String -// { -// format!( "String : {}", self ) -// } -// } - impl< 'a, How > Fields< 'a, &'static str, MaybeAs< 'a, String, How > > for TestObject where From bad8fdc91b78d21696812eea9183c59ad3549d47 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 16:02:40 +0300 Subject: [PATCH 077/143] reflect: ToStringWithFallback --- module/move/assistant/src/to_string.rs | 32 +++++++++---------- .../move/assistant/tests/inc/fields_test.rs | 18 +++++------ module/move/assistant/tests/inc/mod.rs | 1 + .../assistant/tests/inc/to_string_test.rs | 31 ++++++++++++++++++ 4 files changed, 57 insertions(+), 25 deletions(-) create mode 100644 module/move/assistant/tests/inc/to_string_test.rs diff --git a/module/move/assistant/src/to_string.rs b/module/move/assistant/src/to_string.rs index 5158cc172f..5da4cd8486 100644 --- a/module/move/assistant/src/to_string.rs +++ b/module/move/assistant/src/to_string.rs @@ -19,51 +19,51 @@ pub struct WithDisplay; #[ derive( Debug, Default, Clone, Copy ) ] pub struct WithWell; -pub trait ToStringWithFallback< 'a, How, Fallback > +pub trait ToStringWithFallback< How, Fallback > { - fn to_string_with_fallback( &'a self ) -> String; + fn to_string_with_fallback( &self ) -> String; } -impl< 'a, T, How, Fallback > ToStringWithFallback< 'a, How, Fallback > for ( &T, ) +impl< T, How, Fallback > ToStringWithFallback< How, Fallback > for ( &T, ) where - T : ToStringWith< 'a, How >, + T : ToStringWith< How >, { - fn to_string_with_fallback( &'a self ) -> String + fn to_string_with_fallback( &self ) -> String { - < T as ToStringWith< 'a, How > >::to_string_with( self.0 ) + < T as ToStringWith< How > >::to_string_with( self.0 ) } } -impl< 'a, T, How, Fallback > ToStringWithFallback< 'a, How, Fallback > for &( &T, ) +impl< T, How, Fallback > ToStringWithFallback< How, Fallback > for &( &T, ) where - T : ToStringWith< 'a, Fallback >, + T : ToStringWith< Fallback >, { - fn to_string_with_fallback( &'a self ) -> String + fn to_string_with_fallback( &self ) -> String { - < T as ToStringWith< 'a, Fallback > >::to_string_with( self.0 ) + < T as ToStringWith< Fallback > >::to_string_with( self.0 ) } } -pub trait ToStringWith< 'a, How > +pub trait ToStringWith< How > { - fn to_string_with( &'a self ) -> String; + fn to_string_with( &self ) -> String; } -impl< 'a, T > ToStringWith< 'a, WithDebug > for T +impl< T > ToStringWith< WithDebug > for T where T : fmt::Debug, { - fn to_string_with( &'a self ) -> String + fn to_string_with( &self ) -> String { format!( "{:?}", self ) } } -impl< 'a, T > ToStringWith< 'a, WithDisplay > for T +impl< T > ToStringWith< WithDisplay > for T where T : fmt::Display, { - fn to_string_with( &'a self ) -> String + fn to_string_with( &self ) -> String { format!( "{}", self ) } diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index 3382f6fd15..f27ea40162 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -55,10 +55,10 @@ impl< 'a, How > Fields< 'a, &'static str, MaybeAs< 'a, String, How > > for TestObject where How : Clone + Copy + 'static, - String : ToStringWith< 'a, How >, - i64 : ToStringWith< 'a, How >, - Vec< String > : ToStringWith< 'a, How >, - Option< Vec< HashMap< String, String > > > : ToStringWith< 'a, How >, + String : ToStringWith< How >, + i64 : ToStringWith< How >, + Vec< String > : ToStringWith< How >, + Option< Vec< HashMap< String, String > > > : ToStringWith< How >, { fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, How > ) > { @@ -67,11 +67,11 @@ where fn into< 'a, V, How >( src : &'a V ) -> MaybeAs< 'a, String, How > where How : Clone + Copy + 'static, - V : ToStringWith< 'a, How > + 'a, + V : ToStringWith< How > + 'a, { MaybeAs::< 'a, String, How >::from ( - < V as ToStringWith< '_, How > >::to_string_with( src ) + < V as ToStringWith< How > >::to_string_with( src ) ) } @@ -83,11 +83,11 @@ where ) where How : Clone + Copy + 'static, - V : ToStringWith< 'a, How > + 'a, + V : ToStringWith< How > + 'a, { let val = MaybeAs::< 'a, String, How >::from ( - < V as ToStringWith< '_, How > >::to_string_with( src ) + < V as ToStringWith< How > >::to_string_with( src ) ); dst.push( ( key, val ) ); } @@ -119,7 +119,7 @@ where // dst.push( ( "tools", MaybeAs::none() ) ); // } - // dst.push( ( "id", MaybeAs::< 'a, String, How >::from( < String as ToStringWith< '_, How > >::to_string_with( &self.id ) ) ) ); + // dst.push( ( "id", MaybeAs::< 'a, String, How >::from( < String as ToStringWith< How > >::to_string_with( &self.id ) ) ) ); // dst.push( ( "created_at", self.created_at.to_string_with().into() ) ); // dst.push( ( "file_ids", self.file_ids.to_string_with().into() ) ); // diff --git a/module/move/assistant/tests/inc/mod.rs b/module/move/assistant/tests/inc/mod.rs index bd9f33110b..306f1132bd 100644 --- a/module/move/assistant/tests/inc/mod.rs +++ b/module/move/assistant/tests/inc/mod.rs @@ -3,5 +3,6 @@ use super::*; mod fields_test; mod print_test; +mod to_string_test; mod experiment; diff --git a/module/move/assistant/tests/inc/to_string_test.rs b/module/move/assistant/tests/inc/to_string_test.rs new file mode 100644 index 0000000000..d73d223174 --- /dev/null +++ b/module/move/assistant/tests/inc/to_string_test.rs @@ -0,0 +1,31 @@ +#[ allow( unused_imports ) ] +use super::*; + +use assistant:: +{ + Fields, + IteratorTrait, + MaybeAs, + ToStringWith, + WithDebug, +}; + +use std:: +{ + fmt, + // collections::HashMap, + // borrow::Cow, +}; + +// + +#[ test ] +fn test_vec_fields() +{ + + let src = 13i32; + let got = ToStringWith::< WithDebug >::to_string_with( &src ); + let exp = "13".to_string(); + a_id!( got, exp ); + +} From 3dbf392bf179afd360cfc500b60ed9de6ea200aa Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 16:05:04 +0300 Subject: [PATCH 078/143] reflect: ToString --- .../assistant/tests/inc/to_string_test.rs | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/module/move/assistant/tests/inc/to_string_test.rs b/module/move/assistant/tests/inc/to_string_test.rs index d73d223174..ccdf6fcad5 100644 --- a/module/move/assistant/tests/inc/to_string_test.rs +++ b/module/move/assistant/tests/inc/to_string_test.rs @@ -8,6 +8,7 @@ use assistant:: MaybeAs, ToStringWith, WithDebug, + WithDisplay, }; use std:: @@ -20,12 +21,33 @@ use std:: // #[ test ] -fn test_vec_fields() +fn to_string_with_test() { + // - + let src = 13i32; let got = ToStringWith::< WithDebug >::to_string_with( &src ); let exp = "13".to_string(); a_id!( got, exp ); + let src = "abc".to_string(); + let got = ToStringWith::< WithDebug >::to_string_with( &src ); + let exp = "\"abc\"".to_string(); + a_id!( got, exp ); + + // - + + let src = 13i32; + let got = ToStringWith::< WithDisplay >::to_string_with( &src ); + let exp = "13".to_string(); + a_id!( got, exp ); + + let src = "abc".to_string(); + let got = ToStringWith::< WithDisplay >::to_string_with( &src ); + let exp = "abc".to_string(); + a_id!( got, exp ); + + // - + } From 69bc8fb9c6468550654a082a8b01882fdb66104b Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 16:39:02 +0300 Subject: [PATCH 079/143] reflect: ToString --- module/move/assistant/src/to_string.rs | 19 +++++++++---- .../move/assistant/tests/inc/fields_test.rs | 27 ++++++++++--------- module/move/assistant/tests/inc/print_test.rs | 2 +- .../assistant/tests/inc/to_string_test.rs | 18 ++++++------- 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/module/move/assistant/src/to_string.rs b/module/move/assistant/src/to_string.rs index 5da4cd8486..54e50b00b2 100644 --- a/module/move/assistant/src/to_string.rs +++ b/module/move/assistant/src/to_string.rs @@ -8,19 +8,22 @@ use std:: // borrow::Cow, }; -// = - +/// Marker type for using Debug formatting. #[ derive( Debug, Default, Clone, Copy ) ] pub struct WithDebug; +/// Marker type for using Display formatting. #[ derive( Debug, Default, Clone, Copy ) ] pub struct WithDisplay; +/// Marker type for usign Well formatting. #[ derive( Debug, Default, Clone, Copy ) ] pub struct WithWell; +/// Trait to convert a type to a string with a fallback formatting. pub trait ToStringWithFallback< How, Fallback > { + /// Converts the type to a string using the specified formatting or a fallback. fn to_string_with_fallback( &self ) -> String; } @@ -28,9 +31,10 @@ impl< T, How, Fallback > ToStringWithFallback< How, Fallback > for ( &T, ) where T : ToStringWith< How >, { + /// Converts the type to a string using the specified formatting. fn to_string_with_fallback( &self ) -> String { - < T as ToStringWith< How > >::to_string_with( self.0 ) + >::to_string_with( self.0 ) } } @@ -38,14 +42,17 @@ impl< T, How, Fallback > ToStringWithFallback< How, Fallback > for &( &T, ) where T : ToStringWith< Fallback >, { + /// Converts the type to a string using the fallback formatting. fn to_string_with_fallback( &self ) -> String { - < T as ToStringWith< Fallback > >::to_string_with( self.0 ) + >::to_string_with( self.0 ) } } +/// Trait to convert a type to a string using a specified formatting method. pub trait ToStringWith< How > { + /// Converts the type to a string using the specified formatting method. fn to_string_with( &self ) -> String; } @@ -53,6 +60,7 @@ impl< T > ToStringWith< WithDebug > for T where T : fmt::Debug, { + /// Converts the type to a string using Debug formatting. fn to_string_with( &self ) -> String { format!( "{:?}", self ) @@ -63,8 +71,9 @@ impl< T > ToStringWith< WithDisplay > for T where T : fmt::Display, { + /// Converts the type to a string using Display formatting. fn to_string_with( &self ) -> String { format!( "{}", self ) } -} +} \ No newline at end of file diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/move/assistant/tests/inc/fields_test.rs index f27ea40162..0814bd9b01 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/move/assistant/tests/inc/fields_test.rs @@ -12,7 +12,7 @@ use assistant:: use std:: { - fmt, + // fmt, collections::HashMap, borrow::Cow, }; @@ -58,22 +58,22 @@ where String : ToStringWith< How >, i64 : ToStringWith< How >, Vec< String > : ToStringWith< How >, - Option< Vec< HashMap< String, String > > > : ToStringWith< How >, + Vec< HashMap< String, String > > : ToStringWith< How >, { fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, How > ) > { let mut dst : Vec< ( &'static str, MaybeAs< 'a, String, How > ) > = Vec::new(); - fn into< 'a, V, How >( src : &'a V ) -> MaybeAs< 'a, String, How > - where - How : Clone + Copy + 'static, - V : ToStringWith< How > + 'a, - { - MaybeAs::< 'a, String, How >::from - ( - < V as ToStringWith< How > >::to_string_with( src ) - ) - } + // fn into< 'a, V, How >( src : &'a V ) -> MaybeAs< 'a, String, How > + // where + // How : Clone + Copy + 'static, + // V : ToStringWith< How > + 'a, + // { + // MaybeAs::< 'a, String, How >::from + // ( + // < V as ToStringWith< How > >::to_string_with( src ) + // ) + // } fn add< 'a, V, How > ( @@ -99,7 +99,7 @@ where if let Some( tools ) = &self.tools { - add( &mut dst, "tools", &self.tools ); + add( &mut dst, "tools", tools ); } else { @@ -138,6 +138,7 @@ where // +#[ allow( dead_code ) ] fn is_borrowed< 'a, T : Clone >( src : &Option< Cow< 'a, T > > ) -> bool { if src.is_none() diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/move/assistant/tests/inc/print_test.rs index 4436e928a2..549cb72815 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/move/assistant/tests/inc/print_test.rs @@ -10,7 +10,7 @@ use assistant:: TableSize, TableRows, TableHeader, - TableFormatter, + // TableFormatter, Context, }; diff --git a/module/move/assistant/tests/inc/to_string_test.rs b/module/move/assistant/tests/inc/to_string_test.rs index ccdf6fcad5..e55a427187 100644 --- a/module/move/assistant/tests/inc/to_string_test.rs +++ b/module/move/assistant/tests/inc/to_string_test.rs @@ -3,20 +3,20 @@ use super::*; use assistant:: { - Fields, - IteratorTrait, - MaybeAs, + // Fields, + // IteratorTrait, + // MaybeAs, ToStringWith, WithDebug, WithDisplay, }; -use std:: -{ - fmt, - // collections::HashMap, - // borrow::Cow, -}; +// use std:: +// { +// // fmt, +// // collections::HashMap, +// // borrow::Cow, +// }; // From c0da2bb4839c000d284176f4dcf47e89e9167078 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 16:53:20 +0300 Subject: [PATCH 080/143] reflect: ToString --- module/move/assistant/src/to_string.rs | 14 ++++++++++++-- .../move/assistant/tests/inc/to_string_test.rs | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/module/move/assistant/src/to_string.rs b/module/move/assistant/src/to_string.rs index 54e50b00b2..84399402c1 100644 --- a/module/move/assistant/src/to_string.rs +++ b/module/move/assistant/src/to_string.rs @@ -8,6 +8,8 @@ use std:: // borrow::Cow, }; +// == + /// Marker type for using Debug formatting. #[ derive( Debug, Default, Clone, Copy ) ] pub struct WithDebug; @@ -20,6 +22,8 @@ pub struct WithDisplay; #[ derive( Debug, Default, Clone, Copy ) ] pub struct WithWell; +// == + /// Trait to convert a type to a string with a fallback formatting. pub trait ToStringWithFallback< How, Fallback > { @@ -34,7 +38,7 @@ where /// Converts the type to a string using the specified formatting. fn to_string_with_fallback( &self ) -> String { - >::to_string_with( self.0 ) + < T as ToStringWith< How > >::to_string_with( self.0 ) } } @@ -45,10 +49,16 @@ where /// Converts the type to a string using the fallback formatting. fn to_string_with_fallback( &self ) -> String { - >::to_string_with( self.0 ) + < T as ToStringWith< Fallback > >::to_string_with( self.0 ) } } +// pub fn to_string_with_fallback( src : &T ) +// { +// } + +// == + /// Trait to convert a type to a string using a specified formatting method. pub trait ToStringWith< How > { diff --git a/module/move/assistant/tests/inc/to_string_test.rs b/module/move/assistant/tests/inc/to_string_test.rs index e55a427187..ef57084a52 100644 --- a/module/move/assistant/tests/inc/to_string_test.rs +++ b/module/move/assistant/tests/inc/to_string_test.rs @@ -7,6 +7,7 @@ use assistant:: // IteratorTrait, // MaybeAs, ToStringWith, + ToStringWithFallback, WithDebug, WithDisplay, }; @@ -51,3 +52,20 @@ fn to_string_with_test() // - } + +// + +#[ test ] +fn to_string_with_fallback_test() +{ + + // - + + let src = 13i32; + let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); + let exp = "13".to_string(); + a_id!( got, exp ); + + // - + +} From 67306750f1c47fa7b1627c4e07101771a05110ac Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 17:20:53 +0300 Subject: [PATCH 081/143] reflect: ToString --- module/move/assistant/src/to_string.rs | 13 ++++-- .../assistant/tests/inc/to_string_test.rs | 46 ++++++++++++++++++- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/module/move/assistant/src/to_string.rs b/module/move/assistant/src/to_string.rs index 84399402c1..85a9d0674d 100644 --- a/module/move/assistant/src/to_string.rs +++ b/module/move/assistant/src/to_string.rs @@ -33,28 +33,31 @@ pub trait ToStringWithFallback< How, Fallback > impl< T, How, Fallback > ToStringWithFallback< How, Fallback > for ( &T, ) where - T : ToStringWith< How >, + T : ToStringWith< Fallback >, { /// Converts the type to a string using the specified formatting. fn to_string_with_fallback( &self ) -> String { - < T as ToStringWith< How > >::to_string_with( self.0 ) + < T as ToStringWith< Fallback > >::to_string_with( self.0 ) } } impl< T, How, Fallback > ToStringWithFallback< How, Fallback > for &( &T, ) where - T : ToStringWith< Fallback >, + T : ToStringWith< How >, { /// Converts the type to a string using the fallback formatting. fn to_string_with_fallback( &self ) -> String { - < T as ToStringWith< Fallback > >::to_string_with( self.0 ) + < T as ToStringWith< How > >::to_string_with( self.0 ) } } -// pub fn to_string_with_fallback( src : &T ) +// pub fn to_string_with_fallback< T, How, Fallback >( src : &T ) -> String +// where +// T : ToStringWithFallback< How, Fallback >, // { +// ToStringWithFallback::< How, Fallback >::to_string_with_fallback( &( src, ) ) // } // == diff --git a/module/move/assistant/tests/inc/to_string_test.rs b/module/move/assistant/tests/inc/to_string_test.rs index ef57084a52..c1e2a9b996 100644 --- a/module/move/assistant/tests/inc/to_string_test.rs +++ b/module/move/assistant/tests/inc/to_string_test.rs @@ -55,6 +55,11 @@ fn to_string_with_test() // +macro_rules! to_string_with_fallback +{ + () => { < < Self as GraphNodesNominalInterface >::NodeHandle as HasId >::Id }; +} + #[ test ] fn to_string_with_fallback_test() { @@ -62,10 +67,49 @@ fn to_string_with_fallback_test() // - let src = 13i32; - let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); + // let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); + let got = ( &( &src, ) ).to_string_with_fallback(); let exp = "13".to_string(); a_id!( got, exp ); + // let src = "abc".to_string(); + // let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); + // let exp = "abc".to_string(); + // a_id!( got, exp ); + + // - only display + +// struct OnlyDisplay; +// impl fmt::Display for OnlyDisplay +// { +// fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result +// { +// write!( f, "This is OnlyDisplay" ) +// } +// } +// +// let src = OnlyDisplay; +// let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); +// let exp = "This is OnlyDisplay".to_string(); +// a_id!( got, exp ); + + // - only debug + +// struct OnlyDebug; +// impl fmt::Debug for OnlyDebug +// { +// fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result +// { +// write!( f, "This is OnlyDebug" ) +// } +// } +// +// let src = OnlyDebug; +// let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); +// let exp = "This is OnlyDebug".to_string(); +// a_id!( got, exp ); + // - + } From be6a4eaca72df971d843c760cdc5987bbd074e61 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 17:25:09 +0300 Subject: [PATCH 082/143] reflect: ToString --- module/move/assistant/src/wrapper_ref.rs | 34 +++++++++---------- .../assistant/tests/inc/to_string_test.rs | 10 +++--- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/module/move/assistant/src/wrapper_ref.rs b/module/move/assistant/src/wrapper_ref.rs index c369c6503b..dff0835bab 100644 --- a/module/move/assistant/src/wrapper_ref.rs +++ b/module/move/assistant/src/wrapper_ref.rs @@ -2,34 +2,34 @@ use core::fmt; use core::ops::{ Deref }; /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. -pub trait IntoRef< 'a, T > +pub trait IntoRef< 'a, T, Marker > { /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. - fn into_option_cow( self ) -> Ref< 'a, T >; + fn into_ref( self ) -> Ref< 'a, T, Marker >; } -impl< 'a, T > IntoRef< 'a, T > for &'a T +impl< 'a, T, Marker > IntoRef< 'a, T, Marker > for &'a T { #[ inline( always ) ] - fn into_option_cow( self ) -> Ref< 'a, T > + fn into_ref( self ) -> Ref< 'a, T, Marker > { - Ref::< 'a, T >( self ) + Ref::< 'a, T, Marker >::new( self ) } } /// Transparent reference wrapper emphasizing a specific aspect of identity of its internal type. #[ repr( transparent ) ] #[ derive( Clone, Copy ) ] -pub struct Ref< 'a, T >( &'a T ); +pub struct Ref< 'a, T, Marker >( &'a T, ::core::marker::PhantomData< fn() -> Marker > ); -impl< 'a, T > Ref< 'a, T > +impl< 'a, T, Marker > Ref< 'a, T, Marker > { /// Just a constructor. #[ inline( always ) ] pub fn new( src : &'a T ) -> Self { - Self( src ) + Self( src, ::core::marker::PhantomData ) } /// Just a constructor. @@ -41,7 +41,7 @@ impl< 'a, T > Ref< 'a, T > } -impl< 'a, T > AsRef< T > for Ref< 'a, T > +impl< 'a, T, Marker > AsRef< T > for Ref< 'a, T, Marker > { fn as_ref( &self ) -> &T { @@ -49,7 +49,7 @@ impl< 'a, T > AsRef< T > for Ref< 'a, T > } } -impl< 'a, T > Deref for Ref< 'a, T > +impl< 'a, T, Marker > Deref for Ref< 'a, T, Marker > { type Target = T; fn deref( &self ) -> &Self::Target @@ -58,23 +58,23 @@ impl< 'a, T > Deref for Ref< 'a, T > } } -impl< 'a, T > From< &'a T > for Ref< 'a, T > +impl< 'a, T, Marker > From< &'a T > for Ref< 'a, T, Marker > { - fn from( table : &'a T ) -> Self + fn from( src : &'a T ) -> Self { - Ref( table ) + Ref::new( src ) } } -// impl< 'a, T > From< Ref< 'a, T > > for &'a T +// impl< 'a, T, Marker > From< Ref< 'a, T, Marker > > for &'a T // { -// fn from( wrapper : Ref< 'a, T > ) -> &'a T +// fn from( wrapper : Ref< 'a, T, Marker > ) -> &'a T // { // wrapper.0 // } // } -// impl< 'a, T > Default for Ref< 'a, T > +// impl< 'a, T, Marker > Default for Ref< 'a, T, Marker > // where // T : Default, // { @@ -84,7 +84,7 @@ impl< 'a, T > From< &'a T > for Ref< 'a, T > // } // } -impl< 'a, T > fmt::Debug for Ref< 'a, T > +impl< 'a, T, Marker > fmt::Debug for Ref< 'a, T, Marker > where T : fmt::Debug, { diff --git a/module/move/assistant/tests/inc/to_string_test.rs b/module/move/assistant/tests/inc/to_string_test.rs index c1e2a9b996..d871305c80 100644 --- a/module/move/assistant/tests/inc/to_string_test.rs +++ b/module/move/assistant/tests/inc/to_string_test.rs @@ -66,11 +66,11 @@ fn to_string_with_fallback_test() // - - let src = 13i32; - // let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); - let got = ( &( &src, ) ).to_string_with_fallback(); - let exp = "13".to_string(); - a_id!( got, exp ); + // let src = 13i32; + // // let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); + // let got = ( &( &src, ) ).to_string_with_fallback(); + // let exp = "13".to_string(); + // a_id!( got, exp ); // let src = "abc".to_string(); // let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); From bbcfdc7b0ea49c6a30a4a23c81d2608ca82f0e45 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 17:37:08 +0300 Subject: [PATCH 083/143] reflect: ToString --- module/move/assistant/src/to_string.rs | 8 +++++-- module/move/assistant/src/wrapper_ref.rs | 24 +++++++++---------- .../assistant/tests/inc/to_string_test.rs | 11 +++++---- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/module/move/assistant/src/to_string.rs b/module/move/assistant/src/to_string.rs index 85a9d0674d..38216bc413 100644 --- a/module/move/assistant/src/to_string.rs +++ b/module/move/assistant/src/to_string.rs @@ -24,6 +24,10 @@ pub struct WithWell; // == +/// Marker type for ToStringWithFallback. +#[ derive( Debug, Default, Clone, Copy ) ] +pub struct ToStringWithFallbackMarker; + /// Trait to convert a type to a string with a fallback formatting. pub trait ToStringWithFallback< How, Fallback > { @@ -31,7 +35,7 @@ pub trait ToStringWithFallback< How, Fallback > fn to_string_with_fallback( &self ) -> String; } -impl< T, How, Fallback > ToStringWithFallback< How, Fallback > for ( &T, ) +impl< T, How, Fallback > ToStringWithFallback< How, Fallback > for Ref< '_, T, ToStringWithFallbackMarker > where T : ToStringWith< Fallback >, { @@ -42,7 +46,7 @@ where } } -impl< T, How, Fallback > ToStringWithFallback< How, Fallback > for &( &T, ) +impl< T, How, Fallback > ToStringWithFallback< How, Fallback > for &Ref< '_, T, ToStringWithFallbackMarker > where T : ToStringWith< How >, { diff --git a/module/move/assistant/src/wrapper_ref.rs b/module/move/assistant/src/wrapper_ref.rs index dff0835bab..1b1f5e6f80 100644 --- a/module/move/assistant/src/wrapper_ref.rs +++ b/module/move/assistant/src/wrapper_ref.rs @@ -20,7 +20,7 @@ impl< 'a, T, Marker > IntoRef< 'a, T, Marker > for &'a T /// Transparent reference wrapper emphasizing a specific aspect of identity of its internal type. #[ repr( transparent ) ] #[ derive( Clone, Copy ) ] -pub struct Ref< 'a, T, Marker >( &'a T, ::core::marker::PhantomData< fn() -> Marker > ); +pub struct Ref< 'a, T, Marker >( pub &'a T, ::core::marker::PhantomData< fn() -> Marker > ); impl< 'a, T, Marker > Ref< 'a, T, Marker > { @@ -84,14 +84,14 @@ impl< 'a, T, Marker > From< &'a T > for Ref< 'a, T, Marker > // } // } -impl< 'a, T, Marker > fmt::Debug for Ref< 'a, T, Marker > -where - T : fmt::Debug, -{ - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result - { - f.debug_struct( "Ref" ) - .field( "0", &self.0 ) - .finish() - } -} +// impl< 'a, T, Marker > fmt::Debug for Ref< 'a, T, Marker > +// where +// T : fmt::Debug, +// { +// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result +// { +// f.debug_struct( "Ref" ) +// .field( "0", &self.0 ) +// .finish() +// } +// } diff --git a/module/move/assistant/tests/inc/to_string_test.rs b/module/move/assistant/tests/inc/to_string_test.rs index d871305c80..f24de1bd6a 100644 --- a/module/move/assistant/tests/inc/to_string_test.rs +++ b/module/move/assistant/tests/inc/to_string_test.rs @@ -10,6 +10,7 @@ use assistant:: ToStringWithFallback, WithDebug, WithDisplay, + Ref, }; // use std:: @@ -66,11 +67,11 @@ fn to_string_with_fallback_test() // - - // let src = 13i32; - // // let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); - // let got = ( &( &src, ) ).to_string_with_fallback(); - // let exp = "13".to_string(); - // a_id!( got, exp ); + let src = 13i32; + let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &Ref::from( &src ) ); + // let got = ( &Ref::from( &src ) ).to_string_with_fallback(); + let exp = "13".to_string(); + a_id!( got, exp ); // let src = "abc".to_string(); // let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); From 0b65afb7869383014035400993555275e5e26f36 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 18:00:05 +0300 Subject: [PATCH 084/143] reflect: ToString --- module/move/assistant/src/to_string.rs | 6 ++-- .../assistant/tests/inc/to_string_test.rs | 36 ++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/module/move/assistant/src/to_string.rs b/module/move/assistant/src/to_string.rs index 38216bc413..df51840a44 100644 --- a/module/move/assistant/src/to_string.rs +++ b/module/move/assistant/src/to_string.rs @@ -32,7 +32,7 @@ pub struct ToStringWithFallbackMarker; pub trait ToStringWithFallback< How, Fallback > { /// Converts the type to a string using the specified formatting or a fallback. - fn to_string_with_fallback( &self ) -> String; + fn to_string_with_fallback( self ) -> String; } impl< T, How, Fallback > ToStringWithFallback< How, Fallback > for Ref< '_, T, ToStringWithFallbackMarker > @@ -40,7 +40,7 @@ where T : ToStringWith< Fallback >, { /// Converts the type to a string using the specified formatting. - fn to_string_with_fallback( &self ) -> String + fn to_string_with_fallback( self ) -> String { < T as ToStringWith< Fallback > >::to_string_with( self.0 ) } @@ -51,7 +51,7 @@ where T : ToStringWith< How >, { /// Converts the type to a string using the fallback formatting. - fn to_string_with_fallback( &self ) -> String + fn to_string_with_fallback( self ) -> String { < T as ToStringWith< How > >::to_string_with( self.0 ) } diff --git a/module/move/assistant/tests/inc/to_string_test.rs b/module/move/assistant/tests/inc/to_string_test.rs index f24de1bd6a..c04460e013 100644 --- a/module/move/assistant/tests/inc/to_string_test.rs +++ b/module/move/assistant/tests/inc/to_string_test.rs @@ -67,16 +67,16 @@ fn to_string_with_fallback_test() // - - let src = 13i32; - let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &Ref::from( &src ) ); - // let got = ( &Ref::from( &src ) ).to_string_with_fallback(); - let exp = "13".to_string(); - a_id!( got, exp ); - - // let src = "abc".to_string(); - // let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); - // let exp = "abc".to_string(); - // a_id!( got, exp ); +// let src = 13i32; +// let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &Ref::from( &src ) ); +// // let got = ( &Ref::from( &src ) ).to_string_with_fallback(); +// let exp = "13".to_string(); +// a_id!( got, exp ); +// +// let src = "abc".to_string(); +// let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &Ref::from( &src ) ); +// let exp = "abc".to_string(); +// a_id!( got, exp ); // - only display @@ -96,18 +96,28 @@ fn to_string_with_fallback_test() // - only debug +// #[ derive( Clone, Copy ) ] // struct OnlyDebug; +// // impl fmt::Debug for OnlyDebug // { // fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result // { -// write!( f, "This is OnlyDebug" ) +// write!( f, "This is debug" ) // } // } // +// // impl fmt::Display for OnlyDebug +// // { +// // fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result +// // { +// // write!( f, "This is display" ) +// // } +// // } +// // let src = OnlyDebug; -// let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); -// let exp = "This is OnlyDebug".to_string(); +// let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &Ref::from( &src ) ); +// let exp = "This is debug".to_string(); // a_id!( got, exp ); // - From 103334eaffd20b231b019c43a008c320ec78c191 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 18:17:12 +0300 Subject: [PATCH 085/143] reflect: ToString --- module/move/assistant/src/to_string.rs | 30 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/module/move/assistant/src/to_string.rs b/module/move/assistant/src/to_string.rs index df51840a44..9371fc3178 100644 --- a/module/move/assistant/src/to_string.rs +++ b/module/move/assistant/src/to_string.rs @@ -29,31 +29,41 @@ pub struct WithWell; pub struct ToStringWithFallbackMarker; /// Trait to convert a type to a string with a fallback formatting. -pub trait ToStringWithFallback< How, Fallback > +pub trait ToStringWithFallback { /// Converts the type to a string using the specified formatting or a fallback. - fn to_string_with_fallback( self ) -> String; + // fn to_string_with_fallback( self ) -> String; + fn to_string_with_fallback( self : Self ) -> String + // where + // T : ToStringWith< Fallback >, + ; } -impl< T, How, Fallback > ToStringWithFallback< How, Fallback > for Ref< '_, T, ToStringWithFallbackMarker > +impl< T > ToStringWithFallback for Ref< '_, T, ToStringWithFallbackMarker > where - T : ToStringWith< Fallback >, + T : ToStringWith< WithDebug >, { /// Converts the type to a string using the specified formatting. - fn to_string_with_fallback( self ) -> String + fn to_string_with_fallback( self : Self ) -> String + // fn to_string_with_fallback< How, Fallback >( self ) -> String + // where + // T : ToStringWith< Fallback >, { - < T as ToStringWith< Fallback > >::to_string_with( self.0 ) + < T as ToStringWith< WithDebug > >::to_string_with( self.0 ) } } -impl< T, How, Fallback > ToStringWithFallback< How, Fallback > for &Ref< '_, T, ToStringWithFallbackMarker > +impl< T > ToStringWithFallback for &Ref< '_, T, ToStringWithFallbackMarker > where - T : ToStringWith< How >, + T : ToStringWith< WithDisplay >, { /// Converts the type to a string using the fallback formatting. - fn to_string_with_fallback( self ) -> String + // fn to_string_with_fallback( self ) -> String + fn to_string_with_fallback( self : Self ) -> String + // where + // T : ToStringWith< Fallback >, { - < T as ToStringWith< How > >::to_string_with( self.0 ) + < T as ToStringWith< WithDisplay > >::to_string_with( self.0 ) } } From caa41392e118a68716063de33dd407c2dd2ba2d8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 18:26:48 +0300 Subject: [PATCH 086/143] reflect: ToString --- module/move/assistant/src/to_string.rs | 18 ++++++----- .../assistant/tests/inc/to_string_test.rs | 30 ++++++++++++++++++- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/module/move/assistant/src/to_string.rs b/module/move/assistant/src/to_string.rs index 9371fc3178..932e779f94 100644 --- a/module/move/assistant/src/to_string.rs +++ b/module/move/assistant/src/to_string.rs @@ -26,10 +26,10 @@ pub struct WithWell; /// Marker type for ToStringWithFallback. #[ derive( Debug, Default, Clone, Copy ) ] -pub struct ToStringWithFallbackMarker; +pub struct ToStringWithFallbackParams< How, Fallback >( ::core::marker::PhantomData< fn() -> ( How, Fallback ) > ); /// Trait to convert a type to a string with a fallback formatting. -pub trait ToStringWithFallback +pub trait ToStringWithFallback< How, Fallback > { /// Converts the type to a string using the specified formatting or a fallback. // fn to_string_with_fallback( self ) -> String; @@ -39,9 +39,10 @@ pub trait ToStringWithFallback ; } -impl< T > ToStringWithFallback for Ref< '_, T, ToStringWithFallbackMarker > +impl< T, How, Fallback > ToStringWithFallback< How, Fallback > +for Ref< '_, T, ToStringWithFallbackParams< How, Fallback > > where - T : ToStringWith< WithDebug >, + T : ToStringWith< Fallback >, { /// Converts the type to a string using the specified formatting. fn to_string_with_fallback( self : Self ) -> String @@ -49,13 +50,14 @@ where // where // T : ToStringWith< Fallback >, { - < T as ToStringWith< WithDebug > >::to_string_with( self.0 ) + < T as ToStringWith< Fallback > >::to_string_with( self.0 ) } } -impl< T > ToStringWithFallback for &Ref< '_, T, ToStringWithFallbackMarker > +impl< T, How, Fallback > ToStringWithFallback< How, Fallback > +for &Ref< '_, T, ToStringWithFallbackParams< How, Fallback > > where - T : ToStringWith< WithDisplay >, + T : ToStringWith< How >, { /// Converts the type to a string using the fallback formatting. // fn to_string_with_fallback( self ) -> String @@ -63,7 +65,7 @@ where // where // T : ToStringWith< Fallback >, { - < T as ToStringWith< WithDisplay > >::to_string_with( self.0 ) + < T as ToStringWith< How > >::to_string_with( self.0 ) } } diff --git a/module/move/assistant/tests/inc/to_string_test.rs b/module/move/assistant/tests/inc/to_string_test.rs index c04460e013..b166c771cc 100644 --- a/module/move/assistant/tests/inc/to_string_test.rs +++ b/module/move/assistant/tests/inc/to_string_test.rs @@ -8,6 +8,7 @@ use assistant:: // MaybeAs, ToStringWith, ToStringWithFallback, + ToStringWithFallbackParams, WithDebug, WithDisplay, Ref, @@ -120,7 +121,34 @@ fn to_string_with_fallback_test() // let exp = "This is debug".to_string(); // a_id!( got, exp ); - // - + // - only debug + #[ derive( Clone, Copy ) ] + struct OnlyDebug; + + impl fmt::Debug for OnlyDebug + { + fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result + { + write!( f, "This is debug" ) + } + } + + impl fmt::Display for OnlyDebug + { + fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result + { + write!( f, "This is display" ) + } + } + + let src = OnlyDebug; + // let got = ToStringWithFallback::to_string_with_fallback( &Ref::from( &src ) ); + let ref1 = Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ); + let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let exp = "This is debug".to_string(); + a_id!( got, exp ); + + // - } From 66c9c8efa11213a1de30412df6c2dea55a1dad9a Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 18:45:14 +0300 Subject: [PATCH 087/143] reflect: ToString --- module/move/assistant/src/to_string.rs | 22 +----- module/move/assistant/src/wrapper_ref.rs | 18 ++++- .../assistant/tests/inc/to_string_test.rs | 67 ++++++++----------- 3 files changed, 47 insertions(+), 60 deletions(-) diff --git a/module/move/assistant/src/to_string.rs b/module/move/assistant/src/to_string.rs index 932e779f94..5bfe3842be 100644 --- a/module/move/assistant/src/to_string.rs +++ b/module/move/assistant/src/to_string.rs @@ -32,10 +32,7 @@ pub struct ToStringWithFallbackParams< How, Fallback >( ::core::marker::PhantomD pub trait ToStringWithFallback< How, Fallback > { /// Converts the type to a string using the specified formatting or a fallback. - // fn to_string_with_fallback( self ) -> String; - fn to_string_with_fallback( self : Self ) -> String - // where - // T : ToStringWith< Fallback >, + fn to_string_with_fallback( self ) -> String ; } @@ -45,10 +42,7 @@ where T : ToStringWith< Fallback >, { /// Converts the type to a string using the specified formatting. - fn to_string_with_fallback( self : Self ) -> String - // fn to_string_with_fallback< How, Fallback >( self ) -> String - // where - // T : ToStringWith< Fallback >, + fn to_string_with_fallback( self ) -> String { < T as ToStringWith< Fallback > >::to_string_with( self.0 ) } @@ -60,22 +54,12 @@ where T : ToStringWith< How >, { /// Converts the type to a string using the fallback formatting. - // fn to_string_with_fallback( self ) -> String - fn to_string_with_fallback( self : Self ) -> String - // where - // T : ToStringWith< Fallback >, + fn to_string_with_fallback( self ) -> String { < T as ToStringWith< How > >::to_string_with( self.0 ) } } -// pub fn to_string_with_fallback< T, How, Fallback >( src : &T ) -> String -// where -// T : ToStringWithFallback< How, Fallback >, -// { -// ToStringWithFallback::< How, Fallback >::to_string_with_fallback( &( src, ) ) -// } - // == /// Trait to convert a type to a string using a specified formatting method. diff --git a/module/move/assistant/src/wrapper_ref.rs b/module/move/assistant/src/wrapper_ref.rs index 1b1f5e6f80..089fd3691d 100644 --- a/module/move/assistant/src/wrapper_ref.rs +++ b/module/move/assistant/src/wrapper_ref.rs @@ -19,8 +19,22 @@ impl< 'a, T, Marker > IntoRef< 'a, T, Marker > for &'a T /// Transparent reference wrapper emphasizing a specific aspect of identity of its internal type. #[ repr( transparent ) ] -#[ derive( Clone, Copy ) ] -pub struct Ref< 'a, T, Marker >( pub &'a T, ::core::marker::PhantomData< fn() -> Marker > ); +pub struct Ref< 'a, T, Marker >( pub &'a T, ::core::marker::PhantomData< fn() -> Marker > ) +where + ::core::marker::PhantomData< fn( Marker ) > : Copy, + &'a T : Copy, +; + +impl< 'a, T, Marker > Clone for Ref< 'a, T, Marker > +{ + #[ inline( always ) ] + fn clone( &self ) -> Self + { + Self::new( self.0 ) + } +} + +impl< 'a, T, Marker > Copy for Ref< 'a, T, Marker > {} impl< 'a, T, Marker > Ref< 'a, T, Marker > { diff --git a/module/move/assistant/tests/inc/to_string_test.rs b/module/move/assistant/tests/inc/to_string_test.rs index b166c771cc..067c691cd7 100644 --- a/module/move/assistant/tests/inc/to_string_test.rs +++ b/module/move/assistant/tests/inc/to_string_test.rs @@ -55,17 +55,24 @@ fn to_string_with_test() } -// - -macro_rules! to_string_with_fallback -{ - () => { < < Self as GraphNodesNominalInterface >::NodeHandle as HasId >::Id }; -} - #[ test ] fn to_string_with_fallback_test() { + // - Ref should implement copy + + fn f1( src : Ref::< '_, Struct1, ToStringWithFallbackParams< WithDisplay, WithDebug > > ) + where + for< 'a > Ref::< 'a, Struct1, ToStringWithFallbackParams< WithDisplay, WithDebug > > : Copy + Clone, + {} + + struct Struct1; + let src = Struct1; + let ref1 = Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ); + let ref2 = ref1; + f1( ref1 ); + f1( ref2 ); + // - // let src = 13i32; @@ -86,44 +93,19 @@ fn to_string_with_fallback_test() // { // fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result // { -// write!( f, "This is OnlyDisplay" ) +// write!( f, "This is display" ) // } // } // // let src = OnlyDisplay; -// let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); -// let exp = "This is OnlyDisplay".to_string(); +// // let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); +// let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); +// let exp = "This is display".to_string(); // a_id!( got, exp ); // - only debug -// #[ derive( Clone, Copy ) ] -// struct OnlyDebug; -// -// impl fmt::Debug for OnlyDebug -// { -// fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result -// { -// write!( f, "This is debug" ) -// } -// } -// -// // impl fmt::Display for OnlyDebug -// // { -// // fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result -// // { -// // write!( f, "This is display" ) -// // } -// // } -// -// let src = OnlyDebug; -// let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &Ref::from( &src ) ); -// let exp = "This is debug".to_string(); -// a_id!( got, exp ); - - // - only debug - - #[ derive( Clone, Copy ) ] + // #[ derive( Clone, Copy ) ] struct OnlyDebug; impl fmt::Debug for OnlyDebug @@ -143,8 +125,7 @@ fn to_string_with_fallback_test() } let src = OnlyDebug; - // let got = ToStringWithFallback::to_string_with_fallback( &Ref::from( &src ) ); - let ref1 = Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ); + let _ref1 = Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ); let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); let exp = "This is debug".to_string(); a_id!( got, exp ); @@ -152,3 +133,11 @@ fn to_string_with_fallback_test() // - } + + +// + +macro_rules! to_string_with_fallback +{ + () => { < < Self as GraphNodesNominalInterface >::NodeHandle as HasId >::Id }; +} From 731d2822efe57ce89ab2477b399dddb288d3390b Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 18:57:38 +0300 Subject: [PATCH 088/143] reflect: ToString --- module/move/assistant/src/to_string.rs | 15 +++ module/move/assistant/src/wrapper_ref.rs | 3 +- .../assistant/tests/inc/to_string_test.rs | 115 +++++++++++++----- 3 files changed, 99 insertions(+), 34 deletions(-) diff --git a/module/move/assistant/src/to_string.rs b/module/move/assistant/src/to_string.rs index 5bfe3842be..42cdba0474 100644 --- a/module/move/assistant/src/to_string.rs +++ b/module/move/assistant/src/to_string.rs @@ -60,6 +60,21 @@ where } } +// + +#[ macro_export( local_inner_macros ) ] +macro_rules! to_string_with_fallback +{ + ( $how : ty, $fallback : ty, $src : expr ) + => + {{ + ( + &::assistant::Ref::< '_, _, ToStringWithFallbackParams< $how, $fallback > >::from( &$src ) + ) + .to_string_with_fallback() + }}; +} + // == /// Trait to convert a type to a string using a specified formatting method. diff --git a/module/move/assistant/src/wrapper_ref.rs b/module/move/assistant/src/wrapper_ref.rs index 089fd3691d..c90a8e47e1 100644 --- a/module/move/assistant/src/wrapper_ref.rs +++ b/module/move/assistant/src/wrapper_ref.rs @@ -1,4 +1,4 @@ -use core::fmt; +// use core::fmt; use core::ops::{ Deref }; /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. @@ -18,6 +18,7 @@ impl< 'a, T, Marker > IntoRef< 'a, T, Marker > for &'a T } /// Transparent reference wrapper emphasizing a specific aspect of identity of its internal type. +#[ allow( missing_debug_implementations ) ] #[ repr( transparent ) ] pub struct Ref< 'a, T, Marker >( pub &'a T, ::core::marker::PhantomData< fn() -> Marker > ) where diff --git a/module/move/assistant/tests/inc/to_string_test.rs b/module/move/assistant/tests/inc/to_string_test.rs index 067c691cd7..075c5bf4b9 100644 --- a/module/move/assistant/tests/inc/to_string_test.rs +++ b/module/move/assistant/tests/inc/to_string_test.rs @@ -12,6 +12,7 @@ use assistant:: WithDebug, WithDisplay, Ref, + to_string_with_fallback, }; // use std:: @@ -56,12 +57,12 @@ fn to_string_with_test() } #[ test ] -fn to_string_with_fallback_test() +fn to_string_with_fallback_basic() { // - Ref should implement copy - fn f1( src : Ref::< '_, Struct1, ToStringWithFallbackParams< WithDisplay, WithDebug > > ) + fn f1( _src : Ref::< '_, Struct1, ToStringWithFallbackParams< WithDisplay, WithDebug > > ) where for< 'a > Ref::< 'a, Struct1, ToStringWithFallbackParams< WithDisplay, WithDebug > > : Copy + Clone, {} @@ -75,37 +76,44 @@ fn to_string_with_fallback_test() // - -// let src = 13i32; -// let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &Ref::from( &src ) ); -// // let got = ( &Ref::from( &src ) ).to_string_with_fallback(); -// let exp = "13".to_string(); -// a_id!( got, exp ); + let src = 13i32; + let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let exp = "13".to_string(); + a_id!( got, exp ); + + let src = "abc".to_string(); + let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let exp = "abc".to_string(); + a_id!( got, exp ); + + // - + +} + // -// let src = "abc".to_string(); -// let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &Ref::from( &src ) ); -// let exp = "abc".to_string(); -// a_id!( got, exp ); + +#[ test ] +fn to_string_with_fallback_variants() +{ // - only display -// struct OnlyDisplay; -// impl fmt::Display for OnlyDisplay -// { -// fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result -// { -// write!( f, "This is display" ) -// } -// } -// -// let src = OnlyDisplay; -// // let got = ToStringWithFallback::< WithDisplay, WithDebug >::to_string_with_fallback( &( &src, ) ); -// let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); -// let exp = "This is display".to_string(); -// a_id!( got, exp ); + struct OnlyDisplay; + impl fmt::Display for OnlyDisplay + { + fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result + { + write!( f, "This is display" ) + } + } + + let src = OnlyDisplay; + let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let exp = "This is display".to_string(); + a_id!( got, exp ); // - only debug - // #[ derive( Clone, Copy ) ] struct OnlyDebug; impl fmt::Debug for OnlyDebug @@ -116,7 +124,25 @@ fn to_string_with_fallback_test() } } - impl fmt::Display for OnlyDebug + let src = OnlyDebug; + let _ref1 = Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ); + let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let exp = "This is debug".to_string(); + a_id!( got, exp ); + + // - both debug and display + + struct Both; + + impl fmt::Debug for Both + { + fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result + { + write!( f, "This is debug" ) + } + } + + impl fmt::Display for Both { fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result { @@ -124,20 +150,43 @@ fn to_string_with_fallback_test() } } - let src = OnlyDebug; - let _ref1 = Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ); + let src = Both; let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); - let exp = "This is debug".to_string(); + let exp = "This is display".to_string(); a_id!( got, exp ); // - } - // -macro_rules! to_string_with_fallback +#[ test ] +fn to_string_with_fallback_macro() { - () => { < < Self as GraphNodesNominalInterface >::NodeHandle as HasId >::Id }; + + struct Both; + + impl fmt::Debug for Both + { + fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result + { + write!( f, "This is debug" ) + } + } + + impl fmt::Display for Both + { + fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result + { + write!( f, "This is display" ) + } + } + + let src = Both; + // let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); + let exp = "This is display".to_string(); + a_id!( got, exp ); + } From d32b3206fade1b96ffb7113fd1d327a6acab9f54 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 19:10:39 +0300 Subject: [PATCH 089/143] reflect: ToString --- module/move/assistant/src/to_string.rs | 67 ++++++++++++++++++- module/move/assistant/tests/inc/mod.rs | 1 + .../assistant/tests/inc/to_string_example.rs | 55 +++++++++++++++ .../assistant/tests/inc/to_string_test.rs | 11 +++ 4 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 module/move/assistant/tests/inc/to_string_example.rs diff --git a/module/move/assistant/src/to_string.rs b/module/move/assistant/src/to_string.rs index 42cdba0474..669fa86f17 100644 --- a/module/move/assistant/src/to_string.rs +++ b/module/move/assistant/src/to_string.rs @@ -62,14 +62,77 @@ where // +/// Macro to convert a value to a string using a specified formatting method with a fallback. +/// +/// # Parameters +/// - `$how`: The primary formatting type (e.g., `WithDebug`, `WithDisplay`). +/// - `$fallback`: The fallback formatting type. +/// - `$src`: The source value to format. +/// +/// # Example +/// ```rust +/// use core::fmt; +/// use assistant:: +/// { +/// WithDebug, +/// WithDisplay, +/// to_string_with_fallback, +/// }; +/// +/// // Define a struct that implements both Debug and Display traits. +/// struct Both; +/// +/// impl fmt::Debug for Both +/// { +/// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result +/// { +/// write!( f, "This is debug" ) +/// } +/// } +/// +/// impl fmt::Display for Both +/// { +/// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result +/// { +/// write!( f, "This is display" ) +/// } +/// } +/// +/// // Define a struct that implements only the Debug trait. +/// struct OnlyDebug; +/// +/// impl fmt::Debug for OnlyDebug +/// { +/// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result +/// { +/// write!( f, "This is debug" ) +/// } +/// } +/// +/// // Example usage: Using Both which implements both Debug and Display. +/// let src = Both; +/// let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); +/// let exp = "This is display".to_string(); +/// // The primary formatting method WithDisplay is used. +/// assert_eq!( got, exp ); +/// +/// // Example usage: Using OnlyDebug which implements only Debug. +/// let src = OnlyDebug; +/// let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); +/// let exp = "This is debug".to_string(); +/// // The primary formatting method WithDisplay is not available, so the fallback WithDebug is used. +/// assert_eq!( got, exp ); +/// ``` + #[ macro_export( local_inner_macros ) ] macro_rules! to_string_with_fallback { ( $how : ty, $fallback : ty, $src : expr ) => {{ + use assistant::ToStringWithFallback; ( - &::assistant::Ref::< '_, _, ToStringWithFallbackParams< $how, $fallback > >::from( &$src ) + &assistant::Ref::< '_, _, assistant::ToStringWithFallbackParams< $how, $fallback > >::from( &$src ) ) .to_string_with_fallback() }}; @@ -104,4 +167,4 @@ where { format!( "{}", self ) } -} \ No newline at end of file +} diff --git a/module/move/assistant/tests/inc/mod.rs b/module/move/assistant/tests/inc/mod.rs index 306f1132bd..3a22b49591 100644 --- a/module/move/assistant/tests/inc/mod.rs +++ b/module/move/assistant/tests/inc/mod.rs @@ -4,5 +4,6 @@ use super::*; mod fields_test; mod print_test; mod to_string_test; +mod to_string_example; mod experiment; diff --git a/module/move/assistant/tests/inc/to_string_example.rs b/module/move/assistant/tests/inc/to_string_example.rs new file mode 100644 index 0000000000..53fa85452e --- /dev/null +++ b/module/move/assistant/tests/inc/to_string_example.rs @@ -0,0 +1,55 @@ +#[ allow( unused_imports ) ] +use super::*; + + +#[ test ] +fn exmaple() +{ + + use core::fmt; + use assistant:: + { + WithDebug, + WithDisplay, + to_string_with_fallback, + }; + + struct Both; + + impl fmt::Debug for Both + { + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + write!( f, "This is debug" ) + } + } + + impl fmt::Display for Both + { + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + write!( f, "This is display" ) + } + } + + struct OnlyDebug; + + impl fmt::Debug for OnlyDebug + { + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + write!( f, "This is debug" ) + } + } + + let src = Both; + let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); + let exp = "This is display".to_string(); + assert_eq!( got, exp ); + + let src = OnlyDebug; + let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); + let exp = "This is debug".to_string(); + assert_eq!( got, exp ); + +} diff --git a/module/move/assistant/tests/inc/to_string_test.rs b/module/move/assistant/tests/inc/to_string_test.rs index 075c5bf4b9..2faf19ea96 100644 --- a/module/move/assistant/tests/inc/to_string_test.rs +++ b/module/move/assistant/tests/inc/to_string_test.rs @@ -155,6 +155,11 @@ fn to_string_with_fallback_variants() let exp = "This is display".to_string(); a_id!( got, exp ); + let src = Both; + let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDebug, WithDisplay > >::from( &src ) ).to_string_with_fallback(); + let exp = "This is debug".to_string(); + a_id!( got, exp ); + // - } @@ -189,4 +194,10 @@ fn to_string_with_fallback_macro() let exp = "This is display".to_string(); a_id!( got, exp ); + let src = Both; + // let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let got = to_string_with_fallback!( WithDebug, WithDisplay, src ); + let exp = "This is debug".to_string(); + a_id!( got, exp ); + } From e1e104a2a1f3a9b5376eabec6f95c7bba7005001 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 19:57:35 +0300 Subject: [PATCH 090/143] reflect: move out reflect-related entities from assistant --- module/core/reflect_tools/src/reflect.rs | 39 +++ .../reflect_tools/src/reflect/axiomatic.rs | 6 +- .../core/reflect_tools/src/reflect/fields.rs | 131 ++++++++ .../reflect_tools/src/reflect/to_string.rs | 224 ++++++++++++++ .../core/reflect_tools/src/reflect/wrapper.rs | 59 ++++ .../reflect_tools/src/reflect/wrapper/aref.rs | 155 ++++++++++ .../src/reflect/wrapper/maybe_as.rs | 291 ++++++++++++++++++ .../tests/inc/fundamental}/fields_test.rs | 2 +- .../inc/fundamental}/to_string_example.rs | 3 +- .../tests/inc/fundamental}/to_string_test.rs | 2 +- .../array_test.rs} | 0 .../common_test.rs} | 0 .../hashmap_test.rs} | 0 .../hashset_test.rs} | 0 .../inc/{ => group1}/newtype_experiment.rs | 0 .../tests/inc/{ => group1}/only_test/all.rs | 0 .../{ => group1}/only_test/reflect_struct.rs | 2 +- .../only_test/reflect_struct_in_struct.rs | 6 +- .../only_test/reflect_struct_with_lifetime.rs | 2 +- .../primitive_test.rs} | 0 .../slice_test.rs} | 0 .../struct_in_struct_manual_test.rs} | 0 .../struct_manual_test.rs} | 0 .../struct_with_lifetime_manual_test.rs} | 0 .../vec_test.rs} | 0 module/core/reflect_tools/tests/inc/mod.rs | 53 ++-- module/move/assistant/src/reflect.rs | 88 ------ module/move/assistant/src/to_string.rs | 170 ---------- .../assistant/src/wrapper_option_cow_ref.rs | 247 --------------- module/move/assistant/src/wrapper_ref.rs | 112 ------- 30 files changed, 943 insertions(+), 649 deletions(-) create mode 100644 module/core/reflect_tools/src/reflect/fields.rs create mode 100644 module/core/reflect_tools/src/reflect/to_string.rs create mode 100644 module/core/reflect_tools/src/reflect/wrapper.rs create mode 100644 module/core/reflect_tools/src/reflect/wrapper/aref.rs create mode 100644 module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs rename module/{move/assistant/tests/inc => core/reflect_tools/tests/inc/fundamental}/fields_test.rs (99%) rename module/{move/assistant/tests/inc => core/reflect_tools/tests/inc/fundamental}/to_string_example.rs (91%) rename module/{move/assistant/tests/inc => core/reflect_tools/tests/inc/fundamental}/to_string_test.rs (99%) rename module/core/reflect_tools/tests/inc/{reflect_array_test.rs => group1/array_test.rs} (100%) rename module/core/reflect_tools/tests/inc/{reflect_common_test.rs => group1/common_test.rs} (100%) rename module/core/reflect_tools/tests/inc/{reflect_hashmap_test.rs => group1/hashmap_test.rs} (100%) rename module/core/reflect_tools/tests/inc/{reflect_hashset_test.rs => group1/hashset_test.rs} (100%) rename module/core/reflect_tools/tests/inc/{ => group1}/newtype_experiment.rs (100%) rename module/core/reflect_tools/tests/inc/{ => group1}/only_test/all.rs (100%) rename module/core/reflect_tools/tests/inc/{ => group1}/only_test/reflect_struct.rs (90%) rename module/core/reflect_tools/tests/inc/{ => group1}/only_test/reflect_struct_in_struct.rs (84%) rename module/core/reflect_tools/tests/inc/{ => group1}/only_test/reflect_struct_with_lifetime.rs (94%) rename module/core/reflect_tools/tests/inc/{reflect_primitive_test.rs => group1/primitive_test.rs} (100%) rename module/core/reflect_tools/tests/inc/{reflect_slice_test.rs => group1/slice_test.rs} (100%) rename module/core/reflect_tools/tests/inc/{reflect_struct_in_struct_manual_test.rs => group1/struct_in_struct_manual_test.rs} (100%) rename module/core/reflect_tools/tests/inc/{reflect_struct_manual_test.rs => group1/struct_manual_test.rs} (100%) rename module/core/reflect_tools/tests/inc/{reflect_struct_with_lifetime_manual_test.rs => group1/struct_with_lifetime_manual_test.rs} (100%) rename module/core/reflect_tools/tests/inc/{reflect_vec_test.rs => group1/vec_test.rs} (100%) delete mode 100644 module/move/assistant/src/reflect.rs delete mode 100644 module/move/assistant/src/to_string.rs delete mode 100644 module/move/assistant/src/wrapper_option_cow_ref.rs delete mode 100644 module/move/assistant/src/wrapper_ref.rs diff --git a/module/core/reflect_tools/src/reflect.rs b/module/core/reflect_tools/src/reflect.rs index aded0f2009..872981757c 100644 --- a/module/core/reflect_tools/src/reflect.rs +++ b/module/core/reflect_tools/src/reflect.rs @@ -65,6 +65,10 @@ pub mod entity_hashmap; pub mod entity_hashset; pub mod primitive; +pub mod fields; +pub mod to_string; +pub mod wrapper; + #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use protected::*; @@ -96,6 +100,18 @@ pub mod protected #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::primitive::orphan::*; + + // xxx : add features + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::fields::orphan::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::to_string::orphan::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::wrapper::orphan::*; + // pub use super::private:: // { // }; @@ -136,11 +152,23 @@ pub mod exposed #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::primitive::exposed::*; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::fields::exposed::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::to_string::exposed::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::wrapper::exposed::*; + } /// Prelude to use essentials: `use my_module::prelude::*`. pub mod prelude { + #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::axiomatic::prelude::*; @@ -162,4 +190,15 @@ pub mod prelude #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::primitive::prelude::*; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::fields::prelude::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::to_string::prelude::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::wrapper::prelude::*; + } diff --git a/module/core/reflect_tools/src/reflect/axiomatic.rs b/module/core/reflect_tools/src/reflect/axiomatic.rs index df63730d59..24c9a8ed68 100644 --- a/module/core/reflect_tools/src/reflect/axiomatic.rs +++ b/module/core/reflect_tools/src/reflect/axiomatic.rs @@ -357,7 +357,7 @@ pub( crate ) mod private fn fmt( &self, f: &mut core::fmt::Formatter< '_ > ) -> core::fmt::Result { f - .write_str( &format!( "{}#{:?}", self.type_name(), self.type_id() ) ) + .write_str( &format!( "{}#{:?}", Entity::type_name( self ), self.type_id() ) ) } } @@ -369,7 +369,7 @@ pub( crate ) mod private fn fmt( &self, f: &mut core::fmt::Formatter< '_ > ) -> core::fmt::Result { f - .write_str( &format!( "{}#{:?}", self.type_name(), self.type_id() ) ) + .write_str( &format!( "{}#{:?}", Entity::type_name( self ), self.type_id() ) ) } } @@ -381,7 +381,7 @@ pub( crate ) mod private fn fmt( &self, f: &mut core::fmt::Formatter< '_ > ) -> core::fmt::Result { f - .write_str( &format!( "{}#{:?}", self.type_name(), self.type_id() ) ) + .write_str( &format!( "{}#{:?}", Entity::type_name( self ), self.type_id() ) ) } } diff --git a/module/core/reflect_tools/src/reflect/fields.rs b/module/core/reflect_tools/src/reflect/fields.rs new file mode 100644 index 0000000000..888517f730 --- /dev/null +++ b/module/core/reflect_tools/src/reflect/fields.rs @@ -0,0 +1,131 @@ +//! +//! Iterator over fields. +//! + +/// Internal namespace. +pub( crate ) mod private +{ + + // use core::fmt; + use std::borrow::Cow; + + /// A trait for iterators that are also `ExactSizeIterator`. + pub trait _IteratorTrait + where + Self : core::iter::Iterator + ExactSizeIterator + DoubleEndedIterator + { + } + + impl< T > _IteratorTrait for T + where + Self : core::iter::Iterator + ExactSizeIterator + DoubleEndedIterator + { + } + + /// A trait for iterators that implement `_IteratorTrait` and `Clone`. + pub trait IteratorTrait + where + Self : _IteratorTrait + Clone + { + } + + impl< T > IteratorTrait for T + where + Self : _IteratorTrait + Clone + { + } + + /// A trait for iterating over all fields convertible into a specified type within an entity. + /// + /// # Type Parameters + /// + /// - `K`: The key type. + /// - `E`: The element type. + pub trait Fields< 'a, K, E > + where + E : Clone + 'a, + { + /// Returns an iterator over all fields of the specified type within the entity. + fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, E ) >; + // fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, Option< Cow< 'a, E > > ) >; + } + + // /// Return number of fields convertible into a specified type withing an entity. + // /// + // /// # Type Parameters + // /// + // /// - `E`: The element type. + // /// + // pub trait FieldsLen< E > + // { + // /// Return number of fields convertible into a specified type withing an entity. + // fn len( &self ) -> usize; + // } + + /// Trait returning name of type of variable. + pub trait TypeName + { + /// Return name of type of variable. + fn type_name( &self ) -> &'static str; + } + + impl< T > TypeName for T + where + T : ?Sized, + { + #[ inline( always ) ] + fn type_name( &self ) -> &'static str + { + ::core::any::type_name_of_val( self ) + } + } + + // == implementations for collections + + impl< 'a, T > Fields< 'a, usize, Option< Cow< 'a, T > > > for Vec< T > + where + T : Clone + { + fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Option< Cow< 'a, T > > ) > + { + self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) + } + } + +} + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ +} + +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + _IteratorTrait, + IteratorTrait, + Fields, + TypeName, + }; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/core/reflect_tools/src/reflect/to_string.rs b/module/core/reflect_tools/src/reflect/to_string.rs new file mode 100644 index 0000000000..6ed9c54a55 --- /dev/null +++ b/module/core/reflect_tools/src/reflect/to_string.rs @@ -0,0 +1,224 @@ +//! +//! Flexible ToString augmentation. +//! + +/// Internal namespace. +pub( crate ) mod private +{ + + #[ allow( unused_imports ) ] + use crate:: + { + Ref, + }; + + use std:: + { + fmt, + // collections::HashMap, + // borrow::Cow, + }; + + // == + + /// Marker type for using Debug formatting. + #[ derive( Debug, Default, Clone, Copy ) ] + pub struct WithDebug; + + /// Marker type for using Display formatting. + #[ derive( Debug, Default, Clone, Copy ) ] + pub struct WithDisplay; + + /// Marker type for usign Well formatting. + #[ derive( Debug, Default, Clone, Copy ) ] + pub struct WithWell; + + // == + + /// Marker type for ToStringWithFallback. + #[ derive( Debug, Default, Clone, Copy ) ] + pub struct ToStringWithFallbackParams< How, Fallback >( ::core::marker::PhantomData< fn() -> ( How, Fallback ) > ); + + /// Trait to convert a type to a string with a fallback formatting. + pub trait ToStringWithFallback< How, Fallback > + { + /// Converts the type to a string using the specified formatting or a fallback. + fn to_string_with_fallback( self ) -> String + ; + } + + impl< T, How, Fallback > ToStringWithFallback< How, Fallback > + for Ref< '_, T, ToStringWithFallbackParams< How, Fallback > > + where + T : ToStringWith< Fallback >, + { + /// Converts the type to a string using the specified formatting. + fn to_string_with_fallback( self ) -> String + { + < T as ToStringWith< Fallback > >::to_string_with( self.0 ) + } + } + + impl< T, How, Fallback > ToStringWithFallback< How, Fallback > + for &Ref< '_, T, ToStringWithFallbackParams< How, Fallback > > + where + T : ToStringWith< How >, + { + /// Converts the type to a string using the fallback formatting. + fn to_string_with_fallback( self ) -> String + { + < T as ToStringWith< How > >::to_string_with( self.0 ) + } + } + + // + + /// Macro to convert a value to a string using a specified formatting method with a fallback. + /// + /// # Parameters + /// - `$how`: The primary formatting type (e.g., `WithDebug`, `WithDisplay`). + /// - `$fallback`: The fallback formatting type. + /// - `$src`: The source value to format. + /// + /// # Example + /// ```rust + /// use core::fmt; + /// use reflect_tools:: + /// { + /// WithDebug, + /// WithDisplay, + /// to_string_with_fallback, + /// }; + /// + /// // Define a struct that implements both Debug and Display traits. + /// struct Both; + /// + /// impl fmt::Debug for Both + /// { + /// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + /// { + /// write!( f, "This is debug" ) + /// } + /// } + /// + /// impl fmt::Display for Both + /// { + /// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + /// { + /// write!( f, "This is display" ) + /// } + /// } + /// + /// // Define a struct that implements only the Debug trait. + /// struct OnlyDebug; + /// + /// impl fmt::Debug for OnlyDebug + /// { + /// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + /// { + /// write!( f, "This is debug" ) + /// } + /// } + /// + /// // Example usage: Using Both which implements both Debug and Display. + /// let src = Both; + /// let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); + /// let exp = "This is display".to_string(); + /// // The primary formatting method WithDisplay is used. + /// assert_eq!( got, exp ); + /// + /// // Example usage: Using OnlyDebug which implements only Debug. + /// let src = OnlyDebug; + /// let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); + /// let exp = "This is debug".to_string(); + /// // The primary formatting method WithDisplay is not available, so the fallback WithDebug is used. + /// assert_eq!( got, exp ); + /// ``` + + #[ macro_export( local_inner_macros ) ] + macro_rules! to_string_with_fallback + { + ( $how : ty, $fallback : ty, $src : expr ) + => + {{ + use reflect_tools::ToStringWithFallback; + ( + &reflect_tools::Ref::< '_, _, reflect_tools::ToStringWithFallbackParams< $how, $fallback > >::from( &$src ) + ) + .to_string_with_fallback() + }}; + } + + // == + + /// Trait to convert a type to a string using a specified formatting method. + pub trait ToStringWith< How > + { + /// Converts the type to a string using the specified formatting method. + fn to_string_with( &self ) -> String; + } + + impl< T > ToStringWith< WithDebug > for T + where + T : fmt::Debug, + { + /// Converts the type to a string using Debug formatting. + fn to_string_with( &self ) -> String + { + format!( "{:?}", self ) + } + } + + impl< T > ToStringWith< WithDisplay > for T + where + T : fmt::Display, + { + /// Converts the type to a string using Display formatting. + fn to_string_with( &self ) -> String + { + format!( "{}", self ) + } + } + +} + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ +} + +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + WithDebug, + WithDisplay, + WithWell, + ToStringWithFallbackParams, + ToStringWithFallback, + ToStringWith, + }; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + use crate::to_string_with_fallback; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/core/reflect_tools/src/reflect/wrapper.rs b/module/core/reflect_tools/src/reflect/wrapper.rs new file mode 100644 index 0000000000..4ec4c713b4 --- /dev/null +++ b/module/core/reflect_tools/src/reflect/wrapper.rs @@ -0,0 +1,59 @@ +//! +//! Collection of wrappers. +//! + +/// Internal namespace. +pub( crate ) mod private +{ +} + +pub mod aref; +pub mod maybe_as; + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super:: + { + aref::orphan::*, + maybe_as::orphan::*, + }; +} + +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super:: + { + aref::exposed::*, + maybe_as::exposed::*, + }; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super:: + { + aref::prelude::*, + maybe_as::prelude::*, + }; +} diff --git a/module/core/reflect_tools/src/reflect/wrapper/aref.rs b/module/core/reflect_tools/src/reflect/wrapper/aref.rs new file mode 100644 index 0000000000..6a2320a631 --- /dev/null +++ b/module/core/reflect_tools/src/reflect/wrapper/aref.rs @@ -0,0 +1,155 @@ +//! +//! It's often necessary to wrap something inot a local structure and this file contains a resusable local structure for wrapping. +//! + +/// Internal namespace. +pub( crate ) mod private +{ + + // use core::fmt; + use core::ops::{ Deref }; + + /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. + pub trait IntoRef< 'a, T, Marker > + { + /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. + fn into_ref( self ) -> Ref< 'a, T, Marker >; + } + + impl< 'a, T, Marker > IntoRef< 'a, T, Marker > for &'a T + { + #[ inline( always ) ] + fn into_ref( self ) -> Ref< 'a, T, Marker > + { + Ref::< 'a, T, Marker >::new( self ) + } + } + + /// Transparent reference wrapper emphasizing a specific aspect of identity of its internal type. + #[ allow( missing_debug_implementations ) ] + #[ repr( transparent ) ] + pub struct Ref< 'a, T, Marker >( pub &'a T, ::core::marker::PhantomData< fn() -> Marker > ) + where + ::core::marker::PhantomData< fn( Marker ) > : Copy, + &'a T : Copy, + ; + + impl< 'a, T, Marker > Clone for Ref< 'a, T, Marker > + { + #[ inline( always ) ] + fn clone( &self ) -> Self + { + Self::new( self.0 ) + } + } + + impl< 'a, T, Marker > Copy for Ref< 'a, T, Marker > {} + + impl< 'a, T, Marker > Ref< 'a, T, Marker > + { + + /// Just a constructor. + #[ inline( always ) ] + pub fn new( src : &'a T ) -> Self + { + Self( src, ::core::marker::PhantomData ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn inner( self ) -> &'a T + { + self.0 + } + + } + + impl< 'a, T, Marker > AsRef< T > for Ref< 'a, T, Marker > + { + fn as_ref( &self ) -> &T + { + &self.0 + } + } + + impl< 'a, T, Marker > Deref for Ref< 'a, T, Marker > + { + type Target = T; + fn deref( &self ) -> &Self::Target + { + &self.0 + } + } + + impl< 'a, T, Marker > From< &'a T > for Ref< 'a, T, Marker > + { + fn from( src : &'a T ) -> Self + { + Ref::new( src ) + } + } + + // impl< 'a, T, Marker > From< Ref< 'a, T, Marker > > for &'a T + // { + // fn from( wrapper : Ref< 'a, T, Marker > ) -> &'a T + // { + // wrapper.0 + // } + // } + + // impl< 'a, T, Marker > Default for Ref< 'a, T, Marker > + // where + // T : Default, + // { + // fn default() -> Self + // { + // Ref( &T::default() ) + // } + // } + + // impl< 'a, T, Marker > fmt::Debug for Ref< 'a, T, Marker > + // where + // T : fmt::Debug, + // { + // fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + // { + // f.debug_struct( "Ref" ) + // .field( "0", &self.0 ) + // .finish() + // } + // } + +} + +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ +} + +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + IntoRef, + Ref, + }; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs b/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs new file mode 100644 index 0000000000..3c49576ff1 --- /dev/null +++ b/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs @@ -0,0 +1,291 @@ +//! +//! It's often necessary to wrap something inot a local structure and this file contains wrapper of `Option< Cow< 'a, T > >`. +//! + +/// Internal namespace. +pub( crate ) mod private +{ + + use core::fmt; + use std::borrow::Cow; + use core::ops::{ Deref }; + + /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. + pub trait IntoMaybeAs< 'a, T, Marker > + where + T : Clone, + { + /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. + fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker >; + } + + impl< 'a, T, Marker > IntoMaybeAs< 'a, T, Marker > for T + where + T : Clone, + { + #[ inline( always ) ] + fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker > + { + MaybeAs::< 'a, T, Marker >::new( self ) + } + } + + impl< 'a, T, Marker > IntoMaybeAs< 'a, T, Marker > for &'a T + where + T : Clone, + { + #[ inline( always ) ] + fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker > + { + MaybeAs::< 'a, T, Marker >::new_with_ref( self ) + } + } + + // xxx + // impl< 'a, T, Marker > IntoMaybeAs< 'a, T, Marker > for () + // where + // T : Clone, + // { + // #[ inline( always ) ] + // fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker > + // { + // MaybeAs::< 'a, T, Marker >( None ) + // } + // } + + /// Universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. + #[ repr( transparent ) ] + #[ derive( Clone ) ] + pub struct MaybeAs< 'a, T, Marker >( pub Option< Cow< 'a, T > >, ::core::marker::PhantomData< fn() -> Marker > ) + where + T : Clone, + ; + + impl< 'a, T, Marker > MaybeAs< 'a, T, Marker > + where + T : Clone, + { + + /// Just a constructor. + #[ inline( always ) ] + pub fn none() -> Self + { + Self( None, ::core::marker::PhantomData ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn new( src : T ) -> Self + { + Self( Some( Cow::Owned( src ) ), ::core::marker::PhantomData ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn new_with_ref( src : &'a T ) -> Self + { + Self( Some( Cow::Borrowed( src ) ), ::core::marker::PhantomData ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn new_with_inner( src : Option< Cow< 'a, T > > ) -> Self + { + Self( src, ::core::marker::PhantomData ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn inner( self ) -> Option< Cow< 'a, T > > + { + self.0 + } + + } + + impl< 'a, T, Marker > AsRef< Option< Cow< 'a, T > > > for MaybeAs< 'a, T, Marker > + where + T : Clone, + Self : 'a, + { + fn as_ref( &self ) -> &Option< Cow< 'a, T > > + { + &self.0 + } + } + + impl< 'a, T, Marker > Deref for MaybeAs< 'a, T, Marker > + where + T : Clone, + Marker : 'static, + { + type Target = Option< Cow< 'a, T > >; + fn deref( &self ) -> &Option< Cow< 'a, T > > + { + self.as_ref() + } + } + + // impl< 'a, T, Marker > AsRef< T > for MaybeAs< 'a, T, Marker > + // where + // T : Clone, + // Self : 'a, + // { + // fn as_ref( &self ) -> &'a T + // { + // match &self.0 + // { + // Some( src ) => + // { + // match src + // { + // Cow::Borrowed( src ) => src, + // Cow::Owned( src ) => &src, + // } + // }, + // None => panic!( "MaybeAs is None" ), + // } + // } + // } + // + // impl< 'a, T, Marker > Deref for MaybeAs< 'a, T, Marker > + // where + // T : Clone, + // { + // type Target = T; + // fn deref( &self ) -> &'a T + // { + // self.as_ref() + // } + // } + + impl< 'a, T, Marker > From< T > + for MaybeAs< 'a, T, Marker > + where + T : Clone, + { + fn from( src : T ) -> Self + { + MaybeAs::new( src ) + } + } + + impl< 'a, T, Marker > From< Option< Cow< 'a, T > > > + for MaybeAs< 'a, T, Marker > + where + T : Clone, + { + fn from( src : Option< Cow< 'a, T > > ) -> Self + { + MaybeAs::new_with_inner( src ) + } + } + + impl< 'a, T, Marker > From< &'a T > + for MaybeAs< 'a, T, Marker > + where + T : Clone, + { + fn from( src : &'a T ) -> Self + { + MaybeAs::new_with_ref( src ) + } + } + + // impl< 'a, T, Marker > From< () > for MaybeAs< 'a, T, Marker > + // where + // T : (), + // { + // fn from( src : &'a T ) -> Self + // { + // MaybeAs( None ) + // } + // } + + // xxx : more from + + // impl< 'a, T, Marker > From< MaybeAs< 'a, T, Marker > > for &'a T + // where + // T : Clone, + // { + // fn from( wrapper : MaybeAs< 'a, T, Marker > ) -> &'a T + // { + // wrapper.0 + // } + // } + + impl< 'a, T, Marker > Default for MaybeAs< 'a, T, Marker > + where + T : Clone, + T : Default, + { + fn default() -> Self + { + MaybeAs::new( T::default() ) + } + } + + impl< 'a, T, Marker > fmt::Debug for MaybeAs< 'a, T, Marker > + where + T : fmt::Debug, + T : Clone, + { + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f.debug_struct( "MaybeAs" ) + .field( "0", &self.0 ) + .finish() + } + } + + impl< 'a, T, Marker > PartialEq for MaybeAs< 'a, T, Marker > + where + T : Clone + PartialEq, + { + fn eq( &self, other : &Self ) -> bool + { + self.as_ref() == other.as_ref() + } + } + + impl< 'a, T, Marker > Eq for MaybeAs< 'a, T, Marker > + where + T : Clone + Eq, + { + } + +} + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ +} + +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + IntoMaybeAs, + MaybeAs, + }; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/move/assistant/tests/inc/fields_test.rs b/module/core/reflect_tools/tests/inc/fundamental/fields_test.rs similarity index 99% rename from module/move/assistant/tests/inc/fields_test.rs rename to module/core/reflect_tools/tests/inc/fundamental/fields_test.rs index 0814bd9b01..59e9618665 100644 --- a/module/move/assistant/tests/inc/fields_test.rs +++ b/module/core/reflect_tools/tests/inc/fundamental/fields_test.rs @@ -1,7 +1,7 @@ #[ allow( unused_imports ) ] use super::*; -use assistant:: +use the_module:: { Fields, IteratorTrait, diff --git a/module/move/assistant/tests/inc/to_string_example.rs b/module/core/reflect_tools/tests/inc/fundamental/to_string_example.rs similarity index 91% rename from module/move/assistant/tests/inc/to_string_example.rs rename to module/core/reflect_tools/tests/inc/fundamental/to_string_example.rs index 53fa85452e..7baa368760 100644 --- a/module/move/assistant/tests/inc/to_string_example.rs +++ b/module/core/reflect_tools/tests/inc/fundamental/to_string_example.rs @@ -1,13 +1,14 @@ #[ allow( unused_imports ) ] use super::*; +// xxx : qqq : make example from this test and add also into readme #[ test ] fn exmaple() { use core::fmt; - use assistant:: + use reflect_tools:: { WithDebug, WithDisplay, diff --git a/module/move/assistant/tests/inc/to_string_test.rs b/module/core/reflect_tools/tests/inc/fundamental/to_string_test.rs similarity index 99% rename from module/move/assistant/tests/inc/to_string_test.rs rename to module/core/reflect_tools/tests/inc/fundamental/to_string_test.rs index 2faf19ea96..22f7de14fc 100644 --- a/module/move/assistant/tests/inc/to_string_test.rs +++ b/module/core/reflect_tools/tests/inc/fundamental/to_string_test.rs @@ -1,7 +1,7 @@ #[ allow( unused_imports ) ] use super::*; -use assistant:: +use the_module:: { // Fields, // IteratorTrait, diff --git a/module/core/reflect_tools/tests/inc/reflect_array_test.rs b/module/core/reflect_tools/tests/inc/group1/array_test.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/reflect_array_test.rs rename to module/core/reflect_tools/tests/inc/group1/array_test.rs diff --git a/module/core/reflect_tools/tests/inc/reflect_common_test.rs b/module/core/reflect_tools/tests/inc/group1/common_test.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/reflect_common_test.rs rename to module/core/reflect_tools/tests/inc/group1/common_test.rs diff --git a/module/core/reflect_tools/tests/inc/reflect_hashmap_test.rs b/module/core/reflect_tools/tests/inc/group1/hashmap_test.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/reflect_hashmap_test.rs rename to module/core/reflect_tools/tests/inc/group1/hashmap_test.rs diff --git a/module/core/reflect_tools/tests/inc/reflect_hashset_test.rs b/module/core/reflect_tools/tests/inc/group1/hashset_test.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/reflect_hashset_test.rs rename to module/core/reflect_tools/tests/inc/group1/hashset_test.rs diff --git a/module/core/reflect_tools/tests/inc/newtype_experiment.rs b/module/core/reflect_tools/tests/inc/group1/newtype_experiment.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/newtype_experiment.rs rename to module/core/reflect_tools/tests/inc/group1/newtype_experiment.rs diff --git a/module/core/reflect_tools/tests/inc/only_test/all.rs b/module/core/reflect_tools/tests/inc/group1/only_test/all.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/only_test/all.rs rename to module/core/reflect_tools/tests/inc/group1/only_test/all.rs diff --git a/module/core/reflect_tools/tests/inc/only_test/reflect_struct.rs b/module/core/reflect_tools/tests/inc/group1/only_test/reflect_struct.rs similarity index 90% rename from module/core/reflect_tools/tests/inc/only_test/reflect_struct.rs rename to module/core/reflect_tools/tests/inc/group1/only_test/reflect_struct.rs index 482ad7bf84..9b7dddbb6c 100644 --- a/module/core/reflect_tools/tests/inc/only_test/reflect_struct.rs +++ b/module/core/reflect_tools/tests/inc/group1/only_test/reflect_struct.rs @@ -12,7 +12,7 @@ fn reflect_basic_test() a_id!( reflect::reflect( &ins ).is_container(), true ); a_id!( reflect::reflect( &ins ).len(), 3 ); - a_id!( reflect::reflect( &ins ).type_name(), "tests::inc::reflect_struct_manual_test::Struct1" ); + a_id!( reflect::reflect( &ins ).type_name(), "tests::inc::group1::struct_manual_test::Struct1" ); let names = reflect::reflect( &ins ).elements().map( | e | e.key ).collect::< Vec< _ > >(); a_id!( names, vec![ reflect::Primitive::str( "f1" ), reflect::Primitive::str( "f2" ), reflect::Primitive::str( "f3" ) ] ); let types = reflect::reflect( &ins ).elements().map( | e | e.val.type_name() ).collect::< Vec< _ > >(); diff --git a/module/core/reflect_tools/tests/inc/only_test/reflect_struct_in_struct.rs b/module/core/reflect_tools/tests/inc/group1/only_test/reflect_struct_in_struct.rs similarity index 84% rename from module/core/reflect_tools/tests/inc/only_test/reflect_struct_in_struct.rs rename to module/core/reflect_tools/tests/inc/group1/only_test/reflect_struct_in_struct.rs index 999c924393..83f2cd53f0 100644 --- a/module/core/reflect_tools/tests/inc/only_test/reflect_struct_in_struct.rs +++ b/module/core/reflect_tools/tests/inc/group1/only_test/reflect_struct_in_struct.rs @@ -12,17 +12,17 @@ fn reflect_struct_in_struct() a_id!( reflect::reflect( &ins ).is_container(), true ); a_id!( reflect::reflect( &ins ).len(), 3 ); - a_id!( reflect::reflect( &ins ).type_name(), "tests::inc::reflect_struct_in_struct_manual_test::Struct1" ); + a_id!( reflect::reflect( &ins ).type_name(), "tests::inc::group1::struct_in_struct_manual_test::Struct1" ); let names = reflect::reflect( &ins ).elements().map( | e | e.key ).collect::< Vec< _ > >(); a_id!( names, vec![ reflect::Primitive::str( "f1" ), reflect::Primitive::str( "f2" ), reflect::Primitive::str( "f3" ) ] ); let types = reflect::reflect( &ins ).elements().map( | e | e.val.type_name() ).collect::< Vec< _ > >(); - a_id!( types, vec![ "i32", "alloc::string::String", "tests::inc::reflect_struct_in_struct_manual_test::Struct2" ] ); + a_id!( types, vec![ "i32", "alloc::string::String", "tests::inc::group1::struct_in_struct_manual_test::Struct2" ] ); let f3 = reflect::reflect( &ins ).elements().skip( 2 ).next().unwrap(); a_id!( f3.key, reflect::Primitive::str( "f3" ) ); a_id!( f3.val.is_container(), true ); a_id!( f3.val.len(), 3 ); - a_id!( f3.val.type_name(), "tests::inc::reflect_struct_in_struct_manual_test::Struct2" ); + a_id!( f3.val.type_name(), "tests::inc::group1::struct_in_struct_manual_test::Struct2" ); let names = f3.val.elements().map( | e | e.key ).collect::< Vec< _ > >(); a_id!( names, vec![ reflect::Primitive::str( "s1" ), reflect::Primitive::str( "s2" ), reflect::Primitive::str( "s3" ) ] ); let types = f3.val.elements().map( | e | e.val.type_name() ).collect::< Vec< _ > >(); diff --git a/module/core/reflect_tools/tests/inc/only_test/reflect_struct_with_lifetime.rs b/module/core/reflect_tools/tests/inc/group1/only_test/reflect_struct_with_lifetime.rs similarity index 94% rename from module/core/reflect_tools/tests/inc/only_test/reflect_struct_with_lifetime.rs rename to module/core/reflect_tools/tests/inc/group1/only_test/reflect_struct_with_lifetime.rs index 64fb941938..7a61248a1f 100644 --- a/module/core/reflect_tools/tests/inc/only_test/reflect_struct_with_lifetime.rs +++ b/module/core/reflect_tools/tests/inc/group1/only_test/reflect_struct_with_lifetime.rs @@ -30,7 +30,7 @@ fn reflect_struct_with_lifetime() // inspection of structure a_id!( reflect::reflect( &ins ).is_container(), true ); a_id!( reflect::reflect( &ins ).len(), 3 ); - a_id!( reflect::reflect( &ins ).type_name(), "tests::inc::reflect_struct_with_lifetime_manual_test::Struct1" ); + a_id!( reflect::reflect( &ins ).type_name(), "tests::inc::group1::struct_with_lifetime_manual_test::Struct1" ); a_id!( reflect::reflect( &ins ).type_id(), core::any::TypeId::of::< Struct1< 'static, 'static > >() ); let names = reflect::reflect( &ins ).elements().map( | e | e.key ).collect::< Vec< _ > >(); a_id!( names, vec![ reflect::Primitive::str( "f1" ), reflect::Primitive::str( "f2" ), reflect::Primitive::str( "f3" ) ] ); diff --git a/module/core/reflect_tools/tests/inc/reflect_primitive_test.rs b/module/core/reflect_tools/tests/inc/group1/primitive_test.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/reflect_primitive_test.rs rename to module/core/reflect_tools/tests/inc/group1/primitive_test.rs diff --git a/module/core/reflect_tools/tests/inc/reflect_slice_test.rs b/module/core/reflect_tools/tests/inc/group1/slice_test.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/reflect_slice_test.rs rename to module/core/reflect_tools/tests/inc/group1/slice_test.rs diff --git a/module/core/reflect_tools/tests/inc/reflect_struct_in_struct_manual_test.rs b/module/core/reflect_tools/tests/inc/group1/struct_in_struct_manual_test.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/reflect_struct_in_struct_manual_test.rs rename to module/core/reflect_tools/tests/inc/group1/struct_in_struct_manual_test.rs diff --git a/module/core/reflect_tools/tests/inc/reflect_struct_manual_test.rs b/module/core/reflect_tools/tests/inc/group1/struct_manual_test.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/reflect_struct_manual_test.rs rename to module/core/reflect_tools/tests/inc/group1/struct_manual_test.rs diff --git a/module/core/reflect_tools/tests/inc/reflect_struct_with_lifetime_manual_test.rs b/module/core/reflect_tools/tests/inc/group1/struct_with_lifetime_manual_test.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/reflect_struct_with_lifetime_manual_test.rs rename to module/core/reflect_tools/tests/inc/group1/struct_with_lifetime_manual_test.rs diff --git a/module/core/reflect_tools/tests/inc/reflect_vec_test.rs b/module/core/reflect_tools/tests/inc/group1/vec_test.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/reflect_vec_test.rs rename to module/core/reflect_tools/tests/inc/group1/vec_test.rs diff --git a/module/core/reflect_tools/tests/inc/mod.rs b/module/core/reflect_tools/tests/inc/mod.rs index ba3f3136c9..fd496975cd 100644 --- a/module/core/reflect_tools/tests/inc/mod.rs +++ b/module/core/reflect_tools/tests/inc/mod.rs @@ -2,25 +2,36 @@ use super::*; #[ cfg( feature = "reflect_newtype" ) ] -mod newtype_experiment; +// #[ path = "fundamental" ] +mod fundamental +{ + #[ allow( unused_imports ) ] + use super::*; -#[ cfg( feature = "reflect_reflect" ) ] -mod reflect_common_test; -#[ cfg( feature = "reflect_reflect" ) ] -mod reflect_primitive_test; -#[ cfg( feature = "reflect_reflect" ) ] -mod reflect_struct_manual_test; -#[ cfg( feature = "reflect_reflect" ) ] -mod reflect_struct_in_struct_manual_test; -#[ cfg( feature = "reflect_reflect" ) ] -mod reflect_struct_with_lifetime_manual_test; -#[ cfg( feature = "reflect_reflect" ) ] -mod reflect_slice_test; -#[ cfg( feature = "reflect_reflect" ) ] -mod reflect_vec_test; -#[ cfg( feature = "reflect_reflect" ) ] -mod reflect_hashset_test; -#[ cfg( feature = "reflect_reflect" ) ] -mod reflect_hashmap_test; -#[ cfg( feature = "reflect_reflect" ) ] -mod reflect_array_test; + mod fields_test; + mod to_string_test; + mod to_string_example; + +} + +#[ cfg( feature = "reflect_newtype" ) ] +// #[ path = "group1" ] +mod group1 +{ + #[ allow( unused_imports ) ] + use super::*; + + mod newtype_experiment; + + mod common_test; + mod primitive_test; + mod struct_manual_test; + mod struct_in_struct_manual_test; + mod struct_with_lifetime_manual_test; + mod slice_test; + mod vec_test; + mod hashset_test; + mod hashmap_test; + mod array_test; + +} diff --git a/module/move/assistant/src/reflect.rs b/module/move/assistant/src/reflect.rs deleted file mode 100644 index 26291bb04b..0000000000 --- a/module/move/assistant/src/reflect.rs +++ /dev/null @@ -1,88 +0,0 @@ - -// use core::fmt; -use std::borrow::Cow; - -/// A trait for iterators that are also `ExactSizeIterator`. -pub trait _IteratorTrait -where - Self : core::iter::Iterator + ExactSizeIterator + DoubleEndedIterator -{ -} - -impl< T > _IteratorTrait for T -where - Self : core::iter::Iterator + ExactSizeIterator + DoubleEndedIterator -{ -} - -/// A trait for iterators that implement `_IteratorTrait` and `Clone`. -pub trait IteratorTrait -where - Self : _IteratorTrait + Clone -{ -} - -impl< T > IteratorTrait for T -where - Self : _IteratorTrait + Clone -{ -} - -/// A trait for iterating over all fields convertible into a specified type within an entity. -/// -/// # Type Parameters -/// -/// - `K`: The key type. -/// - `E`: The element type. -pub trait Fields< 'a, K, E > -where - E : Clone + 'a, -{ - /// Returns an iterator over all fields of the specified type within the entity. - fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, E ) >; - // fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, Option< Cow< 'a, E > > ) >; -} - -// /// Return number of fields convertible into a specified type withing an entity. -// /// -// /// # Type Parameters -// /// -// /// - `E`: The element type. -// /// -// pub trait FieldsLen< E > -// { -// /// Return number of fields convertible into a specified type withing an entity. -// fn len( &self ) -> usize; -// } - -/// Trait returning name of type of variable. -pub trait TypeName -{ - /// Return name of type of variable. - fn type_name( &self ) -> &'static str; -} - -impl< T > TypeName for T -where - T : ?Sized, -{ - #[ inline( always ) ] - fn type_name( &self ) -> &'static str - { - ::core::any::type_name_of_val( self ) - } -} - -// == implementations for collections - -impl< 'a, T > Fields< 'a, usize, Option< Cow< 'a, T > > > for Vec< T > -where - T : Clone -{ - fn fields( &'a self ) -> impl IteratorTrait< Item = ( usize, Option< Cow< 'a, T > > ) > - { - self.iter().enumerate().map( | ( key, val ) | ( key, Some( Cow::Borrowed( val ) ) ) ) - } -} - -// == \ No newline at end of file diff --git a/module/move/assistant/src/to_string.rs b/module/move/assistant/src/to_string.rs deleted file mode 100644 index 669fa86f17..0000000000 --- a/module/move/assistant/src/to_string.rs +++ /dev/null @@ -1,170 +0,0 @@ -#[ allow( unused_imports ) ] -use super::*; - -use std:: -{ - fmt, - // collections::HashMap, - // borrow::Cow, -}; - -// == - -/// Marker type for using Debug formatting. -#[ derive( Debug, Default, Clone, Copy ) ] -pub struct WithDebug; - -/// Marker type for using Display formatting. -#[ derive( Debug, Default, Clone, Copy ) ] -pub struct WithDisplay; - -/// Marker type for usign Well formatting. -#[ derive( Debug, Default, Clone, Copy ) ] -pub struct WithWell; - -// == - -/// Marker type for ToStringWithFallback. -#[ derive( Debug, Default, Clone, Copy ) ] -pub struct ToStringWithFallbackParams< How, Fallback >( ::core::marker::PhantomData< fn() -> ( How, Fallback ) > ); - -/// Trait to convert a type to a string with a fallback formatting. -pub trait ToStringWithFallback< How, Fallback > -{ - /// Converts the type to a string using the specified formatting or a fallback. - fn to_string_with_fallback( self ) -> String - ; -} - -impl< T, How, Fallback > ToStringWithFallback< How, Fallback > -for Ref< '_, T, ToStringWithFallbackParams< How, Fallback > > -where - T : ToStringWith< Fallback >, -{ - /// Converts the type to a string using the specified formatting. - fn to_string_with_fallback( self ) -> String - { - < T as ToStringWith< Fallback > >::to_string_with( self.0 ) - } -} - -impl< T, How, Fallback > ToStringWithFallback< How, Fallback > -for &Ref< '_, T, ToStringWithFallbackParams< How, Fallback > > -where - T : ToStringWith< How >, -{ - /// Converts the type to a string using the fallback formatting. - fn to_string_with_fallback( self ) -> String - { - < T as ToStringWith< How > >::to_string_with( self.0 ) - } -} - -// - -/// Macro to convert a value to a string using a specified formatting method with a fallback. -/// -/// # Parameters -/// - `$how`: The primary formatting type (e.g., `WithDebug`, `WithDisplay`). -/// - `$fallback`: The fallback formatting type. -/// - `$src`: The source value to format. -/// -/// # Example -/// ```rust -/// use core::fmt; -/// use assistant:: -/// { -/// WithDebug, -/// WithDisplay, -/// to_string_with_fallback, -/// }; -/// -/// // Define a struct that implements both Debug and Display traits. -/// struct Both; -/// -/// impl fmt::Debug for Both -/// { -/// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result -/// { -/// write!( f, "This is debug" ) -/// } -/// } -/// -/// impl fmt::Display for Both -/// { -/// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result -/// { -/// write!( f, "This is display" ) -/// } -/// } -/// -/// // Define a struct that implements only the Debug trait. -/// struct OnlyDebug; -/// -/// impl fmt::Debug for OnlyDebug -/// { -/// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result -/// { -/// write!( f, "This is debug" ) -/// } -/// } -/// -/// // Example usage: Using Both which implements both Debug and Display. -/// let src = Both; -/// let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); -/// let exp = "This is display".to_string(); -/// // The primary formatting method WithDisplay is used. -/// assert_eq!( got, exp ); -/// -/// // Example usage: Using OnlyDebug which implements only Debug. -/// let src = OnlyDebug; -/// let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); -/// let exp = "This is debug".to_string(); -/// // The primary formatting method WithDisplay is not available, so the fallback WithDebug is used. -/// assert_eq!( got, exp ); -/// ``` - -#[ macro_export( local_inner_macros ) ] -macro_rules! to_string_with_fallback -{ - ( $how : ty, $fallback : ty, $src : expr ) - => - {{ - use assistant::ToStringWithFallback; - ( - &assistant::Ref::< '_, _, assistant::ToStringWithFallbackParams< $how, $fallback > >::from( &$src ) - ) - .to_string_with_fallback() - }}; -} - -// == - -/// Trait to convert a type to a string using a specified formatting method. -pub trait ToStringWith< How > -{ - /// Converts the type to a string using the specified formatting method. - fn to_string_with( &self ) -> String; -} - -impl< T > ToStringWith< WithDebug > for T -where - T : fmt::Debug, -{ - /// Converts the type to a string using Debug formatting. - fn to_string_with( &self ) -> String - { - format!( "{:?}", self ) - } -} - -impl< T > ToStringWith< WithDisplay > for T -where - T : fmt::Display, -{ - /// Converts the type to a string using Display formatting. - fn to_string_with( &self ) -> String - { - format!( "{}", self ) - } -} diff --git a/module/move/assistant/src/wrapper_option_cow_ref.rs b/module/move/assistant/src/wrapper_option_cow_ref.rs deleted file mode 100644 index 0a1d7a0ff5..0000000000 --- a/module/move/assistant/src/wrapper_option_cow_ref.rs +++ /dev/null @@ -1,247 +0,0 @@ -use core::fmt; -use std::borrow::Cow; -use core::ops::{ Deref }; - -/// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. -pub trait IntoOptionCow< 'a, T, Marker > -where - T : Clone, -{ - /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. - fn into_option_cow( self ) -> MaybeAs< 'a, T, Marker >; -} - -impl< 'a, T, Marker > IntoOptionCow< 'a, T, Marker > for T -where - T : Clone, -{ - #[ inline( always ) ] - fn into_option_cow( self ) -> MaybeAs< 'a, T, Marker > - { - MaybeAs::< 'a, T, Marker >::new( self ) - } -} - -impl< 'a, T, Marker > IntoOptionCow< 'a, T, Marker > for &'a T -where - T : Clone, -{ - #[ inline( always ) ] - fn into_option_cow( self ) -> MaybeAs< 'a, T, Marker > - { - MaybeAs::< 'a, T, Marker >::new_with_ref( self ) - } -} - -// xxx -// impl< 'a, T, Marker > IntoOptionCow< 'a, T, Marker > for () -// where -// T : Clone, -// { -// #[ inline( always ) ] -// fn into_option_cow( self ) -> MaybeAs< 'a, T, Marker > -// { -// MaybeAs::< 'a, T, Marker >( None ) -// } -// } - -/// Universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. -#[ repr( transparent ) ] -#[ derive( Clone ) ] -pub struct MaybeAs< 'a, T, Marker >( pub Option< Cow< 'a, T > >, ::core::marker::PhantomData< fn() -> Marker > ) -where - T : Clone, -; - -impl< 'a, T, Marker > MaybeAs< 'a, T, Marker > -where - T : Clone, -{ - - /// Just a constructor. - #[ inline( always ) ] - pub fn none() -> Self - { - Self( None, ::core::marker::PhantomData ) - } - - /// Just a constructor. - #[ inline( always ) ] - pub fn new( src : T ) -> Self - { - Self( Some( Cow::Owned( src ) ), ::core::marker::PhantomData ) - } - - /// Just a constructor. - #[ inline( always ) ] - pub fn new_with_ref( src : &'a T ) -> Self - { - Self( Some( Cow::Borrowed( src ) ), ::core::marker::PhantomData ) - } - - /// Just a constructor. - #[ inline( always ) ] - pub fn new_with_inner( src : Option< Cow< 'a, T > > ) -> Self - { - Self( src, ::core::marker::PhantomData ) - } - - /// Just a constructor. - #[ inline( always ) ] - pub fn inner( self ) -> Option< Cow< 'a, T > > - { - self.0 - } - -} - -impl< 'a, T, Marker > AsRef< Option< Cow< 'a, T > > > for MaybeAs< 'a, T, Marker > -where - T : Clone, - Self : 'a, -{ - fn as_ref( &self ) -> &Option< Cow< 'a, T > > - { - &self.0 - } -} - -impl< 'a, T, Marker > Deref for MaybeAs< 'a, T, Marker > -where - T : Clone, - Marker : 'static, -{ - type Target = Option< Cow< 'a, T > >; - fn deref( &self ) -> &Option< Cow< 'a, T > > - { - self.as_ref() - } -} - -// impl< 'a, T, Marker > AsRef< T > for MaybeAs< 'a, T, Marker > -// where -// T : Clone, -// Self : 'a, -// { -// fn as_ref( &self ) -> &'a T -// { -// match &self.0 -// { -// Some( src ) => -// { -// match src -// { -// Cow::Borrowed( src ) => src, -// Cow::Owned( src ) => &src, -// } -// }, -// None => panic!( "MaybeAs is None" ), -// } -// } -// } -// -// impl< 'a, T, Marker > Deref for MaybeAs< 'a, T, Marker > -// where -// T : Clone, -// { -// type Target = T; -// fn deref( &self ) -> &'a T -// { -// self.as_ref() -// } -// } - -impl< 'a, T, Marker > From< T > -for MaybeAs< 'a, T, Marker > -where - T : Clone, -{ - fn from( src : T ) -> Self - { - MaybeAs::new( src ) - } -} - -impl< 'a, T, Marker > From< Option< Cow< 'a, T > > > -for MaybeAs< 'a, T, Marker > -where - T : Clone, -{ - fn from( src : Option< Cow< 'a, T > > ) -> Self - { - MaybeAs::new_with_inner( src ) - } -} - -impl< 'a, T, Marker > From< &'a T > -for MaybeAs< 'a, T, Marker > -where - T : Clone, -{ - fn from( src : &'a T ) -> Self - { - MaybeAs::new_with_ref( src ) - } -} - -// impl< 'a, T, Marker > From< () > for MaybeAs< 'a, T, Marker > -// where -// T : (), -// { -// fn from( src : &'a T ) -> Self -// { -// MaybeAs( None ) -// } -// } - -// xxx : more from - -// impl< 'a, T, Marker > From< MaybeAs< 'a, T, Marker > > for &'a T -// where -// T : Clone, -// { -// fn from( wrapper : MaybeAs< 'a, T, Marker > ) -> &'a T -// { -// wrapper.0 -// } -// } - -impl< 'a, T, Marker > Default for MaybeAs< 'a, T, Marker > -where - T : Clone, - T : Default, -{ - fn default() -> Self - { - MaybeAs::new( T::default() ) - } -} - -impl< 'a, T, Marker > fmt::Debug for MaybeAs< 'a, T, Marker > -where - T : fmt::Debug, - T : Clone, -{ - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result - { - f.debug_struct( "MaybeAs" ) - .field( "0", &self.0 ) - .finish() - } -} - -impl< 'a, T, Marker > PartialEq for MaybeAs< 'a, T, Marker > -where - T : Clone + PartialEq, -{ - fn eq( &self, other : &Self ) -> bool - { - self.as_ref() == other.as_ref() - } -} - -impl< 'a, T, Marker > Eq for MaybeAs< 'a, T, Marker > -where - T : Clone + Eq, -{ -} diff --git a/module/move/assistant/src/wrapper_ref.rs b/module/move/assistant/src/wrapper_ref.rs deleted file mode 100644 index c90a8e47e1..0000000000 --- a/module/move/assistant/src/wrapper_ref.rs +++ /dev/null @@ -1,112 +0,0 @@ -// use core::fmt; -use core::ops::{ Deref }; - -/// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. -pub trait IntoRef< 'a, T, Marker > -{ - /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. - fn into_ref( self ) -> Ref< 'a, T, Marker >; -} - -impl< 'a, T, Marker > IntoRef< 'a, T, Marker > for &'a T -{ - #[ inline( always ) ] - fn into_ref( self ) -> Ref< 'a, T, Marker > - { - Ref::< 'a, T, Marker >::new( self ) - } -} - -/// Transparent reference wrapper emphasizing a specific aspect of identity of its internal type. -#[ allow( missing_debug_implementations ) ] -#[ repr( transparent ) ] -pub struct Ref< 'a, T, Marker >( pub &'a T, ::core::marker::PhantomData< fn() -> Marker > ) -where - ::core::marker::PhantomData< fn( Marker ) > : Copy, - &'a T : Copy, -; - -impl< 'a, T, Marker > Clone for Ref< 'a, T, Marker > -{ - #[ inline( always ) ] - fn clone( &self ) -> Self - { - Self::new( self.0 ) - } -} - -impl< 'a, T, Marker > Copy for Ref< 'a, T, Marker > {} - -impl< 'a, T, Marker > Ref< 'a, T, Marker > -{ - - /// Just a constructor. - #[ inline( always ) ] - pub fn new( src : &'a T ) -> Self - { - Self( src, ::core::marker::PhantomData ) - } - - /// Just a constructor. - #[ inline( always ) ] - pub fn inner( self ) -> &'a T - { - self.0 - } - -} - -impl< 'a, T, Marker > AsRef< T > for Ref< 'a, T, Marker > -{ - fn as_ref( &self ) -> &T - { - &self.0 - } -} - -impl< 'a, T, Marker > Deref for Ref< 'a, T, Marker > -{ - type Target = T; - fn deref( &self ) -> &Self::Target - { - &self.0 - } -} - -impl< 'a, T, Marker > From< &'a T > for Ref< 'a, T, Marker > -{ - fn from( src : &'a T ) -> Self - { - Ref::new( src ) - } -} - -// impl< 'a, T, Marker > From< Ref< 'a, T, Marker > > for &'a T -// { -// fn from( wrapper : Ref< 'a, T, Marker > ) -> &'a T -// { -// wrapper.0 -// } -// } - -// impl< 'a, T, Marker > Default for Ref< 'a, T, Marker > -// where -// T : Default, -// { -// fn default() -> Self -// { -// Ref( &T::default() ) -// } -// } - -// impl< 'a, T, Marker > fmt::Debug for Ref< 'a, T, Marker > -// where -// T : fmt::Debug, -// { -// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result -// { -// f.debug_struct( "Ref" ) -// .field( "0", &self.0 ) -// .finish() -// } -// } From 3e5e3dccaa526f33ea0d0b37561c30ddf31e0cab Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 20:15:52 +0300 Subject: [PATCH 091/143] assistant: use reflect_tools --- .../reflect_tools/src/reflect/to_string.rs | 3 + .../core/reflect_tools/src/reflect/wrapper.rs | 5 + .../reflect_tools/src/reflect/wrapper/aref.rs | 3 + .../src/reflect/wrapper/maybe_as.rs | 3 + module/move/assistant/Cargo.toml | 2 + module/move/assistant/src/as_table.rs | 357 +++++++++-------- module/move/assistant/src/lib.rs | 158 ++++++-- module/move/assistant/src/print.rs | 368 ++++++++++-------- module/move/assistant/src/table.rs | 282 ++++++++------ module/move/assistant/tests/inc/mod.rs | 3 - 10 files changed, 710 insertions(+), 474 deletions(-) diff --git a/module/core/reflect_tools/src/reflect/to_string.rs b/module/core/reflect_tools/src/reflect/to_string.rs index 6ed9c54a55..47216a1585 100644 --- a/module/core/reflect_tools/src/reflect/to_string.rs +++ b/module/core/reflect_tools/src/reflect/to_string.rs @@ -189,6 +189,9 @@ pub use protected::*; /// Protected namespace of the module. pub mod protected { + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; } /// Orphan namespace of the module. diff --git a/module/core/reflect_tools/src/reflect/wrapper.rs b/module/core/reflect_tools/src/reflect/wrapper.rs index 4ec4c713b4..5a93eb2133 100644 --- a/module/core/reflect_tools/src/reflect/wrapper.rs +++ b/module/core/reflect_tools/src/reflect/wrapper.rs @@ -24,6 +24,11 @@ pub mod protected aref::orphan::*, maybe_as::orphan::*, }; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; + } /// Orphan namespace of the module. diff --git a/module/core/reflect_tools/src/reflect/wrapper/aref.rs b/module/core/reflect_tools/src/reflect/wrapper/aref.rs index 6a2320a631..85060915bb 100644 --- a/module/core/reflect_tools/src/reflect/wrapper/aref.rs +++ b/module/core/reflect_tools/src/reflect/wrapper/aref.rs @@ -127,6 +127,9 @@ pub use protected::*; /// Protected namespace of the module. pub mod protected { + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; } /// Orphan namespace of the module. diff --git a/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs b/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs index 3c49576ff1..1cea6d5f7c 100644 --- a/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs +++ b/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs @@ -263,6 +263,9 @@ pub use protected::*; /// Protected namespace of the module. pub mod protected { + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; } /// Orphan namespace of the module. diff --git a/module/move/assistant/Cargo.toml b/module/move/assistant/Cargo.toml index 3626006c1c..c3475e822a 100644 --- a/module/move/assistant/Cargo.toml +++ b/module/move/assistant/Cargo.toml @@ -29,7 +29,9 @@ full = [ "enabled" ] enabled = [ "former/enabled" ] [dependencies] +# xxx : qqq : optimze features former = { workspace = true, features = [ "full" ] } +reflect_tools = { workspace = true, features = [ "full" ] } openai-api-rs = { version = "4.0.9" } tokio = { version = "1", features = ["full"] } dotenv = "0.15" diff --git a/module/move/assistant/src/as_table.rs b/module/move/assistant/src/as_table.rs index 3de5a57dc4..9708851914 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/move/assistant/src/as_table.rs @@ -1,176 +1,219 @@ -use super::*; -use core::ops::{ Deref }; -use core::marker::PhantomData; -use core::fmt; - -/// Transparent wrapper for table-like structures. -#[ repr( transparent ) ] -#[ derive( Clone, Copy ) ] -pub struct AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -( - &'a T, - ::core::marker::PhantomData< ( &'a (), fn () -> ( RowKey, Row, CellKey, Cell, Title ) ) >, -) -where - // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -; - -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, +/// Internal namespace. +pub( crate ) mod private { - /// Just a constructor. - pub fn new( src : &'a T ) -> Self + + use crate::*; + use core::ops::{ Deref }; + use core::marker::PhantomData; + use core::fmt; + + /// Transparent wrapper for table-like structures. + #[ repr( transparent ) ] + #[ derive( Clone, Copy ) ] + pub struct AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > + ( + &'a T, + ::core::marker::PhantomData< ( &'a (), fn () -> ( RowKey, Row, CellKey, Cell, Title ) ) >, + ) + where + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, + // T : TableSize< 'a >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, + ; + + impl< 'a, T, RowKey, Row, CellKey, Cell, Title > AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > + where + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, + // T : TableSize< 'a >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { - Self( src, Default::default() ) + /// Just a constructor. + pub fn new( src : &'a T ) -> Self + { + Self( src, Default::default() ) + } } -} -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > AsRef< T > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ - fn as_ref( &self ) -> &T + impl< 'a, T, RowKey, Row, CellKey, Cell, Title > AsRef< T > for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > + where + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, + // T : TableSize< 'a >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { - &self.0 + fn as_ref( &self ) -> &T + { + &self.0 + } } -} -// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > AsMut< T > -// for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -// where -// // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, -// // T : TableHeader< 'a, CellKey, Title >, -// // T : TableSize< 'a >, -// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, -// Title : fmt::Debug, -// Cell : fmt::Debug + Clone + 'a, -// CellKey : fmt::Debug + Clone, -// { -// fn as_mut( &mut self ) -> &mut T -// { -// &mut self.0 -// } -// } - -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Deref for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ - type Target = T; + // impl< 'a, T, RowKey, Row, CellKey, Cell, Title > AsMut< T > + // for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > + // where + // // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // // T : TableHeader< 'a, CellKey, Title >, + // // T : TableSize< 'a >, + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, + // CellKey : fmt::Debug + Clone, + // { + // fn as_mut( &mut self ) -> &mut T + // { + // &mut self.0 + // } + // } - fn deref( &self ) -> &Self::Target + impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Deref for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > + where + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, + // T : TableSize< 'a >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { - &self.0 + type Target = T; + + fn deref( &self ) -> &Self::Target + { + &self.0 + } } -} -// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > DerefMut -// for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -// where -// // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, -// // T : TableHeader< 'a, CellKey, Title >, -// // T : TableSize< 'a >, -// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, -// Title : fmt::Debug, -// Cell : fmt::Debug + Clone + 'a, -// CellKey : fmt::Debug + Clone, -// { -// fn deref_mut( &mut self ) -> &mut Self::Target -// { -// &mut self.0 -// } -// } - -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > From< &'a T > -for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ - fn from( table : &'a T ) -> Self + // impl< 'a, T, RowKey, Row, CellKey, Cell, Title > DerefMut + // for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > + // where + // // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // // T : TableHeader< 'a, CellKey, Title >, + // // T : TableSize< 'a >, + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, + // CellKey : fmt::Debug + Clone, + // { + // fn deref_mut( &mut self ) -> &mut Self::Target + // { + // &mut self.0 + // } + // } + + impl< 'a, T, RowKey, Row, CellKey, Cell, Title > From< &'a T > + for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > + where + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, + // T : TableSize< 'a >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, + { + fn from( table : &'a T ) -> Self + { + AsTable( table, PhantomData ) + } + } + + // impl< 'a, T, RowKey, Row, CellKey, Cell, Title > From< AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > > + // for &'a T + // where + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, + // CellKey : fmt::Debug + Clone, + // { + // fn from( wrapper : AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > ) -> &'a T + // { + // wrapper.0 + // } + // } + + // impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Default + // for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > + // where + // T : Default, + // // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // // T : TableHeader< 'a, CellKey, Title >, + // // T : TableSize< 'a >, + // Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + // Title : fmt::Debug, + // Cell : fmt::Debug + Clone + 'a, + // CellKey : fmt::Debug + Clone, + // { + // fn default() -> Self + // { + // AsTable( T::default(), PhantomData ) + // } + // } + + impl< 'a, T, RowKey, Row, CellKey, Cell, Title > fmt::Debug for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > + where + T : fmt::Debug, + // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, + // T : TableHeader< 'a, CellKey, Title >, + // T : TableSize< 'a >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { - AsTable( table, PhantomData ) + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f.debug_struct( "AsTable" ) + .field( "0", &self.0 ) + .finish() + } } + +} + +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; } -// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > From< AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > > -// for &'a T -// where -// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, -// Title : fmt::Debug, -// Cell : fmt::Debug + Clone + 'a, -// CellKey : fmt::Debug + Clone, -// { -// fn from( wrapper : AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > ) -> &'a T -// { -// wrapper.0 -// } -// } - -// impl< 'a, T, RowKey, Row, CellKey, Cell, Title > Default -// for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -// where -// T : Default, -// // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, -// // T : TableHeader< 'a, CellKey, Title >, -// // T : TableSize< 'a >, -// Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, -// Title : fmt::Debug, -// Cell : fmt::Debug + Clone + 'a, -// CellKey : fmt::Debug + Clone, -// { -// fn default() -> Self -// { -// AsTable( T::default(), PhantomData ) -// } -// } - -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > fmt::Debug for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - T : fmt::Debug, - // T : TableRows< 'a, RowKey, Row, CellKey, Cell >, - // T : TableHeader< 'a, CellKey, Title >, - // T : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, +/// Orphan namespace of the module. +pub mod orphan { - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: { - f.debug_struct( "AsTable" ) - .field( "0", &self.0 ) - .finish() - } + AsTable, + }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ } diff --git a/module/move/assistant/src/lib.rs b/module/move/assistant/src/lib.rs index 0a07d15add..38cf5d09e9 100644 --- a/module/move/assistant/src/lib.rs +++ b/module/move/assistant/src/lib.rs @@ -4,54 +4,140 @@ #![ doc( html_root_url = "https://docs.rs/assistant/latest/assistant/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -pub use openai_api_rs::v1:: -{ - api::Client, - assistant::AssistantObject, -}; -use std:: +/// Internal namespace. +pub( crate ) mod private { - env, - error::Error, -}; - -use former::Former; - -/// Reflections. -pub mod reflect; -pub use reflect::*; -/// Universal wrapper. -pub mod wrapper_ref; -pub use wrapper_ref::*; -/// Universal wrapper. -pub mod wrapper_option_cow_ref; -pub use wrapper_option_cow_ref::*; -/// Conversion to string. -pub mod to_string; -pub use to_string::*; + + pub use openai_api_rs::v1:: + { + api::Client, + assistant::AssistantObject, + }; + + use std:: + { + env, + error::Error, + }; + + use former::Former; + + /// Options for configuring the OpenAI API client. + #[ derive( Former, Debug ) ] + pub struct ClientOptions + { + /// The API key for authenticating with the OpenAI API. + pub api_key : Option< String >, + } + + /// Creates a new OpenAI API client using the API key from the environment variable `OPENAI_API_KEY`. + pub fn client() -> Result< Client, Box< dyn Error > > + { + let api_key = env::var( "OPENAI_API_KEY" )?; + Ok( Client::new( api_key ) ) + } + + +} + +// /// Reflections. +// pub mod reflect; +// pub use reflect::*; +// /// Universal wrapper. +// pub mod wrapper_ref; +// pub use wrapper_ref::*; +// /// Universal wrapper. +// pub mod wrapper_option_cow_ref; +// pub use wrapper_option_cow_ref::*; +// /// Conversion to string. +// pub mod to_string; +// pub use to_string::*; /// Nice print. pub mod print; -pub use print::*; +// pub use print::*; /// Nice print's wrapper. pub mod as_table; -pub use as_table::*; +// pub use as_table::*; /// Table interface. pub mod table; -pub use table::*; +// pub use table::*; + +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ -/// Options for configuring the OpenAI API client. -#[ derive( Former, Debug ) ] -pub struct ClientOptions + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super:: + { + print::orphan::*, + as_table::orphan::*, + table::orphan::*, + }; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; + +} + +/// Orphan namespace of the module. +pub mod orphan { - /// The API key for authenticating with the OpenAI API. - pub api_key : Option< String >, + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; } -/// Creates a new OpenAI API client using the API key from the environment variable `OPENAI_API_KEY`. -pub fn client() -> Result< Client, Box< dyn Error > > +/// Exposed namespace of the module. +pub mod exposed { - let api_key = env::var( "OPENAI_API_KEY" )?; - Ok( Client::new( api_key ) ) + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super:: + { + print::exposed::*, + as_table::exposed::*, + table::exposed::*, + }; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + ClientOptions, + client, + AssistantObject, + }; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use reflect_tools:: + { + Fields, + _IteratorTrait, + IteratorTrait, + }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super:: + { + print::prelude::*, + as_table::prelude::*, + table::prelude::*, + }; + } diff --git a/module/move/assistant/src/print.rs b/module/move/assistant/src/print.rs index d4c3a7018c..a9ddc87105 100644 --- a/module/move/assistant/src/print.rs +++ b/module/move/assistant/src/print.rs @@ -1,210 +1,256 @@ -use super::*; -use core::fmt; -use former::Former; +/// Internal namespace. +pub( crate ) mod private +{ -//= + use crate::*; + use core::fmt; + use former::Former; -/// Struct to hold options to print data as table. -#[ derive( Debug, Former ) ] -pub struct Styles -{ - /// Delimiter for separating table columns. - pub separator : String, -} + //= -impl Default for Styles -{ - fn default() -> Self + /// Struct to hold options to print data as table. + #[ derive( Debug, Former ) ] + pub struct Styles { - let separator = " | ".to_string(); - Styles { separator } + /// Delimiter for separating table columns. + pub separator : String, } -} -/// Struct for formatting tables. -pub struct Context< 'a > -{ - buf : &'a mut dyn fmt::Write, - styles : Styles, -} + impl Default for Styles + { + fn default() -> Self + { + let separator = " | ".to_string(); + Styles { separator } + } + } -impl< 'a > Context< 'a > -{ - /// Just constructr. - pub fn new( buf : &'a mut dyn fmt::Write, styles : Styles ) -> Self + /// Struct for formatting tables. + pub struct Context< 'a > { - Self { buf, styles } + buf : &'a mut dyn fmt::Write, + styles : Styles, } -} -impl fmt::Debug for Context< '_ > -{ - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + impl< 'a > Context< 'a > { - f - .debug_struct( "Context" ) - .field( "buf", &"dyn fmt::Write" ) - .field( "styles", &self.styles ) - .finish() + /// Just constructr. + pub fn new( buf : &'a mut dyn fmt::Write, styles : Styles ) -> Self + { + Self { buf, styles } + } } -} -/// A trait for converting tables to a string representation. -pub trait TableToString< 'a > -{ - /// Converts the table to a string representation. - /// - /// # Returns - /// - /// A `String` containing the formatted table. - fn table_to_string( &'a self ) -> String; -} + impl fmt::Debug for Context< '_ > + { + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f + .debug_struct( "Context" ) + .field( "buf", &"dyn fmt::Write" ) + .field( "styles", &self.styles ) + .finish() + } + } -impl< 'a, T > TableToString< 'a > for T -where - T : TableFormatter< 'a > -{ - fn table_to_string( &'a self ) -> String + /// A trait for converting tables to a string representation. + pub trait TableToString< 'a > { - let mut output = String::new(); - let mut formatter = Context + /// Converts the table to a string representation. + /// + /// # Returns + /// + /// A `String` containing the formatted table. + fn table_to_string( &'a self ) -> String; + } + + impl< 'a, T > TableToString< 'a > for T + where + T : TableFormatter< 'a > + { + fn table_to_string( &'a self ) -> String { - buf : &mut output, - styles : Styles::default(), - }; - T::fmt( self, &mut formatter ).expect( "Formatting failed" ); - output + let mut output = String::new(); + let mut formatter = Context + { + buf : &mut output, + styles : Styles::default(), + }; + T::fmt( self, &mut formatter ).expect( "Formatting failed" ); + output + } } -} -/// A trait for formatting tables. -/// -/// This trait defines a method for formatting tables, allowing implementations -/// to specify how a table should be formatted and displayed. -/// + /// A trait for formatting tables. + /// + /// This trait defines a method for formatting tables, allowing implementations + /// to specify how a table should be formatted and displayed. + /// -pub trait TableFormatter< 'b > -{ - /// Formats the table and writes the result to the given formatter. - fn fmt< 'a >( &'b self, f : &mut Context< 'a > ) -> fmt::Result; -} + pub trait TableFormatter< 'b > + { + /// Formats the table and writes the result to the given formatter. + fn fmt< 'a >( &'b self, f : &mut Context< 'a > ) -> fmt::Result; + } -/// A trait for formatting tables. -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableFormatter< 'a > -for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, - Self : TableHeader< 'a, CellKey, Title >, - Self : TableSize< 'a >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ - fn fmt( &'a self, f : &mut Context< '_ > ) -> fmt::Result + /// A trait for formatting tables. + impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableFormatter< 'a > + for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > + where + Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, + Self : TableHeader< 'a, CellKey, Title >, + Self : TableSize< 'a >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { - let table_size = self.table_size(); - let mut col_widths : Vec< usize > = vec![ 0 ; table_size[ 1 ] ]; - let separator = &f.styles.separator; + fn fmt( &'a self, f : &mut Context< '_ > ) -> fmt::Result + { + let table_size = self.table_size(); + let mut col_widths : Vec< usize > = vec![ 0 ; table_size[ 1 ] ]; + let separator = &f.styles.separator; - // println!( "{}", self.header().is_some() ); + // println!( "{}", self.header().is_some() ); - if let Some( header ) = self.header() - { - let mut i = 0; - for ( _key, title ) in header + if let Some( header ) = self.header() { - col_widths[ i ] = format!( "{:?}", title ).len(); - i += 1; + let mut i = 0; + for ( _key, title ) in header + { + col_widths[ i ] = format!( "{:?}", title ).len(); + i += 1; + } + writeln!( f.buf )?; } - writeln!( f.buf )?; - } - // dbg!( &col_widths ); + // dbg!( &col_widths ); - // Collect rows - let mut all_rows : Vec< Vec< String > > = Vec::new(); - for row in self.rows() - { - let fields : Vec< String > = row - .cells() - .map - ( - | ( _key, cell ) | - { - match cell + // Collect rows + let mut all_rows : Vec< Vec< String > > = Vec::new(); + for row in self.rows() + { + let fields : Vec< String > = row + .cells() + .map + ( + | ( _key, cell ) | { - Some( cell ) => format!( "{:?}", &cell ), - None => "".to_string(), + match cell + { + Some( cell ) => format!( "{:?}", &cell ), + None => "".to_string(), + } } - } - ) - .collect(); - all_rows.push( fields ); - } + ) + .collect(); + all_rows.push( fields ); + } - for row in &all_rows - { - for ( i, cell ) in row.iter().enumerate() + for row in &all_rows { - if col_widths.len() <= i + for ( i, cell ) in row.iter().enumerate() { - col_widths.push( cell.len() ); - } - else if cell.len() > col_widths[ i ] - { - col_widths[ i ] = cell.len(); + if col_widths.len() <= i + { + col_widths.push( cell.len() ); + } + else if cell.len() > col_widths[ i ] + { + col_widths[ i ] = cell.len(); + } } } - } - // Write the header if provided - if let Some( header ) = self.header() - { - let mut i = 0; - for ( _key, title ) in header + // Write the header if provided + if let Some( header ) = self.header() { - if i > 0 + let mut i = 0; + for ( _key, title ) in header { - write!( f.buf, "{}", separator )?; + if i > 0 + { + write!( f.buf, "{}", separator )?; + } + write!( f.buf, "{:^width$}", format!( "{:?}", title ), width = col_widths[ i ] )?; + // write!( f.buf, "{:?}", title )?; + i += 1; } - write!( f.buf, "{:^width$}", format!( "{:?}", title ), width = col_widths[ i ] )?; - // write!( f.buf, "{:?}", title )?; - i += 1; + writeln!( f.buf )?; } - writeln!( f.buf )?; - } - // dbg!( &col_widths ); + // dbg!( &col_widths ); - // Write rows with proper alignment - for row in &all_rows - { - let mut i = 0; - for cell in row + // Write rows with proper alignment + for row in &all_rows { - if i > 0 + let mut i = 0; + for cell in row { - write!( f.buf, "{}", separator )?; + if i > 0 + { + write!( f.buf, "{}", separator )?; + } + write!( f.buf, "{:^width$}", cell, width = col_widths[ i ] )?; + i += 1; } - write!( f.buf, "{:^width$}", cell, width = col_widths[ i ] )?; - i += 1; + writeln!( f.buf )?; } - writeln!( f.buf )?; - } - // // Write rows with proper alignment - // for row in all_rows - // { - // let formatted_row : Vec< String > = row - // .iter() - // .enumerate() - // .map( | ( i, cell ) | format!( "{:?^width$}", cell, width = col_widths[ i ] ) ) - // .collect(); - // writeln!( f.buf, "{}", formatted_row.join( separator ) )?; - // } - - Ok(()) + // // Write rows with proper alignment + // for row in all_rows + // { + // let formatted_row : Vec< String > = row + // .iter() + // .enumerate() + // .map( | ( i, cell ) | format!( "{:?^width$}", cell, width = col_widths[ i ] ) ) + // .collect(); + // writeln!( f.buf, "{}", formatted_row.join( separator ) )?; + // } + + Ok(()) + } } + +} + +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; +} + +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + Styles, + Context, + TableFormatter, + TableToString, + }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ } diff --git a/module/move/assistant/src/table.rs b/module/move/assistant/src/table.rs index 62a0e4e5ac..5d70946794 100644 --- a/module/move/assistant/src/table.rs +++ b/module/move/assistant/src/table.rs @@ -1,153 +1,201 @@ +/// Internal namespace. +pub( crate ) mod private +{ -use super::*; -use core::fmt; -use std::borrow::Cow; + use crate::*; + use core::fmt; + use std::borrow::Cow; + use reflect_tools:: + { + IteratorTrait, + Fields, + }; -// == + // == -/// A trait for iterating over all rows of a table. -pub trait TableSize< 'a > -{ - /// Returns size of a table. - fn table_size( &'a self ) -> [ usize ; 2 ]; -} + /// A trait for iterating over all rows of a table. + pub trait TableSize< 'a > + { + /// Returns size of a table. + fn table_size( &'a self ) -> [ usize ; 2 ]; + } -/// A trait for iterating over all rows of a table. -pub trait TableRows< 'a, RowKey, Row, CellKey, Cell > -where - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Cell : fmt::Debug + Clone + 'a, -{ - /// Returns an iterator over all rows of the table. - fn rows( &'a self ) -> impl IteratorTrait< Item = Row >; -} + /// A trait for iterating over all rows of a table. + pub trait TableRows< 'a, RowKey, Row, CellKey, Cell > + where + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Cell : fmt::Debug + Clone + 'a, + { + /// Returns an iterator over all rows of the table. + fn rows( &'a self ) -> impl IteratorTrait< Item = Row >; + } -/// Trait returning headers of a table if any. -pub trait TableHeader< 'a, CellKey, Title > -where - Title : fmt::Debug, -{ - /// Returns an iterator over all fields of the specified type within the entity. - fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, Title ) > >; -} + /// Trait returning headers of a table if any. + pub trait TableHeader< 'a, CellKey, Title > + where + Title : fmt::Debug, + { + /// Returns an iterator over all fields of the specified type within the entity. + fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, Title ) > >; + } -/// A trait for iterating over all cells of a row. -pub trait Cells< 'a, CellKey, Cell > -where - Cell : fmt::Debug + Clone + 'a, -{ - /// Returns an iterator over all cells of the row. - fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Option< Cell > ) > - ; -} + /// A trait for iterating over all cells of a row. + pub trait Cells< 'a, CellKey, Cell > + where + Cell : fmt::Debug + Clone + 'a, + { + /// Returns an iterator over all cells of the row. + fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Option< Cell > ) > + ; + } -// == + // == -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableSize< 'a > -for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ - fn table_size( &'a self ) -> [ usize ; 2 ] + impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableSize< 'a > + for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > + where + Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { - let mut rows = self.rows(); - let nrows = rows.len(); - let row = rows.next(); - if let Some( row ) = row + fn table_size( &'a self ) -> [ usize ; 2 ] { - let ncells = row.cells().len(); - [ nrows, ncells ] + let mut rows = self.rows(); + let nrows = rows.len(); + let row = rows.next(); + if let Some( row ) = row + { + let ncells = row.cells().len(); + [ nrows, ncells ] + } + else + { + [ 0, 0 ] + } } - else + } + + impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableRows< 'a, RowKey, Row, CellKey, Cell > + for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > + where + T : Fields< 'a, RowKey, Option< Cow< 'a, Row > > >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + Title : fmt::Debug, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, + { + + fn rows( &'a self ) -> impl IteratorTrait< Item = Row > { - [ 0, 0 ] + self.as_ref().fields().filter_map( move | ( _k, e ) | + { + match e + { + Some( e ) => Some( e.into_owned() ), + None => None, + } + }).collect::< Vec< _ > >().into_iter() } - } -} -impl< 'a, T, RowKey, Row, CellKey, Cell, Title > TableRows< 'a, RowKey, Row, CellKey, Cell > -for AsTable< 'a, T, RowKey, Row, CellKey, Cell, Title > -where - T : Fields< 'a, RowKey, Option< Cow< 'a, Row > > >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - Title : fmt::Debug, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ + } - fn rows( &'a self ) -> impl IteratorTrait< Item = Row > + impl< 'a, T, RowKey, Row, CellKey, Cell > TableHeader< 'a, CellKey, CellKey > + for AsTable< 'a, T, RowKey, Row, CellKey, Cell, CellKey > + where + Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, + Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, + CellKey : fmt::Debug + Clone, + Cell : fmt::Debug + Clone + 'a, + CellKey : fmt::Debug + Clone, { - self.as_ref().fields().filter_map( move | ( _k, e ) | + + fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, CellKey ) > > { - match e + let mut rows = self.rows(); + let row = rows.next(); + if let Some( row ) = row { - Some( e ) => Some( e.into_owned() ), - None => None, + Some + ( + row + .cells() + .map( | ( key, _title ) | ( key.clone(), key ) ) + .collect::< Vec< _ > >() + .into_iter() + ) } - }).collect::< Vec< _ > >().into_iter() - } - -} + else + { + None + } + } -impl< 'a, T, RowKey, Row, CellKey, Cell > TableHeader< 'a, CellKey, CellKey > -for AsTable< 'a, T, RowKey, Row, CellKey, Cell, CellKey > -where - Self : TableRows< 'a, RowKey, Row, CellKey, Cell >, - Row : Clone + for< 'cell > Cells< 'cell, CellKey, Cell > + 'a, - CellKey : fmt::Debug + Clone, - Cell : fmt::Debug + Clone + 'a, - CellKey : fmt::Debug + Clone, -{ + } - fn header( &'a self ) -> Option< impl IteratorTrait< Item = ( CellKey, CellKey ) > > + impl< 'a, Row, CellKey, Cell > Cells< 'a, CellKey, Cell > + for Row + where + Row : Fields< 'a, CellKey, Option< Cow< 'a, Cell > > > + 'a, + Cell : fmt::Debug + Clone + 'a, { - let mut rows = self.rows(); - let row = rows.next(); - if let Some( row ) = row + + fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Option< Cell > ) > { - Some + self.fields().map ( - row - .cells() - .map( | ( key, _title ) | ( key.clone(), key ) ) - .collect::< Vec< _ > >() - .into_iter() + move | ( key, cell ) | + { + match cell + { + Some( cell ) => ( key, Some( cell.into_owned() ) ), + None => ( key, None ) + } + } ) } - else - { - None - } + } } -impl< 'a, Row, CellKey, Cell > Cells< 'a, CellKey, Cell > -for Row -where - Row : Fields< 'a, CellKey, Option< Cow< 'a, Cell > > > + 'a, - Cell : fmt::Debug + Clone + 'a, +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; +} + +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed { - fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Option< Cell > ) > + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: { - self.fields().map - ( - move | ( key, cell ) | - { - match cell - { - Some( cell ) => ( key, Some( cell.into_owned() ) ), - None => ( key, None ) - } - } - ) - } + TableSize, + TableRows, + TableHeader, + Cells, + }; } -// == +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/move/assistant/tests/inc/mod.rs b/module/move/assistant/tests/inc/mod.rs index 3a22b49591..32cb24ce64 100644 --- a/module/move/assistant/tests/inc/mod.rs +++ b/module/move/assistant/tests/inc/mod.rs @@ -1,9 +1,6 @@ #[ allow( unused_imports ) ] use super::*; -mod fields_test; mod print_test; -mod to_string_test; -mod to_string_example; mod experiment; From 19e38b663675633c331b98c809cb6f9ff535748b Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 20:40:09 +0300 Subject: [PATCH 092/143] reflect_tools: refactor to_string code --- module/core/reflect_tools/src/reflect.rs | 10 + .../reflect_tools/src/reflect/to_string.rs | 129 ------ .../src/reflect/to_string_with_fallback.rs | 173 +++++++ .../reflect/to_string_with_fallback/aref.rs | 116 +++++ .../reflect/to_string_with_fallback/params.rs | 7 + .../core/reflect_tools/src/reflect/wrapper.rs | 26 +- .../reflect_tools/src/reflect/wrapper/aref.rs | 206 ++++----- .../src/reflect/wrapper/maybe_as.rs | 431 ++++++++---------- .../tests/inc/fundamental/to_string_test.rs | 154 +------ .../to_string_with_fallback_test.rs | 161 +++++++ module/core/reflect_tools/tests/inc/mod.rs | 1 + 11 files changed, 754 insertions(+), 660 deletions(-) create mode 100644 module/core/reflect_tools/src/reflect/to_string_with_fallback.rs create mode 100644 module/core/reflect_tools/src/reflect/to_string_with_fallback/aref.rs create mode 100644 module/core/reflect_tools/src/reflect/to_string_with_fallback/params.rs create mode 100644 module/core/reflect_tools/tests/inc/fundamental/to_string_with_fallback_test.rs diff --git a/module/core/reflect_tools/src/reflect.rs b/module/core/reflect_tools/src/reflect.rs index 872981757c..325fa5af21 100644 --- a/module/core/reflect_tools/src/reflect.rs +++ b/module/core/reflect_tools/src/reflect.rs @@ -67,6 +67,7 @@ pub mod primitive; pub mod fields; pub mod to_string; +pub mod to_string_with_fallback; pub mod wrapper; #[ doc( inline ) ] @@ -110,6 +111,9 @@ pub mod protected pub use super::to_string::orphan::*; #[ doc( inline ) ] #[ allow( unused_imports ) ] + pub use super::to_string_with_fallback::orphan::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] pub use super::wrapper::orphan::*; // pub use super::private:: @@ -161,6 +165,9 @@ pub mod exposed pub use super::to_string::exposed::*; #[ doc( inline ) ] #[ allow( unused_imports ) ] + pub use super::to_string_with_fallback::exposed::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] pub use super::wrapper::exposed::*; } @@ -199,6 +206,9 @@ pub mod prelude pub use super::to_string::prelude::*; #[ doc( inline ) ] #[ allow( unused_imports ) ] + pub use super::to_string_with_fallback::prelude::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] pub use super::wrapper::prelude::*; } diff --git a/module/core/reflect_tools/src/reflect/to_string.rs b/module/core/reflect_tools/src/reflect/to_string.rs index 47216a1585..7b6dad85b3 100644 --- a/module/core/reflect_tools/src/reflect/to_string.rs +++ b/module/core/reflect_tools/src/reflect/to_string.rs @@ -6,17 +6,9 @@ pub( crate ) mod private { - #[ allow( unused_imports ) ] - use crate:: - { - Ref, - }; - use std:: { fmt, - // collections::HashMap, - // borrow::Cow, }; // == @@ -35,122 +27,6 @@ pub( crate ) mod private // == - /// Marker type for ToStringWithFallback. - #[ derive( Debug, Default, Clone, Copy ) ] - pub struct ToStringWithFallbackParams< How, Fallback >( ::core::marker::PhantomData< fn() -> ( How, Fallback ) > ); - - /// Trait to convert a type to a string with a fallback formatting. - pub trait ToStringWithFallback< How, Fallback > - { - /// Converts the type to a string using the specified formatting or a fallback. - fn to_string_with_fallback( self ) -> String - ; - } - - impl< T, How, Fallback > ToStringWithFallback< How, Fallback > - for Ref< '_, T, ToStringWithFallbackParams< How, Fallback > > - where - T : ToStringWith< Fallback >, - { - /// Converts the type to a string using the specified formatting. - fn to_string_with_fallback( self ) -> String - { - < T as ToStringWith< Fallback > >::to_string_with( self.0 ) - } - } - - impl< T, How, Fallback > ToStringWithFallback< How, Fallback > - for &Ref< '_, T, ToStringWithFallbackParams< How, Fallback > > - where - T : ToStringWith< How >, - { - /// Converts the type to a string using the fallback formatting. - fn to_string_with_fallback( self ) -> String - { - < T as ToStringWith< How > >::to_string_with( self.0 ) - } - } - - // - - /// Macro to convert a value to a string using a specified formatting method with a fallback. - /// - /// # Parameters - /// - `$how`: The primary formatting type (e.g., `WithDebug`, `WithDisplay`). - /// - `$fallback`: The fallback formatting type. - /// - `$src`: The source value to format. - /// - /// # Example - /// ```rust - /// use core::fmt; - /// use reflect_tools:: - /// { - /// WithDebug, - /// WithDisplay, - /// to_string_with_fallback, - /// }; - /// - /// // Define a struct that implements both Debug and Display traits. - /// struct Both; - /// - /// impl fmt::Debug for Both - /// { - /// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result - /// { - /// write!( f, "This is debug" ) - /// } - /// } - /// - /// impl fmt::Display for Both - /// { - /// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result - /// { - /// write!( f, "This is display" ) - /// } - /// } - /// - /// // Define a struct that implements only the Debug trait. - /// struct OnlyDebug; - /// - /// impl fmt::Debug for OnlyDebug - /// { - /// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result - /// { - /// write!( f, "This is debug" ) - /// } - /// } - /// - /// // Example usage: Using Both which implements both Debug and Display. - /// let src = Both; - /// let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); - /// let exp = "This is display".to_string(); - /// // The primary formatting method WithDisplay is used. - /// assert_eq!( got, exp ); - /// - /// // Example usage: Using OnlyDebug which implements only Debug. - /// let src = OnlyDebug; - /// let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); - /// let exp = "This is debug".to_string(); - /// // The primary formatting method WithDisplay is not available, so the fallback WithDebug is used. - /// assert_eq!( got, exp ); - /// ``` - - #[ macro_export( local_inner_macros ) ] - macro_rules! to_string_with_fallback - { - ( $how : ty, $fallback : ty, $src : expr ) - => - {{ - use reflect_tools::ToStringWithFallback; - ( - &reflect_tools::Ref::< '_, _, reflect_tools::ToStringWithFallbackParams< $how, $fallback > >::from( &$src ) - ) - .to_string_with_fallback() - }}; - } - - // == - /// Trait to convert a type to a string using a specified formatting method. pub trait ToStringWith< How > { @@ -212,13 +88,8 @@ pub mod exposed WithDebug, WithDisplay, WithWell, - ToStringWithFallbackParams, - ToStringWithFallback, ToStringWith, }; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - use crate::to_string_with_fallback; } /// Prelude to use essentials: `use my_module::prelude::*`. diff --git a/module/core/reflect_tools/src/reflect/to_string_with_fallback.rs b/module/core/reflect_tools/src/reflect/to_string_with_fallback.rs new file mode 100644 index 0000000000..c572b1c4e1 --- /dev/null +++ b/module/core/reflect_tools/src/reflect/to_string_with_fallback.rs @@ -0,0 +1,173 @@ +//! +//! Flexible ToString augmentation. +//! + +/// Internal namespace. +pub( crate ) mod private +{ + + pub use super:: + { + aref::ToStringWithFallbackRef, + params::ToStringWithFallbackParams, + }; + + use crate::ToStringWith; + + // == + + /// Trait to convert a type to a string with a fallback formatting. + pub trait _ToStringWithFallback< How, Fallback > + { + /// Converts the type to a string using the specified formatting or a fallback. + fn to_string_with_fallback( self ) -> String + ; + } + + impl< T, How, Fallback > _ToStringWithFallback< How, Fallback > + for ToStringWithFallbackRef< '_, T, ToStringWithFallbackParams< How, Fallback > > + where + T : ToStringWith< Fallback >, + { + /// Converts the type to a string using the specified formatting. + fn to_string_with_fallback( self ) -> String + { + < T as ToStringWith< Fallback > >::to_string_with( self.0 ) + } + } + + impl< T, How, Fallback > _ToStringWithFallback< How, Fallback > + for &ToStringWithFallbackRef< '_, T, ToStringWithFallbackParams< How, Fallback > > + where + T : ToStringWith< How >, + { + /// Converts the type to a string using the fallback formatting. + fn to_string_with_fallback( self ) -> String + { + < T as ToStringWith< How > >::to_string_with( self.0 ) + } + } + + // + + /// Macro to convert a value to a string using a specified formatting method with a fallback. + /// + /// # Parameters + /// - `$how`: The primary formatting type (e.g., `WithDebug`, `WithDisplay`). + /// - `$fallback`: The fallback formatting type. + /// - `$src`: The source value to format. + /// + /// # Example + /// ```rust + /// use core::fmt; + /// use reflect_tools:: + /// { + /// WithDebug, + /// WithDisplay, + /// to_string_with_fallback, + /// }; + /// + /// // Define a struct that implements both Debug and Display traits. + /// struct Both; + /// + /// impl fmt::Debug for Both + /// { + /// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + /// { + /// write!( f, "This is debug" ) + /// } + /// } + /// + /// impl fmt::Display for Both + /// { + /// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + /// { + /// write!( f, "This is display" ) + /// } + /// } + /// + /// // Define a struct that implements only the Debug trait. + /// struct OnlyDebug; + /// + /// impl fmt::Debug for OnlyDebug + /// { + /// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + /// { + /// write!( f, "This is debug" ) + /// } + /// } + /// + /// // Example usage: Using Both which implements both Debug and Display. + /// let src = Both; + /// let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); + /// let exp = "This is display".to_string(); + /// // The primary formatting method WithDisplay is used. + /// assert_eq!( got, exp ); + /// + /// // Example usage: Using OnlyDebug which implements only Debug. + /// let src = OnlyDebug; + /// let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); + /// let exp = "This is debug".to_string(); + /// // The primary formatting method WithDisplay is not available, so the fallback WithDebug is used. + /// assert_eq!( got, exp ); + /// ``` + + #[ macro_export( local_inner_macros ) ] + macro_rules! to_string_with_fallback + { + ( $how : ty, $fallback : ty, $src : expr ) + => + {{ + use reflect_tools::_ToStringWithFallback; + ( + &reflect_tools::ToStringWithFallbackRef::< '_, _, reflect_tools::ToStringWithFallbackParams< $how, $fallback > >::from( &$src ) + ) + .to_string_with_fallback() + }}; + } + +} + +mod aref; +mod params; + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; +} + +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + ToStringWithFallbackRef, + ToStringWithFallbackParams, + _ToStringWithFallback, + }; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + use crate::to_string_with_fallback; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/core/reflect_tools/src/reflect/to_string_with_fallback/aref.rs b/module/core/reflect_tools/src/reflect/to_string_with_fallback/aref.rs new file mode 100644 index 0000000000..d1d29345cd --- /dev/null +++ b/module/core/reflect_tools/src/reflect/to_string_with_fallback/aref.rs @@ -0,0 +1,116 @@ +//! +//! Wrapper to wrap argument for trait `_ToStringWithFallback`. +//! + +// use core::fmt; +use core::ops::{ Deref }; + +// /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. +// pub trait ToStringWithFallbackRef< 'a, T, Marker > +// { +// /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. +// fn into_string_with_fallback_ref( self ) -> ToStringWithFallbackRef< 'a, T, Marker >; +// } +// +// impl< 'a, T, Marker > ToStringWithFallbackRef< 'a, T, Marker > for &'a T +// { +// #[ inline( always ) ] +// fn into_string_with_fallback_ref( self ) -> ToStringWithFallbackRef< 'a, T, Marker > +// { +// ToStringWithFallbackRef::< 'a, T, Marker >::new( self ) +// } +// } + +/// Transparent reference wrapper emphasizing a specific aspect of identity of its internal type. +#[ allow( missing_debug_implementations ) ] +#[ repr( transparent ) ] +pub struct ToStringWithFallbackRef< 'a, T, Marker >( pub &'a T, ::core::marker::PhantomData< fn() -> Marker > ) +where + ::core::marker::PhantomData< fn( Marker ) > : Copy, + &'a T : Copy, +; + +impl< 'a, T, Marker > Clone for ToStringWithFallbackRef< 'a, T, Marker > +{ + #[ inline( always ) ] + fn clone( &self ) -> Self + { + Self::new( self.0 ) + } +} + +impl< 'a, T, Marker > Copy for ToStringWithFallbackRef< 'a, T, Marker > {} + +impl< 'a, T, Marker > ToStringWithFallbackRef< 'a, T, Marker > +{ + + /// Just a constructor. + #[ inline( always ) ] + pub fn new( src : &'a T ) -> Self + { + Self( src, ::core::marker::PhantomData ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn inner( self ) -> &'a T + { + self.0 + } + +} + +impl< 'a, T, Marker > AsRef< T > for ToStringWithFallbackRef< 'a, T, Marker > +{ + fn as_ref( &self ) -> &T + { + &self.0 + } +} + +impl< 'a, T, Marker > Deref for ToStringWithFallbackRef< 'a, T, Marker > +{ + type Target = T; + fn deref( &self ) -> &Self::Target + { + &self.0 + } +} + +impl< 'a, T, Marker > From< &'a T > for ToStringWithFallbackRef< 'a, T, Marker > +{ + fn from( src : &'a T ) -> Self + { + ToStringWithFallbackRef::new( src ) + } +} + +// impl< 'a, T, Marker > From< ToStringWithFallbackRef< 'a, T, Marker > > for &'a T +// { +// fn from( wrapper : ToStringWithFallbackRef< 'a, T, Marker > ) -> &'a T +// { +// wrapper.0 +// } +// } + +// impl< 'a, T, Marker > Default for ToStringWithFallbackRef< 'a, T, Marker > +// where +// T : Default, +// { +// fn default() -> Self +// { +// ToStringWithFallbackRef( &T::default() ) +// } +// } + +// impl< 'a, T, Marker > fmt::Debug for ToStringWithFallbackRef< 'a, T, Marker > +// where +// T : fmt::Debug, +// { +// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result +// { +// f.debug_struct( "ToStringWithFallbackRef" ) +// .field( "0", &self.0 ) +// .finish() +// } +// } diff --git a/module/core/reflect_tools/src/reflect/to_string_with_fallback/params.rs b/module/core/reflect_tools/src/reflect/to_string_with_fallback/params.rs new file mode 100644 index 0000000000..1b901ec99c --- /dev/null +++ b/module/core/reflect_tools/src/reflect/to_string_with_fallback/params.rs @@ -0,0 +1,7 @@ +//! +//! Marker type for trait `_ToStringWithFallback` with type parameters. +//! + +/// Marker type for trait `_ToStringWithFallback` with type parameters. +#[ derive( Debug, Default, Clone, Copy ) ] +pub struct ToStringWithFallbackParams< How, Fallback >( ::core::marker::PhantomData< fn() -> ( How, Fallback ) > ); diff --git a/module/core/reflect_tools/src/reflect/wrapper.rs b/module/core/reflect_tools/src/reflect/wrapper.rs index 5a93eb2133..4cd134650f 100644 --- a/module/core/reflect_tools/src/reflect/wrapper.rs +++ b/module/core/reflect_tools/src/reflect/wrapper.rs @@ -7,8 +7,8 @@ pub( crate ) mod private { } -pub mod aref; -pub mod maybe_as; +mod aref; +mod maybe_as; #[ doc( inline ) ] #[ allow( unused_imports ) ] @@ -17,18 +17,9 @@ pub use protected::*; /// Protected namespace of the module. pub mod protected { - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super:: - { - aref::orphan::*, - maybe_as::orphan::*, - }; - #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::orphan::*; - } /// Orphan namespace of the module. @@ -46,19 +37,14 @@ pub mod exposed #[ allow( unused_imports ) ] pub use super:: { - aref::exposed::*, - maybe_as::exposed::*, + aref::IntoRef, + aref::Ref, + maybe_as::IntoMaybeAs, + maybe_as::MaybeAs, }; } /// Prelude to use essentials: `use my_module::prelude::*`. pub mod prelude { - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super:: - { - aref::prelude::*, - maybe_as::prelude::*, - }; } diff --git a/module/core/reflect_tools/src/reflect/wrapper/aref.rs b/module/core/reflect_tools/src/reflect/wrapper/aref.rs index 85060915bb..7e6afeb049 100644 --- a/module/core/reflect_tools/src/reflect/wrapper/aref.rs +++ b/module/core/reflect_tools/src/reflect/wrapper/aref.rs @@ -2,157 +2,115 @@ //! It's often necessary to wrap something inot a local structure and this file contains a resusable local structure for wrapping. //! -/// Internal namespace. -pub( crate ) mod private -{ - - // use core::fmt; - use core::ops::{ Deref }; +// use core::fmt; +use core::ops::{ Deref }; +/// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. +pub trait IntoRef< 'a, T, Marker > +{ /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. - pub trait IntoRef< 'a, T, Marker > - { - /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. - fn into_ref( self ) -> Ref< 'a, T, Marker >; - } + fn into_ref( self ) -> Ref< 'a, T, Marker >; +} - impl< 'a, T, Marker > IntoRef< 'a, T, Marker > for &'a T +impl< 'a, T, Marker > IntoRef< 'a, T, Marker > for &'a T +{ + #[ inline( always ) ] + fn into_ref( self ) -> Ref< 'a, T, Marker > { - #[ inline( always ) ] - fn into_ref( self ) -> Ref< 'a, T, Marker > - { - Ref::< 'a, T, Marker >::new( self ) - } + Ref::< 'a, T, Marker >::new( self ) } +} - /// Transparent reference wrapper emphasizing a specific aspect of identity of its internal type. - #[ allow( missing_debug_implementations ) ] - #[ repr( transparent ) ] - pub struct Ref< 'a, T, Marker >( pub &'a T, ::core::marker::PhantomData< fn() -> Marker > ) - where - ::core::marker::PhantomData< fn( Marker ) > : Copy, - &'a T : Copy, - ; +/// Transparent reference wrapper emphasizing a specific aspect of identity of its internal type. +#[ allow( missing_debug_implementations ) ] +#[ repr( transparent ) ] +pub struct Ref< 'a, T, Marker >( pub &'a T, ::core::marker::PhantomData< fn() -> Marker > ) +where + ::core::marker::PhantomData< fn( Marker ) > : Copy, + &'a T : Copy, +; - impl< 'a, T, Marker > Clone for Ref< 'a, T, Marker > +impl< 'a, T, Marker > Clone for Ref< 'a, T, Marker > +{ + #[ inline( always ) ] + fn clone( &self ) -> Self { - #[ inline( always ) ] - fn clone( &self ) -> Self - { - Self::new( self.0 ) - } + Self::new( self.0 ) } +} - impl< 'a, T, Marker > Copy for Ref< 'a, T, Marker > {} - - impl< 'a, T, Marker > Ref< 'a, T, Marker > - { - - /// Just a constructor. - #[ inline( always ) ] - pub fn new( src : &'a T ) -> Self - { - Self( src, ::core::marker::PhantomData ) - } - - /// Just a constructor. - #[ inline( always ) ] - pub fn inner( self ) -> &'a T - { - self.0 - } - - } +impl< 'a, T, Marker > Copy for Ref< 'a, T, Marker > {} - impl< 'a, T, Marker > AsRef< T > for Ref< 'a, T, Marker > - { - fn as_ref( &self ) -> &T - { - &self.0 - } - } +impl< 'a, T, Marker > Ref< 'a, T, Marker > +{ - impl< 'a, T, Marker > Deref for Ref< 'a, T, Marker > + /// Just a constructor. + #[ inline( always ) ] + pub fn new( src : &'a T ) -> Self { - type Target = T; - fn deref( &self ) -> &Self::Target - { - &self.0 - } + Self( src, ::core::marker::PhantomData ) } - impl< 'a, T, Marker > From< &'a T > for Ref< 'a, T, Marker > + /// Just a constructor. + #[ inline( always ) ] + pub fn inner( self ) -> &'a T { - fn from( src : &'a T ) -> Self - { - Ref::new( src ) - } + self.0 } - // impl< 'a, T, Marker > From< Ref< 'a, T, Marker > > for &'a T - // { - // fn from( wrapper : Ref< 'a, T, Marker > ) -> &'a T - // { - // wrapper.0 - // } - // } - - // impl< 'a, T, Marker > Default for Ref< 'a, T, Marker > - // where - // T : Default, - // { - // fn default() -> Self - // { - // Ref( &T::default() ) - // } - // } - - // impl< 'a, T, Marker > fmt::Debug for Ref< 'a, T, Marker > - // where - // T : fmt::Debug, - // { - // fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result - // { - // f.debug_struct( "Ref" ) - // .field( "0", &self.0 ) - // .finish() - // } - // } - } -#[ allow( unused_imports ) ] -pub use protected::*; - -/// Protected namespace of the module. -pub mod protected +impl< 'a, T, Marker > AsRef< T > for Ref< 'a, T, Marker > { - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::orphan::*; + fn as_ref( &self ) -> &T + { + &self.0 + } } -/// Orphan namespace of the module. -pub mod orphan +impl< 'a, T, Marker > Deref for Ref< 'a, T, Marker > { - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::exposed::*; + type Target = T; + fn deref( &self ) -> &Self::Target + { + &self.0 + } } -/// Exposed namespace of the module. -pub mod exposed +impl< 'a, T, Marker > From< &'a T > for Ref< 'a, T, Marker > { - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::private:: + fn from( src : &'a T ) -> Self { - IntoRef, - Ref, - }; + Ref::new( src ) + } } -/// Prelude to use essentials: `use my_module::prelude::*`. -pub mod prelude -{ -} +// impl< 'a, T, Marker > From< Ref< 'a, T, Marker > > for &'a T +// { +// fn from( wrapper : Ref< 'a, T, Marker > ) -> &'a T +// { +// wrapper.0 +// } +// } + +// impl< 'a, T, Marker > Default for Ref< 'a, T, Marker > +// where +// T : Default, +// { +// fn default() -> Self +// { +// Ref( &T::default() ) +// } +// } + +// impl< 'a, T, Marker > fmt::Debug for Ref< 'a, T, Marker > +// where +// T : fmt::Debug, +// { +// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result +// { +// f.debug_struct( "Ref" ) +// .field( "0", &self.0 ) +// .finish() +// } +// } diff --git a/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs b/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs index 1cea6d5f7c..d9c4a910c3 100644 --- a/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs +++ b/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs @@ -2,293 +2,250 @@ //! It's often necessary to wrap something inot a local structure and this file contains wrapper of `Option< Cow< 'a, T > >`. //! -/// Internal namespace. -pub( crate ) mod private +use core::fmt; +use std::borrow::Cow; +use core::ops::{ Deref }; + +/// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. +pub trait IntoMaybeAs< 'a, T, Marker > +where + T : Clone, { - - use core::fmt; - use std::borrow::Cow; - use core::ops::{ Deref }; - /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. - pub trait IntoMaybeAs< 'a, T, Marker > - where - T : Clone, - { - /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. - fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker >; - } + fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker >; +} - impl< 'a, T, Marker > IntoMaybeAs< 'a, T, Marker > for T - where - T : Clone, +impl< 'a, T, Marker > IntoMaybeAs< 'a, T, Marker > for T +where + T : Clone, +{ + #[ inline( always ) ] + fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker > { - #[ inline( always ) ] - fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker > - { - MaybeAs::< 'a, T, Marker >::new( self ) - } + MaybeAs::< 'a, T, Marker >::new( self ) } +} - impl< 'a, T, Marker > IntoMaybeAs< 'a, T, Marker > for &'a T - where - T : Clone, +impl< 'a, T, Marker > IntoMaybeAs< 'a, T, Marker > for &'a T +where + T : Clone, +{ + #[ inline( always ) ] + fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker > { - #[ inline( always ) ] - fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker > - { - MaybeAs::< 'a, T, Marker >::new_with_ref( self ) - } + MaybeAs::< 'a, T, Marker >::new_with_ref( self ) } +} - // xxx - // impl< 'a, T, Marker > IntoMaybeAs< 'a, T, Marker > for () - // where - // T : Clone, - // { - // #[ inline( always ) ] - // fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker > - // { - // MaybeAs::< 'a, T, Marker >( None ) - // } - // } - - /// Universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. - #[ repr( transparent ) ] - #[ derive( Clone ) ] - pub struct MaybeAs< 'a, T, Marker >( pub Option< Cow< 'a, T > >, ::core::marker::PhantomData< fn() -> Marker > ) - where - T : Clone, - ; +// xxx +// impl< 'a, T, Marker > IntoMaybeAs< 'a, T, Marker > for () +// where +// T : Clone, +// { +// #[ inline( always ) ] +// fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker > +// { +// MaybeAs::< 'a, T, Marker >( None ) +// } +// } + +/// Universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. +#[ repr( transparent ) ] +#[ derive( Clone ) ] +pub struct MaybeAs< 'a, T, Marker >( pub Option< Cow< 'a, T > >, ::core::marker::PhantomData< fn() -> Marker > ) +where + T : Clone, +; + +impl< 'a, T, Marker > MaybeAs< 'a, T, Marker > +where + T : Clone, +{ - impl< 'a, T, Marker > MaybeAs< 'a, T, Marker > - where - T : Clone, + /// Just a constructor. + #[ inline( always ) ] + pub fn none() -> Self { - - /// Just a constructor. - #[ inline( always ) ] - pub fn none() -> Self - { - Self( None, ::core::marker::PhantomData ) - } - - /// Just a constructor. - #[ inline( always ) ] - pub fn new( src : T ) -> Self - { - Self( Some( Cow::Owned( src ) ), ::core::marker::PhantomData ) - } - - /// Just a constructor. - #[ inline( always ) ] - pub fn new_with_ref( src : &'a T ) -> Self - { - Self( Some( Cow::Borrowed( src ) ), ::core::marker::PhantomData ) - } - - /// Just a constructor. - #[ inline( always ) ] - pub fn new_with_inner( src : Option< Cow< 'a, T > > ) -> Self - { - Self( src, ::core::marker::PhantomData ) - } - - /// Just a constructor. - #[ inline( always ) ] - pub fn inner( self ) -> Option< Cow< 'a, T > > - { - self.0 - } - + Self( None, ::core::marker::PhantomData ) } - impl< 'a, T, Marker > AsRef< Option< Cow< 'a, T > > > for MaybeAs< 'a, T, Marker > - where - T : Clone, - Self : 'a, + /// Just a constructor. + #[ inline( always ) ] + pub fn new( src : T ) -> Self { - fn as_ref( &self ) -> &Option< Cow< 'a, T > > - { - &self.0 - } + Self( Some( Cow::Owned( src ) ), ::core::marker::PhantomData ) } - impl< 'a, T, Marker > Deref for MaybeAs< 'a, T, Marker > - where - T : Clone, - Marker : 'static, + /// Just a constructor. + #[ inline( always ) ] + pub fn new_with_ref( src : &'a T ) -> Self { - type Target = Option< Cow< 'a, T > >; - fn deref( &self ) -> &Option< Cow< 'a, T > > - { - self.as_ref() - } + Self( Some( Cow::Borrowed( src ) ), ::core::marker::PhantomData ) } - // impl< 'a, T, Marker > AsRef< T > for MaybeAs< 'a, T, Marker > - // where - // T : Clone, - // Self : 'a, - // { - // fn as_ref( &self ) -> &'a T - // { - // match &self.0 - // { - // Some( src ) => - // { - // match src - // { - // Cow::Borrowed( src ) => src, - // Cow::Owned( src ) => &src, - // } - // }, - // None => panic!( "MaybeAs is None" ), - // } - // } - // } - // - // impl< 'a, T, Marker > Deref for MaybeAs< 'a, T, Marker > - // where - // T : Clone, - // { - // type Target = T; - // fn deref( &self ) -> &'a T - // { - // self.as_ref() - // } - // } - - impl< 'a, T, Marker > From< T > - for MaybeAs< 'a, T, Marker > - where - T : Clone, + /// Just a constructor. + #[ inline( always ) ] + pub fn new_with_inner( src : Option< Cow< 'a, T > > ) -> Self { - fn from( src : T ) -> Self - { - MaybeAs::new( src ) - } + Self( src, ::core::marker::PhantomData ) } - impl< 'a, T, Marker > From< Option< Cow< 'a, T > > > - for MaybeAs< 'a, T, Marker > - where - T : Clone, + /// Just a constructor. + #[ inline( always ) ] + pub fn inner( self ) -> Option< Cow< 'a, T > > { - fn from( src : Option< Cow< 'a, T > > ) -> Self - { - MaybeAs::new_with_inner( src ) - } + self.0 } - impl< 'a, T, Marker > From< &'a T > - for MaybeAs< 'a, T, Marker > - where - T : Clone, +} + +impl< 'a, T, Marker > AsRef< Option< Cow< 'a, T > > > for MaybeAs< 'a, T, Marker > +where + T : Clone, + Self : 'a, +{ + fn as_ref( &self ) -> &Option< Cow< 'a, T > > { - fn from( src : &'a T ) -> Self - { - MaybeAs::new_with_ref( src ) - } + &self.0 } +} - // impl< 'a, T, Marker > From< () > for MaybeAs< 'a, T, Marker > - // where - // T : (), - // { - // fn from( src : &'a T ) -> Self - // { - // MaybeAs( None ) - // } - // } - - // xxx : more from - - // impl< 'a, T, Marker > From< MaybeAs< 'a, T, Marker > > for &'a T - // where - // T : Clone, - // { - // fn from( wrapper : MaybeAs< 'a, T, Marker > ) -> &'a T - // { - // wrapper.0 - // } - // } - - impl< 'a, T, Marker > Default for MaybeAs< 'a, T, Marker > - where - T : Clone, - T : Default, +impl< 'a, T, Marker > Deref for MaybeAs< 'a, T, Marker > +where + T : Clone, + Marker : 'static, +{ + type Target = Option< Cow< 'a, T > >; + fn deref( &self ) -> &Option< Cow< 'a, T > > { - fn default() -> Self - { - MaybeAs::new( T::default() ) - } + self.as_ref() } +} - impl< 'a, T, Marker > fmt::Debug for MaybeAs< 'a, T, Marker > - where - T : fmt::Debug, - T : Clone, +// impl< 'a, T, Marker > AsRef< T > for MaybeAs< 'a, T, Marker > +// where +// T : Clone, +// Self : 'a, +// { +// fn as_ref( &self ) -> &'a T +// { +// match &self.0 +// { +// Some( src ) => +// { +// match src +// { +// Cow::Borrowed( src ) => src, +// Cow::Owned( src ) => &src, +// } +// }, +// None => panic!( "MaybeAs is None" ), +// } +// } +// } +// +// impl< 'a, T, Marker > Deref for MaybeAs< 'a, T, Marker > +// where +// T : Clone, +// { +// type Target = T; +// fn deref( &self ) -> &'a T +// { +// self.as_ref() +// } +// } + +impl< 'a, T, Marker > From< T > +for MaybeAs< 'a, T, Marker > +where + T : Clone, +{ + fn from( src : T ) -> Self { - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result - { - f.debug_struct( "MaybeAs" ) - .field( "0", &self.0 ) - .finish() - } + MaybeAs::new( src ) } +} - impl< 'a, T, Marker > PartialEq for MaybeAs< 'a, T, Marker > - where - T : Clone + PartialEq, +impl< 'a, T, Marker > From< Option< Cow< 'a, T > > > +for MaybeAs< 'a, T, Marker > +where + T : Clone, +{ + fn from( src : Option< Cow< 'a, T > > ) -> Self { - fn eq( &self, other : &Self ) -> bool - { - self.as_ref() == other.as_ref() - } + MaybeAs::new_with_inner( src ) } +} - impl< 'a, T, Marker > Eq for MaybeAs< 'a, T, Marker > - where - T : Clone + Eq, +impl< 'a, T, Marker > From< &'a T > +for MaybeAs< 'a, T, Marker > +where + T : Clone, +{ + fn from( src : &'a T ) -> Self { + MaybeAs::new_with_ref( src ) } - } -#[ doc( inline ) ] -#[ allow( unused_imports ) ] -pub use protected::*; - -/// Protected namespace of the module. -pub mod protected +// impl< 'a, T, Marker > From< () > for MaybeAs< 'a, T, Marker > +// where +// T : (), +// { +// fn from( src : &'a T ) -> Self +// { +// MaybeAs( None ) +// } +// } + +// xxx : more from + +// impl< 'a, T, Marker > From< MaybeAs< 'a, T, Marker > > for &'a T +// where +// T : Clone, +// { +// fn from( wrapper : MaybeAs< 'a, T, Marker > ) -> &'a T +// { +// wrapper.0 +// } +// } + +impl< 'a, T, Marker > Default for MaybeAs< 'a, T, Marker > +where + T : Clone, + T : Default, { - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::orphan::*; + fn default() -> Self + { + MaybeAs::new( T::default() ) + } } -/// Orphan namespace of the module. -pub mod orphan +impl< 'a, T, Marker > fmt::Debug for MaybeAs< 'a, T, Marker > +where + T : fmt::Debug, + T : Clone, { - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::exposed::*; + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f.debug_struct( "MaybeAs" ) + .field( "0", &self.0 ) + .finish() + } } -/// Exposed namespace of the module. -pub mod exposed +impl< 'a, T, Marker > PartialEq for MaybeAs< 'a, T, Marker > +where + T : Clone + PartialEq, { - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::private:: + fn eq( &self, other : &Self ) -> bool { - IntoMaybeAs, - MaybeAs, - }; + self.as_ref() == other.as_ref() + } } -/// Prelude to use essentials: `use my_module::prelude::*`. -pub mod prelude +impl< 'a, T, Marker > Eq for MaybeAs< 'a, T, Marker > +where + T : Clone + Eq, { } diff --git a/module/core/reflect_tools/tests/inc/fundamental/to_string_test.rs b/module/core/reflect_tools/tests/inc/fundamental/to_string_test.rs index 22f7de14fc..0cba5fd0f8 100644 --- a/module/core/reflect_tools/tests/inc/fundamental/to_string_test.rs +++ b/module/core/reflect_tools/tests/inc/fundamental/to_string_test.rs @@ -7,12 +7,12 @@ use the_module:: // IteratorTrait, // MaybeAs, ToStringWith, - ToStringWithFallback, - ToStringWithFallbackParams, + // _ToStringWithFallback, + // ToStringWithFallbackParams, WithDebug, WithDisplay, - Ref, - to_string_with_fallback, + // Ref, + // to_string_with_fallback, }; // use std:: @@ -55,149 +55,3 @@ fn to_string_with_test() // - } - -#[ test ] -fn to_string_with_fallback_basic() -{ - - // - Ref should implement copy - - fn f1( _src : Ref::< '_, Struct1, ToStringWithFallbackParams< WithDisplay, WithDebug > > ) - where - for< 'a > Ref::< 'a, Struct1, ToStringWithFallbackParams< WithDisplay, WithDebug > > : Copy + Clone, - {} - - struct Struct1; - let src = Struct1; - let ref1 = Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ); - let ref2 = ref1; - f1( ref1 ); - f1( ref2 ); - - // - - - let src = 13i32; - let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); - let exp = "13".to_string(); - a_id!( got, exp ); - - let src = "abc".to_string(); - let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); - let exp = "abc".to_string(); - a_id!( got, exp ); - - // - - -} - -// - -#[ test ] -fn to_string_with_fallback_variants() -{ - - // - only display - - struct OnlyDisplay; - impl fmt::Display for OnlyDisplay - { - fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result - { - write!( f, "This is display" ) - } - } - - let src = OnlyDisplay; - let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); - let exp = "This is display".to_string(); - a_id!( got, exp ); - - // - only debug - - struct OnlyDebug; - - impl fmt::Debug for OnlyDebug - { - fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result - { - write!( f, "This is debug" ) - } - } - - let src = OnlyDebug; - let _ref1 = Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ); - let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); - let exp = "This is debug".to_string(); - a_id!( got, exp ); - - // - both debug and display - - struct Both; - - impl fmt::Debug for Both - { - fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result - { - write!( f, "This is debug" ) - } - } - - impl fmt::Display for Both - { - fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result - { - write!( f, "This is display" ) - } - } - - let src = Both; - let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); - let exp = "This is display".to_string(); - a_id!( got, exp ); - - let src = Both; - let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDebug, WithDisplay > >::from( &src ) ).to_string_with_fallback(); - let exp = "This is debug".to_string(); - a_id!( got, exp ); - - // - - -} - -// - -#[ test ] -fn to_string_with_fallback_macro() -{ - - struct Both; - - impl fmt::Debug for Both - { - fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result - { - write!( f, "This is debug" ) - } - } - - impl fmt::Display for Both - { - fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result - { - write!( f, "This is display" ) - } - } - - let src = Both; - // let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); - let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); - let exp = "This is display".to_string(); - a_id!( got, exp ); - - let src = Both; - // let got = ( &Ref::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); - let got = to_string_with_fallback!( WithDebug, WithDisplay, src ); - let exp = "This is debug".to_string(); - a_id!( got, exp ); - -} diff --git a/module/core/reflect_tools/tests/inc/fundamental/to_string_with_fallback_test.rs b/module/core/reflect_tools/tests/inc/fundamental/to_string_with_fallback_test.rs new file mode 100644 index 0000000000..864183b705 --- /dev/null +++ b/module/core/reflect_tools/tests/inc/fundamental/to_string_with_fallback_test.rs @@ -0,0 +1,161 @@ +#[ allow( unused_imports ) ] +use super::*; + +use the_module:: +{ + // ToStringWith, + _ToStringWithFallback, + ToStringWithFallbackParams, + WithDebug, + WithDisplay, + ToStringWithFallbackRef, + to_string_with_fallback, +}; + +// + +#[ test ] +fn to_string_with_fallback_basic() +{ + + // - ToStringWithFallbackRef should implement copy + + fn f1( _src : ToStringWithFallbackRef::< '_, Struct1, ToStringWithFallbackParams< WithDisplay, WithDebug > > ) + where + for< 'a > ToStringWithFallbackRef::< 'a, Struct1, ToStringWithFallbackParams< WithDisplay, WithDebug > > : Copy + Clone, + {} + + struct Struct1; + let src = Struct1; + let ref1 = ToStringWithFallbackRef::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ); + let ref2 = ref1; + f1( ref1 ); + f1( ref2 ); + + // - + + let src = 13i32; + let got = ( &ToStringWithFallbackRef::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let exp = "13".to_string(); + a_id!( got, exp ); + + let src = "abc".to_string(); + let got = ( &ToStringWithFallbackRef::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let exp = "abc".to_string(); + a_id!( got, exp ); + + // - + +} + +// + +#[ test ] +fn to_string_with_fallback_variants() +{ + + // - only display + + struct OnlyDisplay; + impl fmt::Display for OnlyDisplay + { + fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result + { + write!( f, "This is display" ) + } + } + + let src = OnlyDisplay; + let got = ( &ToStringWithFallbackRef::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let exp = "This is display".to_string(); + a_id!( got, exp ); + + // - only debug + + struct OnlyDebug; + + impl fmt::Debug for OnlyDebug + { + fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result + { + write!( f, "This is debug" ) + } + } + + let src = OnlyDebug; + let _ref1 = ToStringWithFallbackRef::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ); + let got = ( &ToStringWithFallbackRef::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let exp = "This is debug".to_string(); + a_id!( got, exp ); + + // - both debug and display + + struct Both; + + impl fmt::Debug for Both + { + fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result + { + write!( f, "This is debug" ) + } + } + + impl fmt::Display for Both + { + fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result + { + write!( f, "This is display" ) + } + } + + let src = Both; + let got = ( &ToStringWithFallbackRef::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let exp = "This is display".to_string(); + a_id!( got, exp ); + + let src = Both; + let got = ( &ToStringWithFallbackRef::< '_, _, ToStringWithFallbackParams< WithDebug, WithDisplay > >::from( &src ) ).to_string_with_fallback(); + let exp = "This is debug".to_string(); + a_id!( got, exp ); + + // - + +} + +// + +#[ test ] +fn to_string_with_fallback_macro() +{ + + struct Both; + + impl fmt::Debug for Both + { + fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result + { + write!( f, "This is debug" ) + } + } + + impl fmt::Display for Both + { + fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result + { + write!( f, "This is display" ) + } + } + + let src = Both; + // let got = ( &ToStringWithFallbackRef::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let got = to_string_with_fallback!( WithDisplay, WithDebug, src ); + let exp = "This is display".to_string(); + a_id!( got, exp ); + + let src = Both; + // let got = ( &ToStringWithFallbackRef::< '_, _, ToStringWithFallbackParams< WithDisplay, WithDebug > >::from( &src ) ).to_string_with_fallback(); + let got = to_string_with_fallback!( WithDebug, WithDisplay, src ); + let exp = "This is debug".to_string(); + a_id!( got, exp ); + +} diff --git a/module/core/reflect_tools/tests/inc/mod.rs b/module/core/reflect_tools/tests/inc/mod.rs index fd496975cd..37b3984116 100644 --- a/module/core/reflect_tools/tests/inc/mod.rs +++ b/module/core/reflect_tools/tests/inc/mod.rs @@ -11,6 +11,7 @@ mod fundamental mod fields_test; mod to_string_test; mod to_string_example; + mod to_string_with_fallback_test; } From 24412dd14e7759391db52165c538dcdff2e7a536 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 21:58:54 +0300 Subject: [PATCH 093/143] format_tools --- Cargo.toml | 7 + module/core/format_tools/Cargo.toml | 52 ++++ module/core/format_tools/License | 22 ++ module/core/format_tools/Readme.md | 30 +++ module/core/format_tools/build.rs | 25 ++ .../examples/format_tools_trivial.rs | 6 + module/core/format_tools/src/format.rs | 107 ++++++++ .../format_tools/src/format}/as_table.rs | 3 + .../format_tools/src/format}/print.rs | 3 + .../format_tools/src/format}/table.rs | 4 + .../src/format}/to_string.rs | 0 .../src/format}/to_string_with_fallback.rs | 6 +- .../format}/to_string_with_fallback/aref.rs | 0 .../format}/to_string_with_fallback/params.rs | 0 .../core/format_tools/src/format/wrapper.rs | 50 ++++ .../format_tools/src/format/wrapper/aref.rs | 116 ++++++++ .../src/format/wrapper/maybe_as.rs | 251 ++++++++++++++++++ module/core/format_tools/src/lib.rs | 77 ++++++ .../format_tools/tests/inc/fields_test.rs | 204 ++++++++++++++ module/core/format_tools/tests/inc/mod.rs | 17 ++ .../format_tools}/tests/inc/print_test.rs | 2 +- .../tests/inc}/to_string_example.rs | 2 +- .../tests/inc}/to_string_test.rs | 0 .../inc}/to_string_with_fallback_test.rs | 0 module/core/format_tools/tests/smoke_test.rs | 14 + module/core/format_tools/tests/tests.rs | 9 + module/core/reflect_tools/Cargo.toml | 10 +- module/core/reflect_tools/src/reflect.rs | 40 +-- .../tests/inc/fundamental/fields_test.rs | 118 ++------ module/core/reflect_tools/tests/inc/mod.rs | 6 +- module/move/assistant/Cargo.toml | 1 + 31 files changed, 1049 insertions(+), 133 deletions(-) create mode 100644 module/core/format_tools/Cargo.toml create mode 100644 module/core/format_tools/License create mode 100644 module/core/format_tools/Readme.md create mode 100644 module/core/format_tools/build.rs create mode 100644 module/core/format_tools/examples/format_tools_trivial.rs create mode 100644 module/core/format_tools/src/format.rs rename module/{move/assistant/src => core/format_tools/src/format}/as_table.rs (99%) rename module/{move/assistant/src => core/format_tools/src/format}/print.rs (99%) rename module/{move/assistant/src => core/format_tools/src/format}/table.rs (99%) rename module/core/{reflect_tools/src/reflect => format_tools/src/format}/to_string.rs (100%) rename module/core/{reflect_tools/src/reflect => format_tools/src/format}/to_string_with_fallback.rs (95%) rename module/core/{reflect_tools/src/reflect => format_tools/src/format}/to_string_with_fallback/aref.rs (100%) rename module/core/{reflect_tools/src/reflect => format_tools/src/format}/to_string_with_fallback/params.rs (100%) create mode 100644 module/core/format_tools/src/format/wrapper.rs create mode 100644 module/core/format_tools/src/format/wrapper/aref.rs create mode 100644 module/core/format_tools/src/format/wrapper/maybe_as.rs create mode 100644 module/core/format_tools/src/lib.rs create mode 100644 module/core/format_tools/tests/inc/fields_test.rs create mode 100644 module/core/format_tools/tests/inc/mod.rs rename module/{move/assistant => core/format_tools}/tests/inc/print_test.rs (99%) rename module/core/{reflect_tools/tests/inc/fundamental => format_tools/tests/inc}/to_string_example.rs (97%) rename module/core/{reflect_tools/tests/inc/fundamental => format_tools/tests/inc}/to_string_test.rs (100%) rename module/core/{reflect_tools/tests/inc/fundamental => format_tools/tests/inc}/to_string_with_fallback_test.rs (100%) create mode 100644 module/core/format_tools/tests/smoke_test.rs create mode 100644 module/core/format_tools/tests/tests.rs diff --git a/Cargo.toml b/Cargo.toml index 008dd82f22..787b070893 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -135,6 +135,13 @@ path = "module/core/reflect_tools_meta" default-features = false features = [ "enabled" ] +[workspace.dependencies.format_tools] +version = "~0.1.0" +path = "module/core/format_tools" +default-features = false +features = [ "enabled" ] +# xxx : remove features, maybe + # [workspace.dependencies.type_constructor] # version = "~0.3.0" # path = "module/core/type_constructor" diff --git a/module/core/format_tools/Cargo.toml b/module/core/format_tools/Cargo.toml new file mode 100644 index 0000000000..f3a45c9d8f --- /dev/null +++ b/module/core/format_tools/Cargo.toml @@ -0,0 +1,52 @@ +[package] +name = "format_tools" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/format_tools" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/format_tools" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/format_tools" +description = """ +Collection of mechanisms for formatting and serialization into string. +""" +categories = [ "algorithms", "development-tools" ] +keywords = [ "fundamental", "general-purpose" ] + +[lints] +workspace = true + +[package.metadata.docs.rs] +features = [ "full" ] +all-features = false +# exclude = [ "/tests", "/examples", "-*" ] + +[features] + +default = [ + "enabled", +] + +full = [ + "enabled", +] +enabled = [ + "reflect_tools/enabled", + # "derive_tools/enabled", + "former/enabled", +] + +[dependencies] +# derive_tools = { workspace = true, features = [ "derive_from", "derive_inner_from" ] } +reflect_tools = { workspace = true, features = [ "reflect_reflect" ] } +former = { workspace = true, features = [ "full" ] } +# qqq : xxx : optmize set of features + +[dev-dependencies] +test_tools = { workspace = true } + +# [build-dependencies] +# cfg_aliases = "0.1.1" diff --git a/module/core/format_tools/License b/module/core/format_tools/License new file mode 100644 index 0000000000..6d5ef8559f --- /dev/null +++ b/module/core/format_tools/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/core/format_tools/Readme.md b/module/core/format_tools/Readme.md new file mode 100644 index 0000000000..d7ed129355 --- /dev/null +++ b/module/core/format_tools/Readme.md @@ -0,0 +1,30 @@ +# Module :: reflect_tools + + + [![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_reflect_tools_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_reflect_tools_push.yml) [![docs.rs](https://img.shields.io/docsrs/reflect_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/reflect_tools) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Freflect_tools%2Fexamples%2Freflect_tools_trivial.rs,RUN_POSTFIX=--example%20reflect_tools_trivial/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + + +Collection of mechanisms for formatting and serialization into string. + + + +```rust +// xxx : qqq : write please +``` + +### To add to your project + +```sh +cargo add reflect_tools +``` + +### Try out from the repository + +```sh +git clone https://github.com/Wandalen/wTools +cd wTools +cd examples/reflect_tools_trivial +cargo run +``` --> diff --git a/module/core/format_tools/build.rs b/module/core/format_tools/build.rs new file mode 100644 index 0000000000..f515253266 --- /dev/null +++ b/module/core/format_tools/build.rs @@ -0,0 +1,25 @@ +//! To avoid messing up with long logical expressions in the codebase. + +// use cfg_aliases::cfg_aliases; + +fn main() +{ + // // Setup cfg aliases + // cfg_aliases! + // { + // all_features : + // { + // all + // ( + // feature = "reflect_reflect" + // ) + // }, + // any_feature : + // { + // any + // ( + // feature = "reflect_reflect" + // ) + // }, + // } +} diff --git a/module/core/format_tools/examples/format_tools_trivial.rs b/module/core/format_tools/examples/format_tools_trivial.rs new file mode 100644 index 0000000000..59c42f74f7 --- /dev/null +++ b/module/core/format_tools/examples/format_tools_trivial.rs @@ -0,0 +1,6 @@ +//! xxx : qqq : write please + +fn main() +{ + // xxx : qqq : write please +} diff --git a/module/core/format_tools/src/format.rs b/module/core/format_tools/src/format.rs new file mode 100644 index 0000000000..845cfd33d2 --- /dev/null +++ b/module/core/format_tools/src/format.rs @@ -0,0 +1,107 @@ +//! +//! Collection of mechanisms for formatting and serialization into string. +//! + +/// Internal namespace. +pub( crate ) mod private +{ +} + +pub mod to_string; +pub mod to_string_with_fallback; +pub mod wrapper; + +pub mod as_table; +pub mod print; +pub mod table; + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + + // xxx : add features + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::to_string::orphan::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::to_string_with_fallback::orphan::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::wrapper::orphan::*; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::as_table::orphan::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::print::orphan::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::table::orphan::*; + +} + +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::to_string::exposed::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::to_string_with_fallback::exposed::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::wrapper::exposed::*; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::as_table::exposed::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::print::exposed::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::table::exposed::*; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::to_string::prelude::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::to_string_with_fallback::prelude::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::wrapper::prelude::*; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::as_table::prelude::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::print::prelude::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::table::prelude::*; + +} diff --git a/module/move/assistant/src/as_table.rs b/module/core/format_tools/src/format/as_table.rs similarity index 99% rename from module/move/assistant/src/as_table.rs rename to module/core/format_tools/src/format/as_table.rs index 9708851914..cc6892a2c8 100644 --- a/module/move/assistant/src/as_table.rs +++ b/module/core/format_tools/src/format/as_table.rs @@ -1,3 +1,6 @@ +//! +//! Nice print's wrapper. +//! /// Internal namespace. pub( crate ) mod private diff --git a/module/move/assistant/src/print.rs b/module/core/format_tools/src/format/print.rs similarity index 99% rename from module/move/assistant/src/print.rs rename to module/core/format_tools/src/format/print.rs index a9ddc87105..72c6e7a53f 100644 --- a/module/move/assistant/src/print.rs +++ b/module/core/format_tools/src/format/print.rs @@ -1,3 +1,6 @@ +//! +//! Nice print. +//! /// Internal namespace. pub( crate ) mod private diff --git a/module/move/assistant/src/table.rs b/module/core/format_tools/src/format/table.rs similarity index 99% rename from module/move/assistant/src/table.rs rename to module/core/format_tools/src/format/table.rs index 5d70946794..c847586e41 100644 --- a/module/move/assistant/src/table.rs +++ b/module/core/format_tools/src/format/table.rs @@ -1,3 +1,7 @@ +//! +//! Table interface. +//! + /// Internal namespace. pub( crate ) mod private { diff --git a/module/core/reflect_tools/src/reflect/to_string.rs b/module/core/format_tools/src/format/to_string.rs similarity index 100% rename from module/core/reflect_tools/src/reflect/to_string.rs rename to module/core/format_tools/src/format/to_string.rs diff --git a/module/core/reflect_tools/src/reflect/to_string_with_fallback.rs b/module/core/format_tools/src/format/to_string_with_fallback.rs similarity index 95% rename from module/core/reflect_tools/src/reflect/to_string_with_fallback.rs rename to module/core/format_tools/src/format/to_string_with_fallback.rs index c572b1c4e1..0d551b2a82 100644 --- a/module/core/reflect_tools/src/reflect/to_string_with_fallback.rs +++ b/module/core/format_tools/src/format/to_string_with_fallback.rs @@ -60,7 +60,7 @@ pub( crate ) mod private /// # Example /// ```rust /// use core::fmt; - /// use reflect_tools:: + /// use format_tools:: /// { /// WithDebug, /// WithDisplay, @@ -118,9 +118,9 @@ pub( crate ) mod private ( $how : ty, $fallback : ty, $src : expr ) => {{ - use reflect_tools::_ToStringWithFallback; + use format_tools::_ToStringWithFallback; ( - &reflect_tools::ToStringWithFallbackRef::< '_, _, reflect_tools::ToStringWithFallbackParams< $how, $fallback > >::from( &$src ) + &format_tools::ToStringWithFallbackRef::< '_, _, format_tools::ToStringWithFallbackParams< $how, $fallback > >::from( &$src ) ) .to_string_with_fallback() }}; diff --git a/module/core/reflect_tools/src/reflect/to_string_with_fallback/aref.rs b/module/core/format_tools/src/format/to_string_with_fallback/aref.rs similarity index 100% rename from module/core/reflect_tools/src/reflect/to_string_with_fallback/aref.rs rename to module/core/format_tools/src/format/to_string_with_fallback/aref.rs diff --git a/module/core/reflect_tools/src/reflect/to_string_with_fallback/params.rs b/module/core/format_tools/src/format/to_string_with_fallback/params.rs similarity index 100% rename from module/core/reflect_tools/src/reflect/to_string_with_fallback/params.rs rename to module/core/format_tools/src/format/to_string_with_fallback/params.rs diff --git a/module/core/format_tools/src/format/wrapper.rs b/module/core/format_tools/src/format/wrapper.rs new file mode 100644 index 0000000000..4cd134650f --- /dev/null +++ b/module/core/format_tools/src/format/wrapper.rs @@ -0,0 +1,50 @@ +//! +//! Collection of wrappers. +//! + +/// Internal namespace. +pub( crate ) mod private +{ +} + +mod aref; +mod maybe_as; + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; +} + +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super:: + { + aref::IntoRef, + aref::Ref, + maybe_as::IntoMaybeAs, + maybe_as::MaybeAs, + }; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/core/format_tools/src/format/wrapper/aref.rs b/module/core/format_tools/src/format/wrapper/aref.rs new file mode 100644 index 0000000000..7e6afeb049 --- /dev/null +++ b/module/core/format_tools/src/format/wrapper/aref.rs @@ -0,0 +1,116 @@ +//! +//! It's often necessary to wrap something inot a local structure and this file contains a resusable local structure for wrapping. +//! + +// use core::fmt; +use core::ops::{ Deref }; + +/// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. +pub trait IntoRef< 'a, T, Marker > +{ + /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. + fn into_ref( self ) -> Ref< 'a, T, Marker >; +} + +impl< 'a, T, Marker > IntoRef< 'a, T, Marker > for &'a T +{ + #[ inline( always ) ] + fn into_ref( self ) -> Ref< 'a, T, Marker > + { + Ref::< 'a, T, Marker >::new( self ) + } +} + +/// Transparent reference wrapper emphasizing a specific aspect of identity of its internal type. +#[ allow( missing_debug_implementations ) ] +#[ repr( transparent ) ] +pub struct Ref< 'a, T, Marker >( pub &'a T, ::core::marker::PhantomData< fn() -> Marker > ) +where + ::core::marker::PhantomData< fn( Marker ) > : Copy, + &'a T : Copy, +; + +impl< 'a, T, Marker > Clone for Ref< 'a, T, Marker > +{ + #[ inline( always ) ] + fn clone( &self ) -> Self + { + Self::new( self.0 ) + } +} + +impl< 'a, T, Marker > Copy for Ref< 'a, T, Marker > {} + +impl< 'a, T, Marker > Ref< 'a, T, Marker > +{ + + /// Just a constructor. + #[ inline( always ) ] + pub fn new( src : &'a T ) -> Self + { + Self( src, ::core::marker::PhantomData ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn inner( self ) -> &'a T + { + self.0 + } + +} + +impl< 'a, T, Marker > AsRef< T > for Ref< 'a, T, Marker > +{ + fn as_ref( &self ) -> &T + { + &self.0 + } +} + +impl< 'a, T, Marker > Deref for Ref< 'a, T, Marker > +{ + type Target = T; + fn deref( &self ) -> &Self::Target + { + &self.0 + } +} + +impl< 'a, T, Marker > From< &'a T > for Ref< 'a, T, Marker > +{ + fn from( src : &'a T ) -> Self + { + Ref::new( src ) + } +} + +// impl< 'a, T, Marker > From< Ref< 'a, T, Marker > > for &'a T +// { +// fn from( wrapper : Ref< 'a, T, Marker > ) -> &'a T +// { +// wrapper.0 +// } +// } + +// impl< 'a, T, Marker > Default for Ref< 'a, T, Marker > +// where +// T : Default, +// { +// fn default() -> Self +// { +// Ref( &T::default() ) +// } +// } + +// impl< 'a, T, Marker > fmt::Debug for Ref< 'a, T, Marker > +// where +// T : fmt::Debug, +// { +// fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result +// { +// f.debug_struct( "Ref" ) +// .field( "0", &self.0 ) +// .finish() +// } +// } diff --git a/module/core/format_tools/src/format/wrapper/maybe_as.rs b/module/core/format_tools/src/format/wrapper/maybe_as.rs new file mode 100644 index 0000000000..d9c4a910c3 --- /dev/null +++ b/module/core/format_tools/src/format/wrapper/maybe_as.rs @@ -0,0 +1,251 @@ +//! +//! It's often necessary to wrap something inot a local structure and this file contains wrapper of `Option< Cow< 'a, T > >`. +//! + +use core::fmt; +use std::borrow::Cow; +use core::ops::{ Deref }; + +/// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. +pub trait IntoMaybeAs< 'a, T, Marker > +where + T : Clone, +{ + /// Converter into universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. + fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker >; +} + +impl< 'a, T, Marker > IntoMaybeAs< 'a, T, Marker > for T +where + T : Clone, +{ + #[ inline( always ) ] + fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker > + { + MaybeAs::< 'a, T, Marker >::new( self ) + } +} + +impl< 'a, T, Marker > IntoMaybeAs< 'a, T, Marker > for &'a T +where + T : Clone, +{ + #[ inline( always ) ] + fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker > + { + MaybeAs::< 'a, T, Marker >::new_with_ref( self ) + } +} + +// xxx +// impl< 'a, T, Marker > IntoMaybeAs< 'a, T, Marker > for () +// where +// T : Clone, +// { +// #[ inline( always ) ] +// fn into_maybe_as( self ) -> MaybeAs< 'a, T, Marker > +// { +// MaybeAs::< 'a, T, Marker >( None ) +// } +// } + +/// Universal wrapper with transparent option of copy on write reference emphasizing a specific aspect of identity of its internal type. +#[ repr( transparent ) ] +#[ derive( Clone ) ] +pub struct MaybeAs< 'a, T, Marker >( pub Option< Cow< 'a, T > >, ::core::marker::PhantomData< fn() -> Marker > ) +where + T : Clone, +; + +impl< 'a, T, Marker > MaybeAs< 'a, T, Marker > +where + T : Clone, +{ + + /// Just a constructor. + #[ inline( always ) ] + pub fn none() -> Self + { + Self( None, ::core::marker::PhantomData ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn new( src : T ) -> Self + { + Self( Some( Cow::Owned( src ) ), ::core::marker::PhantomData ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn new_with_ref( src : &'a T ) -> Self + { + Self( Some( Cow::Borrowed( src ) ), ::core::marker::PhantomData ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn new_with_inner( src : Option< Cow< 'a, T > > ) -> Self + { + Self( src, ::core::marker::PhantomData ) + } + + /// Just a constructor. + #[ inline( always ) ] + pub fn inner( self ) -> Option< Cow< 'a, T > > + { + self.0 + } + +} + +impl< 'a, T, Marker > AsRef< Option< Cow< 'a, T > > > for MaybeAs< 'a, T, Marker > +where + T : Clone, + Self : 'a, +{ + fn as_ref( &self ) -> &Option< Cow< 'a, T > > + { + &self.0 + } +} + +impl< 'a, T, Marker > Deref for MaybeAs< 'a, T, Marker > +where + T : Clone, + Marker : 'static, +{ + type Target = Option< Cow< 'a, T > >; + fn deref( &self ) -> &Option< Cow< 'a, T > > + { + self.as_ref() + } +} + +// impl< 'a, T, Marker > AsRef< T > for MaybeAs< 'a, T, Marker > +// where +// T : Clone, +// Self : 'a, +// { +// fn as_ref( &self ) -> &'a T +// { +// match &self.0 +// { +// Some( src ) => +// { +// match src +// { +// Cow::Borrowed( src ) => src, +// Cow::Owned( src ) => &src, +// } +// }, +// None => panic!( "MaybeAs is None" ), +// } +// } +// } +// +// impl< 'a, T, Marker > Deref for MaybeAs< 'a, T, Marker > +// where +// T : Clone, +// { +// type Target = T; +// fn deref( &self ) -> &'a T +// { +// self.as_ref() +// } +// } + +impl< 'a, T, Marker > From< T > +for MaybeAs< 'a, T, Marker > +where + T : Clone, +{ + fn from( src : T ) -> Self + { + MaybeAs::new( src ) + } +} + +impl< 'a, T, Marker > From< Option< Cow< 'a, T > > > +for MaybeAs< 'a, T, Marker > +where + T : Clone, +{ + fn from( src : Option< Cow< 'a, T > > ) -> Self + { + MaybeAs::new_with_inner( src ) + } +} + +impl< 'a, T, Marker > From< &'a T > +for MaybeAs< 'a, T, Marker > +where + T : Clone, +{ + fn from( src : &'a T ) -> Self + { + MaybeAs::new_with_ref( src ) + } +} + +// impl< 'a, T, Marker > From< () > for MaybeAs< 'a, T, Marker > +// where +// T : (), +// { +// fn from( src : &'a T ) -> Self +// { +// MaybeAs( None ) +// } +// } + +// xxx : more from + +// impl< 'a, T, Marker > From< MaybeAs< 'a, T, Marker > > for &'a T +// where +// T : Clone, +// { +// fn from( wrapper : MaybeAs< 'a, T, Marker > ) -> &'a T +// { +// wrapper.0 +// } +// } + +impl< 'a, T, Marker > Default for MaybeAs< 'a, T, Marker > +where + T : Clone, + T : Default, +{ + fn default() -> Self + { + MaybeAs::new( T::default() ) + } +} + +impl< 'a, T, Marker > fmt::Debug for MaybeAs< 'a, T, Marker > +where + T : fmt::Debug, + T : Clone, +{ + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f.debug_struct( "MaybeAs" ) + .field( "0", &self.0 ) + .finish() + } +} + +impl< 'a, T, Marker > PartialEq for MaybeAs< 'a, T, Marker > +where + T : Clone + PartialEq, +{ + fn eq( &self, other : &Self ) -> bool + { + self.as_ref() == other.as_ref() + } +} + +impl< 'a, T, Marker > Eq for MaybeAs< 'a, T, Marker > +where + T : Clone + Eq, +{ +} diff --git a/module/core/format_tools/src/lib.rs b/module/core/format_tools/src/lib.rs new file mode 100644 index 0000000000..af0ae3ae89 --- /dev/null +++ b/module/core/format_tools/src/lib.rs @@ -0,0 +1,77 @@ +#![ cfg_attr( feature = "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/reflect_tools/latest/reflect_tools/" ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +#[ cfg( feature = "enabled" ) ] +pub mod format; + +/// Namespace with dependencies. +#[ cfg( feature = "enabled" ) ] +pub mod dependency +{ + pub use ::reflect_tools; + pub use ::former; +} + +#[ cfg( feature = "enabled" ) ] +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +#[ cfg( feature = "enabled" ) ] +pub mod protected +{ + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::format::orphan::*; + +} + +/// Orphan namespace of the module. +#[ cfg( feature = "enabled" ) ] +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +#[ cfg( feature = "enabled" ) ] +pub mod exposed +{ + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::prelude::*; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::format::exposed::*; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::dependency::reflect_tools:: + { + Fields, + IteratorTrait, + }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ cfg( feature = "enabled" ) ] +pub mod prelude +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::format::prelude::*; +} diff --git a/module/core/format_tools/tests/inc/fields_test.rs b/module/core/format_tools/tests/inc/fields_test.rs new file mode 100644 index 0000000000..9f6b62261e --- /dev/null +++ b/module/core/format_tools/tests/inc/fields_test.rs @@ -0,0 +1,204 @@ +#[ allow( unused_imports ) ] +use super::*; + +use the_module:: +{ + Fields, + IteratorTrait, + MaybeAs, + ToStringWith, + WithDebug, +}; + +use std:: +{ + // fmt, + collections::HashMap, + borrow::Cow, +}; + +/// Struct representing a test object with various fields. +#[ derive( Clone, Debug ) ] +pub struct TestObject +{ + pub id : String, + pub created_at : i64, + pub file_ids : Vec< String >, + pub tools : Option< Vec< HashMap< String, String > > >, +} + +impl< 'a, How > Fields< 'a, &'static str, MaybeAs< 'a, String, How > > +for TestObject +where + How : Clone + Copy + 'static, + String : ToStringWith< How >, + i64 : ToStringWith< How >, + Vec< String > : ToStringWith< How >, + Vec< HashMap< String, String > > : ToStringWith< How >, +{ + fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, How > ) > + { + let mut dst : Vec< ( &'static str, MaybeAs< 'a, String, How > ) > = Vec::new(); + + // fn into< 'a, V, How >( src : &'a V ) -> MaybeAs< 'a, String, How > + // where + // How : Clone + Copy + 'static, + // V : ToStringWith< How > + 'a, + // { + // MaybeAs::< 'a, String, How >::from + // ( + // < V as ToStringWith< How > >::to_string_with( src ) + // ) + // } + + fn add< 'a, V, How > + ( + dst : &mut Vec< ( &'static str, MaybeAs< 'a, String, How > ) >, + key : &'static str, + src : &'a V + ) + where + How : Clone + Copy + 'static, + V : ToStringWith< How > + 'a, + { + let val = MaybeAs::< 'a, String, How >::from + ( + < V as ToStringWith< How > >::to_string_with( src ) + ); + dst.push( ( key, val ) ); + } + + // dst.push( ( "id", MaybeAs::< 'a, String, How >::from( &self.id ) ) ); + add( &mut dst, "id", &self.id ); + add( &mut dst, "created_at", &self.created_at ); + add( &mut dst, "file_ids", &self.file_ids ); + + if let Some( tools ) = &self.tools + { + add( &mut dst, "tools", tools ); + } + else + { + dst.push( ( "tools", MaybeAs::none() ) ); + } + +// dst.push( ( "id", into( &self.id ) ) ); +// dst.push( ( "created_at", into( &self.created_at ) ) ); +// dst.push( ( "file_ids", into( &self.file_ids ) ) ); +// +// if let Some( tools ) = &self.tools +// { +// dst.push( ( "tools", into( &self.tools ) ) ); +// } +// else +// { +// dst.push( ( "tools", MaybeAs::none() ) ); +// } + + // dst.push( ( "id", MaybeAs::< 'a, String, How >::from( < String as ToStringWith< How > >::to_string_with( &self.id ) ) ) ); +// dst.push( ( "created_at", self.created_at.to_string_with().into() ) ); +// dst.push( ( "file_ids", self.file_ids.to_string_with().into() ) ); +// +// if let Some( tools ) = &self.tools +// { +// dst.push( ( "tools", self.tools.to_string_with().into() ) ); +// } +// else +// { +// dst.push( ( "tools", MaybeAs::none() ) ); +// } + + dst.into_iter() + } +} + +// + +#[ allow( dead_code ) ] +fn is_borrowed< 'a, T : Clone >( src : &Option< Cow< 'a, T > > ) -> bool +{ + if src.is_none() + { + return false; + } + match src.as_ref().unwrap() + { + Cow::Borrowed( _ ) => true, + Cow::Owned( _ ) => false, + } +} + +// + +#[ test ] +fn basic() +{ + let test_object = TestObject + { + id : "12345".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".to_string() ], + tools : Some + ( + vec! + [{ + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + }] + ), + }; + + let fields : Vec< ( &str, MaybeAs< '_, String, WithDebug > ) > = test_object.fields().collect(); + + assert_eq!( fields.len(), 4 ); + // assert!( is_borrowed( &fields[ 0 ].1 ) ); + // assert!( !is_borrowed( &fields[ 1 ].1 ) ); + // assert!( !is_borrowed( &fields[ 2 ].1 ) ); + // assert!( !is_borrowed( &fields[ 3 ].1 ) ); + // xxx + assert_eq!( fields[ 0 ], ( "id", Some( Cow::Borrowed( &"\"12345\"".to_string() ) ).into() ) ); + assert_eq!( fields[ 1 ], ( "created_at", Some( Cow::Owned( "1627845583".to_string() ) ).into() ) ); + assert_eq!( fields[ 2 ], ( "file_ids", Some( Cow::Owned( "[\"file1\", \"file2\"]".to_string() ) ).into() ) ); + assert_eq!( fields[ 3 ].0, "tools" ); + +} + +// + +#[ test ] +fn test_vec_fields() +{ + let test_objects = vec! + [ + TestObject + { + id : "12345".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".to_string() ], + tools : Some + ( + vec! + [{ + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + }] + ), + }, + TestObject + { + id : "67890".to_string(), + created_at : 13, + file_ids : vec![ "file3".to_string(), "file4".to_string() ], + tools : None, + }, + ]; + + let fields : Vec< _ > = test_objects.fields().collect(); + assert_eq!( fields.len(), 2 ); + assert_eq!( fields[ 0 ].0, 0 ); + assert_eq!( fields[ 1 ].0, 1 ); +} diff --git a/module/core/format_tools/tests/inc/mod.rs b/module/core/format_tools/tests/inc/mod.rs new file mode 100644 index 0000000000..fce3d88803 --- /dev/null +++ b/module/core/format_tools/tests/inc/mod.rs @@ -0,0 +1,17 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ cfg( feature = "enabled" ) ] +#[ path = "." ] +mod fundamental +{ + #[ allow( unused_imports ) ] + use super::*; + + mod fields_test; + mod to_string_test; + mod to_string_example; + mod to_string_with_fallback_test; + mod print_test; + +} diff --git a/module/move/assistant/tests/inc/print_test.rs b/module/core/format_tools/tests/inc/print_test.rs similarity index 99% rename from module/move/assistant/tests/inc/print_test.rs rename to module/core/format_tools/tests/inc/print_test.rs index 549cb72815..11cb79403b 100644 --- a/module/move/assistant/tests/inc/print_test.rs +++ b/module/core/format_tools/tests/inc/print_test.rs @@ -1,7 +1,7 @@ #[ allow( unused_imports ) ] use super::*; -use assistant:: +use the_module:: { Fields, IteratorTrait, diff --git a/module/core/reflect_tools/tests/inc/fundamental/to_string_example.rs b/module/core/format_tools/tests/inc/to_string_example.rs similarity index 97% rename from module/core/reflect_tools/tests/inc/fundamental/to_string_example.rs rename to module/core/format_tools/tests/inc/to_string_example.rs index 7baa368760..2bc356a052 100644 --- a/module/core/reflect_tools/tests/inc/fundamental/to_string_example.rs +++ b/module/core/format_tools/tests/inc/to_string_example.rs @@ -8,7 +8,7 @@ fn exmaple() { use core::fmt; - use reflect_tools:: + use format_tools:: { WithDebug, WithDisplay, diff --git a/module/core/reflect_tools/tests/inc/fundamental/to_string_test.rs b/module/core/format_tools/tests/inc/to_string_test.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/fundamental/to_string_test.rs rename to module/core/format_tools/tests/inc/to_string_test.rs diff --git a/module/core/reflect_tools/tests/inc/fundamental/to_string_with_fallback_test.rs b/module/core/format_tools/tests/inc/to_string_with_fallback_test.rs similarity index 100% rename from module/core/reflect_tools/tests/inc/fundamental/to_string_with_fallback_test.rs rename to module/core/format_tools/tests/inc/to_string_with_fallback_test.rs diff --git a/module/core/format_tools/tests/smoke_test.rs b/module/core/format_tools/tests/smoke_test.rs new file mode 100644 index 0000000000..828e9b016b --- /dev/null +++ b/module/core/format_tools/tests/smoke_test.rs @@ -0,0 +1,14 @@ + + +#[ test ] +fn local_smoke_test() +{ + ::test_tools::smoke_test_for_local_run(); +} + + +#[ test ] +fn published_smoke_test() +{ + ::test_tools::smoke_test_for_published_run(); +} diff --git a/module/core/format_tools/tests/tests.rs b/module/core/format_tools/tests/tests.rs new file mode 100644 index 0000000000..6ddece63a2 --- /dev/null +++ b/module/core/format_tools/tests/tests.rs @@ -0,0 +1,9 @@ + +#[ 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/reflect_tools/Cargo.toml b/module/core/reflect_tools/Cargo.toml index b4ff98aff1..42a0b8e4e7 100644 --- a/module/core/reflect_tools/Cargo.toml +++ b/module/core/reflect_tools/Cargo.toml @@ -37,13 +37,17 @@ full = [ "reflect_reflect", "reflect_newtype", ] -enabled = [] +enabled = [ + "reflect_tools_meta/enabled", + "derive_tools/enabled" +] reflect_reflect = [] reflect_newtype = [] [dependencies] -reflect_tools_meta = { workspace = true, features = [ "enabled" ] } -derive_tools = { workspace = true, features = [ "enabled", "derive_from", "derive_inner_from" ] } +reflect_tools_meta = { workspace = true, features = [] } +derive_tools = { workspace = true, features = ["derive_from", "derive_inner_from" ] } +# qqq : xxx : optimize features set [dev-dependencies] test_tools = { workspace = true } diff --git a/module/core/reflect_tools/src/reflect.rs b/module/core/reflect_tools/src/reflect.rs index 325fa5af21..9d3c8a288e 100644 --- a/module/core/reflect_tools/src/reflect.rs +++ b/module/core/reflect_tools/src/reflect.rs @@ -66,8 +66,8 @@ pub mod entity_hashset; pub mod primitive; pub mod fields; -pub mod to_string; -pub mod to_string_with_fallback; +// pub mod to_string; +// pub mod to_string_with_fallback; pub mod wrapper; #[ doc( inline ) ] @@ -106,12 +106,12 @@ pub mod protected #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::fields::orphan::*; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::to_string::orphan::*; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::to_string_with_fallback::orphan::*; + // #[ doc( inline ) ] + // #[ allow( unused_imports ) ] + // pub use super::to_string::orphan::*; + // #[ doc( inline ) ] + // #[ allow( unused_imports ) ] + // pub use super::to_string_with_fallback::orphan::*; #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::wrapper::orphan::*; @@ -160,12 +160,12 @@ pub mod exposed #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::fields::exposed::*; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::to_string::exposed::*; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::to_string_with_fallback::exposed::*; + // #[ doc( inline ) ] + // #[ allow( unused_imports ) ] + // pub use super::to_string::exposed::*; + // #[ doc( inline ) ] + // #[ allow( unused_imports ) ] + // pub use super::to_string_with_fallback::exposed::*; #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::wrapper::exposed::*; @@ -201,12 +201,12 @@ pub mod prelude #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::fields::prelude::*; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::to_string::prelude::*; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::to_string_with_fallback::prelude::*; + // #[ doc( inline ) ] + // #[ allow( unused_imports ) ] + // pub use super::to_string::prelude::*; + // #[ doc( inline ) ] + // #[ allow( unused_imports ) ] + // pub use super::to_string_with_fallback::prelude::*; #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::wrapper::prelude::*; diff --git a/module/core/reflect_tools/tests/inc/fundamental/fields_test.rs b/module/core/reflect_tools/tests/inc/fundamental/fields_test.rs index 59e9618665..703011a643 100644 --- a/module/core/reflect_tools/tests/inc/fundamental/fields_test.rs +++ b/module/core/reflect_tools/tests/inc/fundamental/fields_test.rs @@ -6,8 +6,8 @@ use the_module:: Fields, IteratorTrait, MaybeAs, - ToStringWith, - WithDebug, + // ToStringWith, + // WithDebug, }; use std:: @@ -27,111 +27,26 @@ pub struct TestObject pub tools : Option< Vec< HashMap< String, String > > >, } -// impl< 'a > Fields< 'a, &'static str, Option< Cow< 'a, String > > > -// for TestObject -// { -// fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, Option< Cow< 'a, String > > ) > -// { -// let mut dst : Vec< ( &'static str, Option< Cow< 'a, String > > ) > = Vec::new(); -// -// dst.push( ( "id", Some( Cow::Borrowed( &self.id ) ) ) ); -// dst.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ) ) ); -// dst.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ) ) ); -// -// if let Some( tools ) = &self.tools -// { -// dst.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ) ) ); -// } -// else -// { -// dst.push( ( "tools", None ) ); -// } -// -// dst.into_iter() -// } -// } - -impl< 'a, How > Fields< 'a, &'static str, MaybeAs< 'a, String, How > > +impl< 'a > Fields< 'a, &'static str, MaybeAs< 'a, String, () > > for TestObject -where - How : Clone + Copy + 'static, - String : ToStringWith< How >, - i64 : ToStringWith< How >, - Vec< String > : ToStringWith< How >, - Vec< HashMap< String, String > > : ToStringWith< How >, { - fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, How > ) > + fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, () > ) > { - let mut dst : Vec< ( &'static str, MaybeAs< 'a, String, How > ) > = Vec::new(); - - // fn into< 'a, V, How >( src : &'a V ) -> MaybeAs< 'a, String, How > - // where - // How : Clone + Copy + 'static, - // V : ToStringWith< How > + 'a, - // { - // MaybeAs::< 'a, String, How >::from - // ( - // < V as ToStringWith< How > >::to_string_with( src ) - // ) - // } - - fn add< 'a, V, How > - ( - dst : &mut Vec< ( &'static str, MaybeAs< 'a, String, How > ) >, - key : &'static str, - src : &'a V - ) - where - How : Clone + Copy + 'static, - V : ToStringWith< How > + 'a, - { - let val = MaybeAs::< 'a, String, How >::from - ( - < V as ToStringWith< How > >::to_string_with( src ) - ); - dst.push( ( key, val ) ); - } + let mut dst : Vec< ( &'static str, MaybeAs< 'a, String, () > ) > = Vec::new(); - // dst.push( ( "id", MaybeAs::< 'a, String, How >::from( &self.id ) ) ); - add( &mut dst, "id", &self.id ); - add( &mut dst, "created_at", &self.created_at ); - add( &mut dst, "file_ids", &self.file_ids ); + dst.push( ( "id", Some( Cow::Borrowed( &self.id ) ).into() ) ); + dst.push( ( "created_at", Some( Cow::Owned( self.created_at.to_string() ) ).into() ) ); + dst.push( ( "file_ids", Some( Cow::Owned( format!( "{:?}", self.file_ids ) ) ).into() ) ); if let Some( tools ) = &self.tools { - add( &mut dst, "tools", tools ); + dst.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ).into() ) ); } else { - dst.push( ( "tools", MaybeAs::none() ) ); + dst.push( ( "tools", None.into() ) ); } -// dst.push( ( "id", into( &self.id ) ) ); -// dst.push( ( "created_at", into( &self.created_at ) ) ); -// dst.push( ( "file_ids", into( &self.file_ids ) ) ); -// -// if let Some( tools ) = &self.tools -// { -// dst.push( ( "tools", into( &self.tools ) ) ); -// } -// else -// { -// dst.push( ( "tools", MaybeAs::none() ) ); -// } - - // dst.push( ( "id", MaybeAs::< 'a, String, How >::from( < String as ToStringWith< How > >::to_string_with( &self.id ) ) ) ); -// dst.push( ( "created_at", self.created_at.to_string_with().into() ) ); -// dst.push( ( "file_ids", self.file_ids.to_string_with().into() ) ); -// -// if let Some( tools ) = &self.tools -// { -// dst.push( ( "tools", self.tools.to_string_with().into() ) ); -// } -// else -// { -// dst.push( ( "tools", MaybeAs::none() ) ); -// } - dst.into_iter() } } @@ -174,15 +89,14 @@ fn basic() ), }; - let fields : Vec< ( &str, MaybeAs< '_, String, WithDebug > ) > = test_object.fields().collect(); + let fields : Vec< ( &str, MaybeAs< '_, String, () > ) > = test_object.fields().collect(); assert_eq!( fields.len(), 4 ); - // assert!( is_borrowed( &fields[ 0 ].1 ) ); - // assert!( !is_borrowed( &fields[ 1 ].1 ) ); - // assert!( !is_borrowed( &fields[ 2 ].1 ) ); - // assert!( !is_borrowed( &fields[ 3 ].1 ) ); - // xxx - assert_eq!( fields[ 0 ], ( "id", Some( Cow::Borrowed( &"\"12345\"".to_string() ) ).into() ) ); + 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".to_string() ) ).into() ) ); assert_eq!( fields[ 1 ], ( "created_at", Some( Cow::Owned( "1627845583".to_string() ) ).into() ) ); assert_eq!( fields[ 2 ], ( "file_ids", Some( Cow::Owned( "[\"file1\", \"file2\"]".to_string() ) ).into() ) ); assert_eq!( fields[ 3 ].0, "tools" ); diff --git a/module/core/reflect_tools/tests/inc/mod.rs b/module/core/reflect_tools/tests/inc/mod.rs index 37b3984116..e7531dff91 100644 --- a/module/core/reflect_tools/tests/inc/mod.rs +++ b/module/core/reflect_tools/tests/inc/mod.rs @@ -9,9 +9,9 @@ mod fundamental use super::*; mod fields_test; - mod to_string_test; - mod to_string_example; - mod to_string_with_fallback_test; + // mod to_string_test; + // mod to_string_example; + // mod to_string_with_fallback_test; } diff --git a/module/move/assistant/Cargo.toml b/module/move/assistant/Cargo.toml index c3475e822a..b86bf9f114 100644 --- a/module/move/assistant/Cargo.toml +++ b/module/move/assistant/Cargo.toml @@ -31,6 +31,7 @@ enabled = [ "former/enabled" ] [dependencies] # xxx : qqq : optimze features former = { workspace = true, features = [ "full" ] } +format_tools = { workspace = true, features = [ "full" ] } reflect_tools = { workspace = true, features = [ "full" ] } openai-api-rs = { version = "4.0.9" } tokio = { version = "1", features = ["full"] } From b38c7073dc76d3ec54ee1279a8aa1b00f0167b2a Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 22:04:24 +0300 Subject: [PATCH 094/143] assitant : fix it --- module/move/assistant/Cargo.toml | 6 +- module/move/assistant/src/client.rs | 89 +++++++++++++++++++ module/move/assistant/src/lib.rs | 75 +--------------- module/move/assistant/tests/inc/basic_test.rs | 7 ++ module/move/assistant/tests/inc/mod.rs | 2 +- 5 files changed, 106 insertions(+), 73 deletions(-) create mode 100644 module/move/assistant/src/client.rs create mode 100644 module/move/assistant/tests/inc/basic_test.rs diff --git a/module/move/assistant/Cargo.toml b/module/move/assistant/Cargo.toml index b86bf9f114..6e2af1a870 100644 --- a/module/move/assistant/Cargo.toml +++ b/module/move/assistant/Cargo.toml @@ -26,7 +26,11 @@ all-features = false [features] default = [ "enabled" ] full = [ "enabled" ] -enabled = [ "former/enabled" ] +enabled = [ + "former/enabled", + "format_tools/enabled", + "reflect_tools/enabled", +] [dependencies] # xxx : qqq : optimze features diff --git a/module/move/assistant/src/client.rs b/module/move/assistant/src/client.rs new file mode 100644 index 0000000000..4cd02b5829 --- /dev/null +++ b/module/move/assistant/src/client.rs @@ -0,0 +1,89 @@ +//! +//! Client of API. +//! + +/// Internal namespace. +pub( crate ) mod private +{ + + pub use openai_api_rs::v1:: + { + api::Client, + assistant::AssistantObject, + }; + + use std:: + { + env, + error::Error, + }; + + use former::Former; + + /// Options for configuring the OpenAI API client. + #[ derive( Former, Debug ) ] + pub struct ClientOptions + { + /// The API key for authenticating with the OpenAI API. + pub api_key : Option< String >, + } + + /// Creates a new OpenAI API client using the API key from the environment variable `OPENAI_API_KEY`. + pub fn client() -> Result< Client, Box< dyn Error > > + { + let api_key = env::var( "OPENAI_API_KEY" )?; + Ok( Client::new( api_key ) ) + } + + +} + +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; + +} + +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + ClientOptions, + client, + AssistantObject, + }; + + // #[ doc( inline ) ] + // #[ allow( unused_imports ) ] + // pub use reflect_tools:: + // { + // Fields, + // _IteratorTrait, + // IteratorTrait, + // }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/move/assistant/src/lib.rs b/module/move/assistant/src/lib.rs index 38cf5d09e9..4d5468f9f7 100644 --- a/module/move/assistant/src/lib.rs +++ b/module/move/assistant/src/lib.rs @@ -8,61 +8,9 @@ /// Internal namespace. pub( crate ) mod private { - - pub use openai_api_rs::v1:: - { - api::Client, - assistant::AssistantObject, - }; - - use std:: - { - env, - error::Error, - }; - - use former::Former; - - /// Options for configuring the OpenAI API client. - #[ derive( Former, Debug ) ] - pub struct ClientOptions - { - /// The API key for authenticating with the OpenAI API. - pub api_key : Option< String >, - } - - /// Creates a new OpenAI API client using the API key from the environment variable `OPENAI_API_KEY`. - pub fn client() -> Result< Client, Box< dyn Error > > - { - let api_key = env::var( "OPENAI_API_KEY" )?; - Ok( Client::new( api_key ) ) - } - - } -// /// Reflections. -// pub mod reflect; -// pub use reflect::*; -// /// Universal wrapper. -// pub mod wrapper_ref; -// pub use wrapper_ref::*; -// /// Universal wrapper. -// pub mod wrapper_option_cow_ref; -// pub use wrapper_option_cow_ref::*; -// /// Conversion to string. -// pub mod to_string; -// pub use to_string::*; - -/// Nice print. -pub mod print; -// pub use print::*; -/// Nice print's wrapper. -pub mod as_table; -// pub use as_table::*; -/// Table interface. -pub mod table; -// pub use table::*; +pub mod client; #[ allow( unused_imports ) ] pub use protected::*; @@ -75,9 +23,7 @@ pub mod protected #[ allow( unused_imports ) ] pub use super:: { - print::orphan::*, - as_table::orphan::*, - table::orphan::*, + client::orphan::*, }; #[ doc( inline ) ] @@ -102,18 +48,7 @@ pub mod exposed #[ allow( unused_imports ) ] pub use super:: { - print::exposed::*, - as_table::exposed::*, - table::exposed::*, - }; - - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::private:: - { - ClientOptions, - client, - AssistantObject, + client::exposed::*, }; #[ doc( inline ) ] @@ -135,9 +70,7 @@ pub mod prelude #[ allow( unused_imports ) ] pub use super:: { - print::prelude::*, - as_table::prelude::*, - table::prelude::*, + client::prelude::*, }; } diff --git a/module/move/assistant/tests/inc/basic_test.rs b/module/move/assistant/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/move/assistant/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/move/assistant/tests/inc/mod.rs b/module/move/assistant/tests/inc/mod.rs index 32cb24ce64..0706620c6e 100644 --- a/module/move/assistant/tests/inc/mod.rs +++ b/module/move/assistant/tests/inc/mod.rs @@ -1,6 +1,6 @@ #[ allow( unused_imports ) ] use super::*; -mod print_test; +mod basic_test; mod experiment; From cb129051d1a929519a4c1e6e5ec98e06e3dc4895 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 29 Mar 2025 07:33:14 +0200 Subject: [PATCH 095/143] assistant wip --- .../src/agents/scenario_processed.rs | 99 +++++++++++++++++++ .../move/assistant/src/agents/scenario_raw.rs | 71 +++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 module/move/assistant/src/agents/scenario_processed.rs create mode 100644 module/move/assistant/src/agents/scenario_raw.rs diff --git a/module/move/assistant/src/agents/scenario_processed.rs b/module/move/assistant/src/agents/scenario_processed.rs new file mode 100644 index 0000000000..ada486efba --- /dev/null +++ b/module/move/assistant/src/agents/scenario_processed.rs @@ -0,0 +1,99 @@ +//! +//! Scenario representation. Stores parsed representation of templates and paths. +//! This is the type used for running scenarios. +//! +//! For a more simplistic representation use `ScenarioRaw`. +//! + +mod private +{ + use std::collections::HashMap; + + use crate::*; + use agents:: + { + path::Path, + scenario_raw:: + { + ScenarioRaw, + NodeRaw, + }, + }; + + /// New type for templates in scenarios. + #[ derive( Debug, PartialEq ) ] + pub struct TemplateBody( pub String ); + + /// Struct that represents user written scenarios. + /// + /// This is a processed form of a scenario, paths are distinguished here with types. + /// For more simplistic representation of scenarios, use `ScenarioRaw` type. + #[ derive( Debug, PartialEq ) ] + pub struct ScenarioProcessed + { + /// Nodes in the scenario. + pub nodes: Vec< Node >, + } + + impl TryFrom< ScenarioRaw > for ScenarioProcessed + { + type Error = std::io::Error; + + fn try_from( scenario_raw : ScenarioRaw ) -> Result< Self, Self::Error > + { + let nodes : Result< Vec< Node >, Self::Error > = + scenario_raw.nodes.into_iter().map( | rn | Node::try_from( rn ) ).collect(); + + Ok( Self { nodes : nodes? } ) + } + } + + /// Node representation in a scenario file. + /// + /// This is a processed form of a node, paths are distinguished here with types. + /// For more simplistic representation of scenarios, use `NodeRaw` type. + #[ derive( Debug, PartialEq ) ] + pub struct Node + { + /// ID of the node. Must be unique, will also identify node output. + pub id : String, + + /// Type of the node. + pub typ : Path, + + /// Parameters of the node. + pub params : HashMap< String, String >, + + /// ID of the next node to execute. + pub next : Path, + } + + impl TryFrom< NodeRaw > for Node + { + type Error = std::io::Error; + + fn try_from( node_raw : NodeRaw ) -> Result< Self, Self::Error > + { + Ok + ( + Self + { + id : node_raw.id, + typ : Path::try_from( node_raw.typ )?, + params : node_raw.params, + next : Path::try_from( node_raw.next )?, + } + ) + } + } +} + +crate::mod_interface! +{ + own use + { + TemplateBody, + ScenarioProcessed, + Node, + }; +} \ No newline at end of file diff --git a/module/move/assistant/src/agents/scenario_raw.rs b/module/move/assistant/src/agents/scenario_raw.rs new file mode 100644 index 0000000000..9c588d1fbb --- /dev/null +++ b/module/move/assistant/src/agents/scenario_raw.rs @@ -0,0 +1,71 @@ +//! +//! Raw scenario representation. Captures only the basic syntax of scenario file. +//! +//! For more detailed representation, use `ScenarioProcessed`. +//! + +mod private +{ + use std:: + { + io, + collections::HashMap, + }; + + use former::Former; + use serde:: + { + Serialize, + Deserialize, + }; + + /// Struct that represents user written scenarios. + /// + /// This is a raw form of a scenario, only the general structure is captured there. + /// For more detailed representation of scenarios, use `ScenarioProcessed` type. + #[ derive( Debug, Serialize, Deserialize, Former, PartialEq ) ] + pub struct ScenarioRaw + { + /// Nodes in the scenario. + pub nodes: Vec< NodeRaw >, + } + + impl ScenarioRaw + { + /// Read scenario file in YAML format. + pub fn read( reader : impl io::Read ) -> Result< Self, serde_yaml::Error > + { + serde_yaml::from_reader( reader ) + } + } + + /// Node representation in a scenario file. + /// + /// This is a raw form of a node, only the general structure is captured there. + /// For more detailed representation of scenarios, use `Node` type. + #[ derive( Debug, Serialize, Deserialize, Former, PartialEq ) ] + pub struct NodeRaw + { + /// ID of the node. Must be unique, will also identify node output. + pub id : String, + + /// Type of the node. Represented as a path. + pub typ : String, + + /// Rest of the key-value pairs in the node that are specific to node types. + #[ serde( flatten ) ] + pub params : HashMap< String, String >, + + /// ID of the next node to execute. Represented as a path. + pub next : String, + } +} + +crate::mod_interface! +{ + own use + { + ScenarioRaw, + NodeRaw, + }; +} \ No newline at end of file From ad774c11749c6c0236c81302c1533c4f02e72e49 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 29 Mar 2025 07:45:07 +0200 Subject: [PATCH 096/143] merge issue --- Cargo.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bad88344a2..d919f94184 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -148,12 +148,12 @@ default-features = false # features = [ "enabled" ] # xxx : remove features, maybe -[workspace.dependencies.format_tools] -version = "~0.1.0" -path = "module/core/format_tools" -default-features = false -features = [ "enabled" ] -# xxx : remove features, maybe +# [workspace.dependencies.format_tools] +# version = "~0.1.0" +# path = "module/core/format_tools" +# default-features = false +# features = [ "enabled" ] +# # xxx : remove features, maybe # [workspace.dependencies.type_constructor] # version = "~0.3.0" From 3925a7a61149d2905f0bfe1575894bb1712b4143 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 29 Mar 2025 07:46:34 +0200 Subject: [PATCH 097/143] assistant: formatting --- module/move/assistant/src/debug/run_object.rs | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/module/move/assistant/src/debug/run_object.rs b/module/move/assistant/src/debug/run_object.rs index efe2ce1e02..cc2fda5357 100644 --- a/module/move/assistant/src/debug/run_object.rs +++ b/module/move/assistant/src/debug/run_object.rs @@ -9,28 +9,34 @@ use openai_api_rs::v1::run::RunObject; pub struct RunObjectWrap( pub RunObject ); /// Manually implemented `Clone`, as `RunObject` does not implement it. -impl Clone for RunObjectWrap { - fn clone(&self) -> Self { - RunObjectWrap(RunObject { - id : self.0.id.clone(), - object : self.0.object.clone(), - created_at : self.0.created_at, - thread_id : self.0.thread_id.clone(), - assistant_id : self.0.assistant_id.clone(), - status : self.0.status.clone(), - required_action : self.0.required_action.clone(), - last_error : self.0.last_error.clone(), - expires_at : self.0.expires_at, - started_at : self.0.started_at, - cancelled_at : self.0.cancelled_at, - failed_at : self.0.failed_at, - completed_at : self.0.completed_at, - model : self.0.model.clone(), - instructions : self.0.instructions.clone(), - tools : self.0.tools.clone(), - metadata : self.0.metadata.clone(), - headers : self.0.headers.clone(), - }) +impl Clone for RunObjectWrap +{ + fn clone(&self) -> Self + { + RunObjectWrap + ( + RunObject + { + id : self.0.id.clone(), + object : self.0.object.clone(), + created_at : self.0.created_at, + thread_id : self.0.thread_id.clone(), + assistant_id : self.0.assistant_id.clone(), + status : self.0.status.clone(), + required_action : self.0.required_action.clone(), + last_error : self.0.last_error.clone(), + expires_at : self.0.expires_at, + started_at : self.0.started_at, + cancelled_at : self.0.cancelled_at, + failed_at : self.0.failed_at, + completed_at : self.0.completed_at, + model : self.0.model.clone(), + instructions : self.0.instructions.clone(), + tools : self.0.tools.clone(), + metadata : self.0.metadata.clone(), + headers : self.0.headers.clone(), + } + ) } } From 5c0a13ffdab5fa280976dfd8e762e81c4a079248 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 29 Mar 2025 10:50:20 +0200 Subject: [PATCH 098/143] assistant : renames --- module/move/assistant/src/agents/scenario_processed.rs | 10 +++++----- module/move/assistant/src/agents/scenario_raw.rs | 4 ++-- .../scenario_raw_processors/plantuml_formatter.rs | 4 ++-- .../assistant/tests/inc/agents_tests/test_scenarios.rs | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/module/move/assistant/src/agents/scenario_processed.rs b/module/move/assistant/src/agents/scenario_processed.rs index b43e9c0075..ada486efba 100644 --- a/module/move/assistant/src/agents/scenario_processed.rs +++ b/module/move/assistant/src/agents/scenario_processed.rs @@ -41,9 +41,9 @@ mod private fn try_from( scenario_raw : ScenarioRaw ) -> Result< Self, Self::Error > { - let nodes : Result< Vec< Node >, Self::Error > = + let nodes : Result< Vec< Node >, Self::Error > = scenario_raw.nodes.into_iter().map( | rn | Node::try_from( rn ) ).collect(); - + Ok( Self { nodes : nodes? } ) } } @@ -55,11 +55,11 @@ mod private #[ derive( Debug, PartialEq ) ] pub struct Node { - /// ID of the node. Must be unique, will also identify node output. + /// ID of the node. Must be unique, will also identify node output. pub id : String, /// Type of the node. - pub r#type : Path, + pub typ : Path, /// Parameters of the node. pub params : HashMap< String, String >, @@ -79,7 +79,7 @@ mod private Self { id : node_raw.id, - r#type : Path::try_from( node_raw.r#type )?, + typ : Path::try_from( node_raw.typ )?, params : node_raw.params, next : Path::try_from( node_raw.next )?, } diff --git a/module/move/assistant/src/agents/scenario_raw.rs b/module/move/assistant/src/agents/scenario_raw.rs index 8aef1e2250..9c588d1fbb 100644 --- a/module/move/assistant/src/agents/scenario_raw.rs +++ b/module/move/assistant/src/agents/scenario_raw.rs @@ -46,11 +46,11 @@ mod private #[ derive( Debug, Serialize, Deserialize, Former, PartialEq ) ] pub struct NodeRaw { - /// ID of the node. Must be unique, will also identify node output. + /// ID of the node. Must be unique, will also identify node output. pub id : String, /// Type of the node. Represented as a path. - pub r#type : String, + pub typ : String, /// Rest of the key-value pairs in the node that are specific to node types. #[ serde( flatten ) ] diff --git a/module/move/assistant/src/agents/scenario_raw_processors/plantuml_formatter.rs b/module/move/assistant/src/agents/scenario_raw_processors/plantuml_formatter.rs index 8f1114fe2d..2bfed18c17 100644 --- a/module/move/assistant/src/agents/scenario_raw_processors/plantuml_formatter.rs +++ b/module/move/assistant/src/agents/scenario_raw_processors/plantuml_formatter.rs @@ -25,12 +25,12 @@ mod private writer.write( b" {\n" )?; writer.write( b" \"type\": \"" )?; - writer.write( node.r#type.as_bytes() )?; + writer.write( node.typ.as_bytes() )?; writer.write( b"\"" )?; if node.params.len() > 0 { - writer.write( b"," )?; + writer.write( b"," )?; } writer.write( b"\n" )?; diff --git a/module/move/assistant/tests/inc/agents_tests/test_scenarios.rs b/module/move/assistant/tests/inc/agents_tests/test_scenarios.rs index 02433a68ea..3da3ce3e34 100644 --- a/module/move/assistant/tests/inc/agents_tests/test_scenarios.rs +++ b/module/move/assistant/tests/inc/agents_tests/test_scenarios.rs @@ -14,7 +14,7 @@ pub fn gen_test_scenario_raw() -> ScenarioRaw [ NodeRaw::former() .id( "node_1".to_string() ) - .r#type( "agents::completion".to_string() ) + .typ( "agents::completion".to_string() ) .params( { let mut map : HashMap< String, String > = HashMap::new(); @@ -27,7 +27,7 @@ pub fn gen_test_scenario_raw() -> ScenarioRaw NodeRaw::former() .id( "node_2".to_string() ) - .r#type( "agents::classify".to_string() ) + .typ( "agents::classify".to_string() ) .params( { let mut map : HashMap< String, String > = HashMap::new(); @@ -49,7 +49,7 @@ pub fn gen_test_scenario_raw_wrong() -> ScenarioRaw [ NodeRaw::former() .id( "node_1".to_string() ) - .r#type( ":agents:".to_string() ) // This part is incorrect. Path written in wrong syntax. + .typ( ":agents:".to_string() ) // This part is incorrect. Path written in wrong syntax. .params( { let mut map : HashMap< String, String > = HashMap::new(); From eb06b9bfc4d33e14a673dd7b6fcf21e416508835 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 11:42:20 +0300 Subject: [PATCH 099/143] fix regression --- module/core/clone_dyn_types/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/core/clone_dyn_types/src/lib.rs b/module/core/clone_dyn_types/src/lib.rs index 48e82f2a3b..a89d569ef0 100644 --- a/module/core/clone_dyn_types/src/lib.rs +++ b/module/core/clone_dyn_types/src/lib.rs @@ -190,7 +190,8 @@ mod private unsafe { let mut ptr = ref_dyn as *const T; - let data_ptr = &raw mut ptr as *mut *mut (); // fix clippy + let data_ptr = &mut ptr as *mut *const T as *mut *mut (); // don't change it + // let data_ptr = &raw mut ptr as *mut *mut (); // fix clippy *data_ptr = < T as CloneDyn >::__clone_dyn( ref_dyn, DontCallMe ); Box::from_raw( ptr as *mut T ) } From 8577892a3634b4b9e756db5962788b2a8d529608 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 12:27:28 +0300 Subject: [PATCH 100/143] llm_tools --- module/move/assistant/src/agents.rs | 16 -- module/move/assistant/src/agents/context.rs | 150 ---------- module/move/assistant/src/agents/path.rs | 241 ---------------- .../src/agents/scenario_processed.rs | 99 ------- .../move/assistant/src/agents/scenario_raw.rs | 71 ----- .../src/agents/scenario_raw_processors.rs | 13 - .../plantuml_formatter.rs | 76 ----- .../scenario_raw_processors/yaml_formatter.rs | 26 -- module/move/assistant/src/lib.rs | 1 - module/move/assistant/src/main.rs | 28 -- .../tests/inc/agents_tests/context_test.rs | 128 --------- .../assistant/tests/inc/agents_tests/mod.rs | 9 - .../tests/inc/agents_tests/path_test.rs | 259 ------------------ .../agents_tests/scenario_processed_test.rs | 25 -- .../scenario_raw_processors/mod.rs | 4 - .../plantuml_formatter_test.rs | 33 --- .../yaml_formatter_test.rs | 33 --- .../inc/agents_tests/scenario_raw_test.rs | 49 ---- .../tests/inc/agents_tests/test_scenarios.rs | 64 ----- module/move/assistant/tests/inc/mod.rs | 2 - module/move/assistant/tests/smoke_test.rs | 1 + module/move/assistant/tests/tests.rs | 1 + module/move/llm_tools/.key/readme.md | 20 ++ module/move/llm_tools/Cargo.toml | 61 +++++ module/move/llm_tools/License | 22 ++ module/move/llm_tools/Readme.md | 35 +++ module/move/llm_tools/api/list.http | 11 + module/move/llm_tools/src/bin/main.rs | 55 ++++ module/move/llm_tools/src/client.rs | 39 +++ module/move/llm_tools/src/debug.rs | 30 ++ .../llm_tools/src/debug/assistant_object.rs | 84 ++++++ module/move/llm_tools/src/debug/file_data.rs | 50 ++++ module/move/llm_tools/src/debug/run_object.rs | 79 ++++++ module/move/llm_tools/src/lib.rs | 42 +++ module/move/llm_tools/src/secret.rs | 219 +++++++++++++++ module/move/llm_tools/src/util.rs | 10 + .../move/llm_tools/src/util/display_table.rs | 154 +++++++++++ module/move/llm_tools/tests/inc/basic_test.rs | 7 + module/move/llm_tools/tests/inc/experiment.rs | 0 module/move/llm_tools/tests/inc/mod.rs | 5 + module/move/llm_tools/tests/smoke_test.rs | 13 + module/move/llm_tools/tests/tests.rs | 9 + 42 files changed, 947 insertions(+), 1327 deletions(-) delete mode 100644 module/move/assistant/src/agents.rs delete mode 100644 module/move/assistant/src/agents/context.rs delete mode 100644 module/move/assistant/src/agents/path.rs delete mode 100644 module/move/assistant/src/agents/scenario_processed.rs delete mode 100644 module/move/assistant/src/agents/scenario_raw.rs delete mode 100644 module/move/assistant/src/agents/scenario_raw_processors.rs delete mode 100644 module/move/assistant/src/agents/scenario_raw_processors/plantuml_formatter.rs delete mode 100644 module/move/assistant/src/agents/scenario_raw_processors/yaml_formatter.rs delete mode 100644 module/move/assistant/src/main.rs delete mode 100644 module/move/assistant/tests/inc/agents_tests/context_test.rs delete mode 100644 module/move/assistant/tests/inc/agents_tests/mod.rs delete mode 100644 module/move/assistant/tests/inc/agents_tests/path_test.rs delete mode 100644 module/move/assistant/tests/inc/agents_tests/scenario_processed_test.rs delete mode 100644 module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/mod.rs delete mode 100644 module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/plantuml_formatter_test.rs delete mode 100644 module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/yaml_formatter_test.rs delete mode 100644 module/move/assistant/tests/inc/agents_tests/scenario_raw_test.rs delete mode 100644 module/move/assistant/tests/inc/agents_tests/test_scenarios.rs create mode 100644 module/move/llm_tools/.key/readme.md create mode 100644 module/move/llm_tools/Cargo.toml create mode 100644 module/move/llm_tools/License create mode 100644 module/move/llm_tools/Readme.md create mode 100644 module/move/llm_tools/api/list.http create mode 100644 module/move/llm_tools/src/bin/main.rs create mode 100644 module/move/llm_tools/src/client.rs create mode 100644 module/move/llm_tools/src/debug.rs create mode 100644 module/move/llm_tools/src/debug/assistant_object.rs create mode 100644 module/move/llm_tools/src/debug/file_data.rs create mode 100644 module/move/llm_tools/src/debug/run_object.rs create mode 100644 module/move/llm_tools/src/lib.rs create mode 100644 module/move/llm_tools/src/secret.rs create mode 100644 module/move/llm_tools/src/util.rs create mode 100644 module/move/llm_tools/src/util/display_table.rs create mode 100644 module/move/llm_tools/tests/inc/basic_test.rs create mode 100644 module/move/llm_tools/tests/inc/experiment.rs create mode 100644 module/move/llm_tools/tests/inc/mod.rs create mode 100644 module/move/llm_tools/tests/smoke_test.rs create mode 100644 module/move/llm_tools/tests/tests.rs diff --git a/module/move/assistant/src/agents.rs b/module/move/assistant/src/agents.rs deleted file mode 100644 index 0f04d8a61c..0000000000 --- a/module/move/assistant/src/agents.rs +++ /dev/null @@ -1,16 +0,0 @@ -//! -//! Main module for agents framework. -//! - -mod private {} - -crate::mod_interface! -{ - - layer path; - layer context; - layer scenario_raw; - layer scenario_raw_processors; - layer scenario_processed; - -} \ No newline at end of file diff --git a/module/move/assistant/src/agents/context.rs b/module/move/assistant/src/agents/context.rs deleted file mode 100644 index a18a535780..0000000000 --- a/module/move/assistant/src/agents/context.rs +++ /dev/null @@ -1,150 +0,0 @@ -//! -//! Context representation. Can be used as compile-time context and as a runtime-context. -//! -//! Represents a simplistic "filesystem" with directories and terminal objects. -//! - -mod private -{ - use std::collections::HashMap; - - use crate::*; - use agents::path:: - { - Path, - PATH_SEPARATOR, - }; - - /// Represents a directory in a simplistic in-memory "filesystem" - /// with other directories and terminal objects. - /// - /// `T` is the type of terminal object. - #[ derive( Debug, PartialEq, Clone, Default ) ] - pub struct ContextDir< T > - { - /// Internal map of entry names and entries data (a directory or a terminal object). - map : HashMap< String, ContextEntry< T > >, - } - - impl< T > ContextDir< T > - { - /// Create an empty `ContextDir`. - pub fn new() -> Self - { - Self - { - map : HashMap::new() - } - } - - /// Add new entry to the directory. - /// - /// Returns `true` if entry was successfully added. - /// Returns `false` if there is already and entry with such name. - /// Old entry will not be overriden. - pub fn add( &mut self, name : impl Into< String >, entry : ContextEntry< T > ) -> bool - { - let name = name.into(); - - if self.map.contains_key( name.as_str() ) - { - false - } - else - { - self.map.insert( name, entry ); - true - } - } - - /// Get an entry by its name. Returns `None` is there is no such entry. - /// - /// `name` must be a valid path item. Refer to `path::PATH_ITEM_REGEX_STR` for syntax. - /// - /// This method is useful for quickly getting an entry only by its name. - /// For complex paths, where your object is located in several consecutives directories, - /// you can use `Path` type and use method `ContextDir::get_by_path`. - pub fn get( &self, name : impl AsRef< str > ) -> Option< &ContextEntry< T > > - { - self.map.get( name.as_ref() ) - } - - /// Get an entry by its path. Returns `None` is there is no such entry. - /// - /// This function accepts both relative and absolute paths and it will - /// treat itself as the root. - pub fn get_by_path( &self, path : &Path ) -> Option< &ContextEntry< T > > - { - let mut cur : Option< &ContextEntry< T > > = None; - - for component in path.components() - { - if component == PATH_SEPARATOR - { - continue; - } - - match cur - { - None => - { - cur = self.get( component ); - }, - - Some( entry ) => - { - match entry - { - ContextEntry::Terminal( _ ) => - { - return None; - }, - - ContextEntry::Dir( dir ) => - { - cur = dir.get( component ); - } - } - } - } - - if cur.is_none() - { - return None; - } - } - - cur - } - } - - /// Entry in a simplistic in-memory "filesystem": either a directory or a terminal object `T`. - /// - /// Notice, this struct does not store the name of the entry. - #[ derive( Debug, PartialEq, Clone ) ] - pub enum ContextEntry< T > - { - /// Directory in context. - Dir( ContextDir< T > ), - - /// Terminal object. - Terminal( T ), - } - - impl< T > Into< ContextEntry< T > > for ContextDir< T > - { - fn into( self ) -> ContextEntry< T > - { - ContextEntry::Dir( self ) - } - } -} - -crate::mod_interface! -{ - own use - { - ContextDir, - ContextEntry, - }; -} \ No newline at end of file diff --git a/module/move/assistant/src/agents/path.rs b/module/move/assistant/src/agents/path.rs deleted file mode 100644 index d0c29a15dd..0000000000 --- a/module/move/assistant/src/agents/path.rs +++ /dev/null @@ -1,241 +0,0 @@ -//! -//! Paths in agents graph. -//! - -mod private -{ - use std:: - { - io, - fmt, - ops::Deref, - sync::LazyLock, - }; - - use serde:: - { - Serialize, - Deserialize, - }; - - use regex::Regex; - - /// Path separator string. - pub const PATH_SEPARATOR : &str = "::"; - - /// Regular expression for `Path` items. Represented in `&str`. - /// It is not anchored to start and end of the string. - /// - /// If you want to match against this expression, use `PATH_ITEM_REGEX`. - pub const PATH_ITEM_REGEX_STR : &str = r"[a-zA-Z0-9_ -]+"; - - /// Regular expression for `Path`. You can match whole `&str` with this type. - pub static PATH_REGEX : LazyLock< Regex > = LazyLock::new( || - { - let regex = format! - ( - r"^({sep})?({item}({sep}{item})*({sep})?)?$", - sep = PATH_SEPARATOR, - item = PATH_ITEM_REGEX_STR, - ); - - Regex::new( ®ex ).unwrap() - }); - - /// New type for paths in agents graph. Use `TryFrom` implementation - /// to create `Path`s. - /// - /// Paths resemble filesystem path, path separator is `::`. - /// Absolute path starts with `::`. - #[ derive( Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize ) ] - pub struct Path( String ); - - impl Path - { - /// Returns the parent directory, if it exists. - /// - /// Returns `None` if the `Path` terminates in a root or if it's the empty string. - #[ inline ] - pub fn parent( &self ) -> Option< Path > - { - /// Find parent of a `Path`. - /// - /// This method uses `&str` as an argument instead of `Path` - /// in order to be more general and handle trailing `::` case. - fn find_parent( s : &str ) -> Option< &str > - { - s.rfind( PATH_SEPARATOR ) - .map( | sep_pos | - { - if sep_pos == 0 - { - // We found root. We should not return string before `::`, - // as it will be empty. - Some( PATH_SEPARATOR ) - } - else if sep_pos == s.len() - PATH_SEPARATOR.len() - { - // We found trailing `::`. We should continue looking for last separator. - find_parent( &s[ .. sep_pos ] ) - } - else - { - Some( &s[ .. sep_pos ] ) - } - }) - .flatten() - } - - find_parent( self.0.as_str() ) - .map( | s | Self( s.to_string() ) ) - } - - /// Returns whether the `Path` is relative (does not start with `::`). - pub fn is_relative( &self ) -> bool - { - !self.is_absolute() - } - - /// Returns whether the `Path` is absolute (starts with `::`). - pub fn is_absolute( &self ) -> bool - { - self.0.starts_with( PATH_SEPARATOR ) - } - - /// Creates an owned `Path` by joining a given path to `self`. - /// - /// If path is joined with an absolute path, then this absolute - /// path will be returned. - #[ inline ] - pub fn join( &self, path : &Path ) -> Self - { - if path.is_absolute() - { - path.clone() - } - else - { - if self.0.ends_with( PATH_SEPARATOR ) - { - Self( format!( "{}{}", self.0, path.0 ) ) - } - else - { - Self( format!( "{}::{}", self.0, path.0 ) ) - } - } - } - - /// Checks if the `Path` starts with a given base path. - #[ inline ] - pub fn starts_with( &self, base : &Path ) -> bool - { - self.0.starts_with( base.0.as_str() ) - } - - /// Returns the inner `String`. - #[ inline( always ) ] - pub fn inner( self ) -> String - { - self.0 - } - - /// Iterate over components of a `Path`. If the `Path` is absolute, then the first - /// element will be `::`. - pub fn components( &self ) -> impl Iterator< Item = &str > - { - self.0.split( PATH_SEPARATOR ).map( | c | - { - if c.is_empty() - { - PATH_SEPARATOR - } - else - { - c - } - }) - } - } - - impl fmt::Display for Path - { - #[ inline ] - fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result - { - write!( f, "{}", self.0 ) - } - } - - impl TryFrom< String > for Path - { - type Error = io::Error; - - fn try_from( src : String ) -> Result< Self, Self::Error > - { - if PATH_REGEX.is_match( src.as_str() ) - { - Ok( Self ( src ) ) - } - else - { - Err( io::Error::from( io::ErrorKind::InvalidData ) ) - } - } - } - - impl TryFrom< &str > for Path - { - type Error = io::Error; - - fn try_from( src : &str ) -> Result< Self, Self::Error > - { - if PATH_REGEX.is_match( src ) - { - Ok( Self ( src.to_string() ) ) - } - else - { - Err( io::Error::from( io::ErrorKind::InvalidData ) ) - } - } - } - - impl AsRef< str > for Path - { - #[ inline ] - fn as_ref( &self ) -> &str - { - self.0.as_ref() - } - } - - impl Into< String > for Path - { - #[ inline ] - fn into( self ) -> String - { - self.0 - } - } - - impl Deref for Path - { - type Target = str; - - #[ inline ] - fn deref( &self ) -> &Self::Target - { - &self.0 - } - } -} - -crate::mod_interface! -{ - own use - { - Path, - PATH_SEPARATOR, - }; -} \ No newline at end of file diff --git a/module/move/assistant/src/agents/scenario_processed.rs b/module/move/assistant/src/agents/scenario_processed.rs deleted file mode 100644 index ada486efba..0000000000 --- a/module/move/assistant/src/agents/scenario_processed.rs +++ /dev/null @@ -1,99 +0,0 @@ -//! -//! Scenario representation. Stores parsed representation of templates and paths. -//! This is the type used for running scenarios. -//! -//! For a more simplistic representation use `ScenarioRaw`. -//! - -mod private -{ - use std::collections::HashMap; - - use crate::*; - use agents:: - { - path::Path, - scenario_raw:: - { - ScenarioRaw, - NodeRaw, - }, - }; - - /// New type for templates in scenarios. - #[ derive( Debug, PartialEq ) ] - pub struct TemplateBody( pub String ); - - /// Struct that represents user written scenarios. - /// - /// This is a processed form of a scenario, paths are distinguished here with types. - /// For more simplistic representation of scenarios, use `ScenarioRaw` type. - #[ derive( Debug, PartialEq ) ] - pub struct ScenarioProcessed - { - /// Nodes in the scenario. - pub nodes: Vec< Node >, - } - - impl TryFrom< ScenarioRaw > for ScenarioProcessed - { - type Error = std::io::Error; - - fn try_from( scenario_raw : ScenarioRaw ) -> Result< Self, Self::Error > - { - let nodes : Result< Vec< Node >, Self::Error > = - scenario_raw.nodes.into_iter().map( | rn | Node::try_from( rn ) ).collect(); - - Ok( Self { nodes : nodes? } ) - } - } - - /// Node representation in a scenario file. - /// - /// This is a processed form of a node, paths are distinguished here with types. - /// For more simplistic representation of scenarios, use `NodeRaw` type. - #[ derive( Debug, PartialEq ) ] - pub struct Node - { - /// ID of the node. Must be unique, will also identify node output. - pub id : String, - - /// Type of the node. - pub typ : Path, - - /// Parameters of the node. - pub params : HashMap< String, String >, - - /// ID of the next node to execute. - pub next : Path, - } - - impl TryFrom< NodeRaw > for Node - { - type Error = std::io::Error; - - fn try_from( node_raw : NodeRaw ) -> Result< Self, Self::Error > - { - Ok - ( - Self - { - id : node_raw.id, - typ : Path::try_from( node_raw.typ )?, - params : node_raw.params, - next : Path::try_from( node_raw.next )?, - } - ) - } - } -} - -crate::mod_interface! -{ - own use - { - TemplateBody, - ScenarioProcessed, - Node, - }; -} \ No newline at end of file diff --git a/module/move/assistant/src/agents/scenario_raw.rs b/module/move/assistant/src/agents/scenario_raw.rs deleted file mode 100644 index 9c588d1fbb..0000000000 --- a/module/move/assistant/src/agents/scenario_raw.rs +++ /dev/null @@ -1,71 +0,0 @@ -//! -//! Raw scenario representation. Captures only the basic syntax of scenario file. -//! -//! For more detailed representation, use `ScenarioProcessed`. -//! - -mod private -{ - use std:: - { - io, - collections::HashMap, - }; - - use former::Former; - use serde:: - { - Serialize, - Deserialize, - }; - - /// Struct that represents user written scenarios. - /// - /// This is a raw form of a scenario, only the general structure is captured there. - /// For more detailed representation of scenarios, use `ScenarioProcessed` type. - #[ derive( Debug, Serialize, Deserialize, Former, PartialEq ) ] - pub struct ScenarioRaw - { - /// Nodes in the scenario. - pub nodes: Vec< NodeRaw >, - } - - impl ScenarioRaw - { - /// Read scenario file in YAML format. - pub fn read( reader : impl io::Read ) -> Result< Self, serde_yaml::Error > - { - serde_yaml::from_reader( reader ) - } - } - - /// Node representation in a scenario file. - /// - /// This is a raw form of a node, only the general structure is captured there. - /// For more detailed representation of scenarios, use `Node` type. - #[ derive( Debug, Serialize, Deserialize, Former, PartialEq ) ] - pub struct NodeRaw - { - /// ID of the node. Must be unique, will also identify node output. - pub id : String, - - /// Type of the node. Represented as a path. - pub typ : String, - - /// Rest of the key-value pairs in the node that are specific to node types. - #[ serde( flatten ) ] - pub params : HashMap< String, String >, - - /// ID of the next node to execute. Represented as a path. - pub next : String, - } -} - -crate::mod_interface! -{ - own use - { - ScenarioRaw, - NodeRaw, - }; -} \ No newline at end of file diff --git a/module/move/assistant/src/agents/scenario_raw_processors.rs b/module/move/assistant/src/agents/scenario_raw_processors.rs deleted file mode 100644 index 4e9ebb7798..0000000000 --- a/module/move/assistant/src/agents/scenario_raw_processors.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! -//! `ScenarioRaw` processors: functions that work with `ScenarioRaw`. -//! -//! Currently only formatters are implemented. -//! - -mod private {} - -crate::mod_interface! -{ - layer yaml_formatter; - layer plantuml_formatter; -} \ No newline at end of file diff --git a/module/move/assistant/src/agents/scenario_raw_processors/plantuml_formatter.rs b/module/move/assistant/src/agents/scenario_raw_processors/plantuml_formatter.rs deleted file mode 100644 index 2bfed18c17..0000000000 --- a/module/move/assistant/src/agents/scenario_raw_processors/plantuml_formatter.rs +++ /dev/null @@ -1,76 +0,0 @@ -//! -//! Format scenario in PlantUML diagram. -//! - -mod private -{ - use std::io; - - use crate::*; - use agents::scenario_raw::ScenarioRaw; - - /// Format scenario in PlantUML diagram. - pub fn plantuml_formatter - ( - scenario : &ScenarioRaw, - writer : &mut impl io::Write, - ) -> Result< (), io::Error > - { - writer.write( b"@startuml\n" )?; - - for node in &scenario.nodes - { - writer.write( b"json " )?; - writer.write( node.id.as_bytes() )?; - writer.write( b" {\n" )?; - - writer.write( b" \"type\": \"" )?; - writer.write( node.typ.as_bytes() )?; - writer.write( b"\"" )?; - - if node.params.len() > 0 - { - writer.write( b"," )?; - } - - writer.write( b"\n" )?; - - for ( i, ( key, value ) ) in node.params.iter().enumerate() - { - writer.write( b" \"" )?; - writer.write( key.as_bytes() )?; - writer.write( b"\": \"" )?; - writer.write( value.as_bytes() )?; - writer.write( b"\"" )?; - - if i != node.params.len() - 1 - { - writer.write( b"," )?; - } - - writer.write( b"\n" )?; - } - - writer.write( b"}\n" )?; - } - - writer.write( b"json ::scenario::termination {\n" )?; - writer.write( b"}\n" )?; - - for node in &scenario.nodes - { - writer.write( node.id.as_bytes() )?; - writer.write( b" --> " )?; - writer.write( node.next.as_bytes() )?; - writer.write( b" : next\n" )?; - } - - writer.write( b"@enduml" )?; - Ok( () ) - } -} - -crate::mod_interface! -{ - own use plantuml_formatter; -} \ No newline at end of file diff --git a/module/move/assistant/src/agents/scenario_raw_processors/yaml_formatter.rs b/module/move/assistant/src/agents/scenario_raw_processors/yaml_formatter.rs deleted file mode 100644 index 05d1bb5668..0000000000 --- a/module/move/assistant/src/agents/scenario_raw_processors/yaml_formatter.rs +++ /dev/null @@ -1,26 +0,0 @@ -//! -//! Format scenario in YAML format (pretty-printing). -//! - -mod private -{ - use std::io; - - use crate::*; - use agents::scenario_raw::ScenarioRaw; - - /// Pretty-print `ScenarioRaw` in YAML format. - pub fn yaml_formatter - ( - scenario : &ScenarioRaw, - writer : &mut impl io::Write, - ) -> Result< (), serde_yaml::Error > - { - serde_yaml::to_writer( writer, scenario ) - } -} - -crate::mod_interface! -{ - own use yaml_formatter; -} \ No newline at end of file diff --git a/module/move/assistant/src/lib.rs b/module/move/assistant/src/lib.rs index 4d21799cc5..5a33e41692 100644 --- a/module/move/assistant/src/lib.rs +++ b/module/move/assistant/src/lib.rs @@ -33,7 +33,6 @@ crate::mod_interface! layer actions; layer secret; layer util; - layer agents; exposed use ::reflect_tools:: { diff --git a/module/move/assistant/src/main.rs b/module/move/assistant/src/main.rs deleted file mode 100644 index ad03e3549a..0000000000 --- a/module/move/assistant/src/main.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![ cfg_attr( feature = "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/assistant/latest/assistant/" ) ] -#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] - -use std:: -{ - env, - error::Error, -}; - -use dotenv::dotenv; - -use assistant:: -{ - client, -}; - -#[ tokio::main ] -async fn main() -> Result< (), Box< dyn Error > > -{ - dotenv().ok(); - let client = client()?; - let assistants = client.list_assistant( None, None, None, None )?; - println!( "Assistants: {:?}", assistants.data ); - Ok( () ) -} diff --git a/module/move/assistant/tests/inc/agents_tests/context_test.rs b/module/move/assistant/tests/inc/agents_tests/context_test.rs deleted file mode 100644 index e28fc8c264..0000000000 --- a/module/move/assistant/tests/inc/agents_tests/context_test.rs +++ /dev/null @@ -1,128 +0,0 @@ -use super::*; - -use the_module::agents:: -{ - path::Path, - context:: - { - ContextDir, - ContextEntry, - }, -}; - -#[ test ] -fn context_dir_add_terminal() -{ - let mut ctx : ContextDir< () > = ContextDir::new(); - let entry = ContextEntry::Terminal( () ); - let name = "test"; - - let res = ctx.add( name, entry.clone() ); - - assert!( res ); - assert_eq!( ctx.get( name ), Some( &entry ) ); -} - -#[ test ] -fn context_dir_add_dir() -{ - let mut ctx : ContextDir< () > = ContextDir::new(); - let entry : ContextEntry< () > = ContextDir::new().into(); - let name = "test"; - - let res = ctx.add( name, entry.clone() ); - - assert!( res ); - assert_eq!( ctx.get( name ), Some( &entry ) ); -} - -#[ test ] -fn context_dir_add_duplicate() -{ - let name = "test"; - let orig_entry = ContextEntry::Terminal( 1 ); - - let mut ctx : ContextDir< usize > = ContextDir::new(); - ctx.add( name, orig_entry.clone() ); - - let res = ctx.add( name, ContextEntry::Terminal( 2 ) ); - - assert!( !res ); - assert_eq!( ctx.get( name ), Some( &orig_entry ) ); -} - -#[ test ] -fn context_dir_get() -{ - let mut ctx : ContextDir< usize > = ContextDir::new(); - ctx.add( "test_1", ContextEntry::Terminal( 1 ) ); - ctx.add( "test_2", ContextEntry::Terminal( 2 ) ); - ctx.add( "test_3", ContextEntry::Terminal( 3 ) ); - - assert_eq!( ctx.get( "test_1" ), Some( &ContextEntry::Terminal( 1 ) ) ); - assert_eq!( ctx.get( "test_2" ), Some( &ContextEntry::Terminal( 2 ) ) ); - assert_eq!( ctx.get( "test_3" ), Some( &ContextEntry::Terminal( 3 ) ) ); -} - -#[ test ] -fn context_dir_get_non_existing() -{ - let ctx : ContextDir< () > = ContextDir::new(); - - let res = ctx.get( "test" ); - - assert!( res.is_none() ); -} - -#[ test ] -fn context_dir_get_by_path_relative() -{ - let value_1 = ContextEntry::Terminal( 1 ); - let value_2 = ContextEntry::Terminal( 2 ); - let value_3 = ContextEntry::Terminal( 3 ); - - let mut dir_1 : ContextDir< usize > = ContextDir::new(); - dir_1.add( "value_1", value_1.clone() ); - dir_1.add( "value_2", value_2.clone() ); - - let mut dir_3 : ContextDir< usize > = ContextDir::new(); - dir_3.add( "value_3", value_3.clone() ); - - let mut dir_2 : ContextDir< usize > = ContextDir::new(); - dir_2.add( "dir_3", dir_3.into() ); - - let mut ctx : ContextDir< usize > = ContextDir::new(); - ctx.add( "dir_1", dir_1.into() ); - ctx.add( "dir_2", dir_2.into() ); - - let got_value_1 = ctx.get_by_path( &Path::try_from( "dir_1::value_1" ).unwrap() ); - let got_value_2 = ctx.get_by_path( &Path::try_from( "dir_1::value_2" ).unwrap() ); - let got_value_3 = ctx.get_by_path( &Path::try_from( "dir_2::dir_3::value_3" ).unwrap() ); - - assert_eq!( got_value_1, Some( &value_1 ) ); - assert_eq!( got_value_2, Some( &value_2 ) ); - assert_eq!( got_value_3, Some( &value_3 ) ); -} - -#[ test ] -fn context_dir_get_by_path_absolute() -{ - let entry = ContextEntry::Terminal( () ); - let mut ctx : ContextDir< () > = ContextDir::new(); - ctx.add( "test", entry.clone() ); - - let res = ctx.get_by_path( &&Path::try_from( "::test" ).unwrap() ); - - assert!( res.is_some() ); - assert_eq!( res.unwrap(), &entry ); -} - -#[ test ] -fn context_dir_get_by_path_non_existing() -{ - let ctx : ContextDir< () > = ContextDir::new(); - - let res = ctx.get_by_path( &Path::try_from( "test" ).unwrap() ); - - assert!( res.is_none() ); -} \ No newline at end of file diff --git a/module/move/assistant/tests/inc/agents_tests/mod.rs b/module/move/assistant/tests/inc/agents_tests/mod.rs deleted file mode 100644 index f4260d9ed5..0000000000 --- a/module/move/assistant/tests/inc/agents_tests/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -use super::*; - -mod test_scenarios; - -mod path_test; -mod context_test; -mod scenario_raw_test; -mod scenario_raw_processors; -mod scenario_processed_test; \ No newline at end of file diff --git a/module/move/assistant/tests/inc/agents_tests/path_test.rs b/module/move/assistant/tests/inc/agents_tests/path_test.rs deleted file mode 100644 index 277f4965ff..0000000000 --- a/module/move/assistant/tests/inc/agents_tests/path_test.rs +++ /dev/null @@ -1,259 +0,0 @@ -use super::*; - -use the_module::agents::path::Path; - -#[ test ] -fn path_create_right() -{ - let path_str = "agent::completion"; - - let path = Path::try_from( path_str ); - - assert!( path.is_ok() ); - assert_eq! ( path.unwrap().inner(), path_str ); -} - -#[ test ] -fn path_create_wrong() -{ - let path = Path::try_from( "agent:completion" ); - assert!( path.is_err() ); -} - -#[ test ] -fn path_create_absolute() -{ - let path_str = "::agent::completion"; - - let path = Path::try_from( path_str ); - - assert!( path.is_ok() ); - assert_eq! ( path.unwrap().inner(), path_str ); -} - -#[ test ] -fn path_create_trailing() -{ - let path_str = "agent::completion::"; - - let path = Path::try_from( path_str ); - - assert!( path.is_ok() ); - assert_eq! ( path.unwrap().inner(), path_str ); -} - -#[ test ] -fn path_some_parent_relative() -{ - let path_str = "agent::completion"; - let path = Path::try_from( path_str ).unwrap(); - - let path_parent = path.parent(); - - assert!( path_parent.is_some() ); - assert_eq!( path_parent.unwrap().inner(), "agent" ); -} - -#[ test ] -fn path_some_parent_relative_trailing() -{ - let path_str = "agent::completion::"; - let path = Path::try_from( path_str ).unwrap(); - - let path_parent = path.parent(); - - assert!( path_parent.is_some() ); - assert_eq!( path_parent.unwrap().inner(), "agent" ); -} - -#[ test ] -fn path_some_parent_absolute() -{ - let path_str = "::agent"; - let path = Path::try_from( path_str ).unwrap(); - - let path_parent = path.parent(); - - assert!( path_parent.is_some() ); - assert_eq!( path_parent.unwrap().inner(), "::" ); -} - -#[ test ] -fn path_some_parent_absolute_trailing() -{ - let path_str = "::agent::"; - let path = Path::try_from( path_str ).unwrap(); - - let path_parent = path.parent(); - - assert!( path_parent.is_some() ); - assert_eq!( path_parent.unwrap().inner(), "::" ); -} - -#[ test ] -fn path_none_parent() -{ - let path_str = "agent"; - let path = Path::try_from( path_str ).unwrap(); - - let path_parent = path.parent(); - - assert!( path_parent.is_none() ); -} - -#[ test ] -fn path_is_relative() -{ - let path_str = "agent"; - let path = Path::try_from( path_str ).unwrap(); - - let is_relative = path.is_relative(); - let is_absolute = path.is_absolute(); - - assert!( is_relative ); - assert!( !is_absolute ); -} - -#[ test ] -fn path_is_absolute() -{ - let path_str = "::agent"; - let path = Path::try_from( path_str ).unwrap(); - - let is_relative = path.is_relative(); - let is_absolute = path.is_absolute(); - - assert!( !is_relative ); - assert!( is_absolute ); -} - -#[ test ] -fn path_join_relative() -{ - let orig_path = Path::try_from( "agent" ).unwrap(); - let append = Path::try_from( "completion" ).unwrap(); - - let combined = orig_path.join( &append ); - - assert_eq!( combined.inner(), "agent::completion" ); -} - -#[ test ] -fn path_join_absolute() -{ - let orig_path = Path::try_from( "agent" ).unwrap(); - let append = Path::try_from( "::completion" ).unwrap(); - - let combined = orig_path.join( &append ); - - assert_eq!( combined.inner(), "::completion" ); -} - -#[ test ] -fn path_join_root() -{ - let orig_path = Path::try_from( "::" ).unwrap(); - let append = Path::try_from( "agent" ).unwrap(); - - let combined = orig_path.join( &append ); - - assert_eq!( combined.inner(), "::agent" ); -} - -#[ test ] -fn path_join_trailing() -{ - let orig_path = Path::try_from( "agents::" ).unwrap(); - let append = Path::try_from( "completion" ).unwrap(); - - let combined = orig_path.join( &append ); - - assert_eq!( combined.inner(), "agents::completion" ); -} - -#[ test ] -fn path_starts_with_abs_abs() -{ - let a = Path::try_from( "::agent::completion" ).unwrap(); - let b = Path::try_from( "::agent" ).unwrap(); - - let starts_with = a.starts_with( &b ); - - assert!( starts_with ); -} - -#[ test ] -fn path_starts_with_abs_rel() -{ - let a = Path::try_from( "::agent::completion" ).unwrap(); - let b = Path::try_from( "agent" ).unwrap(); - - let starts_with = a.starts_with( &b ); - - assert!( !starts_with ); -} - -#[ test ] -fn path_starts_with_rel_abs() -{ - let a = Path::try_from( "agent" ).unwrap(); - let b = Path::try_from( "::agent::completion" ).unwrap(); - - let starts_with = a.starts_with( &b ); - - assert!( !starts_with ); -} - -#[ test ] -fn path_starts_with_rel_rel() -{ - let a = Path::try_from( "agent::completion" ).unwrap(); - let b = Path::try_from( "agent" ).unwrap(); - - let starts_with = a.starts_with( &b ); - - assert!( starts_with ); -} - -#[ test ] -fn path_not_starts_with_abs_abs() -{ - let a = Path::try_from( "::agent::completion" ).unwrap(); - let b = Path::try_from( "::output" ).unwrap(); - - let starts_with = a.starts_with( &b ); - - assert!( !starts_with ); -} - -#[ test ] -fn path_not_starts_with_rel_rel() -{ - let a = Path::try_from( "agent::completion" ).unwrap(); - let b = Path::try_from( "output" ).unwrap(); - - let starts_with = a.starts_with( &b ); - - assert!( !starts_with ); -} - -#[ test ] -fn path_inner() -{ - let path_str = "::agent::completion"; - let path = Path::try_from( path_str ).unwrap(); - - let inner = path.inner(); - - assert_eq!( inner, path_str ); -} - -#[ test ] -fn path_components() -{ - let path = Path::try_from( "::agents::completion" ).unwrap(); - - let components : Vec< &str > = path.components().collect(); - - assert_eq!( components, vec![ "::", "agents", "completion" ] ); -} \ No newline at end of file diff --git a/module/move/assistant/tests/inc/agents_tests/scenario_processed_test.rs b/module/move/assistant/tests/inc/agents_tests/scenario_processed_test.rs deleted file mode 100644 index 5fc734ae41..0000000000 --- a/module/move/assistant/tests/inc/agents_tests/scenario_processed_test.rs +++ /dev/null @@ -1,25 +0,0 @@ -use super::*; - -use the_module::agents::scenario_processed::ScenarioProcessed; - -use test_scenarios:: -{ - gen_test_scenario_raw, - gen_test_scenario_raw_wrong, -}; - -#[ test ] -fn scenario_processed_right() -{ - let scenario_processed = ScenarioProcessed::try_from( gen_test_scenario_raw() ); - - assert!( scenario_processed.is_ok() ); -} - -#[ test ] -fn scenario_processed_wrong() -{ - let scenario_processed = ScenarioProcessed::try_from( gen_test_scenario_raw_wrong() ); - - assert!( scenario_processed.is_err() ); -} \ No newline at end of file diff --git a/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/mod.rs b/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/mod.rs deleted file mode 100644 index bbaccfe254..0000000000 --- a/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -use super::*; - -mod plantuml_formatter_test; -mod yaml_formatter_test; \ No newline at end of file diff --git a/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/plantuml_formatter_test.rs b/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/plantuml_formatter_test.rs deleted file mode 100644 index 44d5cf86b7..0000000000 --- a/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/plantuml_formatter_test.rs +++ /dev/null @@ -1,33 +0,0 @@ -use super::*; - -use the_module::agents::scenario_raw_processors::plantuml_formatter::plantuml_formatter; - -use test_scenarios::gen_test_scenario_raw; - - -#[ test ] -fn plantuml_formatter_test() -{ - let expected_plantuml = r#"@startuml -json node_1 { - "type": "agents::completion", - "model": "gpt-4o-mini" -} -json node_2 { - "type": "agents::classify", - "model": "gpt-4o" -} -json ::scenario::termination { -} -node_1 --> node_2 : next -node_2 --> ::scenario::termination : next -@enduml"#; - - let scenario_raw = gen_test_scenario_raw(); - - let mut buffer = Vec::new(); - let result = plantuml_formatter( &scenario_raw, &mut buffer ); - - assert!( result.is_ok() ); - assert_eq!( String::from_utf8( buffer ).unwrap(), expected_plantuml ); -} diff --git a/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/yaml_formatter_test.rs b/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/yaml_formatter_test.rs deleted file mode 100644 index fd64cbacec..0000000000 --- a/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/yaml_formatter_test.rs +++ /dev/null @@ -1,33 +0,0 @@ -use super::*; - -use the_module::agents::scenario_raw_processors::yaml_formatter::yaml_formatter; - -use test_scenarios::gen_test_scenario_raw; - -#[ test ] -fn yaml_formatter_test() -{ - let expected_yaml = r#"nodes: -- id: node_1 - type: agents::completion - model: gpt-4o-mini - next: node_2 -- id: node_2 - type: agents::classify - model: gpt-4o - next: ::scenario::termination"#; - - let scenario_raw = gen_test_scenario_raw(); - - let mut buffer = Vec::new(); - let result = yaml_formatter( &scenario_raw, &mut buffer ); - assert!( result.is_ok() ); - - let result = String::from_utf8( buffer ); - assert!( result.is_ok() ); - - let result = result.unwrap(); - println!( "{}", result ); - - assert_eq!( result.trim(), expected_yaml.trim() ); -} diff --git a/module/move/assistant/tests/inc/agents_tests/scenario_raw_test.rs b/module/move/assistant/tests/inc/agents_tests/scenario_raw_test.rs deleted file mode 100644 index 2f8acc60fe..0000000000 --- a/module/move/assistant/tests/inc/agents_tests/scenario_raw_test.rs +++ /dev/null @@ -1,49 +0,0 @@ -use super::*; - -use the_module::agents::scenario_raw::ScenarioRaw; - -use test_scenarios::gen_test_scenario_raw; - -#[ test ] -fn scenario_read() -{ - let scenario_text = r#" - nodes: - - id: node_1 - type: agents::completion - model: gpt-4o-mini - next: node_2 - - - id: node_2 - type: agents::classify - model: gpt-4o - next: ::scenario::termination - "#; - - let expected_scenario_raw = gen_test_scenario_raw(); - - let scenario_raw = ScenarioRaw::read( scenario_text.as_bytes() ); - - assert!( scenario_raw.is_ok() ); - - let scenario_raw = scenario_raw.unwrap(); - assert_eq!( scenario_raw, expected_scenario_raw ); -} - -#[ test ] -fn scenario_wrong() -{ - let scenario_text = r#" - nodes: - - completion: - model: - company: openai - name: gpt-4o - depends_on: - node_2 - "#; - - let scenario_raw = ScenarioRaw::read( scenario_text.as_bytes() ); - - assert!( scenario_raw.is_err() ); -} \ No newline at end of file diff --git a/module/move/assistant/tests/inc/agents_tests/test_scenarios.rs b/module/move/assistant/tests/inc/agents_tests/test_scenarios.rs deleted file mode 100644 index 3da3ce3e34..0000000000 --- a/module/move/assistant/tests/inc/agents_tests/test_scenarios.rs +++ /dev/null @@ -1,64 +0,0 @@ -use super::*; - -use the_module::agents::scenario_raw:: -{ - ScenarioRaw, - NodeRaw, -}; - -/// Generates an example `ScenarioRaw`. -pub fn gen_test_scenario_raw() -> ScenarioRaw -{ - ScenarioRaw::former() - .nodes( vec! - [ - NodeRaw::former() - .id( "node_1".to_string() ) - .typ( "agents::completion".to_string() ) - .params( - { - let mut map : HashMap< String, String > = HashMap::new(); - map.insert( "model".into(), "gpt-4o-mini".into() ); - map - } - ) - .next( "node_2".to_string() ) - .form(), - - NodeRaw::former() - .id( "node_2".to_string() ) - .typ( "agents::classify".to_string() ) - .params( - { - let mut map : HashMap< String, String > = HashMap::new(); - map.insert( "model".into(), "gpt-4o".into() ); - map - } - ) - .next( "::scenario::termination".to_string() ) - .form(), - ] ) - .form() -} - -/// Generates a `ScenarioRaw` with wrong syntax for `Path`. -pub fn gen_test_scenario_raw_wrong() -> ScenarioRaw -{ - ScenarioRaw::former() - .nodes( vec! - [ - NodeRaw::former() - .id( "node_1".to_string() ) - .typ( ":agents:".to_string() ) // This part is incorrect. Path written in wrong syntax. - .params( - { - let mut map : HashMap< String, String > = HashMap::new(); - map.insert( "model".into(), "gpt-4o-mini".into() ); - map - } - ) - .next( "node_2".to_string() ) - .form(), - ] ) - .form() -} \ No newline at end of file diff --git a/module/move/assistant/tests/inc/mod.rs b/module/move/assistant/tests/inc/mod.rs index abf35e2f97..fd3344b089 100644 --- a/module/move/assistant/tests/inc/mod.rs +++ b/module/move/assistant/tests/inc/mod.rs @@ -1,7 +1,5 @@ #[ allow( unused_imports ) ] use super::*; -mod agents_tests; - mod basic_test; mod experiment; diff --git a/module/move/assistant/tests/smoke_test.rs b/module/move/assistant/tests/smoke_test.rs index 663dd6fb9f..2f3e22aa74 100644 --- a/module/move/assistant/tests/smoke_test.rs +++ b/module/move/assistant/tests/smoke_test.rs @@ -1,3 +1,4 @@ +//! Smoke testing of the crate. #[ test ] fn local_smoke_test() diff --git a/module/move/assistant/tests/tests.rs b/module/move/assistant/tests/tests.rs index c94c4d074f..9c966dc926 100644 --- a/module/move/assistant/tests/tests.rs +++ b/module/move/assistant/tests/tests.rs @@ -1,3 +1,4 @@ +//! All test. include!( "../../../../module/step/meta/src/module/terminal.rs" ); diff --git a/module/move/llm_tools/.key/readme.md b/module/move/llm_tools/.key/readme.md new file mode 100644 index 0000000000..4209c24678 --- /dev/null +++ b/module/move/llm_tools/.key/readme.md @@ -0,0 +1,20 @@ +# Keys + +This document provides a concise example of an environment configuration script, used to set up environment variables for a project. These variables configure application behavior without altering the code. + +## Example of `.key/-env.sh` + +```bash +# OpenAI API key. +OPENAI_API_KEY=sk-proj-ABCDEFG +``` + +## How to Use in Shell + +To apply these variables to your current shell session, use: + +```bash +. ./key/-env.sh +``` + +This command sources the script, making the variables available in your current session. Ensure `-env.sh` is in the `key` directory relative to your current location. \ No newline at end of file diff --git a/module/move/llm_tools/Cargo.toml b/module/move/llm_tools/Cargo.toml new file mode 100644 index 0000000000..0ca1f741dd --- /dev/null +++ b/module/move/llm_tools/Cargo.toml @@ -0,0 +1,61 @@ +[package] +name = "llm_tools" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/llm_tools" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/llm_tools" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/llm_tools" +description = """ +Assist AI in writing code. +""" +categories = [ "algorithms", "development-tools" ] +keywords = [ "fundamental", "general-purpose" ] +default-run = "main" + +[lints] +workspace = true + +[package.metadata.docs.rs] +features = [ "full" ] +all-features = false + +[features] +default = [ "enabled" ] +full = [ "enabled" ] +enabled = [ + "former/enabled", + "format_tools/enabled", + "reflect_tools/enabled", +] + +[[bin]] +name = "main" +path = "src/bin/main.rs" + +[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 = "=5.0.14" } +tokio = { version = "1", features = ["full"] } +dotenv = "0.15" +# clap = { version = "4.5.20", features = ["derive"] } +# pth = "0.21.0" +pth = { workspace = true, features = [ "full" ] } +serde = { version = "1.0.213", features = ["derive"] } +serde_with = "3.11.0" +# error_tools = "0.17.0" +error_tools = { workspace = true, features = [ "full" ] } +derive_tools = { version = "0.32.0", features = ["full"] } +regex = { version = "1.10.3" } +serde_yaml = "0.9" + +[dev-dependencies] +test_tools = { workspace = true } diff --git a/module/move/llm_tools/License b/module/move/llm_tools/License new file mode 100644 index 0000000000..0804aed8e3 --- /dev/null +++ b/module/move/llm_tools/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/move/llm_tools/Readme.md b/module/move/llm_tools/Readme.md new file mode 100644 index 0000000000..9296447b86 --- /dev/null +++ b/module/move/llm_tools/Readme.md @@ -0,0 +1,35 @@ + + +# 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) + +**NOT ready for production** + + + + diff --git a/module/move/llm_tools/api/list.http b/module/move/llm_tools/api/list.http new file mode 100644 index 0000000000..89424758ff --- /dev/null +++ b/module/move/llm_tools/api/list.http @@ -0,0 +1,11 @@ +# use REST Client VSCode plugin +# ctrl+l + +get https://api.openai.com/v1/models +Authorization: Bearer {{openai_token}} +# Content-Type: application/json + +get https://api.openai.com/v1/assistants +Authorization: Bearer {{openai_token}} +OpenAI-Beta: assistants=v2 +Content-Type: application/json diff --git a/module/move/llm_tools/src/bin/main.rs b/module/move/llm_tools/src/bin/main.rs new file mode 100644 index 0000000000..3b4ab6bd22 --- /dev/null +++ b/module/move/llm_tools/src/bin/main.rs @@ -0,0 +1,55 @@ +#![ 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/assistant/latest/assistant/" ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +use std:: +{ + env, + error::Error, +}; + +use format_tools:: +{ + AsTable, + TableFormatter, + output_format, +}; +use dotenv::dotenv; + +use llm_tools:: +{ + client::client, + Secret +}; + +#[ tokio::main ] +async fn main() -> Result< (), Box< dyn Error > > +{ + dotenv().ok(); + + let secret = Secret::load()?; + + let client = client( &secret )?; + + let response = client.file_list().await?; + // println!( "Files: {:?}", response.data ); + let files : Vec< _ > = response.data.into_iter().map( | e | llm_tools::FileDataWrap( e ) ).collect(); + println! + ( + "Files:\n{}", + AsTable::new( &files ).table_to_string_with_format( &output_format::Table::default() ), + ); + + let response = client.list_assistant( None, None, None, None ).await?; + + // println!( "Assistants: {:?}", assistants.data ); + let assistants : Vec< _ > = response.data.into_iter().map( | e | llm_tools::AssistantObjectWrap( e ) ).collect(); + println! + ( + "Assistants:\n{}", + AsTable::new( &assistants ).table_to_string_with_format( &output_format::Records::default() ), + ); + + Ok( () ) +} \ No newline at end of file diff --git a/module/move/llm_tools/src/client.rs b/module/move/llm_tools/src/client.rs new file mode 100644 index 0000000000..1c9fd0bbee --- /dev/null +++ b/module/move/llm_tools/src/client.rs @@ -0,0 +1,39 @@ +//! +//! Client of API. +//! + +/// Define a private namespace for all its items. +mod private +{ + + pub use openai_api_rs::v1:: + { + api::OpenAIClient as Client, + assistant::AssistantObject, + }; + + use std:: + { + error::Error, + }; + + use crate::*; + use secret::Secret; + + /// Creates a new OpenAI API client using the secrets. + pub fn client( secrets : &Secret ) -> Result< Client, Box< dyn Error > > + { + Ok( Client::new( secrets.OPENAI_API_KEY.clone() ) ) + } + +} + +crate::mod_interface! +{ + exposed use + { + Client, + AssistantObject, + client + }; +} diff --git a/module/move/llm_tools/src/debug.rs b/module/move/llm_tools/src/debug.rs new file mode 100644 index 0000000000..294333abf0 --- /dev/null +++ b/module/move/llm_tools/src/debug.rs @@ -0,0 +1,30 @@ +//! +//! Client of API. +//! + +/// Define a private namespace for all its items. +mod private +{ + +} + +use format_tools:: +{ + Fields, + TableWithFields, +}; +use std::borrow::Cow; + +mod assistant_object; +mod file_data; +mod run_object; + +crate::mod_interface! +{ + exposed use + { + assistant_object::AssistantObjectWrap, + file_data::FileDataWrap, + run_object::RunObjectWrap, + }; +} diff --git a/module/move/llm_tools/src/debug/assistant_object.rs b/module/move/llm_tools/src/debug/assistant_object.rs new file mode 100644 index 0000000000..9ebcead56e --- /dev/null +++ b/module/move/llm_tools/src/debug/assistant_object.rs @@ -0,0 +1,84 @@ +use super::*; +use openai_api_rs::v1::assistant; + +/// A wrapper for `AssistantObject` to make pretty print. +#[ derive( Debug ) ] +pub struct AssistantObjectWrap( pub assistant::AssistantObject ); + +/// Manually implemented `Clone`, as `FileData` does not implement it. +impl Clone for AssistantObjectWrap +{ + fn clone( &self ) -> Self + { + // Manually clone each field of the wrapped AssistantObject + AssistantObjectWrap( assistant::AssistantObject + { + id : self.0.id.clone(), + object : self.0.object.clone(), + created_at : self.0.created_at, + name : self.0.name.clone(), + description : self.0.description.clone(), + model : self.0.model.clone(), + instructions : self.0.instructions.clone(), + tools : self.0.tools.clone(), + tool_resources : self.0.tool_resources.clone(), + metadata : self.0.metadata.clone(), + headers : self.0.headers.clone(), + } ) + } +} + +impl TableWithFields for AssistantObjectWrap {} +impl Fields< &'_ str, Option< Cow< '_, str > > > +for AssistantObjectWrap +{ + type Key< 'k > = &'k str; + type Val< 'v > = Option< Cow< 'v, str > >; + + fn fields( &self ) -> impl format_tools::IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > + { + use format_tools::ref_or_display_or_debug_multiline::field; + let mut dst = Vec::new(); + + // Use the field! macro for direct field references + dst.push( field!( &self.0.id ) ); + dst.push( field!( &self.0.object ) ); + dst.push( field!( &self.0.model ) ); + + // Manually handle fields that require function calls + dst.push( ( "created_at", Some( Cow::Owned( self.0.created_at.to_string() ) ) ) ); + dst.push( ( "name", self.0.name.as_deref().map( Cow::Borrowed ) ) ); + dst.push( ( "description", self.0.description.as_deref().map( Cow::Borrowed ) ) ); + dst.push( ( "instructions", self.0.instructions.as_deref().map( Cow::Borrowed ) ) ); + + // Handle complex fields like `tools`, `tool_resources`, `metadata`, and `headers` + if !self.0.tools.is_empty() + { + dst.push( ( "tools", Some( Cow::Borrowed( "tools present" ) ) ) ); + } + else + { + dst.push( ( "tools", Option::None ) ); + } + + if let Some( _metadata ) = &self.0.metadata + { + dst.push( ( "metadata", Some( Cow::Borrowed( "metadata present" ) ) ) ); + } + else + { + dst.push( ( "metadata", Option::None ) ); + } + + if let Some( _headers ) = &self.0.headers + { + dst.push( ( "headers", Some( Cow::Borrowed( "headers present" ) ) ) ); + } + else + { + dst.push( ( "headers", Option::None ) ); + } + + dst.into_iter() + } +} diff --git a/module/move/llm_tools/src/debug/file_data.rs b/module/move/llm_tools/src/debug/file_data.rs new file mode 100644 index 0000000000..b8029949c7 --- /dev/null +++ b/module/move/llm_tools/src/debug/file_data.rs @@ -0,0 +1,50 @@ + +use super::*; +use openai_api_rs::v1::file::FileData; + +// Assuming the `format_tools` module and `field!` macro are defined elsewhere + +/// A wrapper for `FileData` to make pretty print. +#[ derive( Debug ) ] +pub struct FileDataWrap( pub FileData ); + +/// Manually implemented `Clone`, as `FileData` does not implement it. +impl Clone for FileDataWrap +{ + fn clone( &self ) -> Self + { + FileDataWrap( FileData + { + id : self.0.id.clone(), + object : self.0.object.clone(), + bytes : self.0.bytes, + created_at : self.0.created_at, + filename : self.0.filename.clone(), + purpose : self.0.purpose.clone(), + } ) + } +} + +impl TableWithFields for FileDataWrap {} +impl Fields< &'_ str, Option< Cow< '_, str > > > +for FileDataWrap +{ + type Key<'k> = &'k str; + type Val< 'v > = Option< Cow< 'v, str > >; + + fn fields( &self ) -> impl format_tools::IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > + { + use format_tools::ref_or_display_or_debug_multiline::field; + let mut dst = Vec::new(); + + // Use the field! macro for direct field references + dst.push( field!( &self.0.id ) ); + dst.push( field!( &self.0.object ) ); + dst.push( ( "bytes", Some( Cow::Owned( self.0.bytes.to_string() ) ) ) ); + dst.push( ( "created_at", Some( Cow::Owned( self.0.created_at.to_string() ) ) ) ); + dst.push( field!( &self.0.filename ) ); + dst.push( field!( &self.0.purpose ) ); + + dst.into_iter() + } +} diff --git a/module/move/llm_tools/src/debug/run_object.rs b/module/move/llm_tools/src/debug/run_object.rs new file mode 100644 index 0000000000..cc2fda5357 --- /dev/null +++ b/module/move/llm_tools/src/debug/run_object.rs @@ -0,0 +1,79 @@ + +use super::*; +use openai_api_rs::v1::run::RunObject; + +// Assuming the `format_tools` module and `field!` macro are defined elsewhere + +/// A wrapper for `RunObject` to make pretty print. +#[ derive( Debug ) ] +pub struct RunObjectWrap( pub RunObject ); + +/// Manually implemented `Clone`, as `RunObject` does not implement it. +impl Clone for RunObjectWrap +{ + fn clone(&self) -> Self + { + RunObjectWrap + ( + RunObject + { + id : self.0.id.clone(), + object : self.0.object.clone(), + created_at : self.0.created_at, + thread_id : self.0.thread_id.clone(), + assistant_id : self.0.assistant_id.clone(), + status : self.0.status.clone(), + required_action : self.0.required_action.clone(), + last_error : self.0.last_error.clone(), + expires_at : self.0.expires_at, + started_at : self.0.started_at, + cancelled_at : self.0.cancelled_at, + failed_at : self.0.failed_at, + completed_at : self.0.completed_at, + model : self.0.model.clone(), + instructions : self.0.instructions.clone(), + tools : self.0.tools.clone(), + metadata : self.0.metadata.clone(), + headers : self.0.headers.clone(), + } + ) + } +} + +impl TableWithFields for RunObjectWrap {} +impl Fields< &'_ str, Option< Cow< '_, str > > > +for RunObjectWrap +{ + type Key< 'k > = &'k str; + type Val< 'v > = Option< Cow< 'v, str > >; + + fn fields( &self ) -> impl format_tools::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.object ) ); + dst.push( ( "created_at", Some( Cow::Owned( self.0.created_at.to_string() ) ) ) ); + dst.push( field!( &self.0.thread_id ) ); + dst.push( field!( &self.0.assistant_id ) ); + dst.push( field!( &self.0.status ) ); + + dst.push( ( "required_action", self.0.required_action.as_ref().map( |ra| Cow::Owned( format!( "{:?}", ra ) ) ) ) ); + dst.push( ( "last_error", self.0.last_error.as_ref().map( |le| Cow::Owned( format!( "{:?}", le ) ) ) ) ); + dst.push( ( "expires_at", self.0.expires_at.map( |ea| Cow::Owned( ea.to_string() ) ) ) ); + dst.push( ( "started_at", self.0.started_at.map( |sa| Cow::Owned( sa.to_string() ) ) ) ); + dst.push( ( "cancelled_at", self.0.cancelled_at.map( |ca| Cow::Owned( ca.to_string() ) ) ) ); + dst.push( ( "failed_at", self.0.failed_at.map( |fa| Cow::Owned( fa.to_string() ) ) ) ); + dst.push( ( "completed_at", self.0.completed_at.map( |ca| Cow::Owned( ca.to_string() ) ) ) ); + + dst.push( field!( &self.0.model ) ); + dst.push( ( "instructions", self.0.instructions.as_ref().map( |i| Cow::Owned( i.clone() ) ) ) ); + + dst.push( ( "tools", Some( Cow::Owned( format!( "{:?}", self.0.tools ) ) ) ) ); + dst.push( ( "metadata", Some( Cow::Owned( format!( "{:?}", self.0.metadata ) ) ) ) ); + dst.push( ( "headers", self.0.headers.as_ref().map( |h| Cow::Owned( format!( "{:?}", h ) ) ) ) ); + + dst.into_iter() + } +} diff --git a/module/move/llm_tools/src/lib.rs b/module/move/llm_tools/src/lib.rs new file mode 100644 index 0000000000..7299b5df2f --- /dev/null +++ b/module/move/llm_tools/src/lib.rs @@ -0,0 +1,42 @@ +#![ 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/assistant/latest/assistant/" ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +use mod_interface::mod_interface; +use error_tools::thiserror; + +/// Define a private namespace for all its items. +mod private +{ +} + +/// Serde-related exports. +pub mod ser +{ + pub use serde:: + { + Serialize, + Deserialize, + }; + pub use serde_with::*; +} + +// pub mod client; + +crate::mod_interface! +{ + + layer client; + layer debug; + layer secret; + layer util; + + exposed use ::reflect_tools:: + { + Fields, + _IteratorTrait, + IteratorTrait, + }; + +} diff --git a/module/move/llm_tools/src/secret.rs b/module/move/llm_tools/src/secret.rs new file mode 100644 index 0000000000..aa90da77bc --- /dev/null +++ b/module/move/llm_tools/src/secret.rs @@ -0,0 +1,219 @@ +//! +//! Tool's secrets. +//! + +/// Internal namespace. +mod private +{ + use crate::*; + use std:: + { + env, + sync::OnceLock, + }; + + use error_tools::typed::Error; + use ser::DisplayFromStr; + + /// Typed secret error. + #[ ser::serde_as ] + #[ derive( Debug, Error, ser::Serialize ) ] + #[ serde( tag = "type", content = "data" ) ] + pub enum Error + { + + /// Secret file is illformed. + #[ error( "Secret file is illformed\n{0}" ) ] + SecretFileIllformed + ( + #[ from ] + #[ serde_as( as = "DisplayFromStr" ) ] + dotenv::Error + ), + + /// Some variable in the secrets is missing. + #[ error( "Secret misssing the variable {0}" ) ] + VariableMissing( &'static str ), + + /// Some variable in the secrets is illformed. + #[ error( "Secret error processing the variable {0}\n{1}" ) ] + VariableIllformed( &'static str, String ), + + } + + /// Result type for `Secret` methods. + pub type Result< R > = core::result::Result< R, Error >; + + /// Represents the application secrets loaded from environment variables. + #[ derive( Debug ) ] + #[ allow( non_snake_case ) ] + pub struct Secret + { + /// OpenAI API key. + pub OPENAI_API_KEY : String, + } + + impl Secret + { + + /// Loads secrets from environment variables. + /// + /// # Returns + /// + /// * `Result< Self >` - On success, returns a `Secret` instance with values from environment variables. + /// * On failure, returns an error indicating which environment variable is missing or invalid. + #[ allow( non_snake_case ) ] + pub fn load() -> Result< Self > + { + let path = "./.key/-env.sh"; + + // Attempt to load environment variables from the specified file + let r = dotenv::from_filename( path ); + if let Err( ref err ) = r + { + // Only return an error if it's not an Io error, and include the file path in the error message + if !matches!( err, dotenv::Error::Io( _ ) ) + { + return Err( r.expect_err( &format!( "Failed to load {path}" ) ).into() ); + } + } + + let config = Self + { + OPENAI_API_KEY : var( "OPENAI_API_KEY", None )?, + }; + Ok( config ) + } + + /// Reads the secrets, panicking with an explanation if loading fails. + /// + /// # Returns + /// + /// * `Secret` - The loaded secrets. + /// + /// # Panics + /// + /// * Panics with a detailed explanation if the secrets cannot be loaded. + + pub fn read() -> Secret + { + Self::load().unwrap_or_else( | err | + { + let example = include_str!( "../.key/readme.md" ); + let explanation = format! + ( +r#" = Lack of secrets + +Failed to load secret or some its parameters. +{err} + + = Fix + +Either define missing environment variable or make sure `./.key/-env.toml` file has it defined. + + = More information + +{example} +"# + ); + panic!( "{}", explanation ); + }) + } + + /// Retrieves a static reference to the secrets, initializing it if necessary. + /// + /// # Returns + /// + /// * `&'static Secret` - A static reference to the secrets. + /// + /// # Warning + /// + /// * Do not use this function unless absolutely necessary. + /// * Avoid using it in `lib.rs`. + pub fn get() -> &'static Secret + { + static INSTANCE : OnceLock< Secret > = OnceLock::new(); + INSTANCE.get_or_init( || Self::read() ) + } + + } + + /// Retrieves the value of an environment variable as a `String`. + /// + /// This function attempts to fetch the value of the specified environment variable. + /// If the variable is not set, it returns a provided default value if available, or an error if not. + /// + /// # Arguments + /// + /// * `name` - The name of the environment variable to retrieve. + /// * `default` - An optional default value to return if the environment variable is not set. + /// + /// # Returns + /// + /// * `Result` - On success, returns the value of the environment variable or the default value. + /// * On failure, returns an error indicating the missing environment variable. + fn var + ( + name : &'static str, + default : Option< &'static str >, + ) -> Result< String > + { + match env::var( name ) + { + Ok( value ) => Ok( value ), + Err( _ ) => + { + if let Some( default_value ) = default + { + Ok( default_value.to_string() ) + } + else + { + Err( Error::VariableMissing( name ) ) + } + } + } + } + + /// Retrieves the value of an environment variable as an `AbsolutePath`. + /// + /// This function attempts to fetch the value of the specified environment variable and convert it into an `AbsolutePath`. + /// If the variable is not set, it returns a provided default value if available, or an error if not. + /// + /// # Arguments + /// + /// * `name` - The name of the environment variable to retrieve. + /// * `default` - An optional default value to return if the environment variable is not set. + /// + /// # Returns + /// + /// * `Result` - On success, returns the parsed `AbsolutePath`. + /// * On failure, returns an error indicating the missing or ill-formed environment variable. + fn _var_path + ( + name : &'static str, + default : Option< &'static str >, + ) -> Result< pth::AbsolutePath > + { + let p = var( name, default )?; + pth::AbsolutePath::from_paths( ( pth::CurrentPath, p ) ) + .map_err( |e| Error::VariableIllformed( name, e.to_string() ) ) + } + +} + +crate::mod_interface! +{ + + own use + { + Error, + Result, + }; + + orphan use + { + Secret, + }; + +} \ No newline at end of file diff --git a/module/move/llm_tools/src/util.rs b/module/move/llm_tools/src/util.rs new file mode 100644 index 0000000000..7e34c0fd16 --- /dev/null +++ b/module/move/llm_tools/src/util.rs @@ -0,0 +1,10 @@ +//! +//! Collection of utility functions for this crate. +//! + +mod private {} + +crate::mod_interface! +{ + layer display_table; +} \ No newline at end of file diff --git a/module/move/llm_tools/src/util/display_table.rs b/module/move/llm_tools/src/util/display_table.rs new file mode 100644 index 0000000000..ffb99bf052 --- /dev/null +++ b/module/move/llm_tools/src/util/display_table.rs @@ -0,0 +1,154 @@ +//! +//! Function for displaying tabular data according to `TableConfig`. +//! + +mod private +{ + + use std::fmt; + + use format_tools:: + { + TableFormatter, + output_format, + print, + TableOutputFormat, + }; + + // use crate::*; + // use commands::{ TableConfig }; + + /// Common collection of arguments for formatting tabular data. + #[ derive( Debug ) ] + pub struct TableConfig + { + /// Limit table widht. + // #[ arg( long, default_value_t = DEFAULT_MAX_TABLE_WIDTH ) ] + pub max_table_width : usize, + + /// Show tabular data as an ordinary table. + // #[ arg( long ) ] + pub as_table : bool, + + /// Show each record of a tabular data as a separate table. + // #[ arg( long ) ] + pub as_records : bool, + + /// Show only keys (columns) of tabular data. + // #[ arg( long ) ] + pub columns : bool, + + /// Filter columns of tabular data. + // #[ arg( long, value_delimiter( ',' ) ) ] + pub filter_columns : Vec< String >, + } + + /// Function for displaying tabular data according to `TableConfig`. + pub fn display_tabular_data<'a> + ( + data : &'a impl TableFormatter< 'a >, + f : &mut fmt::Formatter< '_ >, + table_config : &'a TableConfig, + ) -> fmt::Result + { + if table_config.as_table + { + display_table( data, f, table_config ) + } + else if table_config.as_records + { + display_records( data, f, table_config ) + } + else if table_config.columns + { + display_columns( data, f, table_config ) + } + else + { + display_table( data, f, table_config ) + } + } + + fn display_table<'a> + ( + data : &'a impl TableFormatter< 'a >, + f : &mut fmt::Formatter< '_ >, + table_config : &'a TableConfig, + ) -> fmt::Result + { + let mut format = output_format::Table::default(); + format.max_width = table_config.max_table_width; + + display_data + ( + data, + f, + format, + &table_config.filter_columns, + ) + } + + fn display_records<'a> + ( + data : &'a impl TableFormatter< 'a >, + f : &mut fmt::Formatter< '_ >, + table_config : &'a TableConfig, + ) -> fmt::Result + { + let mut format = output_format::Records::default(); + format.max_width = table_config.max_table_width; + + display_data + ( + data, + f, + format, + &table_config.filter_columns, + ) + } + + fn display_columns<'a> + ( + data : &'a impl TableFormatter< 'a >, + f : &mut fmt::Formatter< '_ >, + table_config : &'a TableConfig, + ) -> fmt::Result + { + let mut format = output_format::Records::default(); + format.max_width = table_config.max_table_width; + + display_data + ( + data, + f, + format, + &table_config.filter_columns, + ) + } + + fn display_data<'a> + ( + data : &'a impl TableFormatter< 'a >, + f : &mut fmt::Formatter< '_ >, + format : impl TableOutputFormat, + filter_columns : &'a Vec< String >, + ) -> fmt::Result + { + let mut printer = print::Printer::with_format( &format ); + let binding = | title : &str | + { + filter_columns.is_empty() || filter_columns.iter().any( |c| c.as_str() == title ) + }; + printer.filter_col = &binding; + + let mut context = print::Context::new( f, printer ); + TableFormatter::fmt( data, &mut context ) + } + +} + +crate::mod_interface! +{ + own use display_tabular_data; + own use TableConfig; +} \ No newline at end of file diff --git a/module/move/llm_tools/tests/inc/basic_test.rs b/module/move/llm_tools/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/move/llm_tools/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/move/llm_tools/tests/inc/experiment.rs b/module/move/llm_tools/tests/inc/experiment.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/module/move/llm_tools/tests/inc/mod.rs b/module/move/llm_tools/tests/inc/mod.rs new file mode 100644 index 0000000000..fd3344b089 --- /dev/null +++ b/module/move/llm_tools/tests/inc/mod.rs @@ -0,0 +1,5 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; +mod experiment; diff --git a/module/move/llm_tools/tests/smoke_test.rs b/module/move/llm_tools/tests/smoke_test.rs new file mode 100644 index 0000000000..2f3e22aa74 --- /dev/null +++ b/module/move/llm_tools/tests/smoke_test.rs @@ -0,0 +1,13 @@ +//! Smoke testing of the crate. + +#[ test ] +fn local_smoke_test() +{ + ::test_tools::smoke_test_for_local_run(); +} + +#[ test ] +fn published_smoke_test() +{ + ::test_tools::smoke_test_for_published_run(); +} diff --git a/module/move/llm_tools/tests/tests.rs b/module/move/llm_tools/tests/tests.rs new file mode 100644 index 0000000000..b390683e4c --- /dev/null +++ b/module/move/llm_tools/tests/tests.rs @@ -0,0 +1,9 @@ +//! All test. + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; From 1cf740da9db83624d5042efacea8f80f99240f4c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 12:29:12 +0300 Subject: [PATCH 101/143] llm_tools --- module/move/llm_tools/Cargo.toml | 2 +- module/move/llm_tools/Readme.md | 33 +++----------------------------- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/module/move/llm_tools/Cargo.toml b/module/move/llm_tools/Cargo.toml index 0ca1f741dd..efb88280ab 100644 --- a/module/move/llm_tools/Cargo.toml +++ b/module/move/llm_tools/Cargo.toml @@ -11,7 +11,7 @@ documentation = "https://docs.rs/llm_tools" repository = "https://github.com/Wandalen/wTools/tree/master/module/core/llm_tools" homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/llm_tools" description = """ -Assist AI in writing code. +Unified API for AI. """ categories = [ "algorithms", "development-tools" ] keywords = [ "fundamental", "general-purpose" ] diff --git a/module/move/llm_tools/Readme.md b/module/move/llm_tools/Readme.md index 9296447b86..3982fe50dc 100644 --- a/module/move/llm_tools/Readme.md +++ b/module/move/llm_tools/Readme.md @@ -1,35 +1,8 @@ -# 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) +# Module :: llm_tools +[![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/llm_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/llm_tools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) **NOT ready for production** - - - +Unified API for AI. From 2a59f66774865dcd853c429d717120bba1586a66 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 12:33:05 +0300 Subject: [PATCH 102/143] llm_tools --- module/move/llm_tools/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/move/llm_tools/Cargo.toml b/module/move/llm_tools/Cargo.toml index efb88280ab..1cf9f5bdf7 100644 --- a/module/move/llm_tools/Cargo.toml +++ b/module/move/llm_tools/Cargo.toml @@ -53,7 +53,8 @@ serde = { version = "1.0.213", features = ["derive"] } serde_with = "3.11.0" # error_tools = "0.17.0" error_tools = { workspace = true, features = [ "full" ] } -derive_tools = { version = "0.32.0", features = ["full"] } +derive_tools = { workspace = true, features = ["full"] } +# derive_tools = { version = "0.32.0", features = ["full"] } regex = { version = "1.10.3" } serde_yaml = "0.9" From 22e42499f2badf75e24ecdec0edc0955cf4fba53 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 12:37:20 +0300 Subject: [PATCH 103/143] collection_tools-v0.16.0 --- Cargo.toml | 2 +- module/core/collection_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d919f94184..1b30db7010 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -110,7 +110,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.collection_tools] -version = "~0.15.0" +version = "~0.16.0" path = "module/core/collection_tools" default-features = false diff --git a/module/core/collection_tools/Cargo.toml b/module/core/collection_tools/Cargo.toml index d69009a758..d20b65951b 100644 --- a/module/core/collection_tools/Cargo.toml +++ b/module/core/collection_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "collection_tools" -version = "0.15.0" +version = "0.16.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From c2ceafe4ad6beda230ab4ec34f1e7797a0f52a31 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 12:37:32 +0300 Subject: [PATCH 104/143] former_types-v2.13.0 --- Cargo.toml | 2 +- module/core/former_types/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1b30db7010..c69f482b90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -241,7 +241,7 @@ path = "module/core/former_meta" default-features = false [workspace.dependencies.former_types] -version = "~2.12.0" +version = "~2.13.0" path = "module/core/former_types" default-features = false diff --git a/module/core/former_types/Cargo.toml b/module/core/former_types/Cargo.toml index 1049a6c8bd..0524c5c7bd 100644 --- a/module/core/former_types/Cargo.toml +++ b/module/core/former_types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former_types" -version = "2.12.0" +version = "2.13.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From ac7702850c6faad657c9edc486d4966d53d714d9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 12:37:41 +0300 Subject: [PATCH 105/143] interval_adapter-v0.28.0 --- Cargo.toml | 2 +- module/core/interval_adapter/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c69f482b90..02985000c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,7 +98,7 @@ default-features = false # path = "module/core/type_constructor_derive_pair_meta" [workspace.dependencies.interval_adapter] -version = "~0.27.0" +version = "~0.28.0" path = "module/core/interval_adapter" default-features = false # features = [ "enabled" ] diff --git a/module/core/interval_adapter/Cargo.toml b/module/core/interval_adapter/Cargo.toml index 787fac61c8..147d0f621f 100644 --- a/module/core/interval_adapter/Cargo.toml +++ b/module/core/interval_adapter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "interval_adapter" -version = "0.27.0" +version = "0.28.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 4928cff2ae2d10a1ae3e951191fd5b060bfbef1b Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 12:37:50 +0300 Subject: [PATCH 106/143] clone_dyn_types-v0.27.0 --- Cargo.toml | 2 +- module/core/clone_dyn_types/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 02985000c0..c7be699952 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -183,7 +183,7 @@ path = "module/core/clone_dyn_meta" # features = [ "enabled" ] [workspace.dependencies.clone_dyn_types] -version = "~0.26.0" +version = "~0.27.0" path = "module/core/clone_dyn_types" default-features = false # features = [ "enabled" ] diff --git a/module/core/clone_dyn_types/Cargo.toml b/module/core/clone_dyn_types/Cargo.toml index 4a145d0c13..591da29082 100644 --- a/module/core/clone_dyn_types/Cargo.toml +++ b/module/core/clone_dyn_types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clone_dyn_types" -version = "0.26.0" +version = "0.27.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 6eff51b77273b00502c55c5a3f187b58d94efdae Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 12:38:02 +0300 Subject: [PATCH 107/143] iter_tools-v0.25.0 --- Cargo.toml | 2 +- module/core/iter_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c7be699952..81063cb04d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -208,7 +208,7 @@ default-features = false ## iter [workspace.dependencies.iter_tools] -version = "~0.24.0" +version = "~0.25.0" path = "module/core/iter_tools" default-features = false diff --git a/module/core/iter_tools/Cargo.toml b/module/core/iter_tools/Cargo.toml index 7e4dcad983..6cb959cf97 100644 --- a/module/core/iter_tools/Cargo.toml +++ b/module/core/iter_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iter_tools" -version = "0.24.0" +version = "0.25.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 8bd12c67bfcdcefeecec135313e4d6351ffe5634 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 12:38:16 +0300 Subject: [PATCH 108/143] macro_tools-v0.45.0 --- Cargo.toml | 2 +- module/core/macro_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 81063cb04d..67f48461c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -286,7 +286,7 @@ default-features = false ## macro tools [workspace.dependencies.macro_tools] -version = "~0.44.0" +version = "~0.45.0" path = "module/core/macro_tools" default-features = false diff --git a/module/core/macro_tools/Cargo.toml b/module/core/macro_tools/Cargo.toml index 99877d2e6f..b1216b6543 100644 --- a/module/core/macro_tools/Cargo.toml +++ b/module/core/macro_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "macro_tools" -version = "0.44.0" +version = "0.45.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From d99d5f825eb85c127e2140de1161268a8e5eb271 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 13:47:02 +0300 Subject: [PATCH 109/143] fixing error_tools dependenciy problem --- module/alias/cargo_will/tests/smoke_test.rs | 3 +- module/alias/file_tools/tests/smoke_test.rs | 3 +- .../fundamental_data_type/tests/smoke_test.rs | 3 +- module/alias/instance_of/tests/smoke_test.rs | 3 +- module/alias/multilayer/tests/smoke_test.rs | 3 +- .../proc_macro_tools/tests/smoke_test.rs | 3 +- module/alias/proper_tools/tests/smoke_test.rs | 3 +- module/alias/werror/tests/smoke_test.rs | 3 +- module/alias/willbe2/tests/smoke_test.rs | 3 +- module/alias/wproc_macro/tests/smoke_test.rs | 3 +- .../alias/wstring_tools/tests/smoke_test.rs | 3 +- module/blank/draw_lang/tests/smoke_test.rs | 3 +- module/blank/drawboard/tests/smoke_test.rs | 3 +- module/blank/drawql/tests/smoke_test.rs | 3 +- module/blank/exe_tools/tests/smoke_test.rs | 3 +- module/blank/image_tools/tests/smoke_test.rs | 3 +- module/blank/math_tools/tests/smoke_test.rs | 3 +- module/blank/mindx12/tests/smoke_test.rs | 3 +- module/blank/mingl/tests/smoke_test.rs | 3 +- module/blank/minmetal/tests/smoke_test.rs | 3 +- module/blank/minopengl/tests/smoke_test.rs | 3 +- module/blank/minvulkan/tests/smoke_test.rs | 3 +- module/blank/minwebgl/tests/smoke_test.rs | 3 +- module/blank/minwebgpu/tests/smoke_test.rs | 3 +- module/blank/minwgpu/tests/smoke_test.rs | 3 +- module/blank/rustql/tests/smoke_test.rs | 3 +- module/blank/w4d/tests/smoke_test.rs | 3 +- module/core/clone_dyn/tests/smoke_test.rs | 3 +- .../core/clone_dyn_meta/tests/smoke_test.rs | 3 +- .../core/clone_dyn_types/tests/smoke_test.rs | 3 +- .../collection_tools/src/collection/mod.rs | 28 ++++++++++--------- module/core/collection_tools/tests/inc/mod.rs | 3 ++ .../core/collection_tools/tests/smoke_test.rs | 3 +- module/core/collection_tools/tests/tests.rs | 6 ++-- module/core/data_type/tests/smoke_test.rs | 3 +- module/core/derive_tools/tests/smoke_test.rs | 3 +- .../diagnostics_tools/tests/smoke_test.rs | 3 +- module/core/error_tools/tests/inc/mod.rs | 2 ++ module/core/error_tools/tests/smoke_test.rs | 3 +- module/core/error_tools/tests/tests.rs | 4 ++- module/core/for_each/tests/smoke_test.rs | 3 +- module/core/former/tests/smoke_test.rs | 3 +- module/core/former_meta/tests/smoke_test.rs | 3 +- module/core/former_types/tests/smoke_test.rs | 3 +- module/core/fs_tools/tests/smoke_test.rs | 3 +- module/core/implements/tests/smoke_test.rs | 3 +- module/core/impls_index/tests/smoke_test.rs | 3 +- module/core/include_md/tests/smoke_test.rs | 3 +- module/core/inspect_type/tests/smoke_test.rs | 3 +- module/core/is_slice/tests/smoke_test.rs | 3 +- module/core/iter_tools/tests/smoke_test.rs | 3 +- module/core/macro_tools/tests/smoke_test.rs | 3 +- module/core/mem_tools/tests/smoke_test.rs | 3 +- module/core/meta_tools/tests/smoke_test.rs | 3 +- .../mod_interface_meta/tests/smoke_test.rs | 3 +- module/core/process_tools/tests/smoke_test.rs | 3 +- module/core/program_tools/tests/smoke_test.rs | 3 +- module/core/pth/tests/smoke_test.rs | 3 +- module/core/reflect_tools/tests/smoke_test.rs | 3 +- module/core/strs_tools/tests/smoke_test.rs | 3 +- module/core/test_tools/Cargo.toml | 26 ++++++++++++----- module/core/test_tools/src/lib.rs | 22 +++++++++------ module/core/test_tools/tests/inc/mod.rs | 16 +++++------ module/core/test_tools/tests/smoke_test.rs | 2 +- module/core/test_tools/tests/tests.rs | 2 ++ module/core/time_tools/tests/smoke_test.rs | 3 +- module/core/typing_tools/Cargo.toml | 2 -- module/core/typing_tools/tests/smoke_test.rs | 3 +- module/core/variadic_from/tests/smoke_test.rs | 3 +- module/core/wtools/tests/smoke_test.rs | 3 +- module/move/graphs_tools/tests/smoke_test.rs | 3 +- .../tests/smoke_test.rs | 3 +- .../move/plot_interface/tests/smoke_test.rs | 3 +- module/move/sqlx_query/tests/smoke_test.rs | 3 +- module/move/wca/tests/smoke_test.rs | 3 +- module/move/wplot/tests/smoke_test.rs | 3 +- .../_video_experiment/tests/smoke_test.rs | 3 +- .../automata_tools/tests/smoke_test.rs | 3 +- module/postponed/non_std/tests/smoke_test.rs | 3 +- .../postponed/std_tools/tests/smoke_test.rs | 3 +- module/postponed/std_x/tests/smoke_test.rs | 3 +- .../type_constructor/tests/smoke_test.rs | 3 +- .../postponed/wautomata/tests/smoke_test.rs | 3 +- .../postponed/wpublisher/tests/smoke_test.rs | 3 +- module/step/meta/tests/smoke_test.rs | 3 +- .../template_alias/tests/smoke_test.rs | 3 +- .../tests/smoke_test.rs | 3 +- .../tests/smoke_test.rs | 3 +- .../tests/smoke_test.rs | 3 +- 89 files changed, 149 insertions(+), 198 deletions(-) diff --git a/module/alias/cargo_will/tests/smoke_test.rs b/module/alias/cargo_will/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/alias/cargo_will/tests/smoke_test.rs +++ b/module/alias/cargo_will/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/alias/file_tools/tests/smoke_test.rs b/module/alias/file_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/alias/file_tools/tests/smoke_test.rs +++ b/module/alias/file_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/alias/fundamental_data_type/tests/smoke_test.rs b/module/alias/fundamental_data_type/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/alias/fundamental_data_type/tests/smoke_test.rs +++ b/module/alias/fundamental_data_type/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/alias/instance_of/tests/smoke_test.rs b/module/alias/instance_of/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/alias/instance_of/tests/smoke_test.rs +++ b/module/alias/instance_of/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/alias/multilayer/tests/smoke_test.rs b/module/alias/multilayer/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/alias/multilayer/tests/smoke_test.rs +++ b/module/alias/multilayer/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/alias/proc_macro_tools/tests/smoke_test.rs b/module/alias/proc_macro_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/alias/proc_macro_tools/tests/smoke_test.rs +++ b/module/alias/proc_macro_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/alias/proper_tools/tests/smoke_test.rs b/module/alias/proper_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/alias/proper_tools/tests/smoke_test.rs +++ b/module/alias/proper_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/alias/werror/tests/smoke_test.rs b/module/alias/werror/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/alias/werror/tests/smoke_test.rs +++ b/module/alias/werror/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/alias/willbe2/tests/smoke_test.rs b/module/alias/willbe2/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/alias/willbe2/tests/smoke_test.rs +++ b/module/alias/willbe2/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/alias/wproc_macro/tests/smoke_test.rs b/module/alias/wproc_macro/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/alias/wproc_macro/tests/smoke_test.rs +++ b/module/alias/wproc_macro/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/alias/wstring_tools/tests/smoke_test.rs b/module/alias/wstring_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/alias/wstring_tools/tests/smoke_test.rs +++ b/module/alias/wstring_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/draw_lang/tests/smoke_test.rs b/module/blank/draw_lang/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/draw_lang/tests/smoke_test.rs +++ b/module/blank/draw_lang/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/drawboard/tests/smoke_test.rs b/module/blank/drawboard/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/drawboard/tests/smoke_test.rs +++ b/module/blank/drawboard/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/drawql/tests/smoke_test.rs b/module/blank/drawql/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/drawql/tests/smoke_test.rs +++ b/module/blank/drawql/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/exe_tools/tests/smoke_test.rs b/module/blank/exe_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/exe_tools/tests/smoke_test.rs +++ b/module/blank/exe_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/image_tools/tests/smoke_test.rs b/module/blank/image_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/image_tools/tests/smoke_test.rs +++ b/module/blank/image_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/math_tools/tests/smoke_test.rs b/module/blank/math_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/math_tools/tests/smoke_test.rs +++ b/module/blank/math_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/mindx12/tests/smoke_test.rs b/module/blank/mindx12/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/mindx12/tests/smoke_test.rs +++ b/module/blank/mindx12/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/mingl/tests/smoke_test.rs b/module/blank/mingl/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/mingl/tests/smoke_test.rs +++ b/module/blank/mingl/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/minmetal/tests/smoke_test.rs b/module/blank/minmetal/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/minmetal/tests/smoke_test.rs +++ b/module/blank/minmetal/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/minopengl/tests/smoke_test.rs b/module/blank/minopengl/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/minopengl/tests/smoke_test.rs +++ b/module/blank/minopengl/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/minvulkan/tests/smoke_test.rs b/module/blank/minvulkan/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/minvulkan/tests/smoke_test.rs +++ b/module/blank/minvulkan/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/minwebgl/tests/smoke_test.rs b/module/blank/minwebgl/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/minwebgl/tests/smoke_test.rs +++ b/module/blank/minwebgl/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/minwebgpu/tests/smoke_test.rs b/module/blank/minwebgpu/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/minwebgpu/tests/smoke_test.rs +++ b/module/blank/minwebgpu/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/minwgpu/tests/smoke_test.rs b/module/blank/minwgpu/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/minwgpu/tests/smoke_test.rs +++ b/module/blank/minwgpu/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/rustql/tests/smoke_test.rs b/module/blank/rustql/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/rustql/tests/smoke_test.rs +++ b/module/blank/rustql/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/blank/w4d/tests/smoke_test.rs b/module/blank/w4d/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/blank/w4d/tests/smoke_test.rs +++ b/module/blank/w4d/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/clone_dyn/tests/smoke_test.rs b/module/core/clone_dyn/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/clone_dyn/tests/smoke_test.rs +++ b/module/core/clone_dyn/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/clone_dyn_meta/tests/smoke_test.rs b/module/core/clone_dyn_meta/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/clone_dyn_meta/tests/smoke_test.rs +++ b/module/core/clone_dyn_meta/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/clone_dyn_types/tests/smoke_test.rs b/module/core/clone_dyn_types/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/clone_dyn_types/tests/smoke_test.rs +++ b/module/core/clone_dyn_types/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/collection_tools/src/collection/mod.rs b/module/core/collection_tools/src/collection/mod.rs index 22e59e8aae..5508e1263e 100644 --- a/module/core/collection_tools/src/collection/mod.rs +++ b/module/core/collection_tools/src/collection/mod.rs @@ -49,22 +49,10 @@ pub mod own #[ allow( clippy::wildcard_imports ) ] use super::*; - #[ allow( clippy::useless_attribute, clippy::pub_use ) ] - pub use super:: - { - btree_map, - btree_set, - binary_heap, - hash_map, - hash_set, - linked_list, - vector, - vec_deque, - }; - #[ doc( inline ) ] #[ allow( clippy::useless_attribute, clippy::pub_use ) ] pub use orphan::*; + // xxx2 : check } @@ -96,6 +84,20 @@ pub mod exposed #[ allow( clippy::useless_attribute, clippy::pub_use ) ] pub use super::super::collection; + #[ doc( inline ) ] + #[ allow( clippy::useless_attribute, clippy::pub_use ) ] + pub use super:: + { + btree_map, + btree_set, + binary_heap, + hash_map, + hash_set, + linked_list, + vector, + vec_deque, + }; + #[ doc( inline ) ] #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] #[ cfg( feature = "collection_constructors" ) ] diff --git a/module/core/collection_tools/tests/inc/mod.rs b/module/core/collection_tools/tests/inc/mod.rs index 86855a9d84..6e7902f291 100644 --- a/module/core/collection_tools/tests/inc/mod.rs +++ b/module/core/collection_tools/tests/inc/mod.rs @@ -1,5 +1,8 @@ use super::*; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + mod bmap; mod bset; mod heap; diff --git a/module/core/collection_tools/tests/smoke_test.rs b/module/core/collection_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/collection_tools/tests/smoke_test.rs +++ b/module/core/collection_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/collection_tools/tests/tests.rs b/module/core/collection_tools/tests/tests.rs index ecc936c445..ec7c6d3063 100644 --- a/module/core/collection_tools/tests/tests.rs +++ b/module/core/collection_tools/tests/tests.rs @@ -1,10 +1,12 @@ +//! All tests. + #![ allow( unused_imports ) ] #[ path="../../../../module/step/meta/src/module/aggregating.rs" ] mod aggregating; -#[ allow( unused_imports ) ] -use test_tools::exposed::*; +// #[ allow( unused_imports ) ] +// use test_tools::exposed::*; #[ allow( unused_imports ) ] use ::collection_tools as the_module; diff --git a/module/core/data_type/tests/smoke_test.rs b/module/core/data_type/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/data_type/tests/smoke_test.rs +++ b/module/core/data_type/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/derive_tools/tests/smoke_test.rs b/module/core/derive_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/derive_tools/tests/smoke_test.rs +++ b/module/core/derive_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/diagnostics_tools/tests/smoke_test.rs b/module/core/diagnostics_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/diagnostics_tools/tests/smoke_test.rs +++ b/module/core/diagnostics_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/error_tools/tests/inc/mod.rs b/module/core/error_tools/tests/inc/mod.rs index dc239e680e..5e78c0b4c1 100644 --- a/module/core/error_tools/tests/inc/mod.rs +++ b/module/core/error_tools/tests/inc/mod.rs @@ -1,6 +1,8 @@ #[ allow( unused_imports ) ] use super::*; +use test_tools::exposed::*; + mod basic_test; mod namespace_test; diff --git a/module/core/error_tools/tests/smoke_test.rs b/module/core/error_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/error_tools/tests/smoke_test.rs +++ b/module/core/error_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/error_tools/tests/tests.rs b/module/core/error_tools/tests/tests.rs index f217bd0119..4feacbc8fb 100644 --- a/module/core/error_tools/tests/tests.rs +++ b/module/core/error_tools/tests/tests.rs @@ -1,6 +1,8 @@ +//! All tests. + #![ allow( unused_imports ) ] use error_tools as the_module; -use test_tools::exposed::*; +// use test_tools::exposed::*; mod inc; diff --git a/module/core/for_each/tests/smoke_test.rs b/module/core/for_each/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/for_each/tests/smoke_test.rs +++ b/module/core/for_each/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/former/tests/smoke_test.rs b/module/core/former/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/former/tests/smoke_test.rs +++ b/module/core/former/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/former_meta/tests/smoke_test.rs b/module/core/former_meta/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/former_meta/tests/smoke_test.rs +++ b/module/core/former_meta/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/former_types/tests/smoke_test.rs b/module/core/former_types/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/former_types/tests/smoke_test.rs +++ b/module/core/former_types/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/fs_tools/tests/smoke_test.rs b/module/core/fs_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/fs_tools/tests/smoke_test.rs +++ b/module/core/fs_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/implements/tests/smoke_test.rs b/module/core/implements/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/implements/tests/smoke_test.rs +++ b/module/core/implements/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/impls_index/tests/smoke_test.rs b/module/core/impls_index/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/impls_index/tests/smoke_test.rs +++ b/module/core/impls_index/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/include_md/tests/smoke_test.rs b/module/core/include_md/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/include_md/tests/smoke_test.rs +++ b/module/core/include_md/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/inspect_type/tests/smoke_test.rs b/module/core/inspect_type/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/inspect_type/tests/smoke_test.rs +++ b/module/core/inspect_type/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/is_slice/tests/smoke_test.rs b/module/core/is_slice/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/is_slice/tests/smoke_test.rs +++ b/module/core/is_slice/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/iter_tools/tests/smoke_test.rs b/module/core/iter_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/iter_tools/tests/smoke_test.rs +++ b/module/core/iter_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/macro_tools/tests/smoke_test.rs b/module/core/macro_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/macro_tools/tests/smoke_test.rs +++ b/module/core/macro_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/mem_tools/tests/smoke_test.rs b/module/core/mem_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/mem_tools/tests/smoke_test.rs +++ b/module/core/mem_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/meta_tools/tests/smoke_test.rs b/module/core/meta_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/meta_tools/tests/smoke_test.rs +++ b/module/core/meta_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/mod_interface_meta/tests/smoke_test.rs b/module/core/mod_interface_meta/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/mod_interface_meta/tests/smoke_test.rs +++ b/module/core/mod_interface_meta/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/process_tools/tests/smoke_test.rs b/module/core/process_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/process_tools/tests/smoke_test.rs +++ b/module/core/process_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/program_tools/tests/smoke_test.rs b/module/core/program_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/program_tools/tests/smoke_test.rs +++ b/module/core/program_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/pth/tests/smoke_test.rs b/module/core/pth/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/pth/tests/smoke_test.rs +++ b/module/core/pth/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/reflect_tools/tests/smoke_test.rs b/module/core/reflect_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/reflect_tools/tests/smoke_test.rs +++ b/module/core/reflect_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/strs_tools/tests/smoke_test.rs b/module/core/strs_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/strs_tools/tests/smoke_test.rs +++ b/module/core/strs_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/test_tools/Cargo.toml b/module/core/test_tools/Cargo.toml index 4f17161640..47cdf669b2 100644 --- a/module/core/test_tools/Cargo.toml +++ b/module/core/test_tools/Cargo.toml @@ -29,8 +29,8 @@ all-features = false [features] default = [ "enabled", - # "standalone", - "normal", + # "standalone_build", + "normal_build", ] full = [ "default" ] no_std = [ @@ -66,7 +66,7 @@ enabled = [ ] # nightly = [ "typing_tools/nightly" ] -normal = [ +normal_build = [ "dep:error_tools", "dep:collection_tools", "dep:impls_index", @@ -75,13 +75,16 @@ normal = [ "dep:diagnostics_tools", "dep:process_tools", ] -standalone = [ + +# standalone_build vesion of build is used to avoid cyclic dependency +# when crate depend on itself +standalone_build = [ "standalone_error_tools", "standalone_collection_tools", "standalone_impls_index", "standalone_mem_tools", - # "dep:mem_tools", - "dep:typing_tools", + "standalone_typing_tools", + # "dep:typing_tools", "dep:diagnostics_tools", "dep:process_tools", ] @@ -89,6 +92,7 @@ standalone_error_tools = [ "dep:anyhow", "dep:thiserror", "error_typed", "error_ standalone_collection_tools = [ "dep:hashbrown", "collection_constructors", "collection_into_constructors" ] standalone_impls_index = [ "dep:impls_index_meta" ] standalone_mem_tools = [] +standalone_typing_tools = [] # error_tools error_typed = [] @@ -96,6 +100,10 @@ error_untyped = [] # collection_tools collection_constructors = [] collection_into_constructors = [] +# typing_tools +typing_inspect_type = [ "inspect_type/enabled" ] +typing_is_slice = [ "is_slice/enabled" ] +typing_implements = [ "implements/enabled" ] [dependencies] @@ -113,8 +121,8 @@ error_tools = { workspace = true, features = [ "full" ], optional = true } collection_tools = { workspace = true, features = [ "full" ], optional = true } impls_index = { workspace = true, features = [ "full" ], optional = true } mem_tools = { workspace = true, features = [ "full" ], optional = true } - typing_tools = { workspace = true, features = [ "full" ], optional = true } + diagnostics_tools = { workspace = true, features = [ "full" ], optional = true } process_tools = { workspace = true, features = [ "full" ], optional = true } @@ -129,6 +137,10 @@ thiserror = { workspace = true, optional = true } hashbrown = { workspace = true, optional = true } # impls_index impls_index_meta = { workspace = true, optional = true } +# typing_tools +inspect_type = { workspace = true } +is_slice = { workspace = true } +implements = { workspace = true } [build-dependencies] rustc_version = "0.4" diff --git a/module/core/test_tools/src/lib.rs b/module/core/test_tools/src/lib.rs index 4d1b25124e..44b5c7d93b 100644 --- a/module/core/test_tools/src/lib.rs +++ b/module/core/test_tools/src/lib.rs @@ -98,19 +98,19 @@ pub mod test; /// Error tools. #[ cfg( feature = "enabled" ) ] -#[ cfg( feature = "standalone" ) ] +#[ cfg( feature = "standalone_build" ) ] mod standalone { /// Error tools. #[ path = "../../../../core/error_tools/src/error/mod.rs" ] - pub mod error; - pub use error as error_tools; + pub mod error_tools; + pub use error_tools as error; /// Collection tools. #[ path = "../../../../core/collection_tools/src/collection/mod.rs" ] - pub mod collection; - pub use collection as collection_tools; + pub mod collection_tools; + pub use collection_tools as collection; /// impl and index macros. #[ path = "../../../../core/impls_index/src/impls_index/mod.rs" ] @@ -119,27 +119,33 @@ mod standalone /// Memory tools. #[ path = "../../../../core/mem_tools/src/mem.rs" ] pub mod mem_tools; + pub use mem_tools as mem; + + /// Typing tools. + #[ path = "../../../../core/typing_tools/src/typing.rs" ] + pub mod typing_tools; + pub use typing_tools as typing; } #[ cfg( feature = "enabled" ) ] -#[ cfg( feature = "standalone" ) ] +#[ cfg( feature = "standalone_build" ) ] pub use standalone::*; #[ cfg( feature = "enabled" ) ] -#[ cfg( not( feature = "standalone" ) ) ] +#[ cfg( not( feature = "standalone_build" ) ) ] pub use :: { error_tools, collection_tools, impls_index, mem_tools, + typing_tools, }; #[ cfg( feature = "enabled" ) ] pub use :: { - typing_tools, diagnostics_tools, process_tools, }; diff --git a/module/core/test_tools/tests/inc/mod.rs b/module/core/test_tools/tests/inc/mod.rs index a6d6581d75..ff7fad6db8 100644 --- a/module/core/test_tools/tests/inc/mod.rs +++ b/module/core/test_tools/tests/inc/mod.rs @@ -7,20 +7,20 @@ mod try_build_test; // qqq : include tests of all internal dependencies -// /// Error tools. -// #[ path = "../../../../core/error_tools/tests/inc/mod.rs" ] -// pub mod error; +/// Error tools. +#[ path = "../../../../core/error_tools/tests/inc/mod.rs" ] +pub mod error_tests; // pub use error as error_tools; -// -// /// Collection tools. -// #[ path = "../../../../core/collection_tools/tests/inc/mod.rs" ] -// pub mod collection; + +/// Collection tools. +#[ path = "../../../../core/collection_tools/tests/inc/mod.rs" ] +pub mod collection_tests; // pub use collection as collection_tools; // /// impl and index macros. // #[ path = "../../../../core/impls_index/tests/inc/mod.rs" ] // pub mod impls_index; - +// // /// Memory tools. // #[ path = "../../../../core/mem_tools/tests/inc/mod.rs" ] // pub mod mem_tools; diff --git a/module/core/test_tools/tests/smoke_test.rs b/module/core/test_tools/tests/smoke_test.rs index d05a55b089..d31bbdb5e5 100644 --- a/module/core/test_tools/tests/smoke_test.rs +++ b/module/core/test_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the crate. #[ cfg( feature = "enabled" ) ] #[ cfg( not( feature = "no_std" ) ) ] diff --git a/module/core/test_tools/tests/tests.rs b/module/core/test_tools/tests/tests.rs index c9b1261fb2..e1a5c09321 100644 --- a/module/core/test_tools/tests/tests.rs +++ b/module/core/test_tools/tests/tests.rs @@ -1,3 +1,5 @@ +//! All test. + #![ allow( unused_imports ) ] // #![ deny( rust_2018_idioms ) ] diff --git a/module/core/time_tools/tests/smoke_test.rs b/module/core/time_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/time_tools/tests/smoke_test.rs +++ b/module/core/time_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/typing_tools/Cargo.toml b/module/core/typing_tools/Cargo.toml index 2d75db2449..97878deab1 100644 --- a/module/core/typing_tools/Cargo.toml +++ b/module/core/typing_tools/Cargo.toml @@ -25,8 +25,6 @@ workspace = true features = [ "full" ] all-features = false - - [features] default = [ diff --git a/module/core/typing_tools/tests/smoke_test.rs b/module/core/typing_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/typing_tools/tests/smoke_test.rs +++ b/module/core/typing_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/variadic_from/tests/smoke_test.rs b/module/core/variadic_from/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/variadic_from/tests/smoke_test.rs +++ b/module/core/variadic_from/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/wtools/tests/smoke_test.rs b/module/core/wtools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/core/wtools/tests/smoke_test.rs +++ b/module/core/wtools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/move/graphs_tools/tests/smoke_test.rs b/module/move/graphs_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/move/graphs_tools/tests/smoke_test.rs +++ b/module/move/graphs_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/move/graphs_tools_deprecated/tests/smoke_test.rs b/module/move/graphs_tools_deprecated/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/move/graphs_tools_deprecated/tests/smoke_test.rs +++ b/module/move/graphs_tools_deprecated/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/move/plot_interface/tests/smoke_test.rs b/module/move/plot_interface/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/move/plot_interface/tests/smoke_test.rs +++ b/module/move/plot_interface/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/move/sqlx_query/tests/smoke_test.rs b/module/move/sqlx_query/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/move/sqlx_query/tests/smoke_test.rs +++ b/module/move/sqlx_query/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/move/wca/tests/smoke_test.rs b/module/move/wca/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/move/wca/tests/smoke_test.rs +++ b/module/move/wca/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/move/wplot/tests/smoke_test.rs b/module/move/wplot/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/move/wplot/tests/smoke_test.rs +++ b/module/move/wplot/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/postponed/_video_experiment/tests/smoke_test.rs b/module/postponed/_video_experiment/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/postponed/_video_experiment/tests/smoke_test.rs +++ b/module/postponed/_video_experiment/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/postponed/automata_tools/tests/smoke_test.rs b/module/postponed/automata_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/postponed/automata_tools/tests/smoke_test.rs +++ b/module/postponed/automata_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/postponed/non_std/tests/smoke_test.rs b/module/postponed/non_std/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/postponed/non_std/tests/smoke_test.rs +++ b/module/postponed/non_std/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/postponed/std_tools/tests/smoke_test.rs b/module/postponed/std_tools/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/postponed/std_tools/tests/smoke_test.rs +++ b/module/postponed/std_tools/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/postponed/std_x/tests/smoke_test.rs b/module/postponed/std_x/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/postponed/std_x/tests/smoke_test.rs +++ b/module/postponed/std_x/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/postponed/type_constructor/tests/smoke_test.rs b/module/postponed/type_constructor/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/postponed/type_constructor/tests/smoke_test.rs +++ b/module/postponed/type_constructor/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/postponed/wautomata/tests/smoke_test.rs b/module/postponed/wautomata/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/postponed/wautomata/tests/smoke_test.rs +++ b/module/postponed/wautomata/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/postponed/wpublisher/tests/smoke_test.rs b/module/postponed/wpublisher/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/postponed/wpublisher/tests/smoke_test.rs +++ b/module/postponed/wpublisher/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/step/meta/tests/smoke_test.rs b/module/step/meta/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/step/meta/tests/smoke_test.rs +++ b/module/step/meta/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/template/template_alias/tests/smoke_test.rs b/module/template/template_alias/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/template/template_alias/tests/smoke_test.rs +++ b/module/template/template_alias/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/template/template_procedural_macro/tests/smoke_test.rs b/module/template/template_procedural_macro/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/template/template_procedural_macro/tests/smoke_test.rs +++ b/module/template/template_procedural_macro/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/template/template_procedural_macro_meta/tests/smoke_test.rs b/module/template/template_procedural_macro_meta/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/template/template_procedural_macro_meta/tests/smoke_test.rs +++ b/module/template/template_procedural_macro_meta/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/template/template_procedural_macro_runtime/tests/smoke_test.rs b/module/template/template_procedural_macro_runtime/tests/smoke_test.rs index 828e9b016b..c9b1b4daae 100644 --- a/module/template/template_procedural_macro_runtime/tests/smoke_test.rs +++ b/module/template/template_procedural_macro_runtime/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { From 383c294ee85031028a10041d4139974db9c36041 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:22:25 +0300 Subject: [PATCH 110/143] fix test_tools issue --- .cargo/config.toml | 7 + Cargo.toml | 8 + module/core/diagnostics_tools/Cargo.toml | 4 +- .../{diagnostics_tests.rs => all_tests.rs} | 12 +- .../tests/inc/layout_test.rs | 7 +- .../core/diagnostics_tools/tests/inc/mod.rs | 1 + module/core/error_tools/src/error/mod.rs | 8 +- module/core/error_tools/src/error/untyped.rs | 1 + .../error_tools/tests/inc/err_with_test.rs | 2 +- .../error_tools/tests/inc/untyped_test.rs | 4 +- .../examples/former_custom_collection.rs | 4 +- module/core/former/tests/experimental.rs | 5 +- .../inc/former_tests/attribute_feature.rs | 3 +- .../inc/former_tests/parametrized_dyn.rs | 815 +++++++++--------- .../former_tests/subform_collection_custom.rs | 4 +- module/core/former/tests/inc/mod.rs | 5 +- module/core/former/tests/tests.rs | 5 +- .../core/implements/tests/implements_tests.rs | 2 +- .../core/impls_index/src/impls_index/mod.rs | 1 + module/core/impls_index/tests/experiment.rs | 3 +- .../core/impls_index/tests/inc/func_test.rs | 25 +- .../core/impls_index/tests/inc/impls3_test.rs | 3 +- .../impls_index/tests/inc/impls_basic_test.rs | 6 +- module/core/impls_index/tests/inc/mod.rs | 7 +- module/core/impls_index/tests/tests.rs | 5 +- module/core/impls_index_meta/src/impls.rs | 2 +- module/core/inspect_type/build.rs | 52 +- .../examples/inspect_type_trivial.rs | 2 +- module/core/inspect_type/src/lib.rs | 5 +- .../tests/inc/inspect_type_test.rs | 12 +- module/core/inspect_type/tests/inc/mod.rs | 3 + module/core/inspect_type/tests/tests.rs | 7 +- module/core/is_slice/tests/inc/mod.rs | 3 +- module/core/is_slice/tests/is_slice_tests.rs | 7 +- module/core/mem_tools/tests/inc/mem_test.rs | 37 +- module/core/mem_tools/tests/inc/mod.rs | 3 + .../core/mem_tools/tests/mem_tools_tests.rs | 5 +- module/core/process_tools/Cargo.toml | 2 - module/core/test_tools/.cargo/config.toml | 5 + module/core/test_tools/Cargo.toml | 104 ++- module/core/test_tools/src/lib.rs | 54 +- module/core/test_tools/src/test/mod.rs | 4 + module/core/test_tools/src/test/process.rs | 63 ++ .../src/test/process/environment.rs | 114 +++ module/core/test_tools/src/test/smoke_test.rs | 9 +- module/core/test_tools/tests/inc/mod.rs | 27 +- module/core/test_tools/tests/tests.rs | 2 + module/core/typing_tools/tests/inc/mod.rs | 6 +- module/core/typing_tools/tests/tests.rs | 9 +- 49 files changed, 868 insertions(+), 616 deletions(-) rename module/core/diagnostics_tools/tests/{diagnostics_tests.rs => all_tests.rs} (61%) create mode 100644 module/core/test_tools/.cargo/config.toml create mode 100644 module/core/test_tools/src/test/process.rs create mode 100644 module/core/test_tools/src/test/process/environment.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index 38ed1d83cd..70aeac4add 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,7 +1,14 @@ +# qqq : xxx : explain purpose of each line [env] MODULES_PATH = { value = "module", relative = true } WORKSPACE_PATH = { value = ".", relative = true } [net] # offline = true + +# [build] +# rustdocflags = [ "--cfg", "feature=\"normal_build\"" ] + +# [alias] +# test = "test --doc --features normal_build,enabled" diff --git a/Cargo.toml b/Cargo.toml index 67f48461c6..2a50a2e887 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -555,6 +555,11 @@ version = "~1.0" # features = [] # default-features = false +[workspace.dependencies.pretty_assertions] +version = "~1.4.0" +# features = [] +# default-features = false + [workspace.dependencies.hashbrown] version = "~0.14.3" # optional = true @@ -576,3 +581,6 @@ version = "~0.2" [workspace.dependencies.rand] version = "0.8.5" + +[workspace.dependencies.trybuild] +version = "1.0.85" diff --git a/module/core/diagnostics_tools/Cargo.toml b/module/core/diagnostics_tools/Cargo.toml index 6b48adc190..6103e7fb9c 100644 --- a/module/core/diagnostics_tools/Cargo.toml +++ b/module/core/diagnostics_tools/Cargo.toml @@ -43,12 +43,12 @@ no_std = [] use_alloc = [ "no_std" ] enabled = [] -diagnostics_runtime_assertions = [ "pretty_assertions" ] # run-time assertions +diagnostics_runtime_assertions = [ "dep:pretty_assertions" ] # run-time assertions diagnostics_compiletime_assertions = [] # compile-time assertions diagnostics_memory_layout = [] # [dependencies] -pretty_assertions = { version = "~1.4.0", optional = true } +pretty_assertions = { workspace = true, optional = true } [dev-dependencies] test_tools = { workspace = true } diff --git a/module/core/diagnostics_tools/tests/diagnostics_tests.rs b/module/core/diagnostics_tools/tests/all_tests.rs similarity index 61% rename from module/core/diagnostics_tools/tests/diagnostics_tests.rs rename to module/core/diagnostics_tools/tests/all_tests.rs index 46138a3acb..cce190c203 100644 --- a/module/core/diagnostics_tools/tests/diagnostics_tests.rs +++ b/module/core/diagnostics_tools/tests/all_tests.rs @@ -1,3 +1,5 @@ +//! All tests. + // #![ deny( rust_2018_idioms ) ] // #![ deny( missing_debug_implementations ) ] // #![ deny( missing_docs ) ] @@ -5,11 +7,9 @@ // #![ cfg_attr( feature = "type_name_of_val", feature( type_name_of_val ) ) ] // #![ feature( trace_macros ) ] -#[ allow( unused_imports ) ] -use diagnostics_tools as the_module; -#[ allow( unused_imports ) ] -use test_tools::exposed::*; -// #[ path="../../../../module/step/meta/src/module/terminal.rs" ] -// mod terminal; +#![ allow( unused_imports ) ] +#[ path="../../../../module/step/meta/src/module/terminal.rs" ] +mod terminal; +use diagnostics_tools as the_module; mod inc; diff --git a/module/core/diagnostics_tools/tests/inc/layout_test.rs b/module/core/diagnostics_tools/tests/inc/layout_test.rs index 37cd393f46..c0b92f743f 100644 --- a/module/core/diagnostics_tools/tests/inc/layout_test.rs +++ b/module/core/diagnostics_tools/tests/inc/layout_test.rs @@ -64,10 +64,9 @@ tests_impls! } -#[ path = "../../../../step/meta/src/module/aggregating.rs" ] -mod aggregating; - -use crate::only_for_terminal_module; +// #[ path = "../../../../step/meta/src/module/aggregating.rs" ] +// mod aggregating; +// use crate::only_for_terminal_module; only_for_terminal_module! { diff --git a/module/core/diagnostics_tools/tests/inc/mod.rs b/module/core/diagnostics_tools/tests/inc/mod.rs index 68dc070886..4016c1dc8a 100644 --- a/module/core/diagnostics_tools/tests/inc/mod.rs +++ b/module/core/diagnostics_tools/tests/inc/mod.rs @@ -1,4 +1,5 @@ use super::*; +use test_tools::exposed::*; #[ cfg( any( feature = "diagnostics_runtime_assertions", feature = "diagnostics_runtime_assertions" ) ) ] mod cta_test; diff --git a/module/core/error_tools/src/error/mod.rs b/module/core/error_tools/src/error/mod.rs index 9c22df98c3..46d48b7c35 100644 --- a/module/core/error_tools/src/error/mod.rs +++ b/module/core/error_tools/src/error/mod.rs @@ -26,9 +26,9 @@ mod private /// /// A `Result` of type `ReportOk` if the original result is `Ok`, or a tuple `(ReportErr, E)` containing the additional /// context and the original error if the original result is `Err`. - /// + /// /// # Errors - /// + /// /// qqq: errors /// /// # Example @@ -55,9 +55,9 @@ mod private /// /// A `Result` of type `ReportOk` if the original result is `Ok`, or a tuple `(ReportErr, E)` containing the additional /// context and the original error if the original result is `Err`. - /// + /// /// # Errors - /// + /// /// qqq: Errors /// /// # Example diff --git a/module/core/error_tools/src/error/untyped.rs b/module/core/error_tools/src/error/untyped.rs index d4d65afe67..8a57019dc0 100644 --- a/module/core/error_tools/src/error/untyped.rs +++ b/module/core/error_tools/src/error/untyped.rs @@ -43,6 +43,7 @@ pub mod orphan { #[ allow( clippy::wildcard_imports ) ] use super::*; + #[ allow( clippy::useless_attribute, clippy::pub_use ) ] pub use super::super::untyped; #[ allow( clippy::useless_attribute, clippy::pub_use ) ] diff --git a/module/core/error_tools/tests/inc/err_with_test.rs b/module/core/error_tools/tests/inc/err_with_test.rs index 7b3a65516f..3e50ac7d08 100644 --- a/module/core/error_tools/tests/inc/err_with_test.rs +++ b/module/core/error_tools/tests/inc/err_with_test.rs @@ -20,7 +20,7 @@ fn err_with() fn err_with_report() { - use error_tools::ErrWith; + use the_module::ErrWith; let result : Result< (), std::io::Error > = Err( std::io::Error::new( std::io::ErrorKind::Other, "an error occurred" ) ); let report = "additional context"; let got : Result< (), ( &str, std::io::Error ) > = result.err_with_report( &report ); diff --git a/module/core/error_tools/tests/inc/untyped_test.rs b/module/core/error_tools/tests/inc/untyped_test.rs index f1db8e77a9..6e92b663e7 100644 --- a/module/core/error_tools/tests/inc/untyped_test.rs +++ b/module/core/error_tools/tests/inc/untyped_test.rs @@ -10,8 +10,8 @@ tests_impls! { // test.case( "from parse usize error" ); - let err = the_module::untyped::format_err!( "err" ); - a_id!( the_module::untyped::Error::is::< &str >( &err ), true ); + let err = the_module::error::untyped::format_err!( "err" ); + a_id!( the_module::error::untyped::Error::is::< &str >( &err ), true ); a_id!( err.is::< &str >(), true ); a_id!( err.to_string(), "err" ); } diff --git a/module/core/former/examples/former_custom_collection.rs b/module/core/former/examples/former_custom_collection.rs index a3b1e1b667..1f275425d3 100644 --- a/module/core/former/examples/former_custom_collection.rs +++ b/module/core/former/examples/former_custom_collection.rs @@ -44,7 +44,7 @@ fn main() K : core::cmp::Eq + std::hash::Hash, { type Item = K; - type IntoIter = collection_tools::hset::IntoIter< K >; + type IntoIter = collection_tools::hash_set::IntoIter< K >; fn into_iter( self ) -> Self::IntoIter { @@ -58,7 +58,7 @@ fn main() K : core::cmp::Eq + std::hash::Hash, { type Item = &'a K; - type IntoIter = collection_tools::hset::Iter< 'a, K >; + type IntoIter = collection_tools::hash_set::Iter< 'a, K >; fn into_iter( self ) -> Self::IntoIter { diff --git a/module/core/former/tests/experimental.rs b/module/core/former/tests/experimental.rs index fe640ab353..9713734b7b 100644 --- a/module/core/former/tests/experimental.rs +++ b/module/core/former/tests/experimental.rs @@ -1,9 +1,8 @@ +//! For experimenting. +#![ allow( unused_imports ) ] include!( "../../../../module/step/meta/src/module/terminal.rs" ); -#[ allow( unused_imports ) ] -use test_tools::exposed::*; -#[ allow( unused_imports ) ] use former as the_module; // #[ path = "./inc/components_composite.rs" ] diff --git a/module/core/former/tests/inc/former_tests/attribute_feature.rs b/module/core/former/tests/inc/former_tests/attribute_feature.rs index 20dea37cf8..937e0f36cc 100644 --- a/module/core/former/tests/inc/former_tests/attribute_feature.rs +++ b/module/core/former/tests/inc/former_tests/attribute_feature.rs @@ -1,4 +1,5 @@ -#[ allow( unused_imports ) ] +#![ allow( unexpected_cfgs ) ] + use super::*; #[ derive( Debug, PartialEq ) ] diff --git a/module/core/former/tests/inc/former_tests/parametrized_dyn.rs b/module/core/former/tests/inc/former_tests/parametrized_dyn.rs index 813f06f165..04006d88c7 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_dyn.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_dyn.rs @@ -1,405 +1,412 @@ -use super::*; - -pub trait FilterCol : fmt::Debug -{ - fn filter_col( &self, key : &str ) -> bool; -} - -#[ derive( Debug, Default, PartialEq, Clone, Copy ) ] -pub struct All; - -impl All -{ - pub fn instance() -> & 'static dyn FilterCol - { - static INSTANCE : All = All; - &INSTANCE - } -} - -impl Default for &'static dyn FilterCol -{ - #[ inline( always ) ] - fn default() -> Self - { - All::instance() - } -} - -impl FilterCol for All -{ - #[ inline( always ) ] - fn filter_col( &self, _key : &str ) -> bool - { - true - } -} - -#[ derive( Default ) ] -// #[ derive( former::Former ) ] // xxx : qqq : uncomment and fix problem with lifetime -// #[ derive( former::Former ) ] #[ debug ] -pub struct Styles< 'callback > -{ - - // pub output_format : &'static dyn AsRef< str >, - pub filter : &'callback dyn FilterCol, - -} - -// === begin_coercing of generated - -#[automatically_derived] -impl< 'callback > Styles< 'callback > where -{ - #[doc = r""] - #[doc = r" Provides a mechanism to initiate the formation process with a default completion behavior."] - #[doc = r""] - #[inline(always)] - pub fn former() -> StylesFormer< 'callback, StylesFormerDefinition< 'callback, (), Styles< 'callback >, former::ReturnPreformed > > - { - StylesFormer::< 'callback, StylesFormerDefinition< 'callback, (), Styles< 'callback >, former::ReturnPreformed > >::new_coercing(former::ReturnPreformed) - } -} - -impl< 'callback, Definition > former::EntityToFormer< Definition > for Styles< 'callback > -where - Definition : former::FormerDefinition< Storage = StylesFormerStorage< 'callback > >, -{ - type Former = StylesFormer< 'callback, Definition >; -} - -impl< 'callback > former::EntityToStorage for Styles< 'callback > -where -{ - type Storage = StylesFormerStorage< 'callback >; -} - -impl< 'callback, __Context, __Formed, __End > former::EntityToDefinition< __Context, __Formed, __End > for Styles< 'callback > -where - __End : former::FormingEnd< StylesFormerDefinitionTypes< 'callback, __Context, __Formed > >, -{ - type Definition = StylesFormerDefinition< 'callback, __Context, __Formed, __End >; - type Types = StylesFormerDefinitionTypes< 'callback, __Context, __Formed >; -} - -impl< 'callback, __Context, __Formed > former::EntityToDefinitionTypes< __Context, __Formed > for Styles< 'callback > -where -{ - type Types = StylesFormerDefinitionTypes< 'callback, __Context, __Formed >; -} - -#[doc = r" Defines the generic parameters for formation behavior including context, form, and end conditions."] -#[derive(Debug)] -pub struct StylesFormerDefinitionTypes< 'callback, __Context = (), __Formed = Styles< 'callback > > -where -{ - _phantom: ::core::marker::PhantomData< ( & 'callback (), * const __Context, * const __Formed ) >, -} - -impl< 'callback, __Context, __Formed > ::core::default::Default for StylesFormerDefinitionTypes< 'callback, __Context, __Formed > -where -{ - fn default() -> Self - { - Self { _phantom: ::core::marker::PhantomData } - } -} - -impl< 'callback, __Context, __Formed > former::FormerDefinitionTypes for StylesFormerDefinitionTypes< 'callback, __Context, __Formed > -where -{ - type Storage = StylesFormerStorage< 'callback >; - type Formed = __Formed; - type Context = __Context; -} - -#[doc = r" Holds the definition types used during the formation process."] -#[derive(Debug)] -pub struct StylesFormerDefinition< 'callback, __Context = (), __Formed = Styles< 'callback >, __End = former::ReturnPreformed > -where -{ - _phantom: ::core::marker::PhantomData< ( & 'callback (), * const __Context, * const __Formed, * const __End ) >, -} - -impl< 'callback, __Context, __Formed, __End > ::core::default::Default for StylesFormerDefinition< 'callback, __Context, __Formed, __End > -where -{ - fn default() -> Self - { - Self { _phantom: ::core::marker::PhantomData } - } -} - -impl< 'callback, __Context, __Formed, __End > former::FormerDefinition for StylesFormerDefinition< 'callback, __Context, __Formed, __End > -where - __End : former::FormingEnd< StylesFormerDefinitionTypes< 'callback, __Context, __Formed > >, -{ - type Types = StylesFormerDefinitionTypes< 'callback, __Context, __Formed >; - type End = __End; - type Storage = StylesFormerStorage< 'callback >; - type Formed = __Formed; - type Context = __Context; -} - -impl< 'callback, __Context, __Formed > former::FormerMutator for StylesFormerDefinitionTypes< 'callback, __Context, __Formed > -where -{} - -#[doc = "Stores potential values for fields during the formation process."] -#[allow(explicit_outlives_requirements)] -pub struct StylesFormerStorage< 'callback > -where -{ - #[doc = r" A field"] - pub filter: ::core::option::Option< & 'callback dyn FilterCol >, -} - -impl< 'callback > ::core::default::Default for StylesFormerStorage< 'callback > -where -{ - #[inline(always)] - fn default() -> Self - { - Self { filter: ::core::option::Option::None } - } -} - -impl< 'callback > former::Storage for StylesFormerStorage< 'callback > -where -{ - type Preformed = Styles< 'callback >; -} - -impl< 'callback > former::StoragePreform for StylesFormerStorage< 'callback > -where -{ - fn preform(mut self) -> Self::Preformed - { - let filter = if self.filter.is_some() - { - self.filter.take().unwrap() - } - else - { - { - trait MaybeDefault - { - fn maybe_default(self: &Self) -> T - { - panic!("Field 'filter' isn't initialized") - } - } - impl MaybeDefault for &::core::marker::PhantomData - {} - impl MaybeDefault for ::core::marker::PhantomData - where - T: ::core::default::Default, - { - fn maybe_default(self: &Self) -> T - { - T::default() - } - } - (&::core::marker::PhantomData::<&'callback dyn FilterCol>).maybe_default() - } - }; - let result = Styles::< 'callback > { filter }; - return result; - } -} - -#[doc = "\nStructure to form [Styles]. Represents a forming entity designed to construct objects through a builder pattern.\n\nThis structure holds temporary storage and context during the formation process and\nutilizes a defined end strategy to finalize the object creation.\n"] -pub struct StylesFormer< 'callback, Definition = StylesFormerDefinition< 'callback, (), Styles< 'callback >, former::ReturnPreformed > > -where - Definition: former::FormerDefinition< Storage = StylesFormerStorage< 'callback > >, - Definition::Types: former::FormerDefinitionTypes< Storage = StylesFormerStorage< 'callback > >, -{ - #[doc = r" Temporary storage for all fields during the formation process. It contains"] - #[doc = r" partial data that progressively builds up to the final object."] - pub storage: Definition::Storage, - #[doc = r" An optional context providing additional data or state necessary for custom"] - #[doc = r" formation logic or to facilitate this former's role as a subformer within another former."] - pub context: ::core::option::Option< Definition::Context >, - #[doc = r" An optional closure or handler that is invoked to transform the accumulated"] - #[doc = r" temporary storage into the final object structure once formation is complete."] - pub on_end: ::core::option::Option< Definition::End >, -} - -#[automatically_derived] -impl< 'callback, Definition > StylesFormer< 'callback, Definition > -where - Definition: former::FormerDefinition< Storage = StylesFormerStorage< 'callback > >, - Definition::Types: former::FormerDefinitionTypes< Storage = StylesFormerStorage< 'callback > >, -{ - #[doc = r""] - #[doc = r" Initializes a former with an end condition and default storage."] - #[doc = r""] - #[inline(always)] - pub fn new(on_end: Definition::End) -> Self - { - Self::begin_coercing(::core::option::Option::None, ::core::option::Option::None, on_end) - } - - #[doc = r""] - #[doc = r" Initializes a former with a coercible end condition."] - #[doc = r""] - #[inline(always)] - pub fn new_coercing(end: IntoEnd) -> Self - where - IntoEnd: ::core::convert::Into, - { - Self::begin_coercing(::core::option::Option::None, ::core::option::Option::None, end) - } - - #[doc = r""] - #[doc = r" Begins the formation process with specified context and termination logic."] - #[doc = r""] - #[inline(always)] - pub fn begin( - mut storage: ::core::option::Option, - context: ::core::option::Option, - on_end: ::End, - ) -> Self - { - if storage.is_none() - { - storage = ::core::option::Option::Some(::core::default::Default::default()); - } - Self - { - storage: storage.unwrap(), - context: context, - on_end: ::core::option::Option::Some(on_end), - } - } - - #[doc = r""] - #[doc = r" Starts the formation process with coercible end condition and optional initial values."] - #[doc = r""] - #[inline(always)] - pub fn begin_coercing( - mut storage: ::core::option::Option, - context: ::core::option::Option, - on_end: IntoEnd, - ) -> Self - where - IntoEnd: ::core::convert::Into<::End>, - { - if storage.is_none() - { - storage = ::core::option::Option::Some(::core::default::Default::default()); - } - Self - { - storage: storage.unwrap(), - context: context, - on_end: ::core::option::Option::Some(::core::convert::Into::into(on_end)), - } - } - - #[doc = r""] - #[doc = r" Wrapper for `end` to align with common builder pattern terminologies."] - #[doc = r""] - #[inline(always)] - pub fn form(self) -> ::Formed - { - self.end() - } - - #[doc = r""] - #[doc = r" Completes the formation and returns the formed object."] - #[doc = r""] - #[inline(always)] - pub fn end(mut self) -> ::Formed - { - let on_end = self.on_end.take().unwrap(); - let mut context = self.context.take(); - ::form_mutation(&mut self.storage, &mut context); - former::FormingEnd::::call(&on_end, self.storage, context) - } - - #[doc = "Scalar setter for the 'filter' field."] - #[inline] - pub fn filter(mut self, src: Src) -> Self - where - Src: ::core::convert::Into<& 'callback dyn FilterCol>, - { - debug_assert!(self.storage.filter.is_none()); - self.storage.filter = ::core::option::Option::Some(::core::convert::Into::into(src)); - self - } -} - -impl< 'callback, Definition > StylesFormer< 'callback, Definition > -where - Definition: former::FormerDefinition< Storage = StylesFormerStorage< 'callback >, Formed = Styles< 'callback > >, - Definition::Types: former::FormerDefinitionTypes< Storage = StylesFormerStorage< 'callback >, Formed = Styles< 'callback > >, - Definition: former::FormerDefinition< Storage = StylesFormerStorage< 'callback > >, - Definition::Types: former::FormerDefinitionTypes< Storage = StylesFormerStorage< 'callback > >, -{ - #[doc = r" Executes the transformation from the former's storage state to the preformed object as specified by the definition."] - pub fn preform(self) -> ::Formed - { - former::StoragePreform::preform(self.storage) - } -} - -#[automatically_derived] -impl< 'callback, Definition > StylesFormer< 'callback, Definition > -where - Definition: former::FormerDefinition< Storage = StylesFormerStorage< 'callback >, Formed = Styles< 'callback > >, - Definition::Types: former::FormerDefinitionTypes< Storage = StylesFormerStorage< 'callback >, Formed = Styles< 'callback > >, -{ - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] - #[doc = r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] - #[inline(always)] - pub fn perform(self) -> Definition::Formed - { - let result = self.form(); - return result; - } -} - -impl< 'callback, Definition > former::FormerBegin< Definition > for StylesFormer< 'callback, Definition > -where - Definition: former::FormerDefinition< Storage = StylesFormerStorage< 'callback > >, -{ - #[inline(always)] - fn former_begin( - storage: ::core::option::Option, - context: ::core::option::Option, - on_end: Definition::End, - ) -> Self - { - debug_assert!(storage.is_none()); - Self::begin(::core::option::Option::None, context, on_end) - } -} - -#[doc = r" Provides a specialized former for structure using predefined settings for superformer and end conditions."] -#[doc = r""] -#[doc = r" This type alias configures former of the structure with a specific definition to streamline its usage in broader contexts,"] -#[doc = r" especially where structure needs to be integrated into larger structures with a clear termination condition."] -pub type StylesAsSubformer< 'callback, __Superformer, __End > = StylesFormer< 'callback, StylesFormerDefinition< 'callback, __Superformer, __Superformer, __End > >; - -#[doc = "\nRepresents an end condition for former of [`$Styles`], tying the lifecycle of forming processes to a broader context.\n\nThis trait is intended for use with subformer alias, ensuring that end conditions are met according to the\nspecific needs of the broader forming context. It mandates the implementation of `former::FormingEnd`.\n "] -pub trait StylesAsSubformerEnd< 'callback, SuperFormer > -where - Self: former::FormingEnd< StylesFormerDefinitionTypes< 'callback, SuperFormer, SuperFormer > >, -{} -impl< 'callback, SuperFormer, __T > StylesAsSubformerEnd< 'callback, SuperFormer > for __T -where - Self: former::FormingEnd< StylesFormerDefinitionTypes< 'callback, SuperFormer, SuperFormer > >, -{} - -// === end of generated - -#[ test ] -fn basic() -{ -} \ No newline at end of file +// xxx2 : qqq2 : +// - uncomment code +// - duplicate the file and actually use macro Former +// - make macro working taking into account this corner case +// - for your conveniency there expansion of macro is below + +// use super::*; +// use core::fmt; +// +// pub trait FilterCol : fmt::Debug +// { +// fn filter_col( &self, key : &str ) -> bool; +// } +// +// #[ derive( Debug, Default, PartialEq, Clone, Copy ) ] +// pub struct All; +// +// impl All +// { +// pub fn instance() -> & 'static dyn FilterCol +// { +// static INSTANCE : All = All; +// &INSTANCE +// } +// } +// +// impl Default for &'static dyn FilterCol +// { +// #[ inline( always ) ] +// fn default() -> Self +// { +// All::instance() +// } +// } +// +// impl FilterCol for All +// { +// #[ inline( always ) ] +// fn filter_col( &self, _key : &str ) -> bool +// { +// true +// } +// } +// +// #[ derive( Default ) ] +// // #[ derive( former::Former ) ] // xxx : qqq : uncomment and fix problem with lifetime +// // #[ derive( former::Former ) ] #[ debug ] +// pub struct Styles< 'callback > +// { +// +// // pub output_format : &'static dyn AsRef< str >, +// pub filter : &'callback dyn FilterCol, +// +// } +// +// // === begin_coercing of generated +// +// #[automatically_derived] +// impl< 'callback > Styles< 'callback > where +// { +// #[doc = r""] +// #[doc = r" Provides a mechanism to initiate the formation process with a default completion behavior."] +// #[doc = r""] +// #[inline(always)] +// pub fn former() -> StylesFormer< 'callback, StylesFormerDefinition< 'callback, (), Styles< 'callback >, former::ReturnPreformed > > +// { +// StylesFormer::< 'callback, StylesFormerDefinition< 'callback, (), Styles< 'callback >, former::ReturnPreformed > >::new_coercing(former::ReturnPreformed) +// } +// } +// +// impl< 'callback, Definition > former::EntityToFormer< Definition > for Styles< 'callback > +// where +// Definition : former::FormerDefinition< Storage = StylesFormerStorage< 'callback > >, +// { +// type Former = StylesFormer< 'callback, Definition >; +// } +// +// impl< 'callback > former::EntityToStorage for Styles< 'callback > +// where +// { +// type Storage = StylesFormerStorage< 'callback >; +// } +// +// impl< 'callback, __Context, __Formed, __End > former::EntityToDefinition< __Context, __Formed, __End > for Styles< 'callback > +// where +// __End : former::FormingEnd< StylesFormerDefinitionTypes< 'callback, __Context, __Formed > >, +// { +// type Definition = StylesFormerDefinition< 'callback, __Context, __Formed, __End >; +// type Types = StylesFormerDefinitionTypes< 'callback, __Context, __Formed >; +// } +// +// impl< 'callback, __Context, __Formed > former::EntityToDefinitionTypes< __Context, __Formed > for Styles< 'callback > +// where +// { +// type Types = StylesFormerDefinitionTypes< 'callback, __Context, __Formed >; +// } +// +// #[doc = r" Defines the generic parameters for formation behavior including context, form, and end conditions."] +// #[derive(Debug)] +// pub struct StylesFormerDefinitionTypes< 'callback, __Context = (), __Formed = Styles< 'callback > > +// where +// { +// _phantom: ::core::marker::PhantomData< ( & 'callback (), * const __Context, * const __Formed ) >, +// } +// +// impl< 'callback, __Context, __Formed > ::core::default::Default for StylesFormerDefinitionTypes< 'callback, __Context, __Formed > +// where +// { +// fn default() -> Self +// { +// Self { _phantom: ::core::marker::PhantomData } +// } +// } +// +// impl< 'callback, __Context, __Formed > former::FormerDefinitionTypes for StylesFormerDefinitionTypes< 'callback, __Context, __Formed > +// where +// { +// type Storage = StylesFormerStorage< 'callback >; +// type Formed = __Formed; +// type Context = __Context; +// } +// +// #[doc = r" Holds the definition types used during the formation process."] +// #[derive(Debug)] +// pub struct StylesFormerDefinition< 'callback, __Context = (), __Formed = Styles< 'callback >, __End = former::ReturnPreformed > +// where +// { +// _phantom: ::core::marker::PhantomData< ( & 'callback (), * const __Context, * const __Formed, * const __End ) >, +// } +// +// impl< 'callback, __Context, __Formed, __End > ::core::default::Default for StylesFormerDefinition< 'callback, __Context, __Formed, __End > +// where +// { +// fn default() -> Self +// { +// Self { _phantom: ::core::marker::PhantomData } +// } +// } +// +// impl< 'callback, __Context, __Formed, __End > former::FormerDefinition for StylesFormerDefinition< 'callback, __Context, __Formed, __End > +// where +// __End : former::FormingEnd< StylesFormerDefinitionTypes< 'callback, __Context, __Formed > >, +// { +// type Types = StylesFormerDefinitionTypes< 'callback, __Context, __Formed >; +// type End = __End; +// type Storage = StylesFormerStorage< 'callback >; +// type Formed = __Formed; +// type Context = __Context; +// } +// +// impl< 'callback, __Context, __Formed > former::FormerMutator for StylesFormerDefinitionTypes< 'callback, __Context, __Formed > +// where +// {} +// +// #[doc = "Stores potential values for fields during the formation process."] +// #[allow(explicit_outlives_requirements)] +// pub struct StylesFormerStorage< 'callback > +// where +// { +// #[doc = r" A field"] +// pub filter: ::core::option::Option< & 'callback dyn FilterCol >, +// } +// +// impl< 'callback > ::core::default::Default for StylesFormerStorage< 'callback > +// where +// { +// #[inline(always)] +// fn default() -> Self +// { +// Self { filter: ::core::option::Option::None } +// } +// } +// +// impl< 'callback > former::Storage for StylesFormerStorage< 'callback > +// where +// { +// type Preformed = Styles< 'callback >; +// } +// +// impl< 'callback > former::StoragePreform for StylesFormerStorage< 'callback > +// where +// { +// fn preform(mut self) -> Self::Preformed +// { +// let filter = if self.filter.is_some() +// { +// self.filter.take().unwrap() +// } +// else +// { +// { +// trait MaybeDefault +// { +// fn maybe_default(self: &Self) -> T +// { +// panic!("Field 'filter' isn't initialized") +// } +// } +// impl MaybeDefault for &::core::marker::PhantomData +// {} +// impl MaybeDefault for ::core::marker::PhantomData +// where +// T: ::core::default::Default, +// { +// fn maybe_default(self: &Self) -> T +// { +// T::default() +// } +// } +// (&::core::marker::PhantomData::<&'callback dyn FilterCol>).maybe_default() +// } +// }; +// let result = Styles::< 'callback > { filter }; +// return result; +// } +// } +// +// #[doc = "\nStructure to form [Styles]. Represents a forming entity designed to construct objects through a builder pattern.\n\nThis structure holds temporary storage and context during the formation process and\nutilizes a defined end strategy to finalize the object creation.\n"] +// pub struct StylesFormer< 'callback, Definition = StylesFormerDefinition< 'callback, (), Styles< 'callback >, former::ReturnPreformed > > +// where +// Definition: former::FormerDefinition< Storage = StylesFormerStorage< 'callback > >, +// Definition::Types: former::FormerDefinitionTypes< Storage = StylesFormerStorage< 'callback > >, +// { +// #[doc = r" Temporary storage for all fields during the formation process. It contains"] +// #[doc = r" partial data that progressively builds up to the final object."] +// pub storage: Definition::Storage, +// #[doc = r" An optional context providing additional data or state necessary for custom"] +// #[doc = r" formation logic or to facilitate this former's role as a subformer within another former."] +// pub context: ::core::option::Option< Definition::Context >, +// #[doc = r" An optional closure or handler that is invoked to transform the accumulated"] +// #[doc = r" temporary storage into the final object structure once formation is complete."] +// pub on_end: ::core::option::Option< Definition::End >, +// } +// +// #[automatically_derived] +// impl< 'callback, Definition > StylesFormer< 'callback, Definition > +// where +// Definition: former::FormerDefinition< Storage = StylesFormerStorage< 'callback > >, +// Definition::Types: former::FormerDefinitionTypes< Storage = StylesFormerStorage< 'callback > >, +// { +// #[doc = r""] +// #[doc = r" Initializes a former with an end condition and default storage."] +// #[doc = r""] +// #[inline(always)] +// pub fn new(on_end: Definition::End) -> Self +// { +// Self::begin_coercing(::core::option::Option::None, ::core::option::Option::None, on_end) +// } +// +// #[doc = r""] +// #[doc = r" Initializes a former with a coercible end condition."] +// #[doc = r""] +// #[inline(always)] +// pub fn new_coercing(end: IntoEnd) -> Self +// where +// IntoEnd: ::core::convert::Into, +// { +// Self::begin_coercing(::core::option::Option::None, ::core::option::Option::None, end) +// } +// +// #[doc = r""] +// #[doc = r" Begins the formation process with specified context and termination logic."] +// #[doc = r""] +// #[inline(always)] +// pub fn begin( +// mut storage: ::core::option::Option, +// context: ::core::option::Option, +// on_end: ::End, +// ) -> Self +// { +// if storage.is_none() +// { +// storage = ::core::option::Option::Some(::core::default::Default::default()); +// } +// Self +// { +// storage: storage.unwrap(), +// context: context, +// on_end: ::core::option::Option::Some(on_end), +// } +// } +// +// #[doc = r""] +// #[doc = r" Starts the formation process with coercible end condition and optional initial values."] +// #[doc = r""] +// #[inline(always)] +// pub fn begin_coercing( +// mut storage: ::core::option::Option, +// context: ::core::option::Option, +// on_end: IntoEnd, +// ) -> Self +// where +// IntoEnd: ::core::convert::Into<::End>, +// { +// if storage.is_none() +// { +// storage = ::core::option::Option::Some(::core::default::Default::default()); +// } +// Self +// { +// storage: storage.unwrap(), +// context: context, +// on_end: ::core::option::Option::Some(::core::convert::Into::into(on_end)), +// } +// } +// +// #[doc = r""] +// #[doc = r" Wrapper for `end` to align with common builder pattern terminologies."] +// #[doc = r""] +// #[inline(always)] +// pub fn form(self) -> ::Formed +// { +// self.end() +// } +// +// #[doc = r""] +// #[doc = r" Completes the formation and returns the formed object."] +// #[doc = r""] +// #[inline(always)] +// pub fn end(mut self) -> ::Formed +// { +// let on_end = self.on_end.take().unwrap(); +// let mut context = self.context.take(); +// ::form_mutation(&mut self.storage, &mut context); +// former::FormingEnd::::call(&on_end, self.storage, context) +// } +// +// #[doc = "Scalar setter for the 'filter' field."] +// #[inline] +// pub fn filter(mut self, src: Src) -> Self +// where +// Src: ::core::convert::Into<& 'callback dyn FilterCol>, +// { +// debug_assert!(self.storage.filter.is_none()); +// self.storage.filter = ::core::option::Option::Some(::core::convert::Into::into(src)); +// self +// } +// } +// +// impl< 'callback, Definition > StylesFormer< 'callback, Definition > +// where +// Definition: former::FormerDefinition< Storage = StylesFormerStorage< 'callback >, Formed = Styles< 'callback > >, +// Definition::Types: former::FormerDefinitionTypes< Storage = StylesFormerStorage< 'callback >, Formed = Styles< 'callback > >, +// Definition: former::FormerDefinition< Storage = StylesFormerStorage< 'callback > >, +// Definition::Types: former::FormerDefinitionTypes< Storage = StylesFormerStorage< 'callback > >, +// { +// #[doc = r" Executes the transformation from the former's storage state to the preformed object as specified by the definition."] +// pub fn preform(self) -> ::Formed +// { +// former::StoragePreform::preform(self.storage) +// } +// } +// +// #[automatically_derived] +// impl< 'callback, Definition > StylesFormer< 'callback, Definition > +// where +// Definition: former::FormerDefinition< Storage = StylesFormerStorage< 'callback >, Formed = Styles< 'callback > >, +// Definition::Types: former::FormerDefinitionTypes< Storage = StylesFormerStorage< 'callback >, Formed = Styles< 'callback > >, +// { +// #[doc = r""] +// #[doc = r" Finish setting options and call perform on formed entity."] +// #[doc = r""] +// #[doc = r" If `perform` defined then associated method is called and its result returned instead of entity."] +// #[doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] +// #[doc = r""] +// #[inline(always)] +// pub fn perform(self) -> Definition::Formed +// { +// let result = self.form(); +// return result; +// } +// } +// +// impl< 'callback, Definition > former::FormerBegin< Definition > for StylesFormer< 'callback, Definition > +// where +// Definition: former::FormerDefinition< Storage = StylesFormerStorage< 'callback > >, +// { +// #[inline(always)] +// fn former_begin( +// storage: ::core::option::Option, +// context: ::core::option::Option, +// on_end: Definition::End, +// ) -> Self +// { +// debug_assert!(storage.is_none()); +// Self::begin(::core::option::Option::None, context, on_end) +// } +// } +// +// #[doc = r" Provides a specialized former for structure using predefined settings for superformer and end conditions."] +// #[doc = r""] +// #[doc = r" This type alias configures former of the structure with a specific definition to streamline its usage in broader contexts,"] +// #[doc = r" especially where structure needs to be integrated into larger structures with a clear termination condition."] +// pub type StylesAsSubformer< 'callback, __Superformer, __End > = StylesFormer< 'callback, StylesFormerDefinition< 'callback, __Superformer, __Superformer, __End > >; +// +// #[doc = "\nRepresents an end condition for former of [`$Styles`], tying the lifecycle of forming processes to a broader context.\n\nThis trait is intended for use with subformer alias, ensuring that end conditions are met according to the\nspecific needs of the broader forming context. It mandates the implementation of `former::FormingEnd`.\n "] +// pub trait StylesAsSubformerEnd< 'callback, SuperFormer > +// where +// Self: former::FormingEnd< StylesFormerDefinitionTypes< 'callback, SuperFormer, SuperFormer > >, +// {} +// impl< 'callback, SuperFormer, __T > StylesAsSubformerEnd< 'callback, SuperFormer > for __T +// where +// Self: former::FormingEnd< StylesFormerDefinitionTypes< 'callback, SuperFormer, SuperFormer > >, +// {} +// +// // === end of generated +// +// #[ test ] +// fn basic() +// { +// } \ No newline at end of file diff --git a/module/core/former/tests/inc/former_tests/subform_collection_custom.rs b/module/core/former/tests/inc/former_tests/subform_collection_custom.rs index 00851f857d..684cc4775a 100644 --- a/module/core/former/tests/inc/former_tests/subform_collection_custom.rs +++ b/module/core/former/tests/inc/former_tests/subform_collection_custom.rs @@ -36,7 +36,7 @@ where K : core::cmp::Eq + std::hash::Hash, { type Item = K; - type IntoIter = collection_tools::hset::IntoIter< K >; + type IntoIter = collection_tools::hash_set::IntoIter< K >; fn into_iter( self ) -> Self::IntoIter { @@ -49,7 +49,7 @@ where K : core::cmp::Eq + std::hash::Hash, { type Item = &'a K; - type IntoIter = collection_tools::hset::Iter< 'a, K >; + type IntoIter = collection_tools::hash_set::Iter< 'a, K >; fn into_iter( self ) -> Self::IntoIter { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index d259269d35..3405bce07f 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -1,12 +1,11 @@ // #![ deny( missing_docs ) ] -#[ allow( unused_imports ) ] use super::*; +use test_tools::exposed::*; #[ cfg( feature = "derive_former" ) ] mod former_tests { - #[ allow( unused_imports ) ] use super::*; // = basic @@ -53,7 +52,7 @@ mod former_tests // = parametrization - mod parametrized_dyn; + mod parametrized_dyn; // xxx2 : qqq2 : fix the issue #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod parametrized_struct_manual; diff --git a/module/core/former/tests/tests.rs b/module/core/former/tests/tests.rs index fe0db783b8..5796f74d30 100644 --- a/module/core/former/tests/tests.rs +++ b/module/core/former/tests/tests.rs @@ -1,9 +1,8 @@ +//! All tests. +#![ allow( unused_imports ) ] include!( "../../../../module/step/meta/src/module/terminal.rs" ); -#[ allow( unused_imports ) ] -use test_tools::exposed::*; -#[ allow( unused_imports ) ] use former as the_module; #[ cfg( feature = "enabled" ) ] diff --git a/module/core/implements/tests/implements_tests.rs b/module/core/implements/tests/implements_tests.rs index d51c4b2b7d..db13e78660 100644 --- a/module/core/implements/tests/implements_tests.rs +++ b/module/core/implements/tests/implements_tests.rs @@ -1,4 +1,4 @@ -// #![cfg_attr(docsrs, feature(doc_cfg))] +// #![ cfg_attr( docsrs, feature( doc_cfg ) ) ] // #![ cfg_attr( feature = "nightly", feature( type_name_of_val ) ) ] #![ cfg_attr( feature = "nightly", feature( trace_macros ) ) ] #![ cfg_attr( feature = "nightly", feature( meta_idents_concat ) ) ] diff --git a/module/core/impls_index/src/impls_index/mod.rs b/module/core/impls_index/src/impls_index/mod.rs index 5b54558d8d..484e43dd3f 100644 --- a/module/core/impls_index/src/impls_index/mod.rs +++ b/module/core/impls_index/src/impls_index/mod.rs @@ -49,6 +49,7 @@ pub mod orphan pub mod exposed { use super::*; + pub use super::super::impls_index; #[ doc( inline ) ] pub use prelude::*; #[ doc( inline ) ] diff --git a/module/core/impls_index/tests/experiment.rs b/module/core/impls_index/tests/experiment.rs index 85e51cf468..bcb1aca749 100644 --- a/module/core/impls_index/tests/experiment.rs +++ b/module/core/impls_index/tests/experiment.rs @@ -1,10 +1,11 @@ +//! Experimenting. include!( "../../../../module/step/meta/src/module/terminal.rs" ); #[ allow( unused_imports ) ] use impls_index as the_module; #[ allow( unused_imports ) ] -use test_tools::exposed::*; +use test_tools::exposed::{ a_id }; #[ path = "inc/impls3_test.rs" ] mod inc; diff --git a/module/core/impls_index/tests/inc/func_test.rs b/module/core/impls_index/tests/inc/func_test.rs index 7b5d74bbcc..ebe6126f51 100644 --- a/module/core/impls_index/tests/inc/func_test.rs +++ b/module/core/impls_index/tests/inc/func_test.rs @@ -1,9 +1,10 @@ #![ deny( unused_imports ) ] use super::*; -#[ allow ( unused_imports ) ] -use the_module::exposed::*; +// #[ allow ( unused_imports ) ] +// use the_module::exposed::*; // use test_tools::exposed::*; +// use test_tools::a_id; // @@ -12,7 +13,7 @@ fn fn_name() { let f1 = 13; - let f2 = fn_name! + let f2 = the_module::exposed::fn_name! { fn f1() { @@ -29,7 +30,7 @@ fn fn_name() fn fn_rename() { - fn_rename! + the_module::exposed::fn_rename! { @Name { f2 } @Fn @@ -100,7 +101,7 @@ fn fns() }; } - fns! + the_module::exposed::fns! { @Callback { count } @Fns @@ -135,7 +136,7 @@ fn fns() }; } - fns! + the_module::exposed::fns! { @Callback { count } @Fns @@ -172,7 +173,7 @@ fn fns() }; } - fns! + the_module::exposed::fns! { @Callback { count } @Fns @@ -204,7 +205,7 @@ fn fns() }; } - fns! + the_module::exposed::fns! { @Callback { count } @Fns @@ -235,7 +236,7 @@ fn fns() }; } - fns! + the_module::exposed::fns! { @Callback { count } @Fns @@ -268,7 +269,7 @@ fn fns() }; } - fns! + the_module::exposed::fns! { @Callback { count } @Fns @@ -300,7 +301,7 @@ fn fns() // }; // } // -// fns! +// the_module::exposed::fns! // { // @Callback { count } // @Fns @@ -333,7 +334,7 @@ fn fns() } // trace_macros!( true ); - fns! + the_module::exposed::fns! { @Callback { count } @Fns diff --git a/module/core/impls_index/tests/inc/impls3_test.rs b/module/core/impls_index/tests/inc/impls3_test.rs index 1fe454dfc7..350a692a1f 100644 --- a/module/core/impls_index/tests/inc/impls3_test.rs +++ b/module/core/impls_index/tests/inc/impls3_test.rs @@ -1,6 +1,5 @@ use super::*; -use the_module::exposed::impls3; -use the_module::exposed::{ index }; +use the_module::exposed::{ impls3, index, impls_index }; // diff --git a/module/core/impls_index/tests/inc/impls_basic_test.rs b/module/core/impls_index/tests/inc/impls_basic_test.rs index 8a9ef8df85..64ca19ceac 100644 --- a/module/core/impls_index/tests/inc/impls_basic_test.rs +++ b/module/core/impls_index/tests/inc/impls_basic_test.rs @@ -1,8 +1,8 @@ use super::*; -use the_module::exposed::*; +// use the_module::exposed::*; // trace_macros!( true ); -tests_impls! +the_module::exposed::tests_impls! { fn pass1_test() @@ -40,7 +40,7 @@ tests_impls! // trace_macros!( false ); // trace_macros!( true ); -tests_index! +the_module::exposed::tests_index! { pass1_test, fail1_test, diff --git a/module/core/impls_index/tests/inc/mod.rs b/module/core/impls_index/tests/inc/mod.rs index 105f2928cd..624fc01ab8 100644 --- a/module/core/impls_index/tests/inc/mod.rs +++ b/module/core/impls_index/tests/inc/mod.rs @@ -1,9 +1,12 @@ +// To avoid conflicts with test_tools it's important to import only those names which are needed. +use test_tools::a_id; + use super:: { the_module, - only_for_terminal_module, - a_id, + // only_for_terminal_module, + // a_id, }; mod func_test; diff --git a/module/core/impls_index/tests/tests.rs b/module/core/impls_index/tests/tests.rs index b96684ac4a..7cee7cbf9b 100644 --- a/module/core/impls_index/tests/tests.rs +++ b/module/core/impls_index/tests/tests.rs @@ -1,10 +1,9 @@ +//! All tests. + #![ allow( unused_imports ) ] include!( "../../../../module/step/meta/src/module/terminal.rs" ); #[ allow( unused_imports ) ] use impls_index as the_module; -#[ allow( unused_imports ) ] -use test_tools::exposed::*; - mod inc; diff --git a/module/core/impls_index_meta/src/impls.rs b/module/core/impls_index_meta/src/impls.rs index 1ae6c3ee9b..1a59eb4a2e 100644 --- a/module/core/impls_index_meta/src/impls.rs +++ b/module/core/impls_index_meta/src/impls.rs @@ -71,7 +71,7 @@ impl quote::ToTokens for Items2 { ( as $Name2 : ident ) => { - ::impls_index::fn_rename! + impls_index::fn_rename! { @Name { $Name2 } @Fn diff --git a/module/core/inspect_type/build.rs b/module/core/inspect_type/build.rs index e1ddc05383..006a6376e7 100644 --- a/module/core/inspect_type/build.rs +++ b/module/core/inspect_type/build.rs @@ -1,35 +1,35 @@ //! To have information about channel of Rust compiler. -use rustc_version::{ version, version_meta, Channel }; +// use rustc_version::{ version, version_meta, Channel }; fn main() { // Assert we haven't travelled back in time - assert!( version().unwrap().major >= 1 ); + assert!( rustc_version::version().unwrap().major >= 1 ); - // Set cfg flags depending on release channel - match version_meta().unwrap().channel - { - Channel::Stable => - { - println!("cargo:rustc-cfg=RUSTC_IS_STABLE"); - println!("cargo:rustc-check-cfg=cfg(RUSTC_IS_STABLE)"); - } - Channel::Beta => - { - println!("cargo:rustc-cfg=RUSTC_IS_BETA"); - println!("cargo:rustc-check-cfg=cfg(RUSTC_IS_BETA)"); - } - Channel::Nightly => - { - println!("cargo:rustc-cfg=RUSTC_IS_NIGHTLY"); - println!("cargo:rustc-check-cfg=cfg(RUSTC_IS_NIGHTLY)"); - } - Channel::Dev => - { - println!("cargo:rustc-cfg=RUSTC_IS_DEV"); - println!("cargo:rustc-check-cfg=cfg(RUSTC_IS_DEV)"); - } - } + // // Set cfg flags depending on release channel + // match version_meta().unwrap().channel + // { + // Channel::Stable => + // { + // println!("cargo:rustc-cfg=RUSTC_IS_STABLE"); + // println!("cargo:rustc-check-cfg=cfg(RUSTC_IS_STABLE)"); + // } + // Channel::Beta => + // { + // println!("cargo:rustc-cfg=RUSTC_IS_BETA"); + // println!("cargo:rustc-check-cfg=cfg(RUSTC_IS_BETA)"); + // } + // Channel::Nightly => + // { + // println!("cargo:rustc-cfg=RUSTC_IS_NIGHTLY"); + // println!("cargo:rustc-check-cfg=cfg(RUSTC_IS_NIGHTLY)"); + // } + // Channel::Dev => + // { + // println!("cargo:rustc-cfg=RUSTC_IS_DEV"); + // println!("cargo:rustc-check-cfg=cfg(RUSTC_IS_DEV)"); + // } + // } } diff --git a/module/core/inspect_type/examples/inspect_type_trivial.rs b/module/core/inspect_type/examples/inspect_type_trivial.rs index 9f616a8204..260687cf71 100644 --- a/module/core/inspect_type/examples/inspect_type_trivial.rs +++ b/module/core/inspect_type/examples/inspect_type_trivial.rs @@ -1,5 +1,5 @@ //! qqq : write proper description -#![ cfg_attr( feature = "type_name_of_val", feature( type_name_of_val ) ) ] +// #![ cfg_attr( feature = "type_name_of_val", feature( type_name_of_val ) ) ] // // #![ cfg_attr( feature = "nightly", feature( type_name_of_val ) ) ] // #![ rustversion::attr( nightly, feature( type_name_of_val ) ) ] diff --git a/module/core/inspect_type/src/lib.rs b/module/core/inspect_type/src/lib.rs index 8f65d3fb63..06ede7e31c 100644 --- a/module/core/inspect_type/src/lib.rs +++ b/module/core/inspect_type/src/lib.rs @@ -4,9 +4,10 @@ #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] #![ allow( unexpected_cfgs ) ] +// xxx : qqq : no need in nightly anymore // #[ allow( unexpected_cfgs ) ] // #[ cfg( RUSTC_IS_NIGHTLY ) ] -#[ cfg( not( RUSTC_IS_STABLE ) ) ] +// #[ cfg( not( RUSTC_IS_STABLE ) ) ] mod nightly { @@ -96,7 +97,7 @@ pub mod prelude // #[ rustversion::nightly ] // #[ cfg( feature = "type_name_of_val" ) ] // #[ cfg( RUSTC_IS_NIGHTLY ) ] - #[ cfg( not( RUSTC_IS_STABLE ) ) ] + // #[ cfg( not( RUSTC_IS_STABLE ) ) ] #[ doc( inline ) ] pub use super::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 01445f74c4..b279d98ce4 100644 --- a/module/core/inspect_type/tests/inc/inspect_type_test.rs +++ b/module/core/inspect_type/tests/inc/inspect_type_test.rs @@ -4,10 +4,9 @@ use super::*; // -// #[ test_tools::nightly ] -// #[ cfg( feature = "nightly" ) ] -// #[ cfg( RUSTC_IS_NIGHTLY ) ] -#[ cfg( not( RUSTC_IS_STABLE ) ) ] +// use the_module::nightly; + +// #[ cfg( not( RUSTC_IS_STABLE ) ) ] tests_impls! { @@ -43,10 +42,7 @@ tests_impls! // -// #[ test_tools::nightly ] -// #[ cfg( feature = "nightly" ) ] -// #[ cfg( RUSTC_IS_NIGHTLY ) ] -#[ cfg( not( RUSTC_IS_STABLE ) ) ] +// #[ cfg( not( RUSTC_IS_STABLE ) ) ] tests_index! { inspect_to_str_type_of_test, diff --git a/module/core/inspect_type/tests/inc/mod.rs b/module/core/inspect_type/tests/inc/mod.rs index d8be619a97..5867483bff 100644 --- a/module/core/inspect_type/tests/inc/mod.rs +++ b/module/core/inspect_type/tests/inc/mod.rs @@ -1,4 +1,7 @@ #[ allow( unused_imports ) ] use super::*; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + mod inspect_type_test; diff --git a/module/core/inspect_type/tests/tests.rs b/module/core/inspect_type/tests/tests.rs index 8e5818a1f9..8271ec46f8 100644 --- a/module/core/inspect_type/tests/tests.rs +++ b/module/core/inspect_type/tests/tests.rs @@ -1,5 +1,6 @@ -// #![ allow( unexpected_cfgs ) ] +//! All Tests +// #![ allow( unexpected_cfgs ) ] // #![ no_std ] // #![ cfg_attr( feature = "no_std", no_std ) ] @@ -7,7 +8,7 @@ // #![ test_tools::nightly ] // #![ cfg_attr( feature = "type_name_of_val", feature( type_name_of_val ) ) ] // #![ cfg_attr( rustversion::nightly, feature( type_name_of_val ) ) ] -// #![cfg_attr(docsrs, feature(doc_cfg))] +// #![ cfg_attr( docsrs, feature( doc_cfg ) ) ] // // #![ cfg_attr( feature = "nightly", feature( type_name_of_val ) ) ] // #![ cfg_attr( feature = "nightly", feature( trace_macros ) ) ] // #![ cfg_attr( feature = "nightly", feature( meta_idents_concat ) ) ] @@ -16,7 +17,5 @@ #[ allow( unused_imports ) ] use inspect_type as the_module; -#[ allow( unused_imports ) ] -use test_tools::exposed::*; mod inc; diff --git a/module/core/is_slice/tests/inc/mod.rs b/module/core/is_slice/tests/inc/mod.rs index d2e9305da9..9ee358f257 100644 --- a/module/core/is_slice/tests/inc/mod.rs +++ b/module/core/is_slice/tests/inc/mod.rs @@ -1,6 +1,5 @@ -#![ no_std ] -#[ allow( unused_imports ) ] use super::*; +use test_tools::exposed::*; mod is_slice_test; diff --git a/module/core/is_slice/tests/is_slice_tests.rs b/module/core/is_slice/tests/is_slice_tests.rs index 6aad89f853..56b1834ab4 100644 --- a/module/core/is_slice/tests/is_slice_tests.rs +++ b/module/core/is_slice/tests/is_slice_tests.rs @@ -1,10 +1,13 @@ -// #![cfg_attr(docsrs, feature(doc_cfg))] +//! Smoke testing of the package. + +// #![ cfg_attr( docsrs, feature( doc_cfg ) ) ] // #![ cfg_attr( feature = "nightly", feature( type_name_of_val ) ) ] // #![ feature( type_name_of_val ) ] // #![ feature( trace_macros ) ] // #![ feature( meta_idents_concat ) ] +#![ allow( unused_imports ) ] -use test_tools::exposed::*; +// use test_tools::exposed::*; use is_slice as the_module; // #[ path = "./inc.rs" ] diff --git a/module/core/mem_tools/tests/inc/mem_test.rs b/module/core/mem_tools/tests/inc/mem_test.rs index 1b2fa2954e..bc9a9ce519 100644 --- a/module/core/mem_tools/tests/inc/mem_test.rs +++ b/module/core/mem_tools/tests/inc/mem_test.rs @@ -8,21 +8,21 @@ tests_impls! fn same_data() { let buf = [ 0u8; 128 ]; - a_true!( the_module::same_data( &buf, &buf ) ); + a_true!( the_module::mem::same_data( &buf, &buf ) ); let x = [ 0u8; 1 ]; let y = 0u8; - a_true!( the_module::same_data( &x, &y ) ); + a_true!( the_module::mem::same_data( &x, &y ) ); - a_false!( the_module::same_data( &buf, &x ) ); - a_false!( the_module::same_data( &buf, &y ) ); + a_false!( the_module::mem::same_data( &buf, &x ) ); + a_false!( the_module::mem::same_data( &buf, &y ) ); struct H1( &'static str ); struct H2( &'static str ); - a_true!( the_module::same_data( &H1( "hello" ), &H2( "hello" ) ) ); - a_false!( the_module::same_data( &H1( "qwerty" ), &H2( "hello" ) ) ); + a_true!( the_module::mem::same_data( &H1( "hello" ), &H2( "hello" ) ) ); + a_false!( the_module::mem::same_data( &H1( "qwerty" ), &H2( "hello" ) ) ); } @@ -31,15 +31,15 @@ tests_impls! let src1 = "abc"; let src2 = "abc"; - a_true!( the_module::same_ptr( src1, src2 ) ); + a_true!( the_module::mem::same_ptr( src1, src2 ) ); let src1 = ( 1, ); let src2 = ( 1, ); - a_false!( the_module::same_ptr( &src1, &src2 ) ); + a_false!( the_module::mem::same_ptr( &src1, &src2 ) ); let src1 = ( 1 ); let src2 = "abcde"; - a_false!( the_module::same_ptr( &src1, src2 ) ); + a_false!( the_module::mem::same_ptr( &src1, src2 ) ); } @@ -50,15 +50,15 @@ tests_impls! let src1 = "abc"; let src2 = "cba"; - a_true!( the_module::same_size( src1, src2 ) ); + a_true!( the_module::mem::same_size( src1, src2 ) ); let src1 = ( 1, ); let src2 = ( 3, ); - a_true!( the_module::same_size( &src1, &src2 ) ); + a_true!( the_module::mem::same_size( &src1, &src2 ) ); let src1 = ( 1 ); let src2 = "abcde"; - a_false!( the_module::same_size( &src1, src2 ) ); + a_false!( the_module::mem::same_size( &src1, src2 ) ); } @@ -69,15 +69,15 @@ tests_impls! let src1 = "abc"; let src2 = "abc"; - a_true!( the_module::same_region( src1, src2 ) ); + a_true!( the_module::mem::same_region( src1, src2 ) ); let src1 = ( 1, ); let src2 = ( 1, ); - a_false!( the_module::same_region( &src1, &src2 ) ); + a_false!( the_module::mem::same_region( &src1, &src2 ) ); let src1 = ( 1 ); let src2 = "abcde"; - a_false!( the_module::same_region( &src1, src2 ) ); + a_false!( the_module::mem::same_region( &src1, src2 ) ); } @@ -85,24 +85,23 @@ tests_impls! fn samples() { - use the_module as mem; // Are two pointers are the same, not taking into accoint type. // Unlike `std::ptr::eq()` does not require arguments to have the same type. let src1 = ( 1, ); let src2 = ( 1, ); - assert!( !mem::same_ptr( &src1, &src2 ) ); + assert!( !the_module::mem::same_ptr( &src1, &src2 ) ); // Are two pointers points on data of the same size. let src1 = "abc"; let src2 = "cba"; - assert!( mem::same_size( src1, src2 ) ); + assert!( the_module::mem::same_size( src1, src2 ) ); // Are two pointers points on the same region, ie same size and same pointer. // Does not require arguments to have the same type. let src1 = "abc"; let src2 = "abc"; - assert!( mem::same_region( src1, src2 ) ); + assert!( the_module::mem::same_region( src1, src2 ) ); } diff --git a/module/core/mem_tools/tests/inc/mod.rs b/module/core/mem_tools/tests/inc/mod.rs index 9147b3ddcc..cc1110aad5 100644 --- a/module/core/mem_tools/tests/inc/mod.rs +++ b/module/core/mem_tools/tests/inc/mod.rs @@ -1,4 +1,7 @@ #[ allow( unused_imports ) ] use super::*; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + mod mem_test; diff --git a/module/core/mem_tools/tests/mem_tools_tests.rs b/module/core/mem_tools/tests/mem_tools_tests.rs index 5f9856b952..51260d5101 100644 --- a/module/core/mem_tools/tests/mem_tools_tests.rs +++ b/module/core/mem_tools/tests/mem_tools_tests.rs @@ -1,3 +1,5 @@ +//! All tests. + // #![ deny( rust_2018_idioms ) ] // #![ deny( missing_debug_implementations ) ] // #![ deny( missing_docs ) ] @@ -5,8 +7,5 @@ // #![ feature( trace_macros ) ] // #![ feature( type_name_of_val ) ] -#[ allow( unused_imports ) ] -use test_tools::exposed::*; use mem_tools as the_module; - mod inc; diff --git a/module/core/process_tools/Cargo.toml b/module/core/process_tools/Cargo.toml index e358031ef1..6a4e6950b9 100644 --- a/module/core/process_tools/Cargo.toml +++ b/module/core/process_tools/Cargo.toml @@ -19,12 +19,10 @@ keywords = [ "fundamental", "general-purpose" ] [lints] workspace = true - [package.metadata.docs.rs] features = [ "full" ] all-features = false - [features] default = [ "enabled", "process_environment_is_cicd" ] full = [ "default" ] diff --git a/module/core/test_tools/.cargo/config.toml b/module/core/test_tools/.cargo/config.toml new file mode 100644 index 0000000000..14735242a8 --- /dev/null +++ b/module/core/test_tools/.cargo/config.toml @@ -0,0 +1,5 @@ + +[build] +rustdocflags = [ + "--cfg", "feature=\"doctest\"", +] diff --git a/module/core/test_tools/Cargo.toml b/module/core/test_tools/Cargo.toml index 47cdf669b2..4298c413bd 100644 --- a/module/core/test_tools/Cargo.toml +++ b/module/core/test_tools/Cargo.toml @@ -21,59 +21,44 @@ keywords = [ "fundamental", "general-purpose", "testing" ] workspace = true [package.metadata.docs.rs] -features = [ "full" ] +features = [ "normal_build", "enabled" ] all-features = false +no-default-features = false +# features = [ "full" ] +# all-features = false # = features [features] default = [ "enabled", - # "standalone_build", - "normal_build", + "standalone_build", + # "normal_build", + "process_tools", + "process_environment_is_cicd", ] -full = [ "default" ] +full = [ + "default" +] +doctest = [] # for doctest shorcaomings resolution +# doctest does not work properly for aggregators no_std = [ - # "error_tools/no_std", - # "meta_tools/no_std", - # "mem_tools/no_std", - # "typing_tools/no_std", - # "data_type/no_std", - # "diagnostics_tools/no_std", - # "process_tools_published/no_std", - # "former_stable/use_alloc", ] use_alloc = [ "no_std", - # "error_tools/use_alloc", - # "meta_tools/use_alloc", - # "mem_tools/use_alloc", - # "typing_tools/use_alloc", - # "data_type/use_alloc", - # "diagnostics_tools/use_alloc", - # "process_tools_published/use_alloc", - # "former_stable/use_alloc", ] enabled = [ - # "error_tools/enabled", - # "meta_tools/enabled", - # "mem_tools/enabled", - # "typing_tools/enabled", - # "data_type/enabled", - # "diagnostics_tools/enabled", - # "process_tools/enabled", - # "collection_tools/enabled", ] # nightly = [ "typing_tools/nightly" ] normal_build = [ - "dep:error_tools", - "dep:collection_tools", - "dep:impls_index", - "dep:mem_tools", - "dep:typing_tools", - "dep:diagnostics_tools", - "dep:process_tools", + # "dep:error_tools", + # "dep:collection_tools", + # "dep:impls_index", + # "dep:mem_tools", + # "dep:typing_tools", + # "dep:diagnostics_tools", + # # "dep:process_tools", ] # standalone_build vesion of build is used to avoid cyclic dependency @@ -84,15 +69,16 @@ standalone_build = [ "standalone_impls_index", "standalone_mem_tools", "standalone_typing_tools", - # "dep:typing_tools", - "dep:diagnostics_tools", - "dep:process_tools", + "standalone_diagnostics_tools", + # "standalone_process_tools", + # "dep:process_tools", ] standalone_error_tools = [ "dep:anyhow", "dep:thiserror", "error_typed", "error_untyped" ] standalone_collection_tools = [ "dep:hashbrown", "collection_constructors", "collection_into_constructors" ] standalone_impls_index = [ "dep:impls_index_meta" ] standalone_mem_tools = [] -standalone_typing_tools = [] +standalone_typing_tools = [ "typing_implements", "typing_is_slice", "typing_inspect_type" ] +standalone_diagnostics_tools = [ "diagnostics_runtime_assertions", "diagnostics_compiletime_assertions", "diagnostics_memory_layout" ] # error_tools error_typed = [] @@ -104,29 +90,35 @@ collection_into_constructors = [] typing_inspect_type = [ "inspect_type/enabled" ] typing_is_slice = [ "is_slice/enabled" ] typing_implements = [ "implements/enabled" ] +# diagnostics_tools +diagnostics_runtime_assertions = [ "dep:pretty_assertions" ] # run-time assertions +diagnostics_compiletime_assertions = [] # compile-time assertions +diagnostics_memory_layout = [] # +# process_tools +process_tools = [] +process_environment_is_cicd = [] [dependencies] ## external -trybuild = { version = "1.0.85", features = [ "diff" ] } +# xxx : make sure we use workspace dependencies only +# trybuild = { version = "1.0.85", features = [ "diff" ] } +trybuild = { workspace = true, features = [ "diff" ] } rustversion = { workspace = true } num-traits = { workspace = true } rand = { workspace = true } # tempdir = { workspace = true } -## internal - -error_tools = { workspace = true, features = [ "full" ], optional = true } -collection_tools = { workspace = true, features = [ "full" ], optional = true } -impls_index = { workspace = true, features = [ "full" ], optional = true } -mem_tools = { workspace = true, features = [ "full" ], optional = true } -typing_tools = { workspace = true, features = [ "full" ], optional = true } - -diagnostics_tools = { workspace = true, features = [ "full" ], optional = true } -process_tools = { workspace = true, features = [ "full" ], optional = true } - -# former_stable = { workspace = true, features = [ "full" ] } +# ## internal +# +# error_tools = { workspace = true, features = [ "full" ], optional = true } +# collection_tools = { workspace = true, features = [ "full" ], optional = true } +# impls_index = { workspace = true, features = [ "full" ], optional = true } +# mem_tools = { workspace = true, features = [ "full" ], optional = true } +# typing_tools = { workspace = true, features = [ "full" ], optional = true } +# diagnostics_tools = { workspace = true, features = [ "full" ], optional = true } +# # process_tools = { workspace = true, features = [ "full" ], optional = true } ## transient @@ -138,9 +130,11 @@ hashbrown = { workspace = true, optional = true } # impls_index impls_index_meta = { workspace = true, optional = true } # typing_tools -inspect_type = { workspace = true } -is_slice = { workspace = true } -implements = { workspace = true } +inspect_type = { workspace = true, optional = true } +is_slice = { workspace = true, optional = true } +implements = { workspace = true, optional = true } +# diagnostics_tools +pretty_assertions = { workspace = true, optional = true } [build-dependencies] rustc_version = "0.4" diff --git a/module/core/test_tools/src/lib.rs b/module/core/test_tools/src/lib.rs index 44b5c7d93b..31a90abcf7 100644 --- a/module/core/test_tools/src/lib.rs +++ b/module/core/test_tools/src/lib.rs @@ -4,10 +4,23 @@ #![ doc( html_root_url = "https://docs.rs/test_tools/latest/test_tools/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] +// xxx : remove +//! ```rust +//! println!("-- doc test: printing Cargo feature environment variables --"); +//! for (key, val) in std::env::vars() { +//! if key.starts_with("CARGO_FEATURE_") { +//! println!("{}={}", key, val); +//! } +//! } +//! ``` + +// xxx2 : try to repurpose top-level lib.rs fiel for only top level features + /// Namespace with dependencies. #[ allow( unused_imports ) ] #[ cfg( feature = "enabled" ) ] +#[ cfg( not( feature = "doctest" ) ) ] pub mod dependency { @@ -21,6 +34,11 @@ pub mod dependency #[ doc( inline ) ] pub use ::num_traits; + #[ cfg( all( feature = "standalone_build", not( feature = "normal_build" ) ) ) ] + #[ cfg( feature = "standalone_diagnostics_tools" ) ] + #[ doc( inline ) ] + pub use ::pretty_assertions; + #[ doc( inline ) ] pub use super:: { @@ -30,7 +48,7 @@ pub mod dependency mem_tools, typing_tools, diagnostics_tools, - process_tools, + // process_tools, }; } @@ -94,13 +112,21 @@ mod private {} // pub use test::{ compiletime, helper, smoke_test }; #[ cfg( feature = "enabled" ) ] +#[ cfg( not( feature = "doctest" ) ) ] pub mod test; -/// Error tools. +/// Aggegating submodules without using cargo, but including their entry files directly. +/// +/// We don't want to run doctest of included files, because all of the are relative to submodule. +/// So we disable doctests of such submodules with `#[ cfg( not( doctest ) ) ]`. #[ cfg( feature = "enabled" ) ] -#[ cfg( feature = "standalone_build" ) ] +#[ cfg( not( feature = "doctest" ) ) ] +// #[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ] +#[ cfg( all( feature = "standalone_build", not( feature = "normal_build" ) ) ) ] +// #[ cfg( any( not( doctest ), not( feature = "standalone_build" ) ) ) ] mod standalone { + // We don't want to run doctest of aggregate /// Error tools. #[ path = "../../../../core/error_tools/src/error/mod.rs" ] @@ -126,14 +152,21 @@ mod standalone pub mod typing_tools; pub use typing_tools as typing; + /// Dagnostics tools. + #[ path = "../../../../core/diagnostics_tools/src/diag/mod.rs" ] + pub mod diagnostics_tools; + pub use diagnostics_tools as diag; + } #[ cfg( feature = "enabled" ) ] -#[ cfg( feature = "standalone_build" ) ] +#[ cfg( not( feature = "doctest" ) ) ] +#[ cfg( all( feature = "standalone_build", not( feature = "normal_build" ) ) ) ] pub use standalone::*; #[ cfg( feature = "enabled" ) ] -#[ cfg( not( feature = "standalone_build" ) ) ] +#[ cfg( not( feature = "doctest" ) ) ] +#[ cfg( not( all( feature = "standalone_build", not( feature = "normal_build" ) ) ) ) ] pub use :: { error_tools, @@ -141,22 +174,26 @@ pub use :: impls_index, mem_tools, typing_tools, + diagnostics_tools, }; #[ cfg( feature = "enabled" ) ] +#[ cfg( not( feature = "doctest" ) ) ] +#[ allow( unused_imports ) ] pub use :: { - diagnostics_tools, - process_tools, + // process_tools, }; #[ cfg( feature = "enabled" ) ] +#[ cfg( not( feature = "doctest" ) ) ] #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use own::*; /// Own namespace of the module. #[ cfg( feature = "enabled" ) ] +#[ cfg( not( feature = "doctest" ) ) ] #[ allow( unused_imports ) ] pub mod own { @@ -183,6 +220,7 @@ pub mod own /// Shared with parent namespace of the module #[ cfg( feature = "enabled" ) ] +#[ cfg( not( feature = "doctest" ) ) ] #[ allow( unused_imports ) ] pub mod orphan { @@ -198,6 +236,7 @@ pub mod orphan /// Exposed namespace of the module. #[ cfg( feature = "enabled" ) ] +#[ cfg( not( feature = "doctest" ) ) ] #[ allow( unused_imports ) ] pub mod exposed { @@ -224,6 +263,7 @@ pub mod exposed /// Prelude to use essentials: `use my_module::prelude::*`. #[ cfg( feature = "enabled" ) ] +#[ cfg( not( feature = "doctest" ) ) ] #[ allow( unused_imports ) ] pub mod prelude { diff --git a/module/core/test_tools/src/test/mod.rs b/module/core/test_tools/src/test/mod.rs index c13f70ef67..b8ee109966 100644 --- a/module/core/test_tools/src/test/mod.rs +++ b/module/core/test_tools/src/test/mod.rs @@ -20,6 +20,7 @@ pub mod compiletime; pub mod helper; pub mod smoke_test; pub mod version; +pub mod process; #[ cfg( feature = "enabled" ) ] #[ doc( inline ) ] @@ -44,6 +45,7 @@ pub mod own helper::orphan::*, smoke_test::orphan::*, version::orphan::*, + process::orphan::*, }; } @@ -78,6 +80,7 @@ pub mod exposed helper::exposed::*, smoke_test::exposed::*, version::exposed::*, + process::exposed::*, }; #[ doc( inline ) ] @@ -107,6 +110,7 @@ pub mod prelude helper::prelude::*, smoke_test::prelude::*, version::prelude::*, + process::prelude::*, }; } diff --git a/module/core/test_tools/src/test/process.rs b/module/core/test_tools/src/test/process.rs new file mode 100644 index 0000000000..bf59d4b314 --- /dev/null +++ b/module/core/test_tools/src/test/process.rs @@ -0,0 +1,63 @@ + +//! +//! Compact version of module::process_tools. What is needed from process tools +//! + +/// Define a private namespace for all its items. +mod private +{ +} + +pub mod environment; + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; +} + +/// Shared with parent namespace of the module +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; + pub use super::super::process as process_tools; + + #[ doc( inline ) ] + pub use exposed::*; + +} + +/// Exposed namespace of the module. +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + + #[ doc( inline ) ] + pub use prelude::*; + + #[ doc( inline ) ] + pub use private:: + { + }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; + + #[ doc( inline ) ] + pub use + { + }; + +} diff --git a/module/core/test_tools/src/test/process/environment.rs b/module/core/test_tools/src/test/process/environment.rs new file mode 100644 index 0000000000..1f3a146a9b --- /dev/null +++ b/module/core/test_tools/src/test/process/environment.rs @@ -0,0 +1,114 @@ + +//! +//! Environment of a process. +//! + +/// Define a private namespace for all its items. +mod private +{ + + #[ allow( unused_imports ) ] + use crate::*; + + /// Checks if the current execution environment is a Continuous Integration (CI) or Continuous Deployment (CD) pipeline. + /// + /// This function looks for environment variables that are commonly set by CI/CD systems to determine if it's running + /// within such an environment. It supports detection for a variety of popular CI/CD platforms including GitHub Actions, + /// GitLab CI, Travis CI, `CircleCI`, and Jenkins. + /// + /// # Returns + /// - `true` if an environment variable indicating a CI/CD environment is found. + /// - `false` otherwise. + /// + /// # Examples + /// + /// When running in a typical development environment (locally): + /// ```no_run + /// use test_tools::process_tools::environment; + /// assert_eq!( environment::is_cicd(), false ); + /// ``` + /// + /// When running in a CI/CD environment, one of the specified environment variables would be set, and: + /// ```no_run + /// // This example cannot be run as a test since it depends on the environment + /// // the code is executed in. However, in a CI environment, this would return true. + /// use test_tools::process_tools::environment; + /// assert_eq!( environment::is_cicd(), true ); + /// ``` + #[ cfg( feature = "process_environment_is_cicd" ) ] + #[ must_use ] + pub fn is_cicd() -> bool + { + use std::env; + let ci_vars = + [ + "CI", // Common in many CI systems + "GITHUB_ACTIONS", // GitHub Actions + "GITLAB_CI", // GitLab CI + "TRAVIS", // Travis CI + "CIRCLECI", // CircleCI + "JENKINS_URL", // Jenkins + ]; + + ci_vars.iter().any( | &var | env::var( var ).is_ok() ) + } + +} + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; + + #[ doc( inline ) ] + pub use + { + private::is_cicd, + }; + +} + +/// Shared with parent namespace of the module +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; + + #[ doc( inline ) ] + pub use exposed::*; + +} + +/// Exposed namespace of the module. +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + + #[ doc( inline ) ] + pub use prelude::*; + + #[ doc( inline ) ] + pub use private:: + { + }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; + + #[ doc( inline ) ] + pub use + { + }; + +} diff --git a/module/core/test_tools/src/test/smoke_test.rs b/module/core/test_tools/src/test/smoke_test.rs index a99b4ee1a0..f0d9d7ad00 100644 --- a/module/core/test_tools/src/test/smoke_test.rs +++ b/module/core/test_tools/src/test/smoke_test.rs @@ -250,7 +250,6 @@ mod private } /// Run smoke test for both published and local version of the module. - pub fn smoke_tests_run() { smoke_test_for_local_run(); @@ -344,9 +343,13 @@ pub mod own use super::*; #[ doc( inline ) ] - pub use + pub use private:: { - private::*, + SmokeModuleTest, + smoke_test_run, + smoke_tests_run, + smoke_test_for_local_run, + smoke_test_for_published_run, }; } diff --git a/module/core/test_tools/tests/inc/mod.rs b/module/core/test_tools/tests/inc/mod.rs index ff7fad6db8..fa8f21affb 100644 --- a/module/core/test_tools/tests/inc/mod.rs +++ b/module/core/test_tools/tests/inc/mod.rs @@ -3,24 +3,27 @@ use super::*; mod impls_index_test; mod mem_test; mod try_build_test; -// mod wtest_utility; - -// qqq : include tests of all internal dependencies /// Error tools. #[ path = "../../../../core/error_tools/tests/inc/mod.rs" ] pub mod error_tests; -// pub use error as error_tools; /// Collection tools. #[ path = "../../../../core/collection_tools/tests/inc/mod.rs" ] pub mod collection_tests; -// pub use collection as collection_tools; -// /// impl and index macros. -// #[ path = "../../../../core/impls_index/tests/inc/mod.rs" ] -// pub mod impls_index; -// -// /// Memory tools. -// #[ path = "../../../../core/mem_tools/tests/inc/mod.rs" ] -// pub mod mem_tools; +/// impl and index macros. +#[ path = "../../../../core/impls_index/tests/inc/mod.rs" ] +pub mod impls_index_tests; + +/// Memory tools. +#[ path = "../../../../core/mem_tools/tests/inc/mod.rs" ] +pub mod mem_tools_tests; + +/// Typing tools. +#[ path = "../../../../core/typing_tools/tests/inc/mod.rs" ] +pub mod typing_tools_tests; + +/// Diagnostics tools. +#[ path = "../../../../core/diagnostics_tools/tests/inc/mod.rs" ] +pub mod diagnostics_tools_tests; diff --git a/module/core/test_tools/tests/tests.rs b/module/core/test_tools/tests/tests.rs index e1a5c09321..68d3dc1ed4 100644 --- a/module/core/test_tools/tests/tests.rs +++ b/module/core/test_tools/tests/tests.rs @@ -6,6 +6,8 @@ // #![ deny( missing_debug_implementations ) ] // #![ deny( missing_docs ) ] +include!( "../../../../module/step/meta/src/module/aggregating.rs" ); + use test_tools as the_module; // #[ cfg( feature = "enabled" ) ] diff --git a/module/core/typing_tools/tests/inc/mod.rs b/module/core/typing_tools/tests/inc/mod.rs index f6849e47df..992c678289 100644 --- a/module/core/typing_tools/tests/inc/mod.rs +++ b/module/core/typing_tools/tests/inc/mod.rs @@ -1,8 +1,8 @@ -#[ allow( unused_imports ) ] use super::*; -#[ allow( unused_imports ) ] -use the_module::typing as the_module; +use test_tools::exposed::*; +// #[ allow( unused_imports ) ] +// use the_module::typing as the_module; #[ path = "../../../../core/implements/tests/inc/mod.rs" ] mod implements_test; diff --git a/module/core/typing_tools/tests/tests.rs b/module/core/typing_tools/tests/tests.rs index 9f9c82cedc..090a22e25b 100644 --- a/module/core/typing_tools/tests/tests.rs +++ b/module/core/typing_tools/tests/tests.rs @@ -1,10 +1,9 @@ -// xxx -#![ cfg_attr( feature = "type_name_of_val", feature( type_name_of_val ) ) ] +//! All tests. + +// #![ cfg_attr( feature = "type_name_of_val", feature( type_name_of_val ) ) ] // // #![ cfg_attr( feature = "nightly", feature( type_name_of_val ) ) ] +#![ allow( unused_imports ) ] -#[ allow( unused_imports ) ] -use test_tools::exposed::*; -#[ allow( unused_imports ) ] use typing_tools as the_module; mod inc; From e2d687b0ca22ddc729804694f0042e47296b3357 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:22:52 +0300 Subject: [PATCH 111/143] collection_tools-v0.17.0 --- Cargo.toml | 2 +- module/core/collection_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2a50a2e887..c1667f6806 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -110,7 +110,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.collection_tools] -version = "~0.16.0" +version = "~0.17.0" path = "module/core/collection_tools" default-features = false diff --git a/module/core/collection_tools/Cargo.toml b/module/core/collection_tools/Cargo.toml index d20b65951b..816578bb00 100644 --- a/module/core/collection_tools/Cargo.toml +++ b/module/core/collection_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "collection_tools" -version = "0.16.0" +version = "0.17.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 8fe98783945bd8e8c6a8cb8b6bf69b67f1061bbd Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:23:03 +0300 Subject: [PATCH 112/143] former_types-v2.14.0 --- Cargo.toml | 2 +- module/core/former_types/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c1667f6806..d37b439b8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -241,7 +241,7 @@ path = "module/core/former_meta" default-features = false [workspace.dependencies.former_types] -version = "~2.13.0" +version = "~2.14.0" path = "module/core/former_types" default-features = false diff --git a/module/core/former_types/Cargo.toml b/module/core/former_types/Cargo.toml index 0524c5c7bd..54c5034202 100644 --- a/module/core/former_types/Cargo.toml +++ b/module/core/former_types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former_types" -version = "2.13.0" +version = "2.14.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 2d9ccf6094305bffb8eeafe924747e63e4ebb662 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:23:12 +0300 Subject: [PATCH 113/143] clone_dyn_types-v0.28.0 --- Cargo.toml | 2 +- module/core/clone_dyn_types/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d37b439b8e..9cf1a0426d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -183,7 +183,7 @@ path = "module/core/clone_dyn_meta" # features = [ "enabled" ] [workspace.dependencies.clone_dyn_types] -version = "~0.27.0" +version = "~0.28.0" path = "module/core/clone_dyn_types" default-features = false # features = [ "enabled" ] diff --git a/module/core/clone_dyn_types/Cargo.toml b/module/core/clone_dyn_types/Cargo.toml index 591da29082..4debc74c8c 100644 --- a/module/core/clone_dyn_types/Cargo.toml +++ b/module/core/clone_dyn_types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clone_dyn_types" -version = "0.27.0" +version = "0.28.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From ce030015815d0a9a0cd9905c90dfae58a119bb4c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:23:22 +0300 Subject: [PATCH 114/143] iter_tools-v0.26.0 --- Cargo.toml | 2 +- module/core/iter_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9cf1a0426d..181031a814 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -208,7 +208,7 @@ default-features = false ## iter [workspace.dependencies.iter_tools] -version = "~0.25.0" +version = "~0.26.0" path = "module/core/iter_tools" default-features = false diff --git a/module/core/iter_tools/Cargo.toml b/module/core/iter_tools/Cargo.toml index 6cb959cf97..a909fca7c0 100644 --- a/module/core/iter_tools/Cargo.toml +++ b/module/core/iter_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iter_tools" -version = "0.25.0" +version = "0.26.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 299998d65c0557f70d900d1d388a90555b84ee25 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:23:35 +0300 Subject: [PATCH 115/143] macro_tools-v0.46.0 --- Cargo.toml | 2 +- module/core/macro_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 181031a814..9091124b5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -286,7 +286,7 @@ default-features = false ## macro tools [workspace.dependencies.macro_tools] -version = "~0.45.0" +version = "~0.46.0" path = "module/core/macro_tools" default-features = false diff --git a/module/core/macro_tools/Cargo.toml b/module/core/macro_tools/Cargo.toml index b1216b6543..7d98c4f745 100644 --- a/module/core/macro_tools/Cargo.toml +++ b/module/core/macro_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "macro_tools" -version = "0.45.0" +version = "0.46.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 706c61c8763aeec55e62844b314ac2f3a84eec88 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:44:15 +0300 Subject: [PATCH 116/143] fixing test_tools --- Cargo.toml | 8 +- module/core/former/Cargo.toml | 1 - module/core/implements/Cargo.toml | 5 +- .../implements/tests/inc/implements_test.rs | 367 +++++++++--------- module/core/implements/tests/smoke_test.rs | 22 +- .../tests/{implements_tests.rs => tests.rs} | 5 +- module/core/inspect_type/Cargo.toml | 3 +- .../tests/inc/inspect_type_test.rs | 53 +-- module/core/inspect_type/tests/inc/mod.rs | 5 +- module/core/inspect_type/tests/smoke_test.rs | 22 +- module/core/inspect_type/tests/tests.rs | 3 +- module/core/is_slice/Cargo.toml | 3 +- .../core/is_slice/tests/inc/is_slice_test.rs | 42 +- module/core/is_slice/tests/inc/mod.rs | 2 +- module/core/is_slice/tests/is_slice_tests.rs | 3 - module/core/is_slice/tests/smoke_test.rs | 22 +- 16 files changed, 265 insertions(+), 301 deletions(-) rename module/core/implements/tests/{implements_tests.rs => tests.rs} (59%) diff --git a/Cargo.toml b/Cargo.toml index 9091124b5a..8c86d4da36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -408,10 +408,10 @@ version = "~0.11.0" path = "module/core/test_tools" features = [ "full" ] -[workspace.dependencies.test_tools_stable] -package = "test_tools" -version = "~0.10.0" -features = [ "full" ] +# [workspace.dependencies.test_tools_stable] +# package = "test_tools" +# version = "~0.10.0" +# features = [ "full" ] [workspace.dependencies.wtest_basic] version = "~0.4.0" diff --git a/module/core/former/Cargo.toml b/module/core/former/Cargo.toml index df2a419b2b..b35ca32645 100644 --- a/module/core/former/Cargo.toml +++ b/module/core/former/Cargo.toml @@ -63,7 +63,6 @@ former_meta = { workspace = true } former_types = { workspace = true } # collection_tools = { workspace = true, features = [ "collection_constructors" ] } - [dev-dependencies] test_tools = { workspace = true } collection_tools = { workspace = true, features = [ "collection_constructors" ] } diff --git a/module/core/implements/Cargo.toml b/module/core/implements/Cargo.toml index 8c468c0b60..7249f8348a 100644 --- a/module/core/implements/Cargo.toml +++ b/module/core/implements/Cargo.toml @@ -24,8 +24,6 @@ workspace = true features = [ "full" ] all-features = false - - [features] default = [ "enabled" ] full = [ "enabled" ] @@ -36,4 +34,5 @@ enabled = [] [dependencies] [dev-dependencies] -test_tools = { workspace = true } +# this crate should not rely on test_tools to exclude cyclic dependencies +# test_tools = { workspace = true } diff --git a/module/core/implements/tests/inc/implements_test.rs b/module/core/implements/tests/inc/implements_test.rs index 24f39c32d7..e552165c41 100644 --- a/module/core/implements/tests/inc/implements_test.rs +++ b/module/core/implements/tests/inc/implements_test.rs @@ -3,221 +3,216 @@ use super::*; // -tests_impls! +#[ test ] +fn implements_basic() { - #[ test ] - fn implements_basic() - { + trait Trait1 {} + fn impl_trait1( _ : &impl Trait1 ) -> bool { true } - trait Trait1 {} - fn impl_trait1( _ : &impl Trait1 ) -> bool { true } + impl< T : Sized > Trait1 for &[ T ] {} + impl< T : Sized, const N : usize > Trait1 for [ T; N ] {} + impl< T : Sized, const N : usize > Trait1 for &[ T; N ] {} + let src : &[ i32 ] = &[ 1, 2, 3 ]; + assert_eq!( the_module::implements!( src => Trait1 ), true ); + assert_eq!( impl_trait1( &src ), true ); + assert_eq!( the_module::implements!( &[ 1, 2, 3 ] => Trait1 ), true ); + assert_eq!( impl_trait1( &[ 1, 2, 3 ] ), true ); + assert_eq!( the_module::implements!( [ 1, 2, 3 ] => Trait1 ), true ); - impl< T : Sized > Trait1 for &[ T ] {} - impl< T : Sized, const N : usize > Trait1 for [ T; N ] {} - impl< T : Sized, const N : usize > Trait1 for &[ T; N ] {} - let src : &[ i32 ] = &[ 1, 2, 3 ]; - a_id!( the_module::implements!( src => Trait1 ), true ); - a_id!( impl_trait1( &src ), true ); - a_id!( the_module::implements!( &[ 1, 2, 3 ] => Trait1 ), true ); - a_id!( impl_trait1( &[ 1, 2, 3 ] ), true ); - a_id!( the_module::implements!( [ 1, 2, 3 ] => Trait1 ), true ); + impl< T : Sized > Trait1 for Vec< T > {} + assert_eq!( the_module::implements!( vec!( 1, 2, 3 ) => Trait1 ), true ); - impl< T : Sized > Trait1 for Vec< T > {} - a_id!( the_module::implements!( vec!( 1, 2, 3 ) => Trait1 ), true ); + impl Trait1 for f32 {} + assert_eq!( the_module::implements!( 13_f32 => Trait1 ), true ); - impl Trait1 for f32 {} - a_id!( the_module::implements!( 13_f32 => Trait1 ), true ); + assert_eq!( the_module::implements!( true => Copy ), true ); + assert_eq!( the_module::implements!( true => Clone ), true ); - a_id!( the_module::implements!( true => Copy ), true ); - a_id!( the_module::implements!( true => Clone ), true ); + let src = true; + assert_eq!( the_module::implements!( src => Copy ), true ); + assert_eq!( the_module::implements!( src => Clone ), true ); - let src = true; - a_id!( the_module::implements!( src => Copy ), true ); - a_id!( the_module::implements!( src => Clone ), true ); + let src = Box::new( true ); + assert_eq!( the_module::implements!( src => Copy ), false ); + assert_eq!( the_module::implements!( src => Clone ), true ); - let src = Box::new( true ); - a_id!( the_module::implements!( src => Copy ), false ); - a_id!( the_module::implements!( src => Clone ), true ); + assert_eq!( the_module::implements!( Box::new( true ) => std::marker::Copy ), false ); + assert_eq!( the_module::implements!( Box::new( true ) => std::clone::Clone ), true ); - a_id!( the_module::implements!( Box::new( true ) => std::marker::Copy ), false ); - a_id!( the_module::implements!( Box::new( true ) => std::clone::Clone ), true ); +} - } +// - // +#[ test ] +fn instance_of_basic() +{ - #[ test ] - fn instance_of_basic() - { + let src = Box::new( true ); + assert_eq!( the_module::instance_of!( src => Copy ), false ); + assert_eq!( the_module::instance_of!( src => Clone ), true ); - let src = Box::new( true ); - a_id!( the_module::instance_of!( src => Copy ), false ); - a_id!( the_module::instance_of!( src => Clone ), true ); +} - } +// - // +#[ test ] +fn implements_functions() +{ - #[ test ] - fn implements_functions() + let _f = || { + println!( "hello" ); + }; - let _f = || - { - println!( "hello" ); - }; - - let fn_context = vec!( 1, 2, 3 ); - let _fn = || - { - println!( "hello {:?}", fn_context ); - }; - - let mut fn_mut_context = vec!( 1, 2, 3 ); - let _fn_mut = || - { - fn_mut_context[ 0 ] = 3; - println!( "{:?}", fn_mut_context ); - }; - - let mut fn_once_context = vec!( 1, 2, 3 ); - let _fn_once = || - { - fn_once_context[ 0 ] = 3; - let x = fn_once_context; - println!( "{:?}", x ); - }; - - /* */ - - a_id!( the_module::implements!( _fn => Copy ), true ); - a_id!( the_module::implements!( _fn => Clone ), true ); - a_id!( the_module::implements!( _fn => core::ops::Not ), false ); - let _ = _fn.clone(); - - /* */ - - // a_id!( the_module::implements!( function1 => fn() -> () ), true ); - // a_id!( the_module::implements!( &function1 => Fn() -> () ), true ); - // a_id!( the_module::implements!( &function1 => FnMut() -> () ), true ); - // a_id!( the_module::implements!( &function1 => FnOnce() -> () ), true ); - - // a_id!( the_module::implements!( _fn => fn() -> () ), true ); - a_id!( the_module::implements!( _fn => Fn() -> () ), true ); - a_id!( the_module::implements!( _fn => FnMut() -> () ), true ); - a_id!( the_module::implements!( _fn => FnOnce() -> () ), true ); - - // a_id!( the_module::implements!( _fn_mut => fn() -> () ), false ); - // a_id!( the_module::implements!( _fn_mut => Fn() -> () ), false ); - a_id!( the_module::implements!( _fn_mut => FnMut() -> () ), true ); - a_id!( the_module::implements!( _fn_mut => FnOnce() -> () ), true ); - - // a_id!( the_module::implements!( _fn_once => fn() -> () ), false ); - // a_id!( the_module::implements!( _fn_once => Fn() -> () ), false ); - // a_id!( the_module::implements!( _fn_once => FnMut() -> () ), false ); - a_id!( the_module::implements!( _fn_once => FnOnce() -> () ), true ); - - // fn is_f < R > ( _x : fn() -> R ) -> bool { true } - // fn is_fn < R, F : Fn() -> R > ( _x : &F ) -> bool { true } - // fn is_fn_mut < R, F : FnMut() -> R > ( _x : &F ) -> bool { true } - // fn is_fn_once < R, F : FnOnce() -> R > ( _x : &F ) -> bool { true } - // fn function1() -> bool { true } - - } - - // - - #[ test ] - fn pointer_experiment() + let fn_context = vec!( 1, 2, 3 ); + let _fn = || { + println!( "hello {:?}", fn_context ); + }; - let pointer_size = std::mem::size_of::< &u8 >(); - dbg!( &pointer_size ); - a_id!( 2 * pointer_size, std::mem::size_of::< &[ u8 ] >() ); - a_id!( 2 * pointer_size, std::mem::size_of::< *const [ u8 ] >() ); - a_id!( 2 * pointer_size, std::mem::size_of::< Box< [ u8 ] > >() ); - a_id!( 2 * pointer_size, std::mem::size_of::< std::rc::Rc< [ u8 ] > >() ); - a_id!( 1 * pointer_size, std::mem::size_of::< &[ u8 ; 20 ] >() ); + let mut fn_mut_context = vec!( 1, 2, 3 ); + let _fn_mut = || + { + fn_mut_context[ 0 ] = 3; + println!( "{:?}", fn_mut_context ); + }; - } + let mut fn_once_context = vec!( 1, 2, 3 ); + let _fn_once = || + { + fn_once_context[ 0 ] = 3; + let x = fn_once_context; + println!( "{:?}", x ); + }; + + /* */ + + assert_eq!( the_module::implements!( _fn => Copy ), true ); + assert_eq!( the_module::implements!( _fn => Clone ), true ); + assert_eq!( the_module::implements!( _fn => core::ops::Not ), false ); + let _ = _fn.clone(); + + /* */ + + // assert_eq!( the_module::implements!( function1 => fn() -> () ), true ); + // assert_eq!( the_module::implements!( &function1 => Fn() -> () ), true ); + // assert_eq!( the_module::implements!( &function1 => FnMut() -> () ), true ); + // assert_eq!( the_module::implements!( &function1 => FnOnce() -> () ), true ); + + // assert_eq!( the_module::implements!( _fn => fn() -> () ), true ); + assert_eq!( the_module::implements!( _fn => Fn() -> () ), true ); + assert_eq!( the_module::implements!( _fn => FnMut() -> () ), true ); + assert_eq!( the_module::implements!( _fn => FnOnce() -> () ), true ); + + // assert_eq!( the_module::implements!( _fn_mut => fn() -> () ), false ); + // assert_eq!( the_module::implements!( _fn_mut => Fn() -> () ), false ); + assert_eq!( the_module::implements!( _fn_mut => FnMut() -> () ), true ); + assert_eq!( the_module::implements!( _fn_mut => FnOnce() -> () ), true ); + + // assert_eq!( the_module::implements!( _fn_once => fn() -> () ), false ); + // assert_eq!( the_module::implements!( _fn_once => Fn() -> () ), false ); + // assert_eq!( the_module::implements!( _fn_once => FnMut() -> () ), false ); + assert_eq!( the_module::implements!( _fn_once => FnOnce() -> () ), true ); + + // fn is_f < R > ( _x : fn() -> R ) -> bool { true } + // fn is_fn < R, F : Fn() -> R > ( _x : &F ) -> bool { true } + // fn is_fn_mut < R, F : FnMut() -> R > ( _x : &F ) -> bool { true } + // fn is_fn_once < R, F : FnOnce() -> R > ( _x : &F ) -> bool { true } + // fn function1() -> bool { true } - // +} - #[ test ] - fn fn_experiment() - { +// - fn function1() -> bool { true } - - let _f = || - { - println!( "hello" ); - }; - - let fn_context = vec!( 1, 2, 3 ); - let _fn = || - { - println!( "hello {:?}", fn_context ); - }; - - let mut fn_mut_context = vec!( 1, 2, 3 ); - let _fn_mut = || - { - fn_mut_context[ 0 ] = 3; - println!( "{:?}", fn_mut_context ); - }; - - let mut fn_once_context = vec!( 1, 2, 3 ); - let _fn_once = || - { - fn_once_context[ 0 ] = 3; - let x = fn_once_context; - println!( "{:?}", x ); - }; - - a_id!( is_f( function1 ), true ); - a_id!( is_fn( &function1 ), true ); - a_id!( is_fn_mut( &function1 ), true ); - a_id!( is_fn_once( &function1 ), true ); - - a_id!( is_f( _f ), true ); - a_id!( is_fn( &_f ), true ); - a_id!( is_fn_mut( &_f ), true ); - a_id!( is_fn_once( &_f ), true ); - - // a_id!( is_f( _fn ), true ); - a_id!( is_fn( &_fn ), true ); - a_id!( is_fn_mut( &_fn ), true ); - a_id!( is_fn_once( &_fn ), true ); - - // a_id!( is_f( _fn_mut ), true ); - // a_id!( is_fn( &_fn_mut ), true ); - a_id!( is_fn_mut( &_fn_mut ), true ); - a_id!( is_fn_once( &_fn_mut ), true ); - - // a_id!( is_f( _fn_once ), true ); - // a_id!( is_fn( &_fn_once ), true ); - // a_id!( is_fn_mut( &_fn_once ), true ); - a_id!( is_fn_once( &_fn_once ), true ); - - // type Routine< R > = fn() -> R; - fn is_f < R > ( _x : fn() -> R ) -> bool { true } - // fn is_f < R > ( _x : Routine< R > ) -> bool { true } - fn is_fn < R, F : Fn() -> R > ( _x : &F ) -> bool { true } - fn is_fn_mut < R, F : FnMut() -> R > ( _x : &F ) -> bool { true } - fn is_fn_once < R, F : FnOnce() -> R > ( _x : &F ) -> bool { true } - } +#[ test ] +fn pointer_experiment() +{ + + let pointer_size = std::mem::size_of::< &u8 >(); + dbg!( &pointer_size ); + assert_eq!( 2 * pointer_size, std::mem::size_of::< &[ u8 ] >() ); + assert_eq!( 2 * pointer_size, std::mem::size_of::< *const [ u8 ] >() ); + assert_eq!( 2 * pointer_size, std::mem::size_of::< Box< [ u8 ] > >() ); + assert_eq!( 2 * pointer_size, std::mem::size_of::< std::rc::Rc< [ u8 ] > >() ); + assert_eq!( 1 * pointer_size, std::mem::size_of::< &[ u8 ; 20 ] >() ); } // -tests_index! +#[ test ] +fn fn_experiment() { - implements_basic, - instance_of_basic, - implements_functions, - pointer_experiment, - fn_experiment, + + fn function1() -> bool { true } + + let _f = || + { + println!( "hello" ); + }; + + let fn_context = vec!( 1, 2, 3 ); + let _fn = || + { + println!( "hello {:?}", fn_context ); + }; + + let mut fn_mut_context = vec!( 1, 2, 3 ); + let _fn_mut = || + { + fn_mut_context[ 0 ] = 3; + println!( "{:?}", fn_mut_context ); + }; + + let mut fn_once_context = vec!( 1, 2, 3 ); + let _fn_once = || + { + fn_once_context[ 0 ] = 3; + let x = fn_once_context; + println!( "{:?}", x ); + }; + + assert_eq!( is_f( function1 ), true ); + assert_eq!( is_fn( &function1 ), true ); + assert_eq!( is_fn_mut( &function1 ), true ); + assert_eq!( is_fn_once( &function1 ), true ); + + assert_eq!( is_f( _f ), true ); + assert_eq!( is_fn( &_f ), true ); + assert_eq!( is_fn_mut( &_f ), true ); + assert_eq!( is_fn_once( &_f ), true ); + + // assert_eq!( is_f( _fn ), true ); + assert_eq!( is_fn( &_fn ), true ); + assert_eq!( is_fn_mut( &_fn ), true ); + assert_eq!( is_fn_once( &_fn ), true ); + + // assert_eq!( is_f( _fn_mut ), true ); + // assert_eq!( is_fn( &_fn_mut ), true ); + assert_eq!( is_fn_mut( &_fn_mut ), true ); + assert_eq!( is_fn_once( &_fn_mut ), true ); + + // assert_eq!( is_f( _fn_once ), true ); + // assert_eq!( is_fn( &_fn_once ), true ); + // assert_eq!( is_fn_mut( &_fn_once ), true ); + assert_eq!( is_fn_once( &_fn_once ), true ); + + // type Routine< R > = fn() -> R; + fn is_f < R > ( _x : fn() -> R ) -> bool { true } + // fn is_f < R > ( _x : Routine< R > ) -> bool { true } + fn is_fn < R, F : Fn() -> R > ( _x : &F ) -> bool { true } + fn is_fn_mut < R, F : FnMut() -> R > ( _x : &F ) -> bool { true } + fn is_fn_once < R, F : FnOnce() -> R > ( _x : &F ) -> bool { true } } + +// + +// tests_index! +// { +// implements_basic, +// instance_of_basic, +// implements_functions, +// pointer_experiment, +// fn_experiment, +// } diff --git a/module/core/implements/tests/smoke_test.rs b/module/core/implements/tests/smoke_test.rs index c9b1b4daae..ee06731048 100644 --- a/module/core/implements/tests/smoke_test.rs +++ b/module/core/implements/tests/smoke_test.rs @@ -1,13 +1,13 @@ //! Smoke testing of the package. -#[ test ] -fn local_smoke_test() -{ - ::test_tools::smoke_test_for_local_run(); -} - -#[ test ] -fn published_smoke_test() -{ - ::test_tools::smoke_test_for_published_run(); -} +// #[ test ] +// fn local_smoke_test() +// { +// ::test_tools::smoke_test_for_local_run(); +// } +// +// #[ test ] +// fn published_smoke_test() +// { +// ::test_tools::smoke_test_for_published_run(); +// } diff --git a/module/core/implements/tests/implements_tests.rs b/module/core/implements/tests/tests.rs similarity index 59% rename from module/core/implements/tests/implements_tests.rs rename to module/core/implements/tests/tests.rs index db13e78660..9ee09a1d8c 100644 --- a/module/core/implements/tests/implements_tests.rs +++ b/module/core/implements/tests/tests.rs @@ -2,9 +2,10 @@ // #![ cfg_attr( feature = "nightly", feature( type_name_of_val ) ) ] #![ cfg_attr( feature = "nightly", feature( trace_macros ) ) ] #![ cfg_attr( feature = "nightly", feature( meta_idents_concat ) ) ] +// qqq : this feature is generated by build.rs file, but chec does it work properly. should wanring be silented? +// explain how you verify that solution is correct -use test_tools::exposed::*; +// use test_tools::exposed::*; use implements as the_module; - mod inc; diff --git a/module/core/inspect_type/Cargo.toml b/module/core/inspect_type/Cargo.toml index 260320b11b..0f3467e38f 100644 --- a/module/core/inspect_type/Cargo.toml +++ b/module/core/inspect_type/Cargo.toml @@ -32,7 +32,8 @@ enabled = [] [dependencies] [dev-dependencies] -test_tools = { workspace = true } +# this crate should not rely on test_tools to exclude cyclic dependencies +# test_tools = { workspace = true } [build-dependencies] rustc_version = "0.4" 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 b279d98ce4..78bb0ecc2f 100644 --- a/module/core/inspect_type/tests/inc/inspect_type_test.rs +++ b/module/core/inspect_type/tests/inc/inspect_type_test.rs @@ -4,47 +4,32 @@ use super::*; // -// use the_module::nightly; - -// #[ cfg( not( RUSTC_IS_STABLE ) ) ] -tests_impls! +#[ test ] +fn inspect_to_str_type_of_test() { - fn inspect_to_str_type_of_test() - { - - let exp = "sizeof( &[1, 2, 3][..] : &[i32] ) = 16".to_string(); - let got = the_module::inspect_to_str_type_of!( &[ 1, 2, 3 ][ .. ] ); - a_id!( got, exp ); - - let exp = "sizeof( &[1, 2, 3] : &[i32; 3] ) = 8".to_string(); - let got = the_module::inspect_to_str_type_of!( &[ 1, 2, 3 ] ); - a_id!( got, exp ); - - } - - // - - fn inspect_type_of_macro() - { + let exp = "sizeof( &[1, 2, 3][..] : &[i32] ) = 16".to_string(); + let got = the_module::inspect_to_str_type_of!( &[ 1, 2, 3 ][ .. ] ); + assert_eq!( got, exp ); - let exp = "sizeof( &[1, 2, 3][..] : &[i32] ) = 16".to_string(); - let got = the_module::inspect_type_of!( &[ 1, 2, 3 ][ .. ] ); - a_id!( got, exp ); - - let exp = "sizeof( &[1, 2, 3] : &[i32; 3] ) = 8".to_string(); - let got = the_module::inspect_type_of!( &[ 1, 2, 3 ] ); - a_id!( got, exp ); - - } + let exp = "sizeof( &[1, 2, 3] : &[i32; 3] ) = 8".to_string(); + let got = the_module::inspect_to_str_type_of!( &[ 1, 2, 3 ] ); + assert_eq!( got, exp ); } // -// #[ cfg( not( RUSTC_IS_STABLE ) ) ] -tests_index! +#[ test ] +fn inspect_type_of_macro() { - inspect_to_str_type_of_test, - inspect_type_of_macro, + + let exp = "sizeof( &[1, 2, 3][..] : &[i32] ) = 16".to_string(); + let got = the_module::inspect_type_of!( &[ 1, 2, 3 ][ .. ] ); + assert_eq!( got, exp ); + + let exp = "sizeof( &[1, 2, 3] : &[i32; 3] ) = 8".to_string(); + let got = the_module::inspect_type_of!( &[ 1, 2, 3 ] ); + assert_eq!( got, exp ); + } diff --git a/module/core/inspect_type/tests/inc/mod.rs b/module/core/inspect_type/tests/inc/mod.rs index 5867483bff..9e35103f83 100644 --- a/module/core/inspect_type/tests/inc/mod.rs +++ b/module/core/inspect_type/tests/inc/mod.rs @@ -1,7 +1,4 @@ -#[ allow( unused_imports ) ] use super::*; - -#[ allow( unused_imports ) ] -use test_tools::exposed::*; +// use test_tools::exposed::*; mod inspect_type_test; diff --git a/module/core/inspect_type/tests/smoke_test.rs b/module/core/inspect_type/tests/smoke_test.rs index c9b1b4daae..ee06731048 100644 --- a/module/core/inspect_type/tests/smoke_test.rs +++ b/module/core/inspect_type/tests/smoke_test.rs @@ -1,13 +1,13 @@ //! Smoke testing of the package. -#[ test ] -fn local_smoke_test() -{ - ::test_tools::smoke_test_for_local_run(); -} - -#[ test ] -fn published_smoke_test() -{ - ::test_tools::smoke_test_for_published_run(); -} +// #[ test ] +// fn local_smoke_test() +// { +// ::test_tools::smoke_test_for_local_run(); +// } +// +// #[ test ] +// fn published_smoke_test() +// { +// ::test_tools::smoke_test_for_published_run(); +// } diff --git a/module/core/inspect_type/tests/tests.rs b/module/core/inspect_type/tests/tests.rs index 8271ec46f8..4ac3f797ab 100644 --- a/module/core/inspect_type/tests/tests.rs +++ b/module/core/inspect_type/tests/tests.rs @@ -1,4 +1,5 @@ //! All Tests +#![ allow( unused_imports ) ] // #![ allow( unexpected_cfgs ) ] // #![ no_std ] @@ -15,7 +16,5 @@ // #![ cfg_attr( RUSTC_IS_NIGHTLY, feature( type_name_of_val ) ) ] -#[ allow( unused_imports ) ] use inspect_type as the_module; - mod inc; diff --git a/module/core/is_slice/Cargo.toml b/module/core/is_slice/Cargo.toml index 2854cf37cd..77d7c3487f 100644 --- a/module/core/is_slice/Cargo.toml +++ b/module/core/is_slice/Cargo.toml @@ -32,4 +32,5 @@ enabled = [] [dependencies] [dev-dependencies] -test_tools = { workspace = true } +# this crate should not rely on test_tools to exclude cyclic dependencies +# test_tools = { workspace = true } diff --git a/module/core/is_slice/tests/inc/is_slice_test.rs b/module/core/is_slice/tests/inc/is_slice_test.rs index 19d026fde5..ae247a9cb3 100644 --- a/module/core/is_slice/tests/inc/is_slice_test.rs +++ b/module/core/is_slice/tests/inc/is_slice_test.rs @@ -2,33 +2,23 @@ use super::*; // -tests_impls! +#[ test ] +fn is_slice_basic() { - #[ test ] - fn is_slice_basic() - { - let src : &[ i32 ] = &[ 1, 2, 3 ]; - a_id!( the_module::is_slice!( src ), true ); - a_id!( the_module::is_slice!( &[ 1, 2, 3 ][ .. ] ), true ); - a_id!( the_module::is_slice!( &[ 1, 2, 3 ] ), false ); + let src : &[ i32 ] = &[ 1, 2, 3 ]; + assert_eq!( the_module::is_slice!( src ), true ); + assert_eq!( the_module::is_slice!( &[ 1, 2, 3 ][ .. ] ), true ); + assert_eq!( the_module::is_slice!( &[ 1, 2, 3 ] ), false ); - // the_module::inspect_type_of!( &[ 1, 2, 3 ][ .. ] ); - // the_module::inspect_type_of!( &[ 1, 2, 3 ] ); + // the_module::inspect_type_of!( &[ 1, 2, 3 ][ .. ] ); + // the_module::inspect_type_of!( &[ 1, 2, 3 ] ); - a_id!( the_module::is_slice!( vec!( 1, 2, 3 ) ), false ); - a_id!( the_module::is_slice!( 13_f32 ), false ); - a_id!( the_module::is_slice!( true ), false ); - let src = false; - a_id!( the_module::is_slice!( src ), false ); - a_id!( the_module::is_slice!( Box::new( true ) ), false ); - let src = Box::new( true ); - a_id!( the_module::is_slice!( src ), false ); - } -} - -// - -tests_index! -{ - is_slice_basic, + assert_eq!( the_module::is_slice!( vec!( 1, 2, 3 ) ), false ); + assert_eq!( the_module::is_slice!( 13_f32 ), false ); + assert_eq!( the_module::is_slice!( true ), false ); + let src = false; + assert_eq!( the_module::is_slice!( src ), false ); + assert_eq!( the_module::is_slice!( Box::new( true ) ), false ); + let src = Box::new( true ); + assert_eq!( the_module::is_slice!( src ), false ); } diff --git a/module/core/is_slice/tests/inc/mod.rs b/module/core/is_slice/tests/inc/mod.rs index 9ee358f257..3e91d401d9 100644 --- a/module/core/is_slice/tests/inc/mod.rs +++ b/module/core/is_slice/tests/inc/mod.rs @@ -1,5 +1,5 @@ use super::*; -use test_tools::exposed::*; +// use test_tools::exposed::*; mod is_slice_test; diff --git a/module/core/is_slice/tests/is_slice_tests.rs b/module/core/is_slice/tests/is_slice_tests.rs index 56b1834ab4..b859cf6263 100644 --- a/module/core/is_slice/tests/is_slice_tests.rs +++ b/module/core/is_slice/tests/is_slice_tests.rs @@ -7,8 +7,5 @@ // #![ feature( meta_idents_concat ) ] #![ allow( unused_imports ) ] -// use test_tools::exposed::*; use is_slice as the_module; - -// #[ path = "./inc.rs" ] mod inc; diff --git a/module/core/is_slice/tests/smoke_test.rs b/module/core/is_slice/tests/smoke_test.rs index c9b1b4daae..ee06731048 100644 --- a/module/core/is_slice/tests/smoke_test.rs +++ b/module/core/is_slice/tests/smoke_test.rs @@ -1,13 +1,13 @@ //! Smoke testing of the package. -#[ test ] -fn local_smoke_test() -{ - ::test_tools::smoke_test_for_local_run(); -} - -#[ test ] -fn published_smoke_test() -{ - ::test_tools::smoke_test_for_published_run(); -} +// #[ test ] +// fn local_smoke_test() +// { +// ::test_tools::smoke_test_for_local_run(); +// } +// +// #[ test ] +// fn published_smoke_test() +// { +// ::test_tools::smoke_test_for_published_run(); +// } From a866e51df47b0dfb32f30bb41d8ef6e238236187 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:45:40 +0300 Subject: [PATCH 117/143] is_slice-v0.12.0 --- Cargo.toml | 2 +- module/core/is_slice/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8c86d4da36..f8f8f78592 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -332,7 +332,7 @@ path = "module/core/inspect_type" default-features = false [workspace.dependencies.is_slice] -version = "~0.11.0" +version = "~0.12.0" path = "module/core/is_slice" default-features = false diff --git a/module/core/is_slice/Cargo.toml b/module/core/is_slice/Cargo.toml index 77d7c3487f..cde98e4390 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.11.0" +version = "0.12.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From cb81209dd6cc7bf8111ee8bc5359a75ca7a07d4c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:45:49 +0300 Subject: [PATCH 118/143] inspect_type-v0.13.0 --- Cargo.toml | 2 +- module/core/inspect_type/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f8f8f78592..97e78c01b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -327,7 +327,7 @@ path = "module/alias/instance_of" default-features = false [workspace.dependencies.inspect_type] -version = "~0.12.0" +version = "~0.13.0" path = "module/core/inspect_type" default-features = false diff --git a/module/core/inspect_type/Cargo.toml b/module/core/inspect_type/Cargo.toml index 0f3467e38f..cb35a5ecc8 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.12.0" +version = "0.13.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From ce020417451ee85808b06ed08241c361347043a2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:45:56 +0300 Subject: [PATCH 119/143] implements-v0.11.0 --- Cargo.toml | 2 +- module/core/implements/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 97e78c01b9..8879bcc08d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -317,7 +317,7 @@ path = "module/core/typing_tools" default-features = false [workspace.dependencies.implements] -version = "~0.10.0" +version = "~0.11.0" path = "module/core/implements" default-features = false diff --git a/module/core/implements/Cargo.toml b/module/core/implements/Cargo.toml index 7249f8348a..8d97aaedb4 100644 --- a/module/core/implements/Cargo.toml +++ b/module/core/implements/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "implements" -version = "0.10.0" +version = "0.11.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From f4b2ccc8ab36346b5edc88224b57b5ccf9e2de17 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:46:07 +0300 Subject: [PATCH 120/143] impls_index_meta-v0.10.0 --- Cargo.toml | 2 +- module/core/impls_index_meta/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8879bcc08d..591cbfd9f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -251,7 +251,7 @@ path = "module/core/impls_index" default-features = false [workspace.dependencies.impls_index_meta] -version = "~0.9.0" +version = "~0.10.0" path = "module/core/impls_index_meta" [workspace.dependencies.mod_interface] diff --git a/module/core/impls_index_meta/Cargo.toml b/module/core/impls_index_meta/Cargo.toml index 036c5a03d0..00668cfd7b 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.9.0" +version = "0.10.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 3dcaf46a62997788ffe31cabdded94b5797dbd37 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:50:55 +0300 Subject: [PATCH 121/143] fixing test_tools --- Cargo.toml | 2 +- module/core/test_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 591cbfd9f4..e24bc99450 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -404,7 +404,7 @@ version = "~0.4.0" path = "module/alias/wtest" [workspace.dependencies.test_tools] -version = "~0.11.0" +version = "~0.12.0" path = "module/core/test_tools" features = [ "full" ] diff --git a/module/core/test_tools/Cargo.toml b/module/core/test_tools/Cargo.toml index 4298c413bd..19d9c3e617 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.11.0" +version = "0.12.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 3296ac5a699a97ee3694afde9b957e85ef104db3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:52:33 +0300 Subject: [PATCH 122/143] former_meta-v2.12.0 --- Cargo.toml | 2 +- module/core/former_meta/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e24bc99450..3a694ce74d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -236,7 +236,7 @@ default-features = false # default-features = false [workspace.dependencies.former_meta] -version = "~2.11.0" +version = "~2.12.0" path = "module/core/former_meta" default-features = false diff --git a/module/core/former_meta/Cargo.toml b/module/core/former_meta/Cargo.toml index 38845bc3f1..80aab28703 100644 --- a/module/core/former_meta/Cargo.toml +++ b/module/core/former_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former_meta" -version = "2.11.0" +version = "2.12.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 1bb9199140571dcafeccbd58277b0653b5db45ef Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 18:52:48 +0300 Subject: [PATCH 123/143] former-v2.12.0 --- Cargo.toml | 2 +- module/core/former/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3a694ce74d..555b2e52c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -226,7 +226,7 @@ path = "module/core/for_each" default-features = false [workspace.dependencies.former] -version = "~2.11.0" +version = "~2.12.0" path = "module/core/former" default-features = false diff --git a/module/core/former/Cargo.toml b/module/core/former/Cargo.toml index b35ca32645..7c5efd5073 100644 --- a/module/core/former/Cargo.toml +++ b/module/core/former/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former" -version = "2.11.0" +version = "2.12.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 5eb5123e7aeb191f92439231e1f474e64b5d9137 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:00:22 +0300 Subject: [PATCH 124/143] publishing willbe --- module/move/wca/tests/inc/mod.rs | 10 +--------- module/move/wca/tests/{wca_tests.rs => tests.rs} | 9 ++++----- module/move/willbe/tests/inc/mod.rs | 1 + module/move/willbe/tests/smoke_test.rs | 7 +++---- module/move/willbe/tests/tests.rs | 7 ++++--- 5 files changed, 13 insertions(+), 21 deletions(-) rename module/move/wca/tests/{wca_tests.rs => tests.rs} (50%) diff --git a/module/move/wca/tests/inc/mod.rs b/module/move/wca/tests/inc/mod.rs index b51887947e..c805473908 100644 --- a/module/move/wca/tests/inc/mod.rs +++ b/module/move/wca/tests/inc/mod.rs @@ -1,15 +1,7 @@ -#[ allow( unused_imports ) ] use super::*; +use test_tools::exposed::*; - -#[ cfg( not( feature = "no_std" ) ) ] mod parser; -#[ cfg( not( feature = "no_std" ) ) ] mod grammar; -#[ cfg( not( feature = "no_std" ) ) ] mod executor; -#[ cfg( not( feature = "no_std" ) ) ] mod commands_aggregator; - -// aaa : for Bohdan : why commented out? resolve -// aaa : no longer relevant, so removed diff --git a/module/move/wca/tests/wca_tests.rs b/module/move/wca/tests/tests.rs similarity index 50% rename from module/move/wca/tests/wca_tests.rs rename to module/move/wca/tests/tests.rs index ac2fbf9612..cd66cd65aa 100644 --- a/module/move/wca/tests/wca_tests.rs +++ b/module/move/wca/tests/tests.rs @@ -1,12 +1,11 @@ +//! All tests. + // #![ deny( rust_2018_idioms ) ] // #![ deny( missing_debug_implementations ) ] // #![ deny( missing_docs ) ] +#![ allow( unused_imports ) ] -#[ allow( unused_imports ) ] +/// System under test. use wca as the_module; -#[ allow( unused_imports ) ] -use test_tools::exposed::*; -// #[ allow( unused_imports ) ] -// use wca::wtools::*; mod inc; diff --git a/module/move/willbe/tests/inc/mod.rs b/module/move/willbe/tests/inc/mod.rs index 0b456a9b87..be920a6b41 100644 --- a/module/move/willbe/tests/inc/mod.rs +++ b/module/move/willbe/tests/inc/mod.rs @@ -1,4 +1,5 @@ use super::*; +use test_tools::exposed::*; /// Entities of which spaces consists of. mod entity; diff --git a/module/move/willbe/tests/smoke_test.rs b/module/move/willbe/tests/smoke_test.rs index dd681c20c1..c9b1b4daae 100644 --- a/module/move/willbe/tests/smoke_test.rs +++ b/module/move/willbe/tests/smoke_test.rs @@ -1,14 +1,13 @@ - +//! Smoke testing of the package. #[ test ] fn local_smoke_test() { - ::test_tools::smoke_test_for_local_run(); + ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { - ::test_tools::smoke_test_for_published_run(); + ::test_tools::smoke_test_for_published_run(); } diff --git a/module/move/willbe/tests/tests.rs b/module/move/willbe/tests/tests.rs index 3e8c5b7621..cefd199e28 100644 --- a/module/move/willbe/tests/tests.rs +++ b/module/move/willbe/tests/tests.rs @@ -1,9 +1,10 @@ +//! All tests. +#![ allow( unused_imports ) ] + include!( "../../../../module/step/meta/src/module/terminal.rs" ); -#[ allow( unused_imports ) ] +/// System under test. use willbe as the_module; -#[ allow( unused_imports ) ] -use test_tools::exposed::*; /// asset path pub const ASSET_PATH : &str = "tests/asset"; From 5574a95aec4916f45c7c134c1eaa8a587821ac50 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:02:09 +0300 Subject: [PATCH 125/143] derive_tools_meta-v0.32.0 --- Cargo.toml | 2 +- module/core/derive_tools_meta/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 555b2e52c2..9d3780c28c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -124,7 +124,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.derive_tools_meta] -version = "~0.31.0" +version = "~0.32.0" path = "module/core/derive_tools_meta" default-features = false # features = [ "enabled" ] diff --git a/module/core/derive_tools_meta/Cargo.toml b/module/core/derive_tools_meta/Cargo.toml index ce3e0ce395..5e3804d996 100644 --- a/module/core/derive_tools_meta/Cargo.toml +++ b/module/core/derive_tools_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "derive_tools_meta" -version = "0.31.0" +version = "0.32.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 0a3988ec1d682ef0f74b0fe07e8278fa87f049c3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:02:20 +0300 Subject: [PATCH 126/143] clone_dyn_meta-v0.28.0 --- Cargo.toml | 2 +- module/core/clone_dyn_meta/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9d3780c28c..1c1dbc0b99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -178,7 +178,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.clone_dyn_meta] -version = "~0.27.0" +version = "~0.28.0" path = "module/core/clone_dyn_meta" # features = [ "enabled" ] diff --git a/module/core/clone_dyn_meta/Cargo.toml b/module/core/clone_dyn_meta/Cargo.toml index d77ad96088..09eb717e23 100644 --- a/module/core/clone_dyn_meta/Cargo.toml +++ b/module/core/clone_dyn_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clone_dyn_meta" -version = "0.27.0" +version = "0.28.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 5be0b009a537552a0732378dc56e672ff0fa5e0e Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:02:33 +0300 Subject: [PATCH 127/143] clone_dyn-v0.30.0 --- Cargo.toml | 2 +- module/core/clone_dyn/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1c1dbc0b99..6d16086be7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -172,7 +172,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.clone_dyn] -version = "~0.29.0" +version = "~0.30.0" path = "module/core/clone_dyn" default-features = false # features = [ "enabled" ] diff --git a/module/core/clone_dyn/Cargo.toml b/module/core/clone_dyn/Cargo.toml index 400ba0e1fb..2be1b57e42 100644 --- a/module/core/clone_dyn/Cargo.toml +++ b/module/core/clone_dyn/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clone_dyn" -version = "0.29.0" +version = "0.30.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 0c943c17fcf8bf61cc4297052d7ef80d8af549cc Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:02:43 +0300 Subject: [PATCH 128/143] variadic_from-v0.28.0 --- Cargo.toml | 2 +- module/core/variadic_from/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6d16086be7..b1c5253dc9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -166,7 +166,7 @@ path = "module/alias/fundamental_data_type" default-features = false [workspace.dependencies.variadic_from] -version = "~0.27.0" +version = "~0.28.0" path = "module/core/variadic_from" default-features = false # features = [ "enabled" ] diff --git a/module/core/variadic_from/Cargo.toml b/module/core/variadic_from/Cargo.toml index 073a4f994a..7cecdbc449 100644 --- a/module/core/variadic_from/Cargo.toml +++ b/module/core/variadic_from/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "variadic_from" -version = "0.27.0" +version = "0.28.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 09718d390a3d84136243da1b6bc5fb2f04c81365 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:03:00 +0300 Subject: [PATCH 129/143] derive_tools-v0.33.0 --- Cargo.toml | 2 +- module/core/derive_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b1c5253dc9..20fc5e4fc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,7 +118,7 @@ default-features = false ## derive [workspace.dependencies.derive_tools] -version = "~0.32.0" +version = "~0.33.0" path = "module/core/derive_tools" default-features = false # features = [ "enabled" ] diff --git a/module/core/derive_tools/Cargo.toml b/module/core/derive_tools/Cargo.toml index a2d1e31fb4..ed323a7b1e 100644 --- a/module/core/derive_tools/Cargo.toml +++ b/module/core/derive_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "derive_tools" -version = "0.32.0" +version = "0.33.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 5f341c3a33756d794e09f291fe1569552d4d036c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:03:14 +0300 Subject: [PATCH 130/143] mod_interface_meta-v0.30.0 --- Cargo.toml | 2 +- module/core/mod_interface_meta/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 20fc5e4fc8..dec8653de2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -260,7 +260,7 @@ path = "module/core/mod_interface" default-features = false [workspace.dependencies.mod_interface_meta] -version = "~0.29.0" +version = "~0.30.0" path = "module/core/mod_interface_meta" default-features = false diff --git a/module/core/mod_interface_meta/Cargo.toml b/module/core/mod_interface_meta/Cargo.toml index ab3e6c709c..69ba680466 100644 --- a/module/core/mod_interface_meta/Cargo.toml +++ b/module/core/mod_interface_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mod_interface_meta" -version = "0.29.0" +version = "0.30.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 01e8ed842c29cded7626e861c06094a380ec972e Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:03:26 +0300 Subject: [PATCH 131/143] mod_interface-v0.31.0 --- Cargo.toml | 2 +- module/core/mod_interface/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dec8653de2..9039baf0ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -255,7 +255,7 @@ version = "~0.10.0" path = "module/core/impls_index_meta" [workspace.dependencies.mod_interface] -version = "~0.30.0" +version = "~0.31.0" path = "module/core/mod_interface" default-features = false diff --git a/module/core/mod_interface/Cargo.toml b/module/core/mod_interface/Cargo.toml index 8f3e3f76f4..5853e418e2 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.30.0" +version = "0.31.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 9f20d287e5be00afaef35e898cc3c93d13353bef Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:03:37 +0300 Subject: [PATCH 132/143] error_tools-v0.20.0 --- Cargo.toml | 2 +- module/core/error_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9039baf0ad..20965360f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -340,7 +340,7 @@ default-features = false ## error [workspace.dependencies.error_tools] -version = "~0.19.0" +version = "~0.20.0" path = "module/core/error_tools" default-features = false diff --git a/module/core/error_tools/Cargo.toml b/module/core/error_tools/Cargo.toml index dafae99166..670b1fd2b5 100644 --- a/module/core/error_tools/Cargo.toml +++ b/module/core/error_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "error_tools" -version = "0.19.0" +version = "0.20.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 0c2f0622f465b5beb88c92c76d6b2e233148ab84 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:03:51 +0300 Subject: [PATCH 133/143] wca-v0.24.0 --- Cargo.toml | 2 +- module/move/wca/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 20965360f8..d7d1db4f24 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -449,7 +449,7 @@ default-features = false ## ca [workspace.dependencies.wca] -version = "~0.23.0" +version = "~0.24.0" path = "module/move/wca" diff --git a/module/move/wca/Cargo.toml b/module/move/wca/Cargo.toml index 06791cf645..662ecd9c71 100644 --- a/module/move/wca/Cargo.toml +++ b/module/move/wca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wca" -version = "0.23.0" +version = "0.24.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From dee4c82da21e86b8f4033fc79612879987252323 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:04:06 +0300 Subject: [PATCH 134/143] pth-v0.22.0 --- Cargo.toml | 2 +- module/core/pth/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7d1db4f24..72502b2287 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -374,7 +374,7 @@ path = "module/alias/file_tools" default-features = false [workspace.dependencies.pth] -version = "~0.21.0" +version = "~0.22.0" path = "module/core/pth" default-features = false diff --git a/module/core/pth/Cargo.toml b/module/core/pth/Cargo.toml index 79a2141441..0d06f333ef 100644 --- a/module/core/pth/Cargo.toml +++ b/module/core/pth/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pth" -version = "0.21.0" +version = "0.22.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 69aecaf3568d3ae9640216447bd27cf3a8a87196 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:04:24 +0300 Subject: [PATCH 135/143] crates_tools-v0.15.0 --- Cargo.toml | 2 +- module/move/crates_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 72502b2287..b1ab31fa29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -503,7 +503,7 @@ version = "~0.6.0" path = "module/move/deterministic_rand" [workspace.dependencies.crates_tools] -version = "~0.14.0" +version = "~0.15.0" path = "module/move/crates_tools" diff --git a/module/move/crates_tools/Cargo.toml b/module/move/crates_tools/Cargo.toml index 3f14f8e209..62244920ae 100644 --- a/module/move/crates_tools/Cargo.toml +++ b/module/move/crates_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "crates_tools" -version = "0.14.0" +version = "0.15.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 20763140c85bfc1eb95a50308c2e1957bc9734e1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:04:36 +0300 Subject: [PATCH 136/143] process_tools-v0.13.0 --- Cargo.toml | 2 +- module/core/process_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b1ab31fa29..2916b2370c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -387,7 +387,7 @@ default-features = false ## process tools [workspace.dependencies.process_tools] -version = "~0.12.0" +version = "~0.13.0" path = "module/core/process_tools" default-features = false diff --git a/module/core/process_tools/Cargo.toml b/module/core/process_tools/Cargo.toml index 6a4e6950b9..ffd2498fea 100644 --- a/module/core/process_tools/Cargo.toml +++ b/module/core/process_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "process_tools" -version = "0.12.0" +version = "0.13.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 1a19d7ad67ccbe498afeb56c2a941a927418bf5e Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:04:45 +0300 Subject: [PATCH 137/143] data_type-v0.13.0 --- Cargo.toml | 2 +- module/core/data_type/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2916b2370c..c5764ca5e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,7 +80,7 @@ path = "module/alias/std_x" ## data_type [workspace.dependencies.data_type] -version = "~0.12.0" +version = "~0.13.0" path = "module/core/data_type" default-features = false diff --git a/module/core/data_type/Cargo.toml b/module/core/data_type/Cargo.toml index c5f7155d97..91971e6b8e 100644 --- a/module/core/data_type/Cargo.toml +++ b/module/core/data_type/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "data_type" -version = "0.12.0" +version = "0.13.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 705b0e42e6059663b6975de83766addea003e079 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:05:25 +0300 Subject: [PATCH 138/143] willbe-v0.21.0 --- Cargo.toml | 2 +- module/move/willbe/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c5764ca5e1..40ccd71e3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -463,7 +463,7 @@ path = "module/move/wcensor" ## willbe [workspace.dependencies.willbe] -version = "~0.20.0" +version = "~0.21.0" path = "module/move/willbe" diff --git a/module/move/willbe/Cargo.toml b/module/move/willbe/Cargo.toml index e647b11d88..358de1a184 100644 --- a/module/move/willbe/Cargo.toml +++ b/module/move/willbe/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "willbe" -version = "0.20.0" +version = "0.21.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From c4a226c47cdddbf8232ee0cc9229eeccb01f527d Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:06:02 +0300 Subject: [PATCH 139/143] willbe : requests --- module/move/willbe/src/tool/graph.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/move/willbe/src/tool/graph.rs b/module/move/willbe/src/tool/graph.rs index 9f632778bf..e0ba9bc109 100644 --- a/module/move/willbe/src/tool/graph.rs +++ b/module/move/willbe/src/tool/graph.rs @@ -283,8 +283,9 @@ mod private for root in roots { let root = graph.node_indices().find( | &i | graph[ i ] == *root ).unwrap(); + // qqq : no unwraps. simulate crash here and check output. it should be verbal let mut dfs = DfsPostOrder::new( &graph, root ); - 'main : while let Some( n ) = dfs.next(&graph) + 'main : while let Some( n ) = dfs.next( &graph ) { for neighbor in graph.neighbors_directed( n, Outgoing ) { From 8db98c47f0f205f359b63e65c551be680233fbf9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:17:03 +0300 Subject: [PATCH 140/143] reflect_tools_meta-v0.4.0 --- Cargo.toml | 10 +++++++++- module/core/reflect_tools_meta/Cargo.toml | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 40ccd71e3f..edf14da6ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,7 +136,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.reflect_tools_meta] -version = "~0.3.0" +version = "~0.4.0" path = "module/core/reflect_tools_meta" default-features = false # features = [ "enabled" ] @@ -506,6 +506,14 @@ path = "module/move/deterministic_rand" version = "~0.15.0" path = "module/move/crates_tools" +[workspace.dependencies.assistant] +version = "~0.1.0" +path = "module/move/assistant" + +[workspace.dependencies.llm_tools] +version = "~0.1.0" +path = "module/move/llm_tools" + ## steps diff --git a/module/core/reflect_tools_meta/Cargo.toml b/module/core/reflect_tools_meta/Cargo.toml index bd525a2655..3225c58663 100644 --- a/module/core/reflect_tools_meta/Cargo.toml +++ b/module/core/reflect_tools_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reflect_tools_meta" -version = "0.3.0" +version = "0.4.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 5b250221ff0ad69b4ce2c06b2693068b103d5c66 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:17:16 +0300 Subject: [PATCH 141/143] reflect_tools-v0.4.0 --- Cargo.toml | 2 +- module/core/reflect_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index edf14da6ce..371f07bbb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -130,7 +130,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.reflect_tools] -version = "~0.3.0" +version = "~0.4.0" path = "module/core/reflect_tools" default-features = false # features = [ "enabled" ] diff --git a/module/core/reflect_tools/Cargo.toml b/module/core/reflect_tools/Cargo.toml index 80718672c4..6d4715039d 100644 --- a/module/core/reflect_tools/Cargo.toml +++ b/module/core/reflect_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reflect_tools" -version = "0.3.0" +version = "0.4.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From b853fcc7fdfe98e900167a8b0800258ffbf25da0 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:17:29 +0300 Subject: [PATCH 142/143] format_tools-v0.3.0 --- Cargo.toml | 2 +- module/core/format_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 371f07bbb8..2974c2a87d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -142,7 +142,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.format_tools] -version = "~0.2.0" +version = "~0.3.0" path = "module/core/format_tools" default-features = false # features = [ "enabled" ] diff --git a/module/core/format_tools/Cargo.toml b/module/core/format_tools/Cargo.toml index 8cd8b79c01..2f29469253 100644 --- a/module/core/format_tools/Cargo.toml +++ b/module/core/format_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "format_tools" -version = "0.2.0" +version = "0.3.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From f7c494b08a15bf89ea186362168fafd106b12fb7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 5 Apr 2025 19:18:14 +0300 Subject: [PATCH 143/143] llm_tools-v0.2.0 --- Cargo.toml | 2 +- module/move/llm_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2974c2a87d..1b95384bd0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -511,7 +511,7 @@ version = "~0.1.0" path = "module/move/assistant" [workspace.dependencies.llm_tools] -version = "~0.1.0" +version = "~0.2.0" path = "module/move/llm_tools" diff --git a/module/move/llm_tools/Cargo.toml b/module/move/llm_tools/Cargo.toml index 1cf9f5bdf7..325482a155 100644 --- a/module/move/llm_tools/Cargo.toml +++ b/module/move/llm_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "llm_tools" -version = "0.1.0" +version = "0.2.0" edition = "2021" authors = [ "Kostiantyn Wandalen ",