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/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/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/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/core/format_tools/src/format/as_table.rs b/module/core/format_tools/src/format/as_table.rs new file mode 100644 index 0000000000..cc6892a2c8 --- /dev/null +++ b/module/core/format_tools/src/format/as_table.rs @@ -0,0 +1,222 @@ +//! +//! Nice print's wrapper. +//! + +/// Internal namespace. +pub( crate ) mod private +{ + + 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, + { + /// 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 + { + &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; + + 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 + { + 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, + { + 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::*; +} + +/// 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:: + { + AsTable, + }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/core/format_tools/src/format/print.rs b/module/core/format_tools/src/format/print.rs new file mode 100644 index 0000000000..72c6e7a53f --- /dev/null +++ b/module/core/format_tools/src/format/print.rs @@ -0,0 +1,259 @@ +//! +//! Nice print. +//! + +/// 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 + { + let separator = " | ".to_string(); + Styles { separator } + } + } + + /// Struct for formatting tables. + pub struct Context< 'a > + { + buf : &'a mut dyn fmt::Write, + styles : Styles, + } + + impl< 'a > Context< 'a > + { + /// Just constructr. + pub fn new( buf : &'a mut dyn fmt::Write, styles : Styles ) -> Self + { + Self { buf, styles } + } + } + + 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() + } + } + + /// 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< 'a, T > TableToString< 'a > for T + where + T : TableFormatter< 'a > + { + fn table_to_string( &'a self ) -> String + { + 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. + /// + + 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 + { + 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() ); + + if let Some( header ) = self.header() + { + let mut i = 0; + for ( _key, title ) in header + { + col_widths[ i ] = format!( "{:?}", title ).len(); + i += 1; + } + writeln!( f.buf )?; + } + + // 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 + { + Some( cell ) => format!( "{:?}", &cell ), + None => "".to_string(), + } + } + ) + .collect(); + all_rows.push( fields ); + } + + for row in &all_rows + { + for ( i, cell ) in row.iter().enumerate() + { + 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 + { + 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 + { + let mut i = 0; + for cell in row + { + if i > 0 + { + write!( f.buf, "{}", separator )?; + } + write!( f.buf, "{:^width$}", 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(()) + } + } + +} + +#[ 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/core/format_tools/src/format/table.rs b/module/core/format_tools/src/format/table.rs new file mode 100644 index 0000000000..c847586e41 --- /dev/null +++ b/module/core/format_tools/src/format/table.rs @@ -0,0 +1,205 @@ +//! +//! Table interface. +//! + +/// Internal namespace. +pub( crate ) mod private +{ + + 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 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, 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 ] + { + 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, 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 > + { + 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 > 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, Option< Cow< 'a, Cell > > > + 'a, + Cell : fmt::Debug + Clone + 'a, + { + + fn cells( &'a self ) -> impl IteratorTrait< Item = ( CellKey, Option< Cell > ) > + { + self.fields().map + ( + move | ( key, cell ) | + { + match cell + { + Some( cell ) => ( key, Some( cell.into_owned() ) ), + None => ( key, None ) + } + } + ) + } + + } + +} + +#[ 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:: + { + TableSize, + TableRows, + TableHeader, + Cells, + }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/core/format_tools/src/format/to_string.rs b/module/core/format_tools/src/format/to_string.rs new file mode 100644 index 0000000000..7b6dad85b3 --- /dev/null +++ b/module/core/format_tools/src/format/to_string.rs @@ -0,0 +1,98 @@ +//! +//! Flexible ToString augmentation. +//! + +/// Internal namespace. +pub( crate ) mod private +{ + + use std:: + { + fmt, + }; + + // == + + /// 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 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 +{ + #[ 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:: + { + WithDebug, + WithDisplay, + WithWell, + ToStringWith, + }; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/core/format_tools/src/format/to_string_with_fallback.rs b/module/core/format_tools/src/format/to_string_with_fallback.rs new file mode 100644 index 0000000000..0d551b2a82 --- /dev/null +++ b/module/core/format_tools/src/format/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 format_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 format_tools::_ToStringWithFallback; + ( + &format_tools::ToStringWithFallbackRef::< '_, _, format_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/format_tools/src/format/to_string_with_fallback/aref.rs b/module/core/format_tools/src/format/to_string_with_fallback/aref.rs new file mode 100644 index 0000000000..d1d29345cd --- /dev/null +++ b/module/core/format_tools/src/format/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/format_tools/src/format/to_string_with_fallback/params.rs b/module/core/format_tools/src/format/to_string_with_fallback/params.rs new file mode 100644 index 0000000000..1b901ec99c --- /dev/null +++ b/module/core/format_tools/src/format/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/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/core/format_tools/tests/inc/print_test.rs b/module/core/format_tools/tests/inc/print_test.rs new file mode 100644 index 0000000000..11cb79403b --- /dev/null +++ b/module/core/format_tools/tests/inc/print_test.rs @@ -0,0 +1,140 @@ +#[ allow( unused_imports ) ] +use super::*; + +use the_module:: +{ + 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, 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, 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" ) ); + +} diff --git a/module/core/format_tools/tests/inc/to_string_example.rs b/module/core/format_tools/tests/inc/to_string_example.rs new file mode 100644 index 0000000000..2bc356a052 --- /dev/null +++ b/module/core/format_tools/tests/inc/to_string_example.rs @@ -0,0 +1,56 @@ +#[ allow( unused_imports ) ] +use super::*; + +// xxx : qqq : make example from this test and add also into readme + +#[ test ] +fn exmaple() +{ + + use core::fmt; + use format_tools:: + { + 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/core/format_tools/tests/inc/to_string_test.rs b/module/core/format_tools/tests/inc/to_string_test.rs new file mode 100644 index 0000000000..0cba5fd0f8 --- /dev/null +++ b/module/core/format_tools/tests/inc/to_string_test.rs @@ -0,0 +1,57 @@ +#[ allow( unused_imports ) ] +use super::*; + +use the_module:: +{ + // Fields, + // IteratorTrait, + // MaybeAs, + ToStringWith, + // _ToStringWithFallback, + // ToStringWithFallbackParams, + WithDebug, + WithDisplay, + // Ref, + // to_string_with_fallback, +}; + +// use std:: +// { +// // fmt, +// // collections::HashMap, +// // borrow::Cow, +// }; + +// + +#[ test ] +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 ); + + // - + +} diff --git a/module/core/format_tools/tests/inc/to_string_with_fallback_test.rs b/module/core/format_tools/tests/inc/to_string_with_fallback_test.rs new file mode 100644 index 0000000000..864183b705 --- /dev/null +++ b/module/core/format_tools/tests/inc/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/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/former/tests/inc/former_tests/parametrized_slice_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_slice_manual.rs index 6b9632f366..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,20 +122,20 @@ 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" ) } } - 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() } + 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/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/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 aded0f2009..9d3c8a288e 100644 --- a/module/core/reflect_tools/src/reflect.rs +++ b/module/core/reflect_tools/src/reflect.rs @@ -65,6 +65,11 @@ pub mod entity_hashmap; pub mod entity_hashset; pub mod primitive; +pub mod fields; +// pub mod to_string; +// pub mod to_string_with_fallback; +pub mod wrapper; + #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use protected::*; @@ -96,6 +101,21 @@ 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::to_string_with_fallback::orphan::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::wrapper::orphan::*; + // pub use super::private:: // { // }; @@ -136,11 +156,26 @@ 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::to_string_with_fallback::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 +197,18 @@ 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::to_string_with_fallback::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/wrapper.rs b/module/core/reflect_tools/src/reflect/wrapper.rs new file mode 100644 index 0000000000..4cd134650f --- /dev/null +++ b/module/core/reflect_tools/src/reflect/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/reflect_tools/src/reflect/wrapper/aref.rs b/module/core/reflect_tools/src/reflect/wrapper/aref.rs new file mode 100644 index 0000000000..7e6afeb049 --- /dev/null +++ b/module/core/reflect_tools/src/reflect/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/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..d9c4a910c3 --- /dev/null +++ b/module/core/reflect_tools/src/reflect/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/reflect_tools/tests/inc/fundamental/fields_test.rs b/module/core/reflect_tools/tests/inc/fundamental/fields_test.rs new file mode 100644 index 0000000000..703011a643 --- /dev/null +++ b/module/core/reflect_tools/tests/inc/fundamental/fields_test.rs @@ -0,0 +1,142 @@ +#[ 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 > Fields< 'a, &'static str, MaybeAs< 'a, String, () > > +for TestObject +{ + fn fields( &'a self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< 'a, String, () > ) > + { + let mut dst : Vec< ( &'static str, MaybeAs< 'a, String, () > ) > = Vec::new(); + + 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 + { + dst.push( ( "tools", Some( Cow::Owned( format!( "{:?}", tools ) ) ).into() ) ); + } + else + { + dst.push( ( "tools", None.into() ) ); + } + + 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, () > ) > = 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_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/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..e7531dff91 100644 --- a/module/core/reflect_tools/tests/inc/mod.rs +++ b/module/core/reflect_tools/tests/inc/mod.rs @@ -2,25 +2,37 @@ 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; + // mod to_string_with_fallback_test; + +} + +#[ 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/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..6e2af1a870 --- /dev/null +++ b/module/move/assistant/Cargo.toml @@ -0,0 +1,45 @@ +[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 = [ + "former/enabled", + "format_tools/enabled", + "reflect_tools/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"] } +dotenv = "0.15" + +[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/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/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 new file mode 100644 index 0000000000..4d5468f9f7 --- /dev/null +++ b/module/move/assistant/src/lib.rs @@ -0,0 +1,76 @@ +#![ 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" ) ) ] + + +/// Internal namespace. +pub( crate ) mod private +{ +} + +pub mod client; + +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super:: + { + client::orphan::*, + }; + + #[ 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:: + { + client::exposed::*, + }; + + #[ 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:: + { + client::prelude::*, + }; + +} diff --git a/module/move/assistant/src/main.rs b/module/move/assistant/src/main.rs new file mode 100644 index 0000000000..ad03e3549a --- /dev/null +++ b/module/move/assistant/src/main.rs @@ -0,0 +1,28 @@ +#![ 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/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/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 new file mode 100644 index 0000000000..0706620c6e --- /dev/null +++ b/module/move/assistant/tests/inc/mod.rs @@ -0,0 +1,6 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; + +mod experiment; 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() {