diff --git a/.github/workflows/module_async_from_push.yml b/.github/workflows/module_async_from_push.yml new file mode 100644 index 0000000000..dd4257fe08 --- /dev/null +++ b/.github/workflows/module_async_from_push.yml @@ -0,0 +1,24 @@ +name : async_from + +on : + push : + branches : + - 'alpha' + - 'beta' + - 'master' + + +env : + CARGO_TERM_COLOR : always + +jobs : + + # async_from + + test : + uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha + with : + manifest_path : 'module/core/async_from/Cargo.toml' + module_name : 'async_from' + commit_message : ${{ github.event.head_commit.message }} + commiter_username: ${{ github.event.head_commit.committer.username }} diff --git a/.github/workflows/module_async_tools_push.yml b/.github/workflows/module_async_tools_push.yml new file mode 100644 index 0000000000..0310131fd5 --- /dev/null +++ b/.github/workflows/module_async_tools_push.yml @@ -0,0 +1,24 @@ +name : async_tools + +on : + push : + branches : + - 'alpha' + - 'beta' + - 'master' + + +env : + CARGO_TERM_COLOR : always + +jobs : + + # async_tools + + test : + uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha + with : + manifest_path : 'module/core/async_tools/Cargo.toml' + module_name : 'async_tools' + commit_message : ${{ github.event.head_commit.message }} + commiter_username: ${{ github.event.head_commit.committer.username }} diff --git a/.github/workflows/module_graphtools_push.yml b/.github/workflows/module_graphtools_push.yml new file mode 100644 index 0000000000..81fcfc6c0d --- /dev/null +++ b/.github/workflows/module_graphtools_push.yml @@ -0,0 +1,24 @@ +name : graphtools + +on : + push : + branches : + - 'alpha' + - 'beta' + - 'master' + + +env : + CARGO_TERM_COLOR : always + +jobs : + + # graphtools + + test : + uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha + with : + manifest_path : 'module/blank/graphtools/Cargo.toml' + module_name : 'graphtools' + commit_message : ${{ github.event.head_commit.message }} + commiter_username: ${{ github.event.head_commit.committer.username }} diff --git a/.github/workflows/module_mindx_12_push.yml b/.github/workflows/module_mindx_12_push.yml new file mode 100644 index 0000000000..dc1bf11265 --- /dev/null +++ b/.github/workflows/module_mindx_12_push.yml @@ -0,0 +1,24 @@ +name : mindx12 + +on : + push : + branches : + - 'alpha' + - 'beta' + - 'master' + + +env : + CARGO_TERM_COLOR : always + +jobs : + + # mindx12 + + test : + uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha + with : + manifest_path : 'module/blank/mindx12/Cargo.toml' + module_name : 'mindx12' + commit_message : ${{ github.event.head_commit.message }} + commiter_username: ${{ github.event.head_commit.committer.username }} diff --git a/.github/workflows/module_mingl_push.yml b/.github/workflows/module_mingl_push.yml new file mode 100644 index 0000000000..c6ce82da26 --- /dev/null +++ b/.github/workflows/module_mingl_push.yml @@ -0,0 +1,24 @@ +name : mingl + +on : + push : + branches : + - 'alpha' + - 'beta' + - 'master' + + +env : + CARGO_TERM_COLOR : always + +jobs : + + # mingl + + test : + uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha + with : + manifest_path : 'module/blank/mingl/Cargo.toml' + module_name : 'mingl' + commit_message : ${{ github.event.head_commit.message }} + commiter_username: ${{ github.event.head_commit.committer.username }} diff --git a/.github/workflows/module_minmetal_push.yml b/.github/workflows/module_minmetal_push.yml new file mode 100644 index 0000000000..e76b7cf916 --- /dev/null +++ b/.github/workflows/module_minmetal_push.yml @@ -0,0 +1,24 @@ +name : minmetal + +on : + push : + branches : + - 'alpha' + - 'beta' + - 'master' + + +env : + CARGO_TERM_COLOR : always + +jobs : + + # minmetal + + test : + uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha + with : + manifest_path : 'module/blank/minmetal/Cargo.toml' + module_name : 'minmetal' + commit_message : ${{ github.event.head_commit.message }} + commiter_username: ${{ github.event.head_commit.committer.username }} diff --git a/.github/workflows/module_minopengl_push.yml b/.github/workflows/module_minopengl_push.yml new file mode 100644 index 0000000000..5d412de534 --- /dev/null +++ b/.github/workflows/module_minopengl_push.yml @@ -0,0 +1,24 @@ +name : minopengl + +on : + push : + branches : + - 'alpha' + - 'beta' + - 'master' + + +env : + CARGO_TERM_COLOR : always + +jobs : + + # minopengl + + test : + uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha + with : + manifest_path : 'module/blank/minopengl/Cargo.toml' + module_name : 'minopengl' + commit_message : ${{ github.event.head_commit.message }} + commiter_username: ${{ github.event.head_commit.committer.username }} diff --git a/.github/workflows/module_minvulkan_push.yml b/.github/workflows/module_minvulkan_push.yml new file mode 100644 index 0000000000..1350cf0693 --- /dev/null +++ b/.github/workflows/module_minvulkan_push.yml @@ -0,0 +1,24 @@ +name : minvulkan + +on : + push : + branches : + - 'alpha' + - 'beta' + - 'master' + + +env : + CARGO_TERM_COLOR : always + +jobs : + + # minvulkan + + test : + uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha + with : + manifest_path : 'module/blank/minvulkan/Cargo.toml' + module_name : 'minvulkan' + commit_message : ${{ github.event.head_commit.message }} + commiter_username: ${{ github.event.head_commit.committer.username }} diff --git a/.github/workflows/module_minwebgl_push.yml b/.github/workflows/module_minwebgl_push.yml new file mode 100644 index 0000000000..4d63735d10 --- /dev/null +++ b/.github/workflows/module_minwebgl_push.yml @@ -0,0 +1,24 @@ +name : minwebgl + +on : + push : + branches : + - 'alpha' + - 'beta' + - 'master' + + +env : + CARGO_TERM_COLOR : always + +jobs : + + # minwebgl + + test : + uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha + with : + manifest_path : 'module/blank/minwebgl/Cargo.toml' + module_name : 'minwebgl' + commit_message : ${{ github.event.head_commit.message }} + commiter_username: ${{ github.event.head_commit.committer.username }} diff --git a/.github/workflows/module_minwebgpu_push.yml b/.github/workflows/module_minwebgpu_push.yml new file mode 100644 index 0000000000..4e8992613d --- /dev/null +++ b/.github/workflows/module_minwebgpu_push.yml @@ -0,0 +1,24 @@ +name : minwebgpu + +on : + push : + branches : + - 'alpha' + - 'beta' + - 'master' + + +env : + CARGO_TERM_COLOR : always + +jobs : + + # minwebgpu + + test : + uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha + with : + manifest_path : 'module/blank/minwebgpu/Cargo.toml' + module_name : 'minwebgpu' + commit_message : ${{ github.event.head_commit.message }} + commiter_username: ${{ github.event.head_commit.committer.username }} diff --git a/.github/workflows/module_minwgpu_push.yml b/.github/workflows/module_minwgpu_push.yml new file mode 100644 index 0000000000..382a15d19b --- /dev/null +++ b/.github/workflows/module_minwgpu_push.yml @@ -0,0 +1,24 @@ +name : minwgpu + +on : + push : + branches : + - 'alpha' + - 'beta' + - 'master' + + +env : + CARGO_TERM_COLOR : always + +jobs : + + # minwgpu + + test : + uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha + with : + manifest_path : 'module/blank/minwgpu/Cargo.toml' + module_name : 'minwgpu' + commit_message : ${{ github.event.head_commit.message }} + commiter_username: ${{ github.event.head_commit.committer.username }} diff --git a/.github/workflows/module_proper_path_tools_push.yml b/.github/workflows/module_proper_path_tools_push.yml index ebfcf83964..238a9cdb3f 100644 --- a/.github/workflows/module_proper_path_tools_push.yml +++ b/.github/workflows/module_proper_path_tools_push.yml @@ -18,7 +18,7 @@ jobs : test : uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha with : - manifest_path : 'module/core/proper_path_tools/Cargo.toml' + manifest_path : 'module/blank/proper_path_tools/Cargo.toml' module_name : 'proper_path_tools' commit_message : ${{ github.event.head_commit.message }} commiter_username: ${{ github.event.head_commit.committer.username }} diff --git a/.github/workflows/module_pth_push.yml b/.github/workflows/module_pth_push.yml new file mode 100644 index 0000000000..ddff538916 --- /dev/null +++ b/.github/workflows/module_pth_push.yml @@ -0,0 +1,24 @@ +name : pth + +on : + push : + branches : + - 'alpha' + - 'beta' + - 'master' + + +env : + CARGO_TERM_COLOR : always + +jobs : + + # pth + + test : + uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha + with : + manifest_path : 'module/core/pth/Cargo.toml' + module_name : 'pth' + commit_message : ${{ github.event.head_commit.message }} + commiter_username: ${{ github.event.head_commit.committer.username }} diff --git a/.github/workflows/standard_rust_push.yml b/.github/workflows/standard_rust_push.yml index d2fd96bae2..a243d1affe 100644 --- a/.github/workflows/standard_rust_push.yml +++ b/.github/workflows/standard_rust_push.yml @@ -64,20 +64,32 @@ jobs : - name: Build module run: cd ${{ steps.rootpath.outputs.path }} && cargo build && cd - - name: Audit the modules + id: audit run: make audit continue-on-error: true - name: Generate documentation for the modules + id: documentation run: make doc open=no manifest_path=${{ inputs.manifest_path }} continue-on-error: true - name: Lint the modules + id: lint run: make lint manifest_path=${{ inputs.manifest_path }} warnings=no continue-on-error: true - name: Check the modules + id: check run: make check manifest_path=${{ inputs.manifest_path }} continue-on-error: true - name: Check the modules dependencies + id: udeps run: cargo +nightly udeps --all-targets --manifest-path ${{ inputs.manifest_path }} continue-on-error: true + # Added IDs for each step in the test job: This allows referencing the result of each step later. + # + # "Check for errors" step: Now checks the outcome status for each step. + # If any of them have a value of 'failure', this step will fail the job by returning exit 1. + - name: Check for errors + if: steps.audit.outcome != 'success' || steps.documentation.outcome != 'success' || steps.lint.outcome != 'success' || steps.check.outcome != 'success' || steps.udeps.outcome != 'success' + run: exit 1 # release: # if: contains( inputs.commit_message, '+test' ) || contains( inputs.commit_message, 'merge' ) @@ -125,6 +137,9 @@ jobs : # run: cargo miri test --manifest-path ${{ inputs.manifest_path }} will_test : +# This section ensures that `job` `will_test` will only be executed after `checkmate` and if `checkmate` fails, no tests will be run. + needs : + - checkmate if : contains( inputs.commit_message, '+test' ) || inputs.commiter_username == 'web-flow' || startsWith( inputs.commit_message, 'merge' ) concurrency : group : standard_rust_push_${{ inputs.module_name }}_${{ github.ref }}_${{ matrix.os }} diff --git a/Cargo.toml b/Cargo.toml index 8e5c12e5cc..0e22e76fa4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,7 +80,7 @@ path = "module/alias/std_x" ## data_type [workspace.dependencies.data_type] -version = "~0.9.0" +version = "~0.12.0" path = "module/core/data_type" default-features = false @@ -98,19 +98,19 @@ default-features = false # path = "module/core/type_constructor_derive_pair_meta" [workspace.dependencies.interval_adapter] -version = "~0.23.0" +version = "~0.27.0" path = "module/core/interval_adapter" default-features = false -features = [ "enabled" ] +# features = [ "enabled" ] [workspace.dependencies.winterval] version = "~0.3.0" path = "module/alias/winterval" default-features = false -features = [ "enabled" ] +# features = [ "enabled" ] [workspace.dependencies.collection_tools] -version = "~0.11.0" +version = "~0.15.0" path = "module/core/collection_tools" default-features = false @@ -118,34 +118,34 @@ default-features = false ## derive [workspace.dependencies.derive_tools] -version = "~0.27.0" +version = "~0.32.0" path = "module/core/derive_tools" default-features = false -features = [ "enabled" ] +# features = [ "enabled" ] [workspace.dependencies.derive_tools_meta] -version = "~0.26.0" +version = "~0.31.0" path = "module/core/derive_tools_meta" default-features = false -features = [ "enabled" ] +# features = [ "enabled" ] [workspace.dependencies.reflect_tools] version = "~0.3.0" path = "module/core/reflect_tools" default-features = false -features = [ "enabled" ] +# features = [ "enabled" ] [workspace.dependencies.reflect_tools_meta] version = "~0.3.0" path = "module/core/reflect_tools_meta" default-features = false -features = [ "enabled" ] +# features = [ "enabled" ] [workspace.dependencies.format_tools] version = "~0.2.0" path = "module/core/format_tools" default-features = false -features = [ "enabled" ] +# features = [ "enabled" ] # xxx : remove features, maybe # [workspace.dependencies.type_constructor] @@ -159,33 +159,33 @@ path = "module/alias/fundamental_data_type" default-features = false [workspace.dependencies.variadic_from] -version = "~0.22.0" +version = "~0.27.0" path = "module/core/variadic_from" default-features = false -features = [ "enabled" ] +# features = [ "enabled" ] [workspace.dependencies.clone_dyn] -version = "~0.23.0" +version = "~0.29.0" path = "module/core/clone_dyn" default-features = false -features = [ "enabled" ] +# features = [ "enabled" ] [workspace.dependencies.clone_dyn_meta] -version = "~0.23.0" +version = "~0.27.0" path = "module/core/clone_dyn_meta" -features = [ "enabled" ] +# features = [ "enabled" ] [workspace.dependencies.clone_dyn_types] -version = "~0.22.0" +version = "~0.26.0" path = "module/core/clone_dyn_types" default-features = false -features = [ "enabled" ] +# features = [ "enabled" ] ## mem [workspace.dependencies.mem_tools] -version = "~0.6.0" +version = "~0.8.0" path = "module/core/mem_tools" default-features = false @@ -193,7 +193,7 @@ default-features = false ## diagnostics [workspace.dependencies.diagnostics_tools] -version = "~0.8.0" +version = "~0.10.0" path = "module/core/diagnostics_tools" default-features = false @@ -201,7 +201,7 @@ default-features = false ## iter [workspace.dependencies.iter_tools] -version = "~0.20.0" +version = "~0.24.0" path = "module/core/iter_tools" default-features = false @@ -209,17 +209,17 @@ default-features = false ## meta [workspace.dependencies.meta_tools] -version = "~0.10.0" +version = "~0.12.0" path = "module/core/meta_tools" default-features = false [workspace.dependencies.for_each] -version = "~0.8.0" +version = "~0.10.0" path = "module/core/for_each" default-features = false [workspace.dependencies.former] -version = "~2.8.0" +version = "~2.11.0" path = "module/core/former" default-features = false @@ -229,31 +229,31 @@ default-features = false # default-features = false [workspace.dependencies.former_meta] -version = "~2.8.0" +version = "~2.11.0" path = "module/core/former_meta" default-features = false [workspace.dependencies.former_types] -version = "~2.7.0" +version = "~2.12.0" path = "module/core/former_types" default-features = false [workspace.dependencies.impls_index] -version = "~0.7.0" +version = "~0.9.0" path = "module/core/impls_index" default-features = false [workspace.dependencies.impls_index_meta] -version = "~0.7.0" +version = "~0.9.0" path = "module/core/impls_index_meta" [workspace.dependencies.mod_interface] -version = "~0.23.0" +version = "~0.30.0" path = "module/core/mod_interface" default-features = false [workspace.dependencies.mod_interface_meta] -version = "~0.23.0" +version = "~0.29.0" path = "module/core/mod_interface_meta" default-features = false @@ -279,7 +279,7 @@ default-features = false ## macro tools [workspace.dependencies.macro_tools] -version = "~0.39.0" +version = "~0.44.0" path = "module/core/macro_tools" default-features = false @@ -305,12 +305,12 @@ default-features = false ## typing [workspace.dependencies.typing_tools] -version = "~0.8.0" +version = "~0.10.0" path = "module/core/typing_tools" default-features = false [workspace.dependencies.implements] -version = "~0.8.0" +version = "~0.10.0" path = "module/core/implements" default-features = false @@ -320,12 +320,12 @@ path = "module/alias/instance_of" default-features = false [workspace.dependencies.inspect_type] -version = "~0.10.0" +version = "~0.12.0" path = "module/core/inspect_type" default-features = false [workspace.dependencies.is_slice] -version = "~0.9.0" +version = "~0.11.0" path = "module/core/is_slice" default-features = false @@ -333,7 +333,7 @@ default-features = false ## error [workspace.dependencies.error_tools] -version = "~0.16.0" +version = "~0.19.0" path = "module/core/error_tools" default-features = false @@ -345,7 +345,7 @@ path = "module/alias/werror" ## string tools [workspace.dependencies.strs_tools] -version = "~0.16.0" +version = "~0.18.0" path = "module/core/strs_tools" default-features = false @@ -366,23 +366,28 @@ version = "~0.1.0" path = "module/alias/file_tools" default-features = false -[workspace.dependencies.proper_path_tools] -version = "~0.9.0" -path = "module/core/proper_path_tools" +[workspace.dependencies.pth] +version = "~0.21.0" +path = "module/core/pth" default-features = false +# [workspace.dependencies.proper_path_tools] +# version = "~0.15.0" +# path = "module/core/proper_path_tools" +# default-features = false + ## process tools [workspace.dependencies.process_tools] -version = "~0.8.0" +version = "~0.12.0" path = "module/core/process_tools" default-features = false -[workspace.dependencies.process_tools_published] -package = "process_tools" -version = "~0.8.0" -default-features = false +# [workspace.dependencies.process_tools_published] +# package = "process_tools" +# version = "~0.9.0" +# default-features = false ## test @@ -392,19 +397,34 @@ version = "~0.4.0" path = "module/alias/wtest" [workspace.dependencies.test_tools] -version = "~0.9.0" +version = "~0.11.0" path = "module/core/test_tools" +features = [ "full" ] + +[workspace.dependencies.test_tools_stable] +package = "test_tools" +version = "~0.10.0" +features = [ "full" ] [workspace.dependencies.wtest_basic] version = "~0.4.0" path = "module/alias/wtest_basic" +## async + +[workspace.dependencies.async_from] +version = "~0.2.0" +path = "module/core/async_from" + +[workspace.dependencies.async_tools] +version = "~0.1.0" +path = "module/core/async_tools" ## graphs tools [workspace.dependencies.graphs_tools] -version = "~0.2.0" +version = "~0.3.0" path = "module/move/graphs_tools" default-features = false @@ -422,7 +442,7 @@ default-features = false ## ca [workspace.dependencies.wca] -version = "~0.20.0" +version = "~0.23.0" path = "module/move/wca" @@ -436,7 +456,7 @@ path = "module/move/wcensor" ## willbe [workspace.dependencies.willbe] -version = "~0.14.0" +version = "~0.20.0" path = "module/move/willbe" @@ -472,11 +492,11 @@ version = "~0.2.0" path = "module/move/sqlx_query" [workspace.dependencies.deterministic_rand] -version = "~0.5.0" +version = "~0.6.0" path = "module/move/deterministic_rand" [workspace.dependencies.crates_tools] -version = "~0.12.0" +version = "~0.14.0" path = "module/move/crates_tools" @@ -507,3 +527,45 @@ default-features = true version = "~0.3.0" path = "module/test/c" default-features = true + +## External + +[workspace.dependencies.async-trait] +version = "0.1.83" + +[workspace.dependencies.tokio] +version = "1.41.0" +features = [] +default-features = false + +[workspace.dependencies.anyhow] +version = "~1.0" +# features = [] +# default-features = false + +[workspace.dependencies.thiserror] +version = "~1.0" +# features = [] +# default-features = false + +[workspace.dependencies.hashbrown] +version = "~0.14.3" +# optional = true +default-features = false +# features = [ "default" ] + +[workspace.dependencies.paste] +version = "~1.0.14" +default-features = false + +[workspace.dependencies.tempdir] +version = "~0.3.7" + +[workspace.dependencies.rustversion] +version = "~1.0" + +[workspace.dependencies.num-traits] +version = "~0.2" + +[workspace.dependencies.rand] +version = "0.8.5" diff --git a/Readme.md b/Readme.md index 36612d9970..1dd88d3db6 100644 --- a/Readme.md +++ b/Readme.md @@ -27,31 +27,33 @@ Collection of general purpose tools for solving problems. Fundamentally extend t | [clone_dyn](module/core/clone_dyn) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_clone_dyn_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_clone_dyn_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_clone_dyn_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_clone_dyn_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/clone_dyn) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fclone_dyn%2Fexamples%2Fclone_dyn_trivial.rs,RUN_POSTFIX=--example%20clone_dyn_trivial/https://github.com/Wandalen/wTools) | | [variadic_from](module/core/variadic_from) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_variadic_from_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_variadic_from_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_variadic_from_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_variadic_from_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/variadic_from) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fvariadic_from%2Fexamples%2Fvariadic_from_trivial.rs,RUN_POSTFIX=--example%20variadic_from_trivial/https://github.com/Wandalen/wTools) | | [derive_tools](module/core/derive_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_derive_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_derive_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_derive_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_derive_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/derive_tools) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fderive_tools%2Fexamples%2Fderive_tools_trivial.rs,RUN_POSTFIX=--example%20derive_tools_trivial/https://github.com/Wandalen/wTools) | +| [mod_interface_meta](module/core/mod_interface_meta) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_mod_interface_meta_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_mod_interface_meta_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_mod_interface_meta_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_mod_interface_meta_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/mod_interface_meta) | | | [former_meta](module/core/former_meta) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_former_meta_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_former_meta_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_former_meta_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_former_meta_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/former_meta) | | | [impls_index_meta](module/core/impls_index_meta) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_impls_index_meta_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_impls_index_meta_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_impls_index_meta_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_impls_index_meta_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/impls_index_meta) | | -| [mod_interface_meta](module/core/mod_interface_meta) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_mod_interface_meta_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_mod_interface_meta_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_mod_interface_meta_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_mod_interface_meta_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/mod_interface_meta) | | +| [mod_interface](module/core/mod_interface) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_mod_interface_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_mod_interface_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_mod_interface_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_mod_interface_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/mod_interface) | | +| [error_tools](module/core/error_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_error_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_error_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_error_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_error_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/error_tools) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Ferror_tools%2Fexamples%2Ferror_tools_trivial.rs,RUN_POSTFIX=--example%20error_tools_trivial/https://github.com/Wandalen/wTools) | | [for_each](module/core/for_each) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_for_each_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_for_each_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_for_each_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_for_each_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/for_each) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Ffor_each%2Fexamples%2Ffor_each_trivial.rs,RUN_POSTFIX=--example%20for_each_trivial/https://github.com/Wandalen/wTools) | | [former](module/core/former) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_former_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_former_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_former_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_former_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/former) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fformer%2Fexamples%2Fformer_trivial.rs,RUN_POSTFIX=--example%20former_trivial/https://github.com/Wandalen/wTools) | | [implements](module/core/implements) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_implements_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_implements_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_implements_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_implements_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/implements) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fimplements%2Fexamples%2Fimplements_trivial.rs,RUN_POSTFIX=--example%20implements_trivial/https://github.com/Wandalen/wTools) | | [impls_index](module/core/impls_index) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_impls_index_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_impls_index_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_impls_index_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_impls_index_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/impls_index) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fimpls_index%2Fexamples%2Fimpls_index_trivial.rs,RUN_POSTFIX=--example%20impls_index_trivial/https://github.com/Wandalen/wTools) | | [inspect_type](module/core/inspect_type) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_inspect_type_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_inspect_type_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_inspect_type_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_inspect_type_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/inspect_type) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Finspect_type%2Fexamples%2Finspect_type_trivial.rs,RUN_POSTFIX=--example%20inspect_type_trivial/https://github.com/Wandalen/wTools) | | [is_slice](module/core/is_slice) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_is_slice_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_is_slice_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_is_slice_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_is_slice_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/is_slice) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fis_slice%2Fexamples%2Fis_slice_trivial.rs,RUN_POSTFIX=--example%20is_slice_trivial/https://github.com/Wandalen/wTools) | -| [mod_interface](module/core/mod_interface) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_mod_interface_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_mod_interface_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_mod_interface_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_mod_interface_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/mod_interface) | | +| [pth](module/core/pth) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_pth_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_pth_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_pth_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_pth_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/pth) | | | [reflect_tools_meta](module/core/reflect_tools_meta) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_reflect_tools_meta_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_reflect_tools_meta_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_reflect_tools_meta_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_reflect_tools_meta_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/reflect_tools_meta) | | | [data_type](module/core/data_type) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_data_type_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_data_type_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_data_type_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_data_type_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/data_type) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fdata_type%2Fexamples%2Fdata_type_trivial.rs,RUN_POSTFIX=--example%20data_type_trivial/https://github.com/Wandalen/wTools) | | [diagnostics_tools](module/core/diagnostics_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_diagnostics_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_diagnostics_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_diagnostics_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_diagnostics_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/diagnostics_tools) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fdiagnostics_tools%2Fexamples%2Fdiagnostics_tools_trivial.rs,RUN_POSTFIX=--example%20diagnostics_tools_trivial/https://github.com/Wandalen/wTools) | -| [error_tools](module/core/error_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_error_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_error_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_error_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_error_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/error_tools) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Ferror_tools%2Fexamples%2Ferror_tools_trivial.rs,RUN_POSTFIX=--example%20error_tools_trivial/https://github.com/Wandalen/wTools) | | [mem_tools](module/core/mem_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_mem_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_mem_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_mem_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_mem_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/mem_tools) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fmem_tools%2Fexamples%2Fmem_tools_trivial.rs,RUN_POSTFIX=--example%20mem_tools_trivial/https://github.com/Wandalen/wTools) | | [meta_tools](module/core/meta_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_meta_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_meta_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_meta_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_meta_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/meta_tools) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fmeta_tools%2Fexamples%2Fmeta_tools_trivial.rs,RUN_POSTFIX=--example%20meta_tools_trivial/https://github.com/Wandalen/wTools) | -| [proper_path_tools](module/core/proper_path_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_proper_path_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_proper_path_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_proper_path_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_proper_path_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/proper_path_tools) | | +| [process_tools](module/core/process_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_process_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_process_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_process_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_process_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/process_tools) | | | [reflect_tools](module/core/reflect_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_reflect_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_reflect_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_reflect_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_reflect_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/reflect_tools) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=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) | | [strs_tools](module/core/strs_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_strs_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_strs_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_strs_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_strs_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/strs_tools) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fstrs_tools%2Fexamples%2Fstrs_tools_trivial.rs,RUN_POSTFIX=--example%20strs_tools_trivial/https://github.com/Wandalen/wTools) | | [time_tools](module/core/time_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_time_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_time_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_time_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_time_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/time_tools) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Ftime_tools%2Fexamples%2Ftime_tools_trivial.rs,RUN_POSTFIX=--example%20time_tools_trivial/https://github.com/Wandalen/wTools) | | [typing_tools](module/core/typing_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_typing_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_typing_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_typing_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_typing_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/typing_tools) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Ftyping_tools%2Fexamples%2Ftyping_tools_trivial.rs,RUN_POSTFIX=--example%20typing_tools_trivial/https://github.com/Wandalen/wTools) | +| [async_from](module/core/async_from) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_async_from_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_async_from_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_async_from_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_async_from_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/async_from) | | +| [async_tools](module/core/async_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_async_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_async_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_async_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_async_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/async_tools) | | | [format_tools](module/core/format_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_format_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_format_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_format_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_format_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/format_tools) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fformat_tools%2Fexamples%2Fformat_tools_trivial.rs,RUN_POSTFIX=--example%20format_tools_trivial/https://github.com/Wandalen/wTools) | | [fs_tools](module/core/fs_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_fs_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_fs_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_fs_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_fs_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/fs_tools) | | | [include_md](module/core/include_md) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_include_md_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_include_md_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_include_md_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_include_md_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/include_md) | | -| [process_tools](module/core/process_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_process_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_process_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_process_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_process_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/process_tools) | | | [program_tools](module/core/program_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_program_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_program_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_program_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_program_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/program_tools) | | | [test_tools](module/core/test_tools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_test_tools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_test_tools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_test_tools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_test_tools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/test_tools) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Ftest_tools%2Fexamples%2Ftest_tools_trivial.rs,RUN_POSTFIX=--example%20test_tools_trivial/https://github.com/Wandalen/wTools) | | [wtools](module/core/wtools) | [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_wtools_push.yml?label=&branch=master)](https://github.com/Wandalen/wTools/actions/workflows/module_wtools_push.yml?query=branch%3Amaster) | [![rust-status](https://img.shields.io/github/actions/workflow/status/Wandalen/wTools/module_wtools_push.yml?label=&branch=alpha)](https://github.com/Wandalen/wTools/actions/workflows/module_wtools_push.yml?query=branch%3Aalpha) | [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/wtools) | [![Open in Gitpod](https://raster.shields.io/static/v1?label=&message=try&color=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fwtools%2Fexamples%2Fwtools_trivial.rs,RUN_POSTFIX=--example%20wtools_trivial/https://github.com/Wandalen/wTools) | diff --git a/module/alias/cargo_will/License b/module/alias/cargo_will/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/alias/cargo_will/License +++ b/module/alias/cargo_will/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/cargo_will/src/bin/willbe.rs b/module/alias/cargo_will/src/bin/willbe.rs index 39d2429139..c2850a237c 100644 --- a/module/alias/cargo_will/src/bin/willbe.rs +++ b/module/alias/cargo_will/src/bin/willbe.rs @@ -6,7 +6,7 @@ #[ allow( unused_imports ) ] use::willbe::*; -fn main() -> Result< (), wtools::error::untyped::Error > +fn main() -> Result< (), error::untyped::Error > { Ok( willbe::run( std::env::args().collect() )? ) } diff --git a/module/alias/file_tools/License b/module/alias/file_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/alias/file_tools/License +++ b/module/alias/file_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/fundamental_data_type/License b/module/alias/fundamental_data_type/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/alias/fundamental_data_type/License +++ b/module/alias/fundamental_data_type/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/instance_of/License b/module/alias/instance_of/License index e3e9e057cf..c32986cee3 100644 --- a/module/alias/instance_of/License +++ b/module/alias/instance_of/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/instance_of/src/typing/implements_lib.rs b/module/alias/instance_of/src/typing/implements_lib.rs index 1a3f76aa7e..4129608ed8 100644 --- a/module/alias/instance_of/src/typing/implements_lib.rs +++ b/module/alias/instance_of/src/typing/implements_lib.rs @@ -15,7 +15,7 @@ // #[ macro_use ] mod implements_impl; -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/alias/instance_of/src/typing/is_slice_lib.rs b/module/alias/instance_of/src/typing/is_slice_lib.rs index 0f4a45cbc4..f3479787d1 100644 --- a/module/alias/instance_of/src/typing/is_slice_lib.rs +++ b/module/alias/instance_of/src/typing/is_slice_lib.rs @@ -12,7 +12,7 @@ #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/alias/multilayer/License b/module/alias/multilayer/License index e3e9e057cf..c32986cee3 100644 --- a/module/alias/multilayer/License +++ b/module/alias/multilayer/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/proc_macro_tools/License b/module/alias/proc_macro_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/alias/proc_macro_tools/License +++ b/module/alias/proc_macro_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/proper_tools/License b/module/alias/proper_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/alias/proper_tools/License +++ b/module/alias/proper_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/werror/License b/module/alias/werror/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/alias/werror/License +++ b/module/alias/werror/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/willbe2/License b/module/alias/willbe2/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/alias/willbe2/License +++ b/module/alias/willbe2/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/winterval/License b/module/alias/winterval/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/alias/winterval/License +++ b/module/alias/winterval/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/wproc_macro/License b/module/alias/wproc_macro/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/alias/wproc_macro/License +++ b/module/alias/wproc_macro/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/wstring_tools/License b/module/alias/wstring_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/alias/wstring_tools/License +++ b/module/alias/wstring_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/wtest/License b/module/alias/wtest/License index e3e9e057cf..c32986cee3 100644 --- a/module/alias/wtest/License +++ b/module/alias/wtest/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/wtest_basic/Cargo.toml b/module/alias/wtest_basic/Cargo.toml index 3d5e3d1218..6e6ceb65fd 100644 --- a/module/alias/wtest_basic/Cargo.toml +++ b/module/alias/wtest_basic/Cargo.toml @@ -58,7 +58,7 @@ enabled = [ "test_tools/enabled" ] [dependencies] -test_tools = { workspace = true, features = [ "full" ] } +test_tools = { workspace = true, default-features = true } # ## external # @@ -76,5 +76,5 @@ test_tools = { workspace = true, features = [ "full" ] } # data_type = { workspace = true, features = [ "full" ] } # diagnostics_tools = { workspace = true, features = [ "full" ] } -# [dev-dependencies] -# test_tools = { workspace = true } +[dev-dependencies] +test_tools = { workspace = true } diff --git a/module/alias/wtest_basic/License b/module/alias/wtest_basic/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/alias/wtest_basic/License +++ b/module/alias/wtest_basic/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/alias/wtest_basic/src/test/basic/helper.rs b/module/alias/wtest_basic/src/test/basic/helper.rs index fd3f8907d2..dc9ed8372b 100644 --- a/module/alias/wtest_basic/src/test/basic/helper.rs +++ b/module/alias/wtest_basic/src/test/basic/helper.rs @@ -3,7 +3,7 @@ //! Helpers. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/alias/wtest_basic/src/test/basic/mod.rs b/module/alias/wtest_basic/src/test/basic/mod.rs index 9e9e011623..034ebb427a 100644 --- a/module/alias/wtest_basic/src/test/basic/mod.rs +++ b/module/alias/wtest_basic/src/test/basic/mod.rs @@ -3,7 +3,7 @@ //! Basic tools for testing. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { } diff --git a/module/blank/brain_tools/License b/module/blank/brain_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/blank/brain_tools/License +++ b/module/blank/brain_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/blank/draw_lang/License b/module/blank/draw_lang/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/blank/draw_lang/License +++ b/module/blank/draw_lang/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/blank/drawboard/License b/module/blank/drawboard/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/blank/drawboard/License +++ b/module/blank/drawboard/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/blank/drawql/License b/module/blank/drawql/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/blank/drawql/License +++ b/module/blank/drawql/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/blank/exe_tools/License b/module/blank/exe_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/blank/exe_tools/License +++ b/module/blank/exe_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/blank/graphtools/Cargo.toml b/module/blank/graphtools/Cargo.toml new file mode 100644 index 0000000000..67a3c06564 --- /dev/null +++ b/module/blank/graphtools/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "graphtools" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/graphtools" +repository = "https://github.com/Wandalen/wTools/tree/master/module/blank/graphtools" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/blank/graphtools" +description = """ +Tools to manipulate graphs. +""" +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/core/proper_path_tools/License b/module/blank/graphtools/License similarity index 93% rename from module/core/proper_path_tools/License rename to module/blank/graphtools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/proper_path_tools/License +++ b/module/blank/graphtools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/blank/graphtools/Readme.md b/module/blank/graphtools/Readme.md new file mode 100644 index 0000000000..175776ccd1 --- /dev/null +++ b/module/blank/graphtools/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: graphtools +[![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/graphtools?color=e3e8f0&logo=docs.rs)](https://docs.rs/graphtools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Tools to manipulate graphs. + + diff --git a/module/blank/graphtools/src/lib.rs b/module/blank/graphtools/src/lib.rs new file mode 100644 index 0000000000..4168554e8f --- /dev/null +++ b/module/blank/graphtools/src/lib.rs @@ -0,0 +1,11 @@ + +#![ 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/graphtools/tests/inc/basic_test.rs b/module/blank/graphtools/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/graphtools/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/graphtools/tests/inc/mod.rs b/module/blank/graphtools/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/graphtools/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/blank/graphtools/tests/smoke_test.rs b/module/blank/graphtools/tests/smoke_test.rs new file mode 100644 index 0000000000..663dd6fb9f --- /dev/null +++ b/module/blank/graphtools/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/graphtools/tests/tests.rs b/module/blank/graphtools/tests/tests.rs new file mode 100644 index 0000000000..574f34b114 --- /dev/null +++ b/module/blank/graphtools/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/image_tools/License b/module/blank/image_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/blank/image_tools/License +++ b/module/blank/image_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/blank/math_tools/License b/module/blank/math_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/blank/math_tools/License +++ b/module/blank/math_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/blank/mindx12/Cargo.toml b/module/blank/mindx12/Cargo.toml new file mode 100644 index 0000000000..a26d724817 --- /dev/null +++ b/module/blank/mindx12/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "mindx12" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/mindx12" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/mindx12" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/mindx12" +description = """ +Draw language. +""" +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/mindx12/License b/module/blank/mindx12/License new file mode 100644 index 0000000000..0804aed8e3 --- /dev/null +++ b/module/blank/mindx12/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/blank/mindx12/Readme.md b/module/blank/mindx12/Readme.md new file mode 100644 index 0000000000..adc110369e --- /dev/null +++ b/module/blank/mindx12/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: mindx12 +[![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/Modulemindx12Push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/Modulemindx12Push.yml) [![docs.rs](https://img.shields.io/docsrs/mindx12?color=e3e8f0&logo=docs.rs)](https://docs.rs/mindx12) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Draw language. + + diff --git a/module/blank/mindx12/src/lib.rs b/module/blank/mindx12/src/lib.rs new file mode 100644 index 0000000000..8736456366 --- /dev/null +++ b/module/blank/mindx12/src/lib.rs @@ -0,0 +1,10 @@ + +#![ 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 = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/blank/mindx12/tests/inc/basic_test.rs b/module/blank/mindx12/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/mindx12/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/mindx12/tests/inc/mod.rs b/module/blank/mindx12/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/mindx12/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/core/proper_path_tools/tests/smoke_test.rs b/module/blank/mindx12/tests/smoke_test.rs similarity index 100% rename from module/core/proper_path_tools/tests/smoke_test.rs rename to module/blank/mindx12/tests/smoke_test.rs diff --git a/module/blank/mindx12/tests/tests.rs b/module/blank/mindx12/tests/tests.rs new file mode 100644 index 0000000000..5a33e742f0 --- /dev/null +++ b/module/blank/mindx12/tests/tests.rs @@ -0,0 +1,10 @@ + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use mindx12 as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/blank/mingl/Cargo.toml b/module/blank/mingl/Cargo.toml new file mode 100644 index 0000000000..dbd89af97e --- /dev/null +++ b/module/blank/mingl/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "mingl" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/mingl" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/mingl" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/mingl" +description = """ +Draw language. +""" +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/mingl/License b/module/blank/mingl/License new file mode 100644 index 0000000000..0804aed8e3 --- /dev/null +++ b/module/blank/mingl/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/blank/mingl/Readme.md b/module/blank/mingl/Readme.md new file mode 100644 index 0000000000..3a3390cd6c --- /dev/null +++ b/module/blank/mingl/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: draw_lang +[![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/Moduledraw_langPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/Moduledraw_langPush.yml) [![docs.rs](https://img.shields.io/docsrs/draw_lang?color=e3e8f0&logo=docs.rs)](https://docs.rs/draw_lang) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Draw language. + + diff --git a/module/blank/mingl/src/lib.rs b/module/blank/mingl/src/lib.rs new file mode 100644 index 0000000000..8736456366 --- /dev/null +++ b/module/blank/mingl/src/lib.rs @@ -0,0 +1,10 @@ + +#![ 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 = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/blank/mingl/tests/inc/basic_test.rs b/module/blank/mingl/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/mingl/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/mingl/tests/inc/mod.rs b/module/blank/mingl/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/mingl/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/blank/mingl/tests/smoke_test.rs b/module/blank/mingl/tests/smoke_test.rs new file mode 100644 index 0000000000..828e9b016b --- /dev/null +++ b/module/blank/mingl/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/blank/mingl/tests/tests.rs b/module/blank/mingl/tests/tests.rs new file mode 100644 index 0000000000..3e3cefe2bd --- /dev/null +++ b/module/blank/mingl/tests/tests.rs @@ -0,0 +1,10 @@ + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use mingl as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/blank/minmetal/Cargo.toml b/module/blank/minmetal/Cargo.toml new file mode 100644 index 0000000000..72527fb754 --- /dev/null +++ b/module/blank/minmetal/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "minmetal" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/minmetal" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/minmetal" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/minmetal" +description = """ +Draw language. +""" +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/minmetal/License b/module/blank/minmetal/License new file mode 100644 index 0000000000..0804aed8e3 --- /dev/null +++ b/module/blank/minmetal/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/blank/minmetal/Readme.md b/module/blank/minmetal/Readme.md new file mode 100644 index 0000000000..f701fbedf7 --- /dev/null +++ b/module/blank/minmetal/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: minmetal +[![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/ModuleminmetalPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/ModuleminmetalPush.yml) [![docs.rs](https://img.shields.io/docsrs/minmetal?color=e3e8f0&logo=docs.rs)](https://docs.rs/minmetal) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Draw language. + + diff --git a/module/blank/minmetal/src/lib.rs b/module/blank/minmetal/src/lib.rs new file mode 100644 index 0000000000..8736456366 --- /dev/null +++ b/module/blank/minmetal/src/lib.rs @@ -0,0 +1,10 @@ + +#![ 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 = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/blank/minmetal/tests/inc/basic_test.rs b/module/blank/minmetal/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/minmetal/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/minmetal/tests/inc/mod.rs b/module/blank/minmetal/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/minmetal/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/blank/minmetal/tests/smoke_test.rs b/module/blank/minmetal/tests/smoke_test.rs new file mode 100644 index 0000000000..828e9b016b --- /dev/null +++ b/module/blank/minmetal/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/blank/minmetal/tests/tests.rs b/module/blank/minmetal/tests/tests.rs new file mode 100644 index 0000000000..f2f68bee4f --- /dev/null +++ b/module/blank/minmetal/tests/tests.rs @@ -0,0 +1,10 @@ + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use minmetal as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/blank/minopengl/Cargo.toml b/module/blank/minopengl/Cargo.toml new file mode 100644 index 0000000000..8be8629874 --- /dev/null +++ b/module/blank/minopengl/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "minopengl" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/minopengl" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/minopengl" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/minopengl" +description = """ +Draw language. +""" +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/minopengl/License b/module/blank/minopengl/License new file mode 100644 index 0000000000..0804aed8e3 --- /dev/null +++ b/module/blank/minopengl/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/blank/minopengl/Readme.md b/module/blank/minopengl/Readme.md new file mode 100644 index 0000000000..7d19f733ea --- /dev/null +++ b/module/blank/minopengl/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: minopengl +[![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/ModuleminopenglPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/ModuleminopenglPush.yml) [![docs.rs](https://img.shields.io/docsrs/minopengl?color=e3e8f0&logo=docs.rs)](https://docs.rs/minopengl) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Draw language. + + diff --git a/module/blank/minopengl/src/lib.rs b/module/blank/minopengl/src/lib.rs new file mode 100644 index 0000000000..8736456366 --- /dev/null +++ b/module/blank/minopengl/src/lib.rs @@ -0,0 +1,10 @@ + +#![ 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 = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/blank/minopengl/tests/inc/basic_test.rs b/module/blank/minopengl/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/minopengl/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/minopengl/tests/inc/mod.rs b/module/blank/minopengl/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/minopengl/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/blank/minopengl/tests/smoke_test.rs b/module/blank/minopengl/tests/smoke_test.rs new file mode 100644 index 0000000000..828e9b016b --- /dev/null +++ b/module/blank/minopengl/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/blank/minopengl/tests/tests.rs b/module/blank/minopengl/tests/tests.rs new file mode 100644 index 0000000000..8a64879a19 --- /dev/null +++ b/module/blank/minopengl/tests/tests.rs @@ -0,0 +1,10 @@ + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use minopengl as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/blank/minvulkan/Cargo.toml b/module/blank/minvulkan/Cargo.toml new file mode 100644 index 0000000000..69ce9bda5d --- /dev/null +++ b/module/blank/minvulkan/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "minvulkan" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/minvulkan" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/minvulkan" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/minvulkan" +description = """ +Draw language. +""" +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/minvulkan/License b/module/blank/minvulkan/License new file mode 100644 index 0000000000..0804aed8e3 --- /dev/null +++ b/module/blank/minvulkan/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/blank/minvulkan/Readme.md b/module/blank/minvulkan/Readme.md new file mode 100644 index 0000000000..69b19ad55c --- /dev/null +++ b/module/blank/minvulkan/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: minvulkan +[![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/ModuleminvulkanPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/ModuleminvulkanPush.yml) [![docs.rs](https://img.shields.io/docsrs/minvulkan?color=e3e8f0&logo=docs.rs)](https://docs.rs/minvulkan) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Draw language. + + diff --git a/module/blank/minvulkan/src/lib.rs b/module/blank/minvulkan/src/lib.rs new file mode 100644 index 0000000000..8736456366 --- /dev/null +++ b/module/blank/minvulkan/src/lib.rs @@ -0,0 +1,10 @@ + +#![ 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 = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/blank/minvulkan/tests/inc/basic_test.rs b/module/blank/minvulkan/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/minvulkan/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/minvulkan/tests/inc/mod.rs b/module/blank/minvulkan/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/minvulkan/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/blank/minvulkan/tests/smoke_test.rs b/module/blank/minvulkan/tests/smoke_test.rs new file mode 100644 index 0000000000..828e9b016b --- /dev/null +++ b/module/blank/minvulkan/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/blank/minvulkan/tests/tests.rs b/module/blank/minvulkan/tests/tests.rs new file mode 100644 index 0000000000..d2d5f19233 --- /dev/null +++ b/module/blank/minvulkan/tests/tests.rs @@ -0,0 +1,10 @@ + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use minvulkan as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/blank/minwebgl/Cargo.toml b/module/blank/minwebgl/Cargo.toml new file mode 100644 index 0000000000..06d52581fb --- /dev/null +++ b/module/blank/minwebgl/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "minwebgl" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/minwebgl" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/minwebgl" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/minwebgl" +description = """ +Draw language. +""" +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/minwebgl/License b/module/blank/minwebgl/License new file mode 100644 index 0000000000..0804aed8e3 --- /dev/null +++ b/module/blank/minwebgl/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/blank/minwebgl/Readme.md b/module/blank/minwebgl/Readme.md new file mode 100644 index 0000000000..5b92138916 --- /dev/null +++ b/module/blank/minwebgl/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: minwebgl +[![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/ModuleminwebglPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/ModuleminwebglPush.yml) [![docs.rs](https://img.shields.io/docsrs/minwebgl?color=e3e8f0&logo=docs.rs)](https://docs.rs/minwebgl) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Draw language. + + diff --git a/module/blank/minwebgl/src/lib.rs b/module/blank/minwebgl/src/lib.rs new file mode 100644 index 0000000000..8736456366 --- /dev/null +++ b/module/blank/minwebgl/src/lib.rs @@ -0,0 +1,10 @@ + +#![ 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 = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/blank/minwebgl/tests/inc/basic_test.rs b/module/blank/minwebgl/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/minwebgl/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/minwebgl/tests/inc/mod.rs b/module/blank/minwebgl/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/minwebgl/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/blank/minwebgl/tests/smoke_test.rs b/module/blank/minwebgl/tests/smoke_test.rs new file mode 100644 index 0000000000..828e9b016b --- /dev/null +++ b/module/blank/minwebgl/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/blank/minwebgl/tests/tests.rs b/module/blank/minwebgl/tests/tests.rs new file mode 100644 index 0000000000..f830fcaa61 --- /dev/null +++ b/module/blank/minwebgl/tests/tests.rs @@ -0,0 +1,10 @@ + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use minwebgl as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/blank/minwebgpu/Cargo.toml b/module/blank/minwebgpu/Cargo.toml new file mode 100644 index 0000000000..c543c5be36 --- /dev/null +++ b/module/blank/minwebgpu/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "minwebgpu" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/minwebgpu" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/minwebgpu" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/minwebgpu" +description = """ +Draw language. +""" +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/minwebgpu/License b/module/blank/minwebgpu/License new file mode 100644 index 0000000000..0804aed8e3 --- /dev/null +++ b/module/blank/minwebgpu/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/blank/minwebgpu/Readme.md b/module/blank/minwebgpu/Readme.md new file mode 100644 index 0000000000..259dee0ab2 --- /dev/null +++ b/module/blank/minwebgpu/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: minwebgpu +[![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/ModuleminwebgpuPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/ModuleminwebgpuPush.yml) [![docs.rs](https://img.shields.io/docsrs/minwebgpu?color=e3e8f0&logo=docs.rs)](https://docs.rs/minwebgpu) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Draw language. + + diff --git a/module/blank/minwebgpu/src/lib.rs b/module/blank/minwebgpu/src/lib.rs new file mode 100644 index 0000000000..8736456366 --- /dev/null +++ b/module/blank/minwebgpu/src/lib.rs @@ -0,0 +1,10 @@ + +#![ 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 = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/blank/minwebgpu/tests/inc/basic_test.rs b/module/blank/minwebgpu/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/minwebgpu/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/minwebgpu/tests/inc/mod.rs b/module/blank/minwebgpu/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/minwebgpu/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/blank/minwebgpu/tests/smoke_test.rs b/module/blank/minwebgpu/tests/smoke_test.rs new file mode 100644 index 0000000000..828e9b016b --- /dev/null +++ b/module/blank/minwebgpu/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/blank/minwebgpu/tests/tests.rs b/module/blank/minwebgpu/tests/tests.rs new file mode 100644 index 0000000000..849473f639 --- /dev/null +++ b/module/blank/minwebgpu/tests/tests.rs @@ -0,0 +1,10 @@ + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use minwebgpu as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/blank/minwgpu/Cargo.toml b/module/blank/minwgpu/Cargo.toml new file mode 100644 index 0000000000..25841190ba --- /dev/null +++ b/module/blank/minwgpu/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "minwgpu" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/minwgpu" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/minwgpu" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/minwgpu" +description = """ +Draw language. +""" +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/minwgpu/License b/module/blank/minwgpu/License new file mode 100644 index 0000000000..0804aed8e3 --- /dev/null +++ b/module/blank/minwgpu/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/blank/minwgpu/Readme.md b/module/blank/minwgpu/Readme.md new file mode 100644 index 0000000000..1c8ca98d8a --- /dev/null +++ b/module/blank/minwgpu/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: minwgpu +[![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/ModuleminwgpuPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/ModuleminwgpuPush.yml) [![docs.rs](https://img.shields.io/docsrs/minwgpu?color=e3e8f0&logo=docs.rs)](https://docs.rs/minwgpu) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Draw language. + + diff --git a/module/blank/minwgpu/src/lib.rs b/module/blank/minwgpu/src/lib.rs new file mode 100644 index 0000000000..8736456366 --- /dev/null +++ b/module/blank/minwgpu/src/lib.rs @@ -0,0 +1,10 @@ + +#![ 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 = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/blank/minwgpu/tests/inc/basic_test.rs b/module/blank/minwgpu/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/minwgpu/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/minwgpu/tests/inc/mod.rs b/module/blank/minwgpu/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/minwgpu/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/blank/minwgpu/tests/smoke_test.rs b/module/blank/minwgpu/tests/smoke_test.rs new file mode 100644 index 0000000000..828e9b016b --- /dev/null +++ b/module/blank/minwgpu/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/blank/minwgpu/tests/tests.rs b/module/blank/minwgpu/tests/tests.rs new file mode 100644 index 0000000000..9bcb27960e --- /dev/null +++ b/module/blank/minwgpu/tests/tests.rs @@ -0,0 +1,10 @@ + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use minwgpu as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/blank/paths_tools/License b/module/blank/paths_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/blank/paths_tools/License +++ b/module/blank/paths_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/blank/proper_path_tools/Cargo.toml b/module/blank/proper_path_tools/Cargo.toml new file mode 100644 index 0000000000..4fe862c57e --- /dev/null +++ b/module/blank/proper_path_tools/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "proper_path_tools" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/proper_path_tools" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/proper_path_tools" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/proper_path_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/proper_path_tools/License b/module/blank/proper_path_tools/License new file mode 100644 index 0000000000..0804aed8e3 --- /dev/null +++ b/module/blank/proper_path_tools/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/blank/proper_path_tools/Readme.md b/module/blank/proper_path_tools/Readme.md new file mode 100644 index 0000000000..7fd9f99168 --- /dev/null +++ b/module/blank/proper_path_tools/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: proper_path_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/Moduleproper_path_toolsPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/Moduleproper_path_toolsPush.yml) [![docs.rs](https://img.shields.io/docsrs/proper_path_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/proper_path_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/proper_path_tools/src/lib.rs b/module/blank/proper_path_tools/src/lib.rs new file mode 100644 index 0000000000..b96a03ed21 --- /dev/null +++ b/module/blank/proper_path_tools/src/lib.rs @@ -0,0 +1,11 @@ + +#![ 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/proper_path_tools/latest/proper_path_tools/" ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/blank/proper_path_tools/tests/inc/basic_test.rs b/module/blank/proper_path_tools/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/proper_path_tools/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/proper_path_tools/tests/inc/mod.rs b/module/blank/proper_path_tools/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/proper_path_tools/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/blank/proper_path_tools/tests/smoke_test.rs b/module/blank/proper_path_tools/tests/smoke_test.rs new file mode 100644 index 0000000000..663dd6fb9f --- /dev/null +++ b/module/blank/proper_path_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/core/proper_path_tools/tests/tests.rs b/module/blank/proper_path_tools/tests/tests.rs similarity index 100% rename from module/core/proper_path_tools/tests/tests.rs rename to module/blank/proper_path_tools/tests/tests.rs diff --git a/module/blank/rustql/License b/module/blank/rustql/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/blank/rustql/License +++ b/module/blank/rustql/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/blank/second_brain/License b/module/blank/second_brain/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/blank/second_brain/License +++ b/module/blank/second_brain/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/blank/w4d/License b/module/blank/w4d/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/blank/w4d/License +++ b/module/blank/w4d/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/blank/wlang/License b/module/blank/wlang/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/blank/wlang/License +++ b/module/blank/wlang/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/async_from/Cargo.toml b/module/core/async_from/Cargo.toml new file mode 100644 index 0000000000..b6be30c5c7 --- /dev/null +++ b/module/core/async_from/Cargo.toml @@ -0,0 +1,38 @@ +[package] +name = "async_from" +version = "0.2.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/async_from" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/async_from" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/async_from" +description = """ +Async version of From, Into, TryFrom, TryInto. +""" +categories = [ "algorithms", "development-tools" ] +keywords = [ "fundamental", "general-purpose" ] + +[lints] +workspace = true + +[package.metadata.docs.rs] +features = [ "full" ] +all-features = false + +[features] +default = [ "enabled", "async_from", "async_try_from" ] +full = [ "default" ] +enabled = [] +async_from = [] +async_try_from = [] + +[dependencies] +async-trait = { workspace = true } + +[dev-dependencies] +# test_tools = { workspace = true } +tokio = { workspace = true, features = [ "rt-multi-thread", "time", "macros" ] } diff --git a/module/core/async_from/License b/module/core/async_from/License new file mode 100644 index 0000000000..0804aed8e3 --- /dev/null +++ b/module/core/async_from/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/core/async_from/Readme.md b/module/core/async_from/Readme.md new file mode 100644 index 0000000000..374fd4595c --- /dev/null +++ b/module/core/async_from/Readme.md @@ -0,0 +1,91 @@ + + +# Module :: async_from +[![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/Moduleasync_fromPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/Moduleasync_fromPush.yml) [![docs.rs](https://img.shields.io/docsrs/async_from?color=e3e8f0&logo=docs.rs)](https://docs.rs/async_from) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Async version of From, Into, TryFrom, TryInto. + +The `async_from` crate provides asynchronous versions of the well-known `From`, `Into`, `TryFrom`, and `TryInto` traits. These traits are essential for handling conversions in Rust, and their asynchronous counterparts, allowing for conversions that involve asynchronous operations. + +## Why Asynchronous Conversion Traits? + +In Rust, the `From`, `Into`, `TryFrom`, and `TryInto` traits provide a standardized way to handle type conversions. The `async_from` module extends this functionality to asynchronous contexts with `AsyncFrom`, `AsyncInto`, `AsyncTryFrom`, and `AsyncTryInto` traits, offering several key benefits: + +- **Simplicity**: Allow straightforward conversions without boilerplate, even in asynchronous contexts. +- **Consistency**: Provide a uniform interface for conversions across different types, aiding in writing predictable and maintainable code. +- **Error Handling**: Enable safe and explicit handling of conversion failures, essential for robust error management in commercial applications. +- **Asynchronous Contexts**: Facilitate conversions involving asynchronous operations, such as network requests or database queries, which are common in modern applications. + +The `async_from` provides developers with the tools needed to handle complex conversions in an async context efficiently, which is particularly important for commercial applications requiring reliable and efficient handling of asynchronous operations. + +### `AsyncFrom` and `AsyncInto` + +Trait for asynchronous conversions from a type T. + +These traits are designed for infallible asynchronous conversions. They allow you to convert types asynchronously, returning the result directly. + +```rust +use async_from::{ async_trait, AsyncFrom, AsyncInto }; + +struct MyNumber( u32 ); + +#[ async_trait ] +impl AsyncFrom< String > for MyNumber +{ + async fn async_from( value : String ) -> Self + { + let num = value.parse::< u32 >().unwrap_or( 0 ); + MyNumber( num ) + } +} + +#[ tokio::main ] +async fn main() +{ + let num = MyNumber::async_from( "42".to_string() ).await; + println!( "Converted: {}", num.0 ); + let num : MyNumber = "42".to_string().async_into().await; + println!( "Converted: {}", num.0 ); +} +``` + +### `AsyncTryFrom` and `AsyncTryInto` + +Trait for asynchronous fallible conversions from a type T. + +These traits are for fallible asynchronous conversions, where the conversion might fail. They return a `Result` wrapped in a `Future`, allowing you to handle errors gracefully. + +```rust +use async_from::{ async_trait, AsyncTryFrom, AsyncTryInto }; +use std::num::ParseIntError; + +struct MyNumber( u32 ); + +#[ async_trait ] +impl AsyncTryFrom< String > for MyNumber +{ + type Error = ParseIntError; + + async fn async_try_from( value : String ) -> Result< Self, Self::Error > + { + let num = value.parse::< u32 >()?; + Ok( MyNumber( num ) ) + } +} + +#[ tokio::main ] +async fn main() +{ + match MyNumber::async_try_from( "42".to_string() ).await + { + Ok( my_num ) => println!( "Converted successfully: {}", my_num.0 ), + Err( e ) => println!( "Conversion failed: {:?}", e ), + } + let result : Result< MyNumber, _ > = "42".to_string().async_try_into().await; + match result + { + Ok( my_num ) => println!( "Converted successfully using AsyncTryInto: {}", my_num.0 ), + Err( e ) => println!( "Conversion failed using AsyncTryInto: {:?}", e ), + } +} +``` diff --git a/module/core/async_from/src/lib.rs b/module/core/async_from/src/lib.rs new file mode 100644 index 0000000000..669dcf988e --- /dev/null +++ b/module/core/async_from/src/lib.rs @@ -0,0 +1,316 @@ + +#![ 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/async_from/latest/async_from/" ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Namespace with dependencies. +#[ cfg( feature = "enabled" ) ] +pub mod dependency +{ + pub use ::async_trait; +} + +/// Define a private namespace for all its items. +#[ cfg( feature = "enabled" ) ] +mod private +{ + + pub use async_trait::async_trait; + use std::fmt::Debug; + + /// Trait for asynchronous conversions from a type `T`. + /// + /// This trait allows for conversions that occur asynchronously, returning a `Future`. + /// + /// # Example + /// + /// ```rust + /// use async_from::{ async_trait, AsyncFrom }; + /// + /// struct MyNumber( u32 ); + /// + /// #[ async_trait ] + /// impl AsyncFrom< String > for MyNumber + /// { + /// async fn async_from( value : String ) -> Self + /// { + /// let num = value.parse::< u32 >().unwrap_or( 0 ); + /// MyNumber( num ) + /// } + /// } + /// + /// #[ tokio::main ] + /// async fn main() + /// { + /// let num = MyNumber::async_from( "42".to_string() ).await; + /// println!( "Converted: {}", num.0 ); + /// } + /// ``` + #[ cfg( feature = "async_from" ) ] + #[ async_trait ] + pub trait AsyncFrom< T > : Sized + { + /// Asynchronously converts a value of type `T` into `Self`. + /// + /// # Arguments + /// + /// * `value` - The value to be converted. + /// + /// # Returns + /// + /// * `Self` - The converted value. + async fn async_from( value : T ) -> Self; + } + + /// Trait for asynchronous conversions into a type `T`. + /// + /// This trait provides a method to convert `Self` into `T` asynchronously. + /// + /// # Example + /// + /// ```rust + /// use async_from::{ async_trait, AsyncFrom, AsyncInto }; + /// + /// struct MyNumber( u32 ); + /// + /// #[ async_trait ] + /// impl AsyncFrom< String > for MyNumber + /// { + /// async fn async_from( value : String ) -> Self + /// { + /// let num = value.parse::< u32 >().unwrap_or( 0 ); + /// MyNumber( num ) + /// } + /// } + /// + /// #[ tokio::main ] + /// async fn main() + /// { + /// let num : MyNumber = "42".to_string().async_into().await; + /// println!( "Converted: {}", num.0 ); + /// } + /// ``` + #[ async_trait ] + #[ cfg( feature = "async_from" ) ] + pub trait AsyncInto< T > : Sized + { + /// Asynchronously converts `Self` into a value of type `T`. + /// + /// # Returns + /// + /// * `T` - The converted value. + async fn async_into( self ) -> T; + } + + /// Blanket implementation of `AsyncInto` for any type that implements `AsyncFrom`. + /// + /// This implementation allows any type `T` that implements `AsyncFrom` to also implement `AsyncInto`. + #[ async_trait ] + #[ cfg( feature = "async_from" ) ] + impl< T, U > AsyncInto< U > for T + where + U : AsyncFrom< T > + Send, + T : Send, + { + /// Asynchronously converts `Self` into a value of type `U` using `AsyncFrom`. + /// + /// # Returns + /// + /// * `U` - The converted value. + async fn async_into( self ) -> U + { + U::async_from( self ).await + } + } + + /// Trait for asynchronous fallible conversions from a type `T`. + /// + /// This trait allows for conversions that may fail, returning a `Result` wrapped in a `Future`. + /// + /// # Example + /// + /// ```rust + /// use async_from::{ async_trait, AsyncTryFrom }; + /// use std::num::ParseIntError; + /// + /// struct MyNumber( u32 ); + /// + /// #[ async_trait ] + /// impl AsyncTryFrom< String > for MyNumber + /// { + /// type Error = ParseIntError; + /// + /// async fn async_try_from( value : String ) -> Result< Self, Self::Error > + /// { + /// let num = value.parse::< u32 >()?; + /// Ok( MyNumber( num ) ) + /// } + /// } + /// + /// #[ tokio::main ] + /// async fn main() + /// { + /// match MyNumber::async_try_from( "42".to_string() ).await + /// { + /// Ok( my_num ) => println!( "Converted successfully: {}", my_num.0 ), + /// Err( e ) => println!( "Conversion failed: {:?}", e ), + /// } + /// } + /// ``` + #[ async_trait ] + #[ cfg( feature = "async_try_from" ) ] + pub trait AsyncTryFrom< T > : Sized + { + /// The error type returned if the conversion fails. + type Error : Debug; + + /// Asynchronously attempts to convert a value of type `T` into `Self`. + /// + /// # Arguments + /// + /// * `value` - The value to be converted. + /// + /// # Returns + /// + /// * `Result` - On success, returns the converted value. On failure, returns an error. + async fn async_try_from( value : T ) -> Result< Self, Self::Error >; + } + + /// Trait for asynchronous fallible conversions into a type `T`. + /// + /// This trait provides a method to convert `Self` into `T`, potentially returning an error. + /// + /// # Example + /// + /// ```rust + /// use async_from::{ async_trait, AsyncTryFrom, AsyncTryInto }; + /// use std::num::ParseIntError; + /// + /// struct MyNumber( u32 ); + /// + /// #[ async_trait ] + /// impl AsyncTryFrom< String > for MyNumber + /// { + /// type Error = ParseIntError; + /// + /// async fn async_try_from( value : String ) -> Result< Self, Self::Error > + /// { + /// let num = value.parse::< u32 >()?; + /// Ok( MyNumber( num ) ) + /// } + /// } + /// + /// #[ tokio::main ] + /// async fn main() + /// { + /// let result : Result< MyNumber, _ > = "42".to_string().async_try_into().await; + /// match result + /// { + /// Ok( my_num ) => println!( "Converted successfully using AsyncTryInto: {}", my_num.0 ), + /// Err( e ) => println!( "Conversion failed using AsyncTryInto: {:?}", e ), + /// } + /// } + /// ``` + #[ async_trait ] + #[ cfg( feature = "async_try_from" ) ] + pub trait AsyncTryInto< T > : Sized + { + /// The error type returned if the conversion fails. + type Error : Debug; + + /// Asynchronously attempts to convert `Self` into a value of type `T`. + /// + /// # Returns + /// + /// * `Result` - On success, returns the converted value. On failure, returns an error. + async fn async_try_into( self ) -> Result< T, Self::Error >; + } + + /// Blanket implementation of `AsyncTryInto` for any type that implements `AsyncTryFrom`. + /// + /// This implementation allows any type `T` that implements `AsyncTryFrom` to also implement `AsyncTryInto`. + #[ async_trait ] + #[ cfg( feature = "async_try_from" ) ] + impl< T, U > AsyncTryInto< U > for T + where + U : AsyncTryFrom< T > + Send, + T : Send, + { + type Error = U::Error; + + /// Asynchronously converts `Self` into a value of type `U` using `AsyncTryFrom`. + /// + /// # Returns + /// + /// * `Result` - On success, returns the converted value. On failure, returns an error. + async fn async_try_into( self ) -> Result< U, Self::Error > + { + U::async_try_from( self ).await + } + } + +} + +#[ cfg( feature = "enabled" ) ] +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; + #[ doc( inline ) ] + pub use orphan::*; +} + +/// Orphan namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; + #[ doc( inline ) ] + pub use exposed::*; + +} + +/// Exposed namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + + #[ doc( inline ) ] + pub use prelude::*; + + #[ doc( inline ) ] + pub use ::async_trait::async_trait; + + #[ cfg( feature = "async_from" ) ] + pub use private:: + { + AsyncFrom, + AsyncInto, + }; + + #[ cfg( feature = "async_try_from" ) ] + pub use private:: + { + AsyncTryFrom, + AsyncTryInto, + }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; +} diff --git a/module/core/async_from/tests/inc/basic_test.rs b/module/core/async_from/tests/inc/basic_test.rs new file mode 100644 index 0000000000..dce63a4c1e --- /dev/null +++ b/module/core/async_from/tests/inc/basic_test.rs @@ -0,0 +1,84 @@ +use super::*; + +#[ tokio::test ] +async fn async_try_from_test() +{ + + // Example implementation of AsyncTryFrom for a custom type + struct MyNumber( u32 ); + + // xxx : qqq : broken + // #[ the_module::async_trait ] + // impl< 'a > the_module::AsyncTryFrom< &'a str > for MyNumber + // { + // type Error = std::num::ParseIntError; + // + // async fn async_try_from( value : &'a str ) -> Result< Self, Self::Error > + // { + // // Simulate asynchronous work + // tokio::time::sleep( tokio::time::Duration::from_millis( 1 ) ).await; + // let num = value.parse::< u32 >()?; + // Ok( MyNumber( num ) ) + // } + // } + + #[ the_module::async_trait ] + impl the_module::AsyncTryFrom< String > for MyNumber + { + type Error = std::num::ParseIntError; + + async fn async_try_from( value : String ) -> Result< Self, Self::Error > + { + // Simulate asynchronous work + tokio::time::sleep( tokio::time::Duration::from_millis( 10 ) ).await; + let num = value.parse::< u32 >()?; + Ok( MyNumber( num ) ) + } + } + + use the_module::{ AsyncTryFrom, AsyncTryInto }; + + // Using AsyncTryFrom directly + match MyNumber::async_try_from( "42".to_string() ).await + { + Ok( my_num ) => println!( "Converted successfully: {}", my_num.0 ), + Err( e ) => println!( "Conversion failed: {:?}", e ), + } + + // Using AsyncTryInto, which is automatically implemented + let result : Result< MyNumber, _ > = "42".to_string().async_try_into().await; + match result + { + Ok( my_num ) => println!( "Converted successfully using AsyncTryInto: {}", my_num.0 ), + Err( e ) => println!( "Conversion failed using AsyncTryInto: {:?}", e ), + } +} + +#[ tokio::test ] +async fn async_from_test() +{ + // Example implementation of AsyncFrom for a custom type + struct MyNumber( u32 ); + + #[ the_module::async_trait ] + impl the_module::AsyncFrom< String > for MyNumber + { + async fn async_from( value : String ) -> Self + { + // Simulate asynchronous work + tokio::time::sleep( tokio::time::Duration::from_millis( 10 ) ).await; + let num = value.parse::< u32 >().unwrap_or( 0 ); + MyNumber( num ) + } + } + + use the_module::{ AsyncFrom, AsyncInto }; + + // Using AsyncFrom directly + let my_num : MyNumber = MyNumber::async_from( "42".to_string() ).await; + println!( "Converted successfully using AsyncFrom: {}", my_num.0 ); + + // Using AsyncInto, which is automatically implemented + let my_num : MyNumber = "42".to_string().async_into().await; + println!( "Converted successfully using AsyncInto: {}", my_num.0 ); +} diff --git a/module/core/async_from/tests/inc/mod.rs b/module/core/async_from/tests/inc/mod.rs new file mode 100644 index 0000000000..329271ad56 --- /dev/null +++ b/module/core/async_from/tests/inc/mod.rs @@ -0,0 +1,3 @@ +use super::*; + +mod basic_test; diff --git a/module/core/async_from/tests/tests.rs b/module/core/async_from/tests/tests.rs new file mode 100644 index 0000000000..299521de4e --- /dev/null +++ b/module/core/async_from/tests/tests.rs @@ -0,0 +1,9 @@ +#![ allow( unused_imports ) ] + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +use async_from as the_module; +// use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/core/async_tools/Cargo.toml b/module/core/async_tools/Cargo.toml new file mode 100644 index 0000000000..0f6c4f835b --- /dev/null +++ b/module/core/async_tools/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "async_tools" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/async_tools" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/async_tools" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/async_tools" +description = """ +Toolkit for asynchronous programming. +""" +categories = [ "algorithms", "development-tools" ] +keywords = [ "fundamental", "general-purpose" ] + +[lints] +workspace = true + +[package.metadata.docs.rs] +features = [ "full" ] +all-features = false + +[features] +default = [ "enabled", "async_from", "async_try_from" ] +full = [ "default" ] +enabled = [] +async_from = [ "async_from/async_from" ] +async_try_from = [ "async_from/async_try_from" ] + +[dependencies] +async-trait = { workspace = true } +async_from = { workspace = true } + +[dev-dependencies] +# test_tools = { workspace = true } +tokio = { workspace = true, default-features = false, features = [ "rt-multi-thread", "time", "macros" ] } diff --git a/module/core/async_tools/License b/module/core/async_tools/License new file mode 100644 index 0000000000..0804aed8e3 --- /dev/null +++ b/module/core/async_tools/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/core/async_tools/Readme.md b/module/core/async_tools/Readme.md new file mode 100644 index 0000000000..0b469a2688 --- /dev/null +++ b/module/core/async_tools/Readme.md @@ -0,0 +1,6 @@ + + +# Module :: async_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/Moduleasync_fromPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/Moduleasync_fromPush.yml) [![docs.rs](https://img.shields.io/docsrs/async_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/async_tools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Toolkit for asynchronous programming. diff --git a/module/core/async_tools/src/lib.rs b/module/core/async_tools/src/lib.rs new file mode 100644 index 0000000000..0390e0dbe2 --- /dev/null +++ b/module/core/async_tools/src/lib.rs @@ -0,0 +1,79 @@ + +#![ 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/async_tools/latest/async_tools/" ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Namespace with dependencies. +#[ cfg( feature = "enabled" ) ] +pub mod dependency +{ + pub use ::async_trait; + pub use ::async_from; +} + +/// Define a private namespace for all its items. +#[ cfg( feature = "enabled" ) ] +mod private +{ +} + +#[ cfg( feature = "enabled" ) ] +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; + #[ doc( inline ) ] + pub use orphan::*; + + #[ doc( inline ) ] + pub use ::async_from::orphan::*; + +} + +/// Orphan namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; + #[ doc( inline ) ] + pub use exposed::*; + +} + +/// Exposed namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + + #[ doc( inline ) ] + pub use prelude::*; + + #[ doc( inline ) ] + pub use ::async_trait::async_trait; + + #[ doc( inline ) ] + pub use ::async_from::exposed::*; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; + + #[ doc( inline ) ] + pub use ::async_from::prelude::*; + +} diff --git a/module/core/async_tools/tests/inc/basic_test.rs b/module/core/async_tools/tests/inc/basic_test.rs new file mode 100644 index 0000000000..c652899926 --- /dev/null +++ b/module/core/async_tools/tests/inc/basic_test.rs @@ -0,0 +1,84 @@ +use super::*; + +#[ tokio::test ] +async fn async_try_from_test() +{ + + // Example implementation of AsyncTryFrom for a custom type + struct MyNumber( u32 ); + + // xxx : qqq : broken + // #[ the_module::async_trait ] + // impl< 'a > the_module::AsyncTryFrom< &'a str > for MyNumber + // { + // type Error = std::num::ParseIntError; + // + // async fn async_try_from( value : &'a str ) -> Result< Self, Self::Error > + // { + // // Simulate asynchronous work + // tokio::time::sleep( tokio::time::Duration::from_millis( 1 ) ).await; + // let num = value.parse::< u32 >()?; + // Ok( MyNumber( num ) ) + // } + // } + + #[ the_module::async_trait ] + impl the_module::AsyncTryFrom< String > for MyNumber + { + type Error = std::num::ParseIntError; + + async fn async_try_from( value : String ) -> Result< Self, Self::Error > + { + // Simulate asynchronous work + tokio::time::sleep( tokio::time::Duration::from_millis( 10 ) ).await; + let num = value.parse::< u32 >()?; + Ok( MyNumber( num ) ) + } + } + + use the_module::{ AsyncTryFrom, AsyncTryInto }; + + // Using AsyncTryFrom directly + match MyNumber::async_try_from( "42".to_string() ).await + { + Ok( my_num ) => println!( "Converted successfully: {}", my_num.0 ), + Err( e ) => println!( "Conversion failed: {:?}", e ), + } + + // Using AsyncTryInto, which is automatically implemented + let result : Result< MyNumber, _ > = "42".to_string().async_try_into().await; + match result + { + Ok( my_num ) => println!( "Converted successfully using AsyncTryInto: {}", my_num.0 ), + Err( e ) => println!( "Conversion failed using AsyncTryInto: {:?}", e ), + } +} + +#[ tokio::test ] +async fn async_from_test() +{ + // Example implementation of AsyncFrom for a custom type + struct MyNumber( u32 ); + + #[ the_module::async_trait ] + impl the_module::AsyncFrom< String > for MyNumber + { + async fn async_tools( value : String ) -> Self + { + // Simulate asynchronous work + tokio::time::sleep( tokio::time::Duration::from_millis( 10 ) ).await; + let num = value.parse::< u32 >().unwrap_or( 0 ); + MyNumber( num ) + } + } + + use the_module::{ AsyncFrom, AsyncInto }; + + // Using AsyncFrom directly + let my_num : MyNumber = MyNumber::async_tools( "42".to_string() ).await; + println!( "Converted successfully using AsyncFrom: {}", my_num.0 ); + + // Using AsyncInto, which is automatically implemented + let my_num : MyNumber = "42".to_string().async_into().await; + println!( "Converted successfully using AsyncInto: {}", my_num.0 ); +} diff --git a/module/core/async_tools/tests/inc/mod.rs b/module/core/async_tools/tests/inc/mod.rs new file mode 100644 index 0000000000..329271ad56 --- /dev/null +++ b/module/core/async_tools/tests/inc/mod.rs @@ -0,0 +1,3 @@ +use super::*; + +mod basic_test; diff --git a/module/core/async_tools/tests/tests.rs b/module/core/async_tools/tests/tests.rs new file mode 100644 index 0000000000..42f32553db --- /dev/null +++ b/module/core/async_tools/tests/tests.rs @@ -0,0 +1,10 @@ +#![ allow( unused_imports ) ] + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +use async_tools as the_module; +// use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +#[ path = "../../../../module/core/async_from/tests/inc/mod.rs" ] +mod inc; diff --git a/module/core/clone_dyn/Cargo.toml b/module/core/clone_dyn/Cargo.toml index 922f03fc69..400ba0e1fb 100644 --- a/module/core/clone_dyn/Cargo.toml +++ b/module/core/clone_dyn/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clone_dyn" -version = "0.23.0" +version = "0.29.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -26,16 +26,17 @@ all-features = false [features] -default = [ "enabled", "clone_dyn_types", "clone_dyn_meta" ] -full = [ "enabled", "clone_dyn_types", "clone_dyn_meta" ] +default = [ "enabled", "clone_dyn_types", "derive_clone_dyn" ] +full = [ "enabled", "clone_dyn_types", "derive_clone_dyn" ] enabled = [] clone_dyn_types = [ "dep:clone_dyn_types", "clone_dyn_types/enabled" ] -clone_dyn_meta = [ "dep:clone_dyn_meta", "clone_dyn_meta/enabled", "clone_dyn_types" ] +derive_clone_dyn = [ "dep:clone_dyn_meta", "clone_dyn_meta/enabled", "clone_dyn_types" ] [dependencies] clone_dyn_meta = { workspace = true, optional = true } clone_dyn_types = { workspace = true, optional = true } +# clone_dyn_types = { version = "0.27.0", optional = true } [dev-dependencies] test_tools = { workspace = true } diff --git a/module/core/clone_dyn/License b/module/core/clone_dyn/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/clone_dyn/License +++ b/module/core/clone_dyn/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/clone_dyn/Readme.md b/module/core/clone_dyn/Readme.md index f23c03a8c9..43e159b62c 100644 --- a/module/core/clone_dyn/Readme.md +++ b/module/core/clone_dyn/Readme.md @@ -70,9 +70,9 @@ The main function demonstrates the overall usage by creating a vector, obtaining ```rust -# #[ cfg( not( all( feature = "enabled", feature = "clone_dyn_meta" ) ) ) ] +# #[ cfg( not( all( feature = "enabled", feature = "derive_clone_dyn" ) ) ) ] # fn main() {} -# #[ cfg( all( feature = "enabled", feature = "clone_dyn_meta" ) ) ] +# #[ cfg( all( feature = "enabled", feature = "derive_clone_dyn" ) ) ] # fn main() # { diff --git a/module/core/clone_dyn/examples/clone_dyn_trivial.rs b/module/core/clone_dyn/examples/clone_dyn_trivial.rs index cd67d1cbea..aecf14563d 100644 --- a/module/core/clone_dyn/examples/clone_dyn_trivial.rs +++ b/module/core/clone_dyn/examples/clone_dyn_trivial.rs @@ -56,9 +56,9 @@ //! The main function demonstrates the overall usage by creating a vector, obtaining an iterator, and using the iterator to print elements. //! -#[ cfg( not( all( feature = "enabled", feature = "clone_dyn_meta" ) ) ) ] +#[ cfg( not( all( feature = "enabled", feature = "derive_clone_dyn" ) ) ) ] fn main() {} -#[ cfg( all( feature = "enabled", feature = "clone_dyn_meta" ) ) ] +#[ cfg( all( feature = "enabled", feature = "derive_clone_dyn" ) ) ] fn main() { use clone_dyn::{ clone_dyn, CloneDyn }; diff --git a/module/core/clone_dyn/src/lib.rs b/module/core/clone_dyn/src/lib.rs index 2f2ba25890..57ae64c7f8 100644 --- a/module/core/clone_dyn/src/lib.rs +++ b/module/core/clone_dyn/src/lib.rs @@ -5,17 +5,16 @@ #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] /// Namespace with dependencies. - #[ cfg( feature = "enabled" ) ] pub mod dependency { - #[ cfg( feature = "clone_dyn_meta" ) ] + #[ cfg( feature = "derive_clone_dyn" ) ] pub use ::clone_dyn_meta; #[ cfg( feature = "clone_dyn_types" ) ] pub use ::clone_dyn_types; } -/// Internal namespace. +/// Define a private namespace for all its items. #[ cfg( feature = "enabled" ) ] mod private { @@ -72,7 +71,7 @@ pub mod prelude #[ doc( inline ) ] #[ allow( unused_imports ) ] - #[ cfg( feature = "clone_dyn_meta" ) ] + #[ cfg( feature = "derive_clone_dyn" ) ] pub use ::clone_dyn_meta::clone_dyn; #[ doc( inline ) ] diff --git a/module/core/clone_dyn/tests/inc/mod.rs b/module/core/clone_dyn/tests/inc/mod.rs index fc05ba6236..6e0cb7295a 100644 --- a/module/core/clone_dyn/tests/inc/mod.rs +++ b/module/core/clone_dyn/tests/inc/mod.rs @@ -2,9 +2,9 @@ #[ allow( unused_imports ) ] use super::*; -#[ cfg( feature = "clone_dyn_meta" ) ] +#[ cfg( feature = "derive_clone_dyn" ) ] pub mod basic_manual; -#[ cfg( feature = "clone_dyn_meta" ) ] +#[ cfg( feature = "derive_clone_dyn" ) ] pub mod basic; -#[ cfg( feature = "clone_dyn_meta" ) ] +#[ cfg( feature = "derive_clone_dyn" ) ] pub mod parametrized; diff --git a/module/core/clone_dyn_meta/Cargo.toml b/module/core/clone_dyn_meta/Cargo.toml index 35a9783798..d77ad96088 100644 --- a/module/core/clone_dyn_meta/Cargo.toml +++ b/module/core/clone_dyn_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clone_dyn_meta" -version = "0.23.0" +version = "0.27.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/clone_dyn_meta/License b/module/core/clone_dyn_meta/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/clone_dyn_meta/License +++ b/module/core/clone_dyn_meta/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/clone_dyn_types/Cargo.toml b/module/core/clone_dyn_types/Cargo.toml index 9c5db44b4a..4a145d0c13 100644 --- a/module/core/clone_dyn_types/Cargo.toml +++ b/module/core/clone_dyn_types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clone_dyn_types" -version = "0.22.0" +version = "0.26.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/clone_dyn_types/License b/module/core/clone_dyn_types/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/clone_dyn_types/License +++ b/module/core/clone_dyn_types/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/clone_dyn_types/src/lib.rs b/module/core/clone_dyn_types/src/lib.rs index 3fc94133df..cc55badce4 100644 --- a/module/core/clone_dyn_types/src/lib.rs +++ b/module/core/clone_dyn_types/src/lib.rs @@ -10,7 +10,7 @@ pub mod dependency { } -/// Internal namespace. +/// Define a private namespace for all its items. // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] #[ cfg( feature = "enabled" ) ] mod private diff --git a/module/core/collection_tools/Cargo.toml b/module/core/collection_tools/Cargo.toml index 303edaa2df..d69009a758 100644 --- a/module/core/collection_tools/Cargo.toml +++ b/module/core/collection_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "collection_tools" -version = "0.11.0" +version = "0.15.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -11,16 +11,14 @@ documentation = "https://docs.rs/collection_tools" repository = "https://github.com/Wandalen/wTools/tree/master/module/core/collection_tools" homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/collection_tools" description = """ -Collection of general purpose tools to manipulate collections( containers like Vec/HashMap/HashSet ). +General purpose tools to manipulate collections( containers like Vec/HashMap/HashSet ). """ categories = [ "algorithms", "development-tools" ] keywords = [ "fundamental", "general-purpose" ] - [lints] workspace = true - [package.metadata.docs.rs] features = [ "full" ] all-features = false @@ -28,31 +26,26 @@ all-features = false [features] no_std = [ - "test_tools/no_std", ] use_alloc = [ - "no_std", # qqq : for Anton : why is that better? -- use_alloc means that we do not use std, but alloc and hashbrown + "no_std", "hashbrown", - # "test_tools/use_alloc", // why is it needed? -- not needed, removed ] default = [ "enabled", - # "reexports", "collection_constructors", "collection_into_constructors", ] full = [ "enabled", - # "reexports", "collection_constructors", "collection_into_constructors", ] enabled = [] -# reexports = [] # Collection constructors, like `hmap!{ "key" => "val" }` collection_constructors = [] @@ -63,7 +56,7 @@ collection_into_constructors = [] [dependencies] ## external -hashbrown = { version = "~0.14.3", optional = true, default-features = false, features = [ "default" ] } +hashbrown = { workspace = true, optional = true, default-features = false, features = [ "default" ] } [dev-dependencies] test_tools = { workspace = true } diff --git a/module/core/collection_tools/License b/module/core/collection_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/collection_tools/License +++ b/module/core/collection_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/collection_tools/Readme.md b/module/core/collection_tools/Readme.md index 1430c6d6ef..2b6f2b0ab6 100644 --- a/module/core/collection_tools/Readme.md +++ b/module/core/collection_tools/Readme.md @@ -5,7 +5,7 @@ [![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_collection_tools_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_collection_tools_push.yml) [![docs.rs](https://img.shields.io/docsrs/collection_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/collection_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%2Fcollection_tools%2Fexamples%2Fcollection_tools_trivial.rs,RUN_POSTFIX=--example%20collection_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 general purpose tools to manipulate collections( containers like Vec/HashMap/HashSet... ). +General purpose tools to manipulate collections( containers like Vec/HashMap/HashSet... ). ### Basic Use Case :: Variadic Constructors for Collections @@ -71,7 +71,7 @@ assert_eq!( meta_list, meta_list ); ### Basic Use Case :: `no_std` `HashSet` / `HashMap` -When implementing a `no_std` environment with the `use_alloc` feature in your Rust project, you'll encounter a challenge: collections like `Vec` are imported differently depending on the availability of the `std` library. Moreover, to use data structures such as `HashSet` or `HashMap` in a `no_std` context, it's necessary to depend on third-party crates, as these are not provided by the `alloc` crate directly. This crate aims to simplify the process of designing Rust libraries or applications that require these collections in a `no_std` environment, offering a more streamlined approach to working with dynamic data structures without the standard library. +When implementing a `no_std` ( `!use_std` ) environment with the `use_alloc` feature in your Rust project, you'll encounter a challenge: collections like `Vec` are imported differently depending on the availability of the `std` library. Moreover, to use data structures such as `HashSet` or `HashMap` in a `no_std` context, it's necessary to depend on third-party crates, as these are not provided by the `alloc` crate directly. This crate aims to simplify the process of designing Rust libraries or applications that require these collections in a `no_std` environment, offering a more streamlined approach to working with dynamic data structures without the standard library. You can do @@ -98,7 +98,7 @@ Instead of # #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] # { -#[ cfg( feature = "use_alloc" ) ] +#[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ] use hashbrown::HashSet; // a `no_std` replacement for `HashSet` #[ cfg( not( feature = "no_std" ) ) ] use std::collections::HashSet; @@ -120,7 +120,8 @@ While strict macros require you to have all members of the same type, more relax For example: ```rust -# #[ cfg( all( feature = "enabled", feature = "collection_into_constructors", any( not( feature = "no_std" ), feature = "use_alloc" ) ) ) ] +# #[ cfg( all( feature = "enabled", feature = "collection_into_constructors" ) ) ] +# #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] # { use std::borrow::Cow; let vec : Vec< String > = collection_tools::into_vec!( "&str", "String".to_string(), Cow::from( "Cow" ) ); diff --git a/module/core/collection_tools/examples/collection_tools_trivial.rs b/module/core/collection_tools/examples/collection_tools_trivial.rs index 8a11bb85bf..79ff09bf0d 100644 --- a/module/core/collection_tools/examples/collection_tools_trivial.rs +++ b/module/core/collection_tools/examples/collection_tools_trivial.rs @@ -19,18 +19,15 @@ //! a `HashMap`, making your code cleaner and more concise. This is particularly useful in cases //! where you need to define a map with a known set of key-value pairs upfront. -#[ cfg( not( all -( -// not( feature = "use_alloc" ) ) ], - all( feature = "enabled", feature = "collection_constructors" ), - any( not( feature = "no_std" ), feature = "use_alloc" ) +#[ cfg( not( all( + feature = "enabled", + feature = "collection_constructors", + any( feature = "use_alloc", not( feature = "no_std" ) ) )))] -fn main(){} +fn main() {} -// zzz : aaa : rid of `#[ cfg( not( feature = "use_alloc" ) ) ]` -- Rid of by not relying on std -// #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( all( feature = "enabled", feature = "collection_constructors" ) ) ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +#[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] fn main() { use collection_tools::*; diff --git a/module/core/collection_tools/src/collection.rs b/module/core/collection_tools/src/collection.rs deleted file mode 100644 index ed2b504917..0000000000 --- a/module/core/collection_tools/src/collection.rs +++ /dev/null @@ -1,33 +0,0 @@ -/// Not meant to be called directly. -#[ doc( hidden ) ] -#[ macro_export( local_inner_macros ) ] -macro_rules! count -{ - ( @single $( $x : tt )* ) => ( () ); - - ( - @count $( $rest : expr ),* - ) - => - ( - < [ () ] >::len( &[ $( count!( @single $rest ) ),* ] ) - ); -} - -/// [std::collections::BTreeMap] macros -pub mod bmap; -/// [std::collections::BTreeSet] macros -pub mod bset; -/// [std::collections::BinaryHeap] macros -pub mod heap; -/// [std::collections::HashMap] macros -pub mod hmap; -/// [std::collections::HashSet] macros -pub mod hset; -/// [std::collections::LinkedList] macros -pub mod llist; -/// [Vec] macros -pub mod vec; -/// [std::collections::VecDeque] macros -pub mod deque; - diff --git a/module/core/collection_tools/src/collection/heap.rs b/module/core/collection_tools/src/collection/binary_heap.rs similarity index 95% rename from module/core/collection_tools/src/collection/heap.rs rename to module/core/collection_tools/src/collection/binary_heap.rs index 8d38492497..965f5804c5 100644 --- a/module/core/collection_tools/src/collection/heap.rs +++ b/module/core/collection_tools/src/collection/binary_heap.rs @@ -1,6 +1,9 @@ +#[ allow( unused_imports ) ] +use super::*; + #[ doc( inline ) ] #[ allow( unused_imports ) ] - pub use alloc::collections::binary_heap::*; +pub use alloc::collections::binary_heap::*; /// Creates a `BinaryHeap` from a list of elements. /// @@ -57,7 +60,7 @@ macro_rules! heap => {{ let _cap = count!( @count $( $key ),* ); - let mut _heap = $crate::heap::BinaryHeap::with_capacity( _cap ); + let mut _heap = $crate::collection::BinaryHeap::with_capacity( _cap ); $( _heap.push( $key ); )* @@ -146,7 +149,7 @@ macro_rules! into_heap => {{ let _cap = count!( @count $( $key ),* ); - let mut _heap = $crate::heap::BinaryHeap::with_capacity( _cap ); + let mut _heap = $crate::collection::BinaryHeap::with_capacity( _cap ); $( _heap.push( Into::into( $key ) ); )* diff --git a/module/core/collection_tools/src/collection/bmap.rs b/module/core/collection_tools/src/collection/btree_map.rs similarity index 97% rename from module/core/collection_tools/src/collection/bmap.rs rename to module/core/collection_tools/src/collection/btree_map.rs index e96f045e84..2e4ec94f13 100644 --- a/module/core/collection_tools/src/collection/bmap.rs +++ b/module/core/collection_tools/src/collection/btree_map.rs @@ -1,3 +1,6 @@ +#[ allow( unused_imports ) ] +use super::*; + #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use alloc::collections::btree_map::*; @@ -70,7 +73,7 @@ macro_rules! bmap ) => {{ - let mut _map = $crate::bmap::BTreeMap::new(); + let mut _map = $crate::collection::BTreeMap::new(); $( let _ = _map.insert( $key , $value ); )* @@ -163,7 +166,7 @@ macro_rules! into_bmap ) => {{ - let mut _map = $crate::bmap::BTreeMap::new(); + let mut _map = $crate::collection::BTreeMap::new(); $( let _ = _map.insert( Into::into( $key ), Into::into( $value ) ); )* diff --git a/module/core/collection_tools/src/collection/bset.rs b/module/core/collection_tools/src/collection/btree_set.rs similarity index 96% rename from module/core/collection_tools/src/collection/bset.rs rename to module/core/collection_tools/src/collection/btree_set.rs index c0c6d249ed..7111811c2e 100644 --- a/module/core/collection_tools/src/collection/bset.rs +++ b/module/core/collection_tools/src/collection/btree_set.rs @@ -1,3 +1,6 @@ +#[ allow( unused_imports ) ] +use super::*; + #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use alloc::collections::btree_set::*; @@ -56,7 +59,7 @@ macro_rules! bset ) => {{ - let mut _set = $crate::bset::BTreeSet::new(); + let mut _set = $crate::collection::BTreeSet::new(); $( _set.insert( $key ); )* @@ -149,7 +152,7 @@ macro_rules! into_bset ) => {{ - let mut _set = $crate::bset::BTreeSet::new(); + let mut _set = $crate::collection::BTreeSet::new(); $( _set.insert( Into::into( $key ) ); )* diff --git a/module/core/collection_tools/src/collection/hmap.rs b/module/core/collection_tools/src/collection/hash_map.rs similarity index 93% rename from module/core/collection_tools/src/collection/hmap.rs rename to module/core/collection_tools/src/collection/hash_map.rs index eceac4ee9b..8ebbc9f90f 100644 --- a/module/core/collection_tools/src/collection/hmap.rs +++ b/module/core/collection_tools/src/collection/hash_map.rs @@ -1,7 +1,12 @@ -#[ cfg( feature = "use_alloc" ) ] +#[ allow( unused_imports ) ] +use super::*; + +// xxx : qqq : wrong +#[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ] #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use crate::dependency::hashbrown::hash_map::*; + #[ cfg( not( feature = "no_std" ) ) ] #[ doc( inline ) ] #[ allow( unused_imports ) ] @@ -14,7 +19,7 @@ pub use std::collections::hash_map::*; /// # Origin /// /// This collection can be reexported from different crates: -/// - from `std`, if `no_std` flag if off +/// - from `std`, if `use_std` is on ( `no_std` flag if off ) /// - from `hashbrown`, if `use_alloc` flag if on /// /// # Syntax @@ -77,7 +82,7 @@ macro_rules! hmap => {{ let _cap = count!( @count $( $key ),* ); - let mut _map = $crate::hmap::HashMap::with_capacity( _cap ); + let mut _map = $crate::collection::HashMap::with_capacity( _cap ); $( let _ = _map.insert( $key, $value ); )* @@ -98,7 +103,7 @@ macro_rules! hmap /// # Origin /// /// This collection can be reexported from different crates: -/// - from `std`, if `no_std` flag if off +/// - from `std`, if `use_std` is on ( `no_std` flag if off ) /// - from `hashbrown`, if `use_alloc` flag if on /// /// # Syntax @@ -172,7 +177,7 @@ macro_rules! into_hmap => {{ let _cap = count!( @count $( $key ),* ); - let mut _map = $crate::hmap::HashMap::with_capacity( _cap ); + let mut _map = $crate::collection::HashMap::with_capacity( _cap ); $( let _ = _map.insert( Into::into( $key ), Into::into( $value ) ); )* diff --git a/module/core/collection_tools/src/collection/hset.rs b/module/core/collection_tools/src/collection/hash_set.rs similarity index 94% rename from module/core/collection_tools/src/collection/hset.rs rename to module/core/collection_tools/src/collection/hash_set.rs index b9b2d682da..6fe8d8287a 100644 --- a/module/core/collection_tools/src/collection/hset.rs +++ b/module/core/collection_tools/src/collection/hash_set.rs @@ -1,7 +1,11 @@ +#[ allow( unused_imports ) ] +use super::*; + #[ cfg( feature = "use_alloc" ) ] #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use crate::dependency::hashbrown::hash_set::*; + #[ cfg( not( feature = "no_std" ) ) ] #[ doc( inline ) ] #[ allow( unused_imports ) ] @@ -14,7 +18,7 @@ pub use std::collections::hash_set::*; /// # Origin /// /// This collection can be reexported from different crates: -/// - from `std`, if `no_std` flag if off +/// - from `std`, if `use_std` is on ( `no_std` flag if off ) /// - from `hashbrown`, if `use_alloc` flag if on /// /// # Syntax @@ -77,7 +81,7 @@ macro_rules! hset => {{ let _cap = count!( @count $( $key ),* ); - let mut _set = $crate::hset::HashSet::with_capacity( _cap ); + let mut _set = $crate::collection::HashSet::with_capacity( _cap ); $( let _ = _set.insert( $key ); )* @@ -96,9 +100,9 @@ macro_rules! hset /// type `T` used in the `HashSet`. Also, this means that sometimes you must specify the type of collection's items. /// /// # Origin -/// +/// /// This collection can be reexported from different crates: -/// - from `std`, if `no_std` flag if off +/// - from `std`, if `use_std` is on ( `no_std` flag if off ) /// - from `hashbrown`, if `use_alloc` flag if on /// /// # Syntax @@ -173,7 +177,7 @@ macro_rules! into_hset => {{ let _cap = count!( @count $( $key ),* ); - let mut _set = $crate::hset::HashSet::with_capacity( _cap ); + let mut _set = $crate::collection::HashSet::with_capacity( _cap ); $( let _ = _set.insert( Into::into( $key ) ); )* diff --git a/module/core/collection_tools/src/collection/llist.rs b/module/core/collection_tools/src/collection/linked_list.rs similarity index 97% rename from module/core/collection_tools/src/collection/llist.rs rename to module/core/collection_tools/src/collection/linked_list.rs index e6c8ddbe68..cc23637be1 100644 --- a/module/core/collection_tools/src/collection/llist.rs +++ b/module/core/collection_tools/src/collection/linked_list.rs @@ -1,3 +1,6 @@ +#[ allow( unused_imports ) ] +use super::*; + #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use alloc::collections::linked_list::*; @@ -70,7 +73,7 @@ macro_rules! llist {{ // "The LinkedList allows pushing and popping elements at either end in constant time." // So no `with_capacity` - let mut _lst = $crate::llist::LinkedList::new(); + let mut _lst = $crate::collection::LinkedList::new(); $( _lst.push_back( $key ); )* @@ -164,7 +167,7 @@ macro_rules! into_llist {{ // "The LinkedList allows pushing and popping elements at either end in constant time." // So no `with_capacity` - let mut _lst = $crate::llist::LinkedList::new(); + let mut _lst = $crate::collection::LinkedList::new(); $( _lst.push_back( Into::into( $key ) ); )* diff --git a/module/core/collection_tools/src/collection/mod.rs b/module/core/collection_tools/src/collection/mod.rs new file mode 100644 index 0000000000..0f74158835 --- /dev/null +++ b/module/core/collection_tools/src/collection/mod.rs @@ -0,0 +1,160 @@ +/// Not meant to be called directly. +#[ doc( hidden ) ] +#[ macro_export( local_inner_macros ) ] +macro_rules! count +{ + ( @single $( $x : tt )* ) => ( () ); + + ( + @count $( $rest : expr ),* + ) + => + ( + < [ () ] >::len( &[ $( count!( @single $rest ) ),* ] ) + ); +} + +#[ cfg( feature = "enabled" ) ] +#[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] +extern crate alloc; + +/// [std::collections::BTreeMap] macros +pub mod btree_map; +/// [std::collections::BTreeSet] macros +pub mod btree_set; +/// [std::collections::BinaryHeap] macros +pub mod binary_heap; +/// [std::collections::HashMap] macros +pub mod hash_map; +/// [std::collections::HashSet] macros +pub mod hash_set; +/// [std::collections::LinkedList] macros +pub mod linked_list; +/// [Vec] macros +pub mod vector; +/// [std::collections::VecDeque] macros +pub mod vec_deque; + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +#[ cfg( feature = "enabled" ) ] +pub use own::*; + +/// Own namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; + + pub use super:: + { + btree_map, + btree_set, + binary_heap, + hash_map, + hash_set, + linked_list, + vector, + vec_deque, + }; + + #[ doc( inline ) ] + pub use orphan::*; + +} + +/// Parented namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; + #[ doc( inline ) ] + pub use exposed::*; +} + +/// Exposed namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + + #[ doc( inline ) ] + pub use prelude::*; + + #[ doc( inline ) ] + pub use super::super::collection; + + #[ doc( inline ) ] + #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] + #[ cfg( feature = "collection_constructors" ) ] + pub use crate:: + { + vec as dlist, + deque, + llist, + hset, + hmap, + bmap, + bset, + }; + + #[ doc( inline ) ] + #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] + #[ cfg( feature = "collection_into_constructors" ) ] + pub use crate:: + { + into_vec, + into_vec as into_dlist, + into_vecd, + into_llist, + into_hset, + into_hmap, + into_bmap, + into_bset, + }; + + // #[ cfg( feature = "reexports" ) ] + #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] + #[ doc( inline ) ] + pub use + { + btree_map::BTreeMap, + btree_set::BTreeSet, + binary_heap::BinaryHeap, + hash_map::HashMap, + hash_set::HashSet, + linked_list::LinkedList, + vector::Vec, + vec_deque::VecDeque, + }; + + // #[ cfg( feature = "reexports" ) ] + #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] + #[ doc( inline ) ] + pub use + { + LinkedList as Llist, + Vec as Dlist, + VecDeque as Deque, + HashMap as Map, + HashMap as Hmap, + HashSet as Set, + HashSet as Hset, + BTreeMap as Bmap, + BTreeSet as Bset, + }; + + // qqq : cover by tests presence of all containers immidiately in collection_tools::* and in collection_tools::exposed::* + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; +} diff --git a/module/core/collection_tools/src/collection/deque.rs b/module/core/collection_tools/src/collection/vec_deque.rs similarity index 96% rename from module/core/collection_tools/src/collection/deque.rs rename to module/core/collection_tools/src/collection/vec_deque.rs index 66b106c6ec..1060d01c0b 100644 --- a/module/core/collection_tools/src/collection/deque.rs +++ b/module/core/collection_tools/src/collection/vec_deque.rs @@ -1,3 +1,6 @@ +#[ allow( unused_imports ) ] +use super::*; + #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use alloc::collections::vec_deque::*; @@ -75,7 +78,7 @@ macro_rules! deque => {{ let _cap = count!( @count $( $key ),* ); - let mut _vecd = $crate::deque::VecDeque::with_capacity( _cap ); + let mut _vecd = $crate::collection::VecDeque::with_capacity( _cap ); $( _vecd.push_back( $key ); )* @@ -168,7 +171,7 @@ macro_rules! into_vecd => {{ let _cap = count!( @count $( $key ),* ); - let mut _vecd = $crate::deque::VecDeque::with_capacity( _cap ); + let mut _vecd = $crate::collection::VecDeque::with_capacity( _cap ); $( _vecd.push_back( Into::into( $key ) ); )* diff --git a/module/core/collection_tools/src/collection/vec.rs b/module/core/collection_tools/src/collection/vector.rs similarity index 96% rename from module/core/collection_tools/src/collection/vec.rs rename to module/core/collection_tools/src/collection/vector.rs index 2c19db388f..0ae9ccf6dd 100644 --- a/module/core/collection_tools/src/collection/vec.rs +++ b/module/core/collection_tools/src/collection/vector.rs @@ -1,6 +1,10 @@ +#[ allow( unused_imports ) ] +use super::*; + #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use alloc::vec::*; + #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use core::slice::{ Iter, IterMut }; @@ -73,7 +77,7 @@ macro_rules! vec => {{ let _cap = count!( @count $( $key ),* ); - let mut _vec = $crate::vec::Vec::with_capacity( _cap ); + let mut _vec = $crate::collection::Vec::with_capacity( _cap ); $( _vec.push( $key ); )* @@ -167,7 +171,7 @@ macro_rules! into_vec => {{ let _cap = count!( @count $( $key ),* ); - let mut _vec = $crate::vec::Vec::with_capacity( _cap ); + let mut _vec = $crate::collection::Vec::with_capacity( _cap ); $( _vec.push( Into::into( $key ) ); )* diff --git a/module/core/collection_tools/src/lib.rs b/module/core/collection_tools/src/lib.rs index 5d0c5976a4..bcbbb4bdbc 100644 --- a/module/core/collection_tools/src/lib.rs +++ b/module/core/collection_tools/src/lib.rs @@ -4,17 +4,18 @@ #![ doc( html_root_url = "https://docs.rs/collection_tools/latest/collection_tools/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -#[ cfg( feature = "enabled" ) ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -extern crate alloc; +// #[ cfg( feature = "enabled" ) ] +// #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] +// extern crate alloc; /// Module containing all collection macros #[ cfg( feature = "enabled" ) ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -mod collection; -#[ cfg( feature = "enabled" ) ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -pub use collection::*; +#[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] +pub mod collection; + +// #[ cfg( feature = "enabled" ) ] +// #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] +// pub use collection::*; /// Namespace with dependencies. #[ cfg( feature = "enabled" ) ] @@ -36,10 +37,13 @@ pub use own::*; #[ allow( unused_imports ) ] pub mod own { - use super::*; + // use super::*; #[ doc( inline ) ] - pub use orphan::*; + pub use super::orphan::*; + + #[ doc( inline ) ] + pub use super::collection::own::*; } @@ -51,6 +55,10 @@ pub mod orphan use super::*; #[ doc( inline ) ] pub use exposed::*; + + #[ doc( inline ) ] + pub use collection::orphan::*; + } /// Exposed namespace of the module. @@ -64,66 +72,7 @@ pub mod exposed pub use prelude::*; #[ doc( inline ) ] - #[ cfg( feature = "collection_constructors" ) ] - pub use crate:: - { - vec as dlist, - deque, - llist, - hset, - hmap, - bmap, - bset, - }; - - #[ doc( inline ) ] - #[ cfg( feature = "collection_into_constructors" ) ] - pub use crate:: - { - into_vec, - into_vec as into_dlist, - into_vecd, - into_llist, - into_hset, - into_hmap, - into_bmap, - into_bset, - }; - - // #[ cfg( feature = "reexports" ) ] - #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use crate:: - { - bmap::BTreeMap, - bset::BTreeSet, - heap::BinaryHeap, - hmap::HashMap, - hset::HashSet, - llist::LinkedList, - vec::Vec, - deque::VecDeque, - }; - - // #[ cfg( feature = "reexports" ) ] - #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use - { - LinkedList as Llist, - Vec as Dlist, - VecDeque as Deque, - HashMap as Map, - HashMap as Hmap, - HashSet as Set, - HashSet as Hset, - BTreeMap as Bmap, - BTreeSet as Bset, - }; - - // qqq : cover by tests presence of all containers immidiately in collection_tools::* and in collection_tools::exposed::* + pub use collection::exposed::*; } @@ -133,4 +82,16 @@ pub mod exposed pub mod prelude { use super::*; + + #[ doc( inline ) ] + pub use collection::prelude::*; + } + +// pub use own::collection as xxx; +// pub use hmap as xxx; +// pub use own::HashMap as xxx; +// pub fn x() +// { +// let x : HashMap< usize, usize > = hmap!{}; +// } diff --git a/module/core/collection_tools/tests/inc/bmap.rs b/module/core/collection_tools/tests/inc/bmap.rs index af3d54dae5..113e69f810 100644 --- a/module/core/collection_tools/tests/inc/bmap.rs +++ b/module/core/collection_tools/tests/inc/bmap.rs @@ -68,7 +68,7 @@ fn iters() impl IntoIterator for MyContainer { type Item = ( i32, i32 ); - type IntoIter = the_module::bmap::IntoIter< i32, i32 >; + type IntoIter = the_module::btree_map::IntoIter< i32, i32 >; fn into_iter( self ) -> Self::IntoIter { @@ -79,7 +79,7 @@ fn iters() impl< 'a > IntoIterator for &'a MyContainer { type Item = ( &'a i32, &'a i32 ); - type IntoIter = the_module::bmap::Iter< 'a, i32, i32 >; + type IntoIter = the_module::btree_map::Iter< 'a, i32, i32 >; fn into_iter( self ) -> Self::IntoIter { diff --git a/module/core/collection_tools/tests/inc/bset.rs b/module/core/collection_tools/tests/inc/bset.rs index 2a427d0a26..9fb625bf30 100644 --- a/module/core/collection_tools/tests/inc/bset.rs +++ b/module/core/collection_tools/tests/inc/bset.rs @@ -67,7 +67,7 @@ fn iters() impl IntoIterator for MyContainer { type Item = i32; - type IntoIter = the_module::bset::IntoIter< i32 >; + type IntoIter = the_module::btree_set::IntoIter< i32 >; fn into_iter( self ) -> Self::IntoIter { @@ -78,7 +78,7 @@ fn iters() impl< 'a > IntoIterator for &'a MyContainer { type Item = &'a i32; - type IntoIter = the_module::bset::Iter< 'a, i32 >; + type IntoIter = the_module::btree_set::Iter< 'a, i32 >; fn into_iter( self ) -> Self::IntoIter { diff --git a/module/core/collection_tools/tests/inc/deque.rs b/module/core/collection_tools/tests/inc/deque.rs index 41c3d323b1..d58c72d8cc 100644 --- a/module/core/collection_tools/tests/inc/deque.rs +++ b/module/core/collection_tools/tests/inc/deque.rs @@ -50,8 +50,8 @@ fn into_constructor() exp.push_front( 3 ); assert_eq!( got, exp ); - let _got : DequeList< &str > = the_module::deque!( "b" ); - let _got : DequeList< &str > = the_module::exposed::deque!( "b" ); + let _got = the_module::deque!( "b" ); + let _got = the_module::exposed::deque!( "b" ); } @@ -66,7 +66,7 @@ fn iters() impl IntoIterator for MyContainer { type Item = i32; - type IntoIter = the_module::deque::IntoIter< i32 >; + type IntoIter = the_module::vec_deque::IntoIter< i32 >; fn into_iter( self ) -> Self::IntoIter { @@ -77,7 +77,7 @@ fn iters() impl< 'a > IntoIterator for &'a MyContainer { type Item = &'a i32; - type IntoIter = the_module::deque::Iter< 'a, i32 >; + type IntoIter = the_module::vec_deque::Iter< 'a, i32 >; fn into_iter( self ) -> Self::IntoIter { @@ -88,7 +88,7 @@ fn iters() impl< 'a > IntoIterator for &'a mut MyContainer { type Item = &'a mut i32; - type IntoIter = the_module::deque::IterMut< 'a, i32 >; + type IntoIter = the_module::vec_deque::IterMut< 'a, i32 >; fn into_iter( self ) -> Self::IntoIter { diff --git a/module/core/collection_tools/tests/inc/heap.rs b/module/core/collection_tools/tests/inc/heap.rs index a342548cfc..ad251e0b39 100644 --- a/module/core/collection_tools/tests/inc/heap.rs +++ b/module/core/collection_tools/tests/inc/heap.rs @@ -62,7 +62,7 @@ fn iters() impl IntoIterator for MyContainer { type Item = i32; - type IntoIter = the_module::heap::IntoIter< i32 >; + type IntoIter = the_module::binary_heap::IntoIter< i32 >; fn into_iter( self ) -> Self::IntoIter { @@ -73,7 +73,7 @@ fn iters() impl< 'a > IntoIterator for &'a MyContainer { type Item = &'a i32; - type IntoIter = the_module::heap::Iter< 'a, i32 >; + type IntoIter = the_module::binary_heap::Iter< 'a, i32 >; fn into_iter( self ) -> Self::IntoIter { diff --git a/module/core/collection_tools/tests/inc/hmap.rs b/module/core/collection_tools/tests/inc/hmap.rs index 629c7155a6..042b4c8653 100644 --- a/module/core/collection_tools/tests/inc/hmap.rs +++ b/module/core/collection_tools/tests/inc/hmap.rs @@ -77,7 +77,7 @@ fn iters() impl IntoIterator for MyContainer { type Item = ( i32, i32 ); - type IntoIter = the_module::hmap::IntoIter< i32, i32 >; + type IntoIter = the_module::hash_map::IntoIter< i32, i32 >; fn into_iter( self ) -> Self::IntoIter { @@ -88,7 +88,7 @@ fn iters() impl< 'a > IntoIterator for &'a MyContainer { type Item = ( &'a i32, &'a i32 ); - type IntoIter = the_module::hmap::Iter< 'a, i32, i32 >; + type IntoIter = the_module::hash_map::Iter< 'a, i32, i32 >; fn into_iter( self ) -> Self::IntoIter { @@ -99,7 +99,7 @@ fn iters() impl< 'a > IntoIterator for &'a mut MyContainer { type Item = ( &'a i32, &'a mut i32 ); - type IntoIter = the_module::hmap::IterMut< 'a, i32, i32 >; + type IntoIter = the_module::hash_map::IterMut< 'a, i32, i32 >; fn into_iter( self ) -> Self::IntoIter { diff --git a/module/core/collection_tools/tests/inc/hset.rs b/module/core/collection_tools/tests/inc/hset.rs index c844836874..b3af31cb2d 100644 --- a/module/core/collection_tools/tests/inc/hset.rs +++ b/module/core/collection_tools/tests/inc/hset.rs @@ -74,7 +74,7 @@ fn iters() impl IntoIterator for MyContainer { type Item = i32; - type IntoIter = the_module::hset::IntoIter< i32 >; + type IntoIter = the_module::hash_set::IntoIter< i32 >; fn into_iter( self ) -> Self::IntoIter { @@ -85,7 +85,7 @@ fn iters() impl< 'a > IntoIterator for &'a MyContainer { type Item = &'a i32; - type IntoIter = the_module::hset::Iter< 'a, i32 >; + type IntoIter = the_module::hash_set::Iter< 'a, i32 >; fn into_iter( self ) -> Self::IntoIter { diff --git a/module/core/collection_tools/tests/inc/llist.rs b/module/core/collection_tools/tests/inc/llist.rs index 68620e2a69..3a861b0ec2 100644 --- a/module/core/collection_tools/tests/inc/llist.rs +++ b/module/core/collection_tools/tests/inc/llist.rs @@ -67,7 +67,7 @@ fn iters() impl IntoIterator for MyContainer { type Item = i32; - type IntoIter = the_module::llist::IntoIter< i32 >; + type IntoIter = the_module::linked_list::IntoIter< i32 >; fn into_iter( self ) -> Self::IntoIter { @@ -78,7 +78,7 @@ fn iters() impl< 'a > IntoIterator for &'a MyContainer { type Item = &'a i32; - type IntoIter = the_module::llist::Iter< 'a, i32 >; + type IntoIter = the_module::linked_list::Iter< 'a, i32 >; fn into_iter( self ) -> Self::IntoIter { @@ -89,7 +89,7 @@ fn iters() impl< 'a > IntoIterator for &'a mut MyContainer { type Item = &'a mut i32; - type IntoIter = the_module::llist::IterMut< 'a, i32 >; + type IntoIter = the_module::linked_list::IterMut< 'a, i32 >; fn into_iter( self ) -> Self::IntoIter { diff --git a/module/core/collection_tools/tests/inc/mod.rs b/module/core/collection_tools/tests/inc/mod.rs index ddd10e261d..86855a9d84 100644 --- a/module/core/collection_tools/tests/inc/mod.rs +++ b/module/core/collection_tools/tests/inc/mod.rs @@ -9,6 +9,7 @@ mod llist; mod vec; mod deque; +mod namespace_test; mod components; // qqq : make subdirectory for each container -- done diff --git a/module/core/collection_tools/tests/inc/namespace_test.rs b/module/core/collection_tools/tests/inc/namespace_test.rs new file mode 100644 index 0000000000..841ecac64f --- /dev/null +++ b/module/core/collection_tools/tests/inc/namespace_test.rs @@ -0,0 +1,12 @@ +use super::*; + +#[ test ] +fn exposed_main_namespace() +{ + + let _v : Vec< u32 > = the_module::collection::Vec::new(); + let _v : Vec< u32 > = the_module::exposed::collection::Vec::new(); + use the_module::exposed::*; + let _v : Vec< u32 > = collection::Vec::new(); + +} \ No newline at end of file diff --git a/module/core/collection_tools/tests/inc/vec.rs b/module/core/collection_tools/tests/inc/vec.rs index ff9480659f..5bf78631ba 100644 --- a/module/core/collection_tools/tests/inc/vec.rs +++ b/module/core/collection_tools/tests/inc/vec.rs @@ -1,6 +1,7 @@ use super::*; #[ test ] +#[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] fn reexport() { @@ -12,7 +13,8 @@ fn reexport() let got = vec1.last().unwrap().clone(); assert_eq!( got, 2 ); - let mut vec2 : the_module::DynList< i32 > = the_module::DynList::new(); + use std::vec::Vec as DynList; + let mut vec2 : DynList< i32 > = DynList::new(); vec2.push( 1 ); vec2.push( 2 ); let got = vec2.first().unwrap().clone(); @@ -84,7 +86,7 @@ fn iters() impl IntoIterator for MyContainer { type Item = i32; - type IntoIter = the_module::vec::IntoIter< i32 >; + type IntoIter = the_module::vector::IntoIter< i32 >; // qqq : should work -- works fn into_iter( self ) -> Self::IntoIter @@ -96,7 +98,7 @@ fn iters() impl< 'a > IntoIterator for &'a MyContainer { type Item = &'a i32; - type IntoIter = the_module::vec::Iter< 'a, i32 >; + type IntoIter = the_module::vector::Iter< 'a, i32 >; fn into_iter( self ) -> Self::IntoIter { @@ -107,7 +109,7 @@ fn iters() impl< 'a > IntoIterator for &'a mut MyContainer { type Item = &'a mut i32; - type IntoIter = the_module::vec::IterMut< 'a, i32 >; + type IntoIter = the_module::vector::IterMut< 'a, i32 >; fn into_iter( self ) -> Self::IntoIter { diff --git a/module/core/collection_tools/tests/tests.rs b/module/core/collection_tools/tests/tests.rs index a36c5debec..ecc936c445 100644 --- a/module/core/collection_tools/tests/tests.rs +++ b/module/core/collection_tools/tests/tests.rs @@ -1,4 +1,4 @@ -// usual tests +#![ allow( unused_imports ) ] #[ path="../../../../module/step/meta/src/module/aggregating.rs" ] mod aggregating; diff --git a/module/core/data_type/Cargo.toml b/module/core/data_type/Cargo.toml index 0328fc7e83..c5f7155d97 100644 --- a/module/core/data_type/Cargo.toml +++ b/module/core/data_type/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "data_type" -version = "0.9.0" +version = "0.12.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -32,7 +32,6 @@ default = [ # "use_std", "enabled", "dt_either", - "dt_prelude", "dt_interval", "dt_collection", # "dt_make", @@ -43,7 +42,6 @@ full = [ # "use_std", "enabled", "dt_either", - "dt_prelude", "dt_interval", "dt_collection", # "dt_make", @@ -54,43 +52,18 @@ no_std = [] use_alloc = [ "no_std" ] enabled = [] -# dt_prelude = [ "collection_tools/reexports" ] -dt_prelude = [] # rid of maybe? dt_interval = [ "interval_adapter/enabled" ] dt_collection = [ "collection_tools/enabled" ] dt_either = [ "either" ] # qqq : for Anton : integrate all features of collection_tools into data_type and reuse tests -# dt_type_constructor = [ "type_constructor/enabled" ] -# dt_make = [ "type_constructor/make" ] -# dt_vectorized_from = [ "type_constructor/vectorized_from" ] - -# = entries - -# [lib] -# name = "data_type" -# path = "src/dt/data_type_lib.rs" - -# [[test]] -# name = "data_type_test" -# path = "tests/dt/data_type_tests.rs" -# -# [[test]] -# name = "data_type_smoke_test" -# path = "tests/_integration_test/smoke_test.rs" -# -# [[example]] -# name = "data_type_trivial" -# path = "examples/data_type_trivial/src/main.rs" - [dependencies] ## external either = { version = "~1.6", optional = true } ## internal -# type_constructor = { workspace = true } interval_adapter = { workspace = true } collection_tools = { workspace = true } diff --git a/module/core/data_type/License b/module/core/data_type/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/data_type/License +++ b/module/core/data_type/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/data_type/src/dt.rs b/module/core/data_type/src/dt.rs index 69c9e80518..f384f56072 100644 --- a/module/core/data_type/src/dt.rs +++ b/module/core/data_type/src/dt.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { } diff --git a/module/core/data_type/src/lib.rs b/module/core/data_type/src/lib.rs index 5f16a02ecb..7cdff4fae2 100644 --- a/module/core/data_type/src/lib.rs +++ b/module/core/data_type/src/lib.rs @@ -123,13 +123,13 @@ pub mod prelude pub use crate::dependency::collection_tools::prelude::*; // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - #[ cfg( feature = "dt_prelude" ) ] - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use core:: - { - fmt, - }; + // #[ cfg( feature = "dt_prelude" ) ] + // #[ doc( inline ) ] + // #[ allow( unused_imports ) ] + // pub use core:: + // { + // fmt, + // }; } diff --git a/module/core/derive_tools/Cargo.toml b/module/core/derive_tools/Cargo.toml index 3d8f47c0cc..a2d1e31fb4 100644 --- a/module/core/derive_tools/Cargo.toml +++ b/module/core/derive_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "derive_tools" -version = "0.27.0" +version = "0.32.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -203,7 +203,7 @@ parse-display = { version = "~0.8.2", optional = true, default-features = false ## internal derive_tools_meta = { workspace = true, optional = true, features = [] } variadic_from = { workspace = true, optional = true, features = [] } -clone_dyn = { workspace = true, optional = true, features = [ "clone_dyn_types", "clone_dyn_meta" ] } +clone_dyn = { workspace = true, optional = true, features = [ "clone_dyn_types", "derive_clone_dyn" ] } [dev-dependencies] diff --git a/module/core/derive_tools/License b/module/core/derive_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/derive_tools/License +++ b/module/core/derive_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/derive_tools/src/lib.rs b/module/core/derive_tools/src/lib.rs index 7c3ddfdecf..62468ed1dc 100644 --- a/module/core/derive_tools/src/lib.rs +++ b/module/core/derive_tools/src/lib.rs @@ -144,6 +144,7 @@ pub mod exposed #[ cfg( feature = "derive_strum" ) ] #[ doc( inline ) ] pub use ::strum::*; + // qqq : xxx : name all #[ cfg( any( feature = "derive_variadic_from", feature = "type_variadic_from" ) ) ] #[ doc( inline ) ] @@ -201,3 +202,44 @@ pub mod prelude pub use ::variadic_from::prelude::*; } + +// xxx : minimize dependendencies +// Adding aho-corasick v1.1.3 +// Adding cfg_aliases v0.1.1 (latest: v0.2.1) +// Adding clone_dyn v0.24.0 +// Adding clone_dyn_meta v0.24.0 +// Adding clone_dyn_types v0.23.0 +// Adding collection_tools v0.12.0 +// Adding const_format v0.2.33 +// Adding const_format_proc_macros v0.2.33 +// Adding convert_case v0.6.0 +// Adding derive_more v1.0.0 +// Adding derive_more-impl v1.0.0 +// Adding derive_tools v0.28.0 +// Adding derive_tools_meta v0.27.0 +// Adding either v1.13.0 +// Adding former_types v2.8.0 +// Adding heck v0.4.1 (latest: v0.5.0) +// Adding interval_adapter v0.24.0 +// Adding iter_tools v0.21.0 +// Adding itertools v0.11.0 (latest: v0.13.0) +// Adding macro_tools v0.40.0 +// Adding parse-display v0.8.2 (latest: v0.10.0) +// Adding parse-display-derive v0.8.2 (latest: v0.10.0) +// Adding phf v0.10.1 (latest: v0.11.2) +// Adding phf_generator v0.10.0 (latest: v0.11.2) +// Adding phf_macros v0.10.0 (latest: v0.11.2) +// Adding phf_shared v0.10.0 (latest: v0.11.2) +// Adding proc-macro-hack v0.5.20+deprecated +// Adding regex v1.10.6 +// Adding regex-automata v0.4.7 +// Adding regex-syntax v0.7.5 (latest: v0.8.4) +// Adding regex-syntax v0.8.4 +// Adding rustversion v1.0.17 +// Adding structmeta v0.2.0 (latest: v0.3.0) +// Adding structmeta-derive v0.2.0 (latest: v0.3.0) +// Adding strum v0.25.0 (latest: v0.26.3) +// Adding strum_macros v0.25.3 (latest: v0.26.4) +// Adding unicode-segmentation v1.11.0 +// Adding unicode-xid v0.2.5 +// Adding variadic_from v0.23.0 \ No newline at end of file diff --git a/module/core/derive_tools/tests/inc/new/basic_manual_test.rs b/module/core/derive_tools/tests/inc/new/basic_manual_test.rs index 993956eefa..c7f40395c6 100644 --- a/module/core/derive_tools/tests/inc/new/basic_manual_test.rs +++ b/module/core/derive_tools/tests/inc/new/basic_manual_test.rs @@ -1,15 +1,20 @@ use super::*; -#[ derive( Debug, Clone, Copy, PartialEq ) ] -pub struct IsTransparent( bool ); - -impl IsTransparent +mod mod1 { - #[ inline( always ) ] - fn new( src : bool ) -> Self + + #[ derive( Debug, Clone, Copy, PartialEq ) ] + pub struct Struct1( pub bool ); + + impl Struct1 { - Self( src ) + #[ inline( always ) ] + pub fn new( src : bool ) -> Self + { + Self( src ) + } } + } include!( "./only_test/basic.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/basic_test.rs b/module/core/derive_tools/tests/inc/new/basic_test.rs index 6cea8c5a49..c96850d3de 100644 --- a/module/core/derive_tools/tests/inc/new/basic_test.rs +++ b/module/core/derive_tools/tests/inc/new/basic_test.rs @@ -1,6 +1,10 @@ use super::*; -#[ derive( Debug, Clone, Copy, PartialEq, the_module::New ) ] -pub struct IsTransparent( bool ); +mod mod1 +{ + use super::*; + #[ derive( Debug, Clone, Copy, PartialEq, the_module::New ) ] + pub struct Struct1( pub bool ); +} include!( "./only_test/basic.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/multiple_named_manual_test.rs b/module/core/derive_tools/tests/inc/new/multiple_named_manual_test.rs index 839456b1a0..45a7007502 100644 --- a/module/core/derive_tools/tests/inc/new/multiple_named_manual_test.rs +++ b/module/core/derive_tools/tests/inc/new/multiple_named_manual_test.rs @@ -1,19 +1,24 @@ use super::*; -#[ derive( Debug, PartialEq, Eq ) ] -struct StructNamedFields +mod mod1 { - a : i32, - b : bool, -} -impl StructNamedFields -{ - #[ inline( always ) ] - fn new( a : i32, b : bool ) -> Self + #[ derive( Debug, PartialEq, Eq ) ] + pub struct Struct1 + { + pub a : i32, + pub b : bool, + } + + impl Struct1 { - Self{ a, b } + #[ inline( always ) ] + pub fn new( a : i32, b : bool ) -> Self + { + Self{ a, b } + } } + } include!( "./only_test/multiple_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/multiple_named_test.rs b/module/core/derive_tools/tests/inc/new/multiple_named_test.rs index c3988146df..3e148771eb 100644 --- a/module/core/derive_tools/tests/inc/new/multiple_named_test.rs +++ b/module/core/derive_tools/tests/inc/new/multiple_named_test.rs @@ -1,11 +1,17 @@ use super::*; -#[ derive( Debug, PartialEq, Eq, the_module::New ) ] -// #[ debug ] -struct StructNamedFields +mod mod1 { - a : i32, - b : bool, + use super::*; + + #[ derive( Debug, PartialEq, Eq, the_module::New ) ] + // #[ debug ] + pub struct Struct1 + { + pub a : i32, + pub b : bool, + } + } include!( "./only_test/multiple_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/multiple_unnamed_manual_test.rs b/module/core/derive_tools/tests/inc/new/multiple_unnamed_manual_test.rs index 08ee277851..bed9e79851 100644 --- a/module/core/derive_tools/tests/inc/new/multiple_unnamed_manual_test.rs +++ b/module/core/derive_tools/tests/inc/new/multiple_unnamed_manual_test.rs @@ -1,15 +1,20 @@ use super::*; -#[ derive( Debug, PartialEq, Eq ) ] -struct StructWithManyFields( i32, bool ); - -impl StructWithManyFields +mod mod1 { - #[ inline( always ) ] - fn new( src1 : i32, src2 : bool ) -> Self + + #[ derive( Debug, PartialEq, Eq ) ] + pub struct Struct1( pub i32, pub bool ); + + impl Struct1 { - Self( src1, src2 ) + #[ inline( always ) ] + pub fn new( src1 : i32, src2 : bool ) -> Self + { + Self( src1, src2 ) + } } + } include!( "./only_test/multiple_unnamed.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/multiple_unnamed_test.rs b/module/core/derive_tools/tests/inc/new/multiple_unnamed_test.rs index 6a8f882287..8df3f37489 100644 --- a/module/core/derive_tools/tests/inc/new/multiple_unnamed_test.rs +++ b/module/core/derive_tools/tests/inc/new/multiple_unnamed_test.rs @@ -1,6 +1,12 @@ use super::*; -#[ derive( Debug, PartialEq, Eq, the_module::New ) ] -struct StructWithManyFields( i32, bool ); +mod mod1 +{ + use super::*; + + #[ derive( Debug, PartialEq, Eq, the_module::New ) ] + pub struct Struct1( pub i32, pub bool ); + +} include!( "./only_test/multiple_unnamed.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/named_manual_test.rs b/module/core/derive_tools/tests/inc/new/named_manual_test.rs index 679afeec66..56f656a1c9 100644 --- a/module/core/derive_tools/tests/inc/new/named_manual_test.rs +++ b/module/core/derive_tools/tests/inc/new/named_manual_test.rs @@ -1,18 +1,23 @@ use super::*; -#[ derive( Debug, PartialEq, Eq ) ] -struct MyStruct +mod mod1 { - a : i32, -} -impl MyStruct -{ - #[ inline( always ) ] - fn new( src : i32 ) -> Self + #[ derive( Debug, PartialEq, Eq ) ] + pub struct Struct1 + { + pub a : i32, + } + + impl Struct1 { - Self{ a : src } + #[ inline( always ) ] + pub fn new( src : i32 ) -> Self + { + Self{ a : src } + } } + } include!( "./only_test/named.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/named_test.rs b/module/core/derive_tools/tests/inc/new/named_test.rs index 1df964f76f..66d8fd8ac0 100644 --- a/module/core/derive_tools/tests/inc/new/named_test.rs +++ b/module/core/derive_tools/tests/inc/new/named_test.rs @@ -1,9 +1,15 @@ use super::*; -#[ derive( Debug, PartialEq, Eq, the_module::New ) ] -struct MyStruct +mod mod1 { - a : i32, + use super::*; + + #[ derive( Debug, PartialEq, Eq, the_module::New ) ] + pub struct Struct1 + { + pub a : i32, + } + } include!( "./only_test/named.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/only_test/basic.rs b/module/core/derive_tools/tests/inc/new/only_test/basic.rs index 7dadc915f2..cfaf3127df 100644 --- a/module/core/derive_tools/tests/inc/new/only_test/basic.rs +++ b/module/core/derive_tools/tests/inc/new/only_test/basic.rs @@ -2,12 +2,13 @@ #[ test ] fn from_test() { + use mod1::Struct1; - let got = IsTransparent::new( true ); - let exp = IsTransparent( true ); + let got = Struct1::new( true ); + let exp = Struct1( true ); a_id!( got, exp ); - let got = IsTransparent::new( false ); - let exp = IsTransparent( false ); + let got = Struct1::new( false ); + let exp = Struct1( false ); a_id!( got, exp ); } diff --git a/module/core/derive_tools/tests/inc/new/only_test/multiple_named.rs b/module/core/derive_tools/tests/inc/new/only_test/multiple_named.rs index eebdbba992..adf93b4c93 100644 --- a/module/core/derive_tools/tests/inc/new/only_test/multiple_named.rs +++ b/module/core/derive_tools/tests/inc/new/only_test/multiple_named.rs @@ -1,7 +1,9 @@ #[ test ] fn from_named() { - let got : StructNamedFields = StructNamedFields::new( 10, true ); - let exp = StructNamedFields{ a : 10 , b : true }; + use mod1::Struct1; + + let got : Struct1 = Struct1::new( 10, true ); + let exp = Struct1{ a : 10 , b : true }; a_id!( got, exp ); } diff --git a/module/core/derive_tools/tests/inc/new/only_test/multiple_unnamed.rs b/module/core/derive_tools/tests/inc/new/only_test/multiple_unnamed.rs index 94abf3c133..f8d960c898 100644 --- a/module/core/derive_tools/tests/inc/new/only_test/multiple_unnamed.rs +++ b/module/core/derive_tools/tests/inc/new/only_test/multiple_unnamed.rs @@ -1,7 +1,9 @@ #[ test ] fn from_named() { - let got : StructWithManyFields = StructWithManyFields::new( 10, true ); - let exp = StructWithManyFields( 10 , true ); + use mod1::Struct1; + + let got : Struct1 = Struct1::new( 10, true ); + let exp = Struct1( 10 , true ); a_id!( got, exp ); } diff --git a/module/core/derive_tools/tests/inc/new/only_test/named.rs b/module/core/derive_tools/tests/inc/new/only_test/named.rs index b654961735..71804413ce 100644 --- a/module/core/derive_tools/tests/inc/new/only_test/named.rs +++ b/module/core/derive_tools/tests/inc/new/only_test/named.rs @@ -1,7 +1,9 @@ #[ test ] fn from_named() { - let got : MyStruct = MyStruct::new( 13 ); - let exp = MyStruct { a : 13 }; + use mod1::Struct1; + + let got : Struct1 = Struct1::new( 13 ); + let exp = Struct1 { a : 13 }; a_id!( got, exp ); } diff --git a/module/core/derive_tools/tests/inc/new/only_test/unit.rs b/module/core/derive_tools/tests/inc/new/only_test/unit.rs index 279908a05d..9366152172 100644 --- a/module/core/derive_tools/tests/inc/new/only_test/unit.rs +++ b/module/core/derive_tools/tests/inc/new/only_test/unit.rs @@ -1,7 +1,9 @@ #[ test ] fn from_named() { - let got : UnitStruct = UnitStruct::new(); - let exp = UnitStruct; + use mod1::Struct1; + + let got : Struct1 = Struct1::new(); + let exp = Struct1; a_id!( got, exp ); } diff --git a/module/core/derive_tools/tests/inc/new/unit_manual_test.rs b/module/core/derive_tools/tests/inc/new/unit_manual_test.rs index d5fc60e6c5..2d04912112 100644 --- a/module/core/derive_tools/tests/inc/new/unit_manual_test.rs +++ b/module/core/derive_tools/tests/inc/new/unit_manual_test.rs @@ -1,15 +1,20 @@ use super::*; -#[ derive( Debug, Clone, Copy, PartialEq ) ] -struct UnitStruct; - -impl UnitStruct +mod mod1 { - #[ inline( always ) ] - fn new() -> Self + + #[ derive( Debug, Clone, Copy, PartialEq ) ] + pub struct Struct1; + + impl Struct1 { - Self + #[ inline( always ) ] + pub fn new() -> Self + { + Self + } } + } include!( "./only_test/unit.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/unit_test.rs b/module/core/derive_tools/tests/inc/new/unit_test.rs index 606df185d8..4e40c31a0e 100644 --- a/module/core/derive_tools/tests/inc/new/unit_test.rs +++ b/module/core/derive_tools/tests/inc/new/unit_test.rs @@ -1,6 +1,12 @@ use super::*; -#[ derive( Debug, Clone, Copy, PartialEq, the_module::New ) ] -struct UnitStruct; +mod mod1 +{ + use super::*; + + #[ derive( Debug, Clone, Copy, PartialEq, the_module::New ) ] + pub struct Struct1; + +} include!( "./only_test/unit.rs" ); diff --git a/module/core/derive_tools_meta/Cargo.toml b/module/core/derive_tools_meta/Cargo.toml index 3ab4e3998c..ce3e0ce395 100644 --- a/module/core/derive_tools_meta/Cargo.toml +++ b/module/core/derive_tools_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "derive_tools_meta" -version = "0.26.0" +version = "0.31.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/derive_tools_meta/License b/module/core/derive_tools_meta/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/derive_tools_meta/License +++ b/module/core/derive_tools_meta/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/derive_tools_meta/src/derive/new.rs b/module/core/derive_tools_meta/src/derive/new.rs index 2f0341c159..5e274c3eb1 100644 --- a/module/core/derive_tools_meta/src/derive/new.rs +++ b/module/core/derive_tools_meta/src/derive/new.rs @@ -145,7 +145,7 @@ fn generate_unit #generics_where { #[ inline( always ) ] - fn new() -> Self + pub fn new() -> Self { Self } @@ -175,8 +175,8 @@ fn generate_single_field_named #generics_where { #[ inline( always ) ] - // fn new( src : i32 ) -> Self - fn new( src : #field_type ) -> Self + // pub fn new( src : i32 ) -> Self + pub fn new( src : #field_type ) -> Self { // Self { a : src } Self { #field_name: src } @@ -207,8 +207,8 @@ fn generate_single_field #generics_where { #[ inline( always ) ] - // fn new( src : bool ) -> Self - fn new( src : #field_type ) -> Self + // pub fn new( src : bool ) -> Self + pub fn new( src : #field_type ) -> Self { // Self( src ) Self( src ) @@ -248,8 +248,8 @@ fn generate_multiple_fields_named< 'a > #generics_where { #[ inline( always ) ] - // fn new( src : ( i32, bool ) ) -> Self - fn new( #( #val_type ),* ) -> Self + // pub fn new( src : ( i32, bool ) ) -> Self + pub fn new( #( #val_type ),* ) -> Self { // StructNamedFields{ a : src.0, b : src.1 } #item_name { #( #field_names ),* } @@ -287,8 +287,8 @@ fn generate_multiple_fields< 'a > #generics_where { #[ inline( always ) ] - // fn new( src : (i32, bool) ) -> Self - fn new( src : ( #( #field_types ),* ) ) -> Self + // pub fn new( src : (i32, bool) ) -> Self + pub fn new( src : ( #( #field_types ),* ) ) -> Self { // StructWithManyFields( src.0, src.1 ) #item_name( #( #params ),* ) @@ -359,7 +359,7 @@ where {2} {{ #[ inline ] - fn new( src : {args} ) -> Self + pub fn new( src : {args} ) -> Self {{ Self::{variant_name}( {use_src} ) }} @@ -388,7 +388,7 @@ field : {variant_name}"#, #generics_where { #[ inline ] - fn new( src : #args ) -> Self + pub fn new( src : #args ) -> Self { Self::#variant_name( #use_src ) } diff --git a/module/core/diagnostics_tools/Cargo.toml b/module/core/diagnostics_tools/Cargo.toml index c2b7d7e994..6b48adc190 100644 --- a/module/core/diagnostics_tools/Cargo.toml +++ b/module/core/diagnostics_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "diagnostics_tools" -version = "0.8.0" +version = "0.10.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/diagnostics_tools/License b/module/core/diagnostics_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/diagnostics_tools/License +++ b/module/core/diagnostics_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/diagnostics_tools/src/diag/rta.rs b/module/core/diagnostics_tools/src/diag/rta.rs index 27f8d991ec..4bd27b3bba 100644 --- a/module/core/diagnostics_tools/src/diag/rta.rs +++ b/module/core/diagnostics_tools/src/diag/rta.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { @@ -289,4 +289,3 @@ pub mod prelude }; } - diff --git a/module/core/diagnostics_tools/src/lib.rs b/module/core/diagnostics_tools/src/lib.rs index a3415c710e..8ed4ccb486 100644 --- a/module/core/diagnostics_tools/src/lib.rs +++ b/module/core/diagnostics_tools/src/lib.rs @@ -31,7 +31,6 @@ pub mod own #[ doc( inline ) ] pub use orphan::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::diag::orphan::*; } @@ -54,7 +53,6 @@ pub mod exposed #[ doc( inline ) ] pub use prelude::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::diag::exposed::*; } @@ -65,6 +63,5 @@ pub mod prelude { use super::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::diag::prelude::*; } diff --git a/module/core/error_tools/Cargo.toml b/module/core/error_tools/Cargo.toml index 1ea9fe9535..dafae99166 100644 --- a/module/core/error_tools/Cargo.toml +++ b/module/core/error_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "error_tools" -version = "0.16.0" +version = "0.19.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -48,8 +48,9 @@ error_untyped = [ "anyhow" ] # = entry [dependencies] -anyhow = { version = "~1.0", optional = true } -thiserror = { version = "~1.0", optional = true } +anyhow = { workspace = true, optional = true } +thiserror = { workspace = true, optional = true } [dev-dependencies] test_tools = { workspace = true } +# xxx : qqq : review \ No newline at end of file diff --git a/module/core/error_tools/License b/module/core/error_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/error_tools/License +++ b/module/core/error_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/error_tools/examples/error_tools_trivial.rs b/module/core/error_tools/examples/error_tools_trivial.rs index cc6fc29f24..e6ddd65432 100644 --- a/module/core/error_tools/examples/error_tools_trivial.rs +++ b/module/core/error_tools/examples/error_tools_trivial.rs @@ -17,5 +17,5 @@ fn main() fn f1() -> error_tools::untyped::Result< () > { let _read = std::fs::read_to_string( "Cargo.toml" )?; - Err( error_tools::BasicError::new( "Some error" ).into() ) + Err( error_tools::untyped::format_err!( "Some error" ) ) } diff --git a/module/core/error_tools/src/assert.rs b/module/core/error_tools/src/error/assert.rs similarity index 98% rename from module/core/error_tools/src/assert.rs rename to module/core/error_tools/src/error/assert.rs index 50c72b0bdf..52f45d29bf 100644 --- a/module/core/error_tools/src/assert.rs +++ b/module/core/error_tools/src/error/assert.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { /// diff --git a/module/core/error_tools/src/error.rs b/module/core/error_tools/src/error/mod.rs similarity index 54% rename from module/core/error_tools/src/error.rs rename to module/core/error_tools/src/error/mod.rs index 730f9c477c..4d9c79ddaa 100644 --- a/module/core/error_tools/src/error.rs +++ b/module/core/error_tools/src/error/mod.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { pub use std::error::Error as ErrorTrait; @@ -96,132 +96,178 @@ mod private /// helps in defining such results more concisely. pub type ResultWithReport< Report, Error > = Result< Report, ( Report, Error ) >; - /// - /// Macro to generate an error descriptor. - /// - /// ### Basic use-case. - /// ```rust - /// # use error_tools::{ BasicError, err }; - /// fn f1() -> BasicError - /// { - /// return err!( "No attr" ); - /// } - /// ``` - /// - - #[ macro_export ] - macro_rules! err - { - - ( $msg : expr ) => - { - $crate::BasicError::new( $msg ).into() - }; - ( $msg : expr, $( $arg : expr ),+ $(,)? ) => - { - $crate::BasicError::new( format!( $msg, $( $arg ),+ ) ).into() - }; - - } - - /// - /// Macro to return an Err( error ) generating error descriptor. - /// - /// ### Basic use-case. - /// ```rust - /// # use error_tools::{ BasicError, return_err }; - /// fn f1() -> Result< (), BasicError > - /// { - /// return_err!( "No attr" ); - /// } - /// ``` - /// - - #[ macro_export ] - macro_rules! return_err - { - - ( $msg : expr ) => - { - return Result::Err( $crate::err!( $msg ) ) - }; - ( $msg : expr, $( $arg : expr ),+ $(,)? ) => - { - return Result::Err( $crate::err!( $msg, $( $arg ),+ ) ) - }; - - } - - // zzz : review - - /// baic implementation of generic BasicError - - #[ derive( core::fmt::Debug, core::clone::Clone, core::cmp::PartialEq, core::cmp::Eq ) ] - pub struct BasicError - { - msg : String, - } - - impl BasicError - { - /// Constructor expecting message with description. - pub fn new< Msg : Into< String > >( msg : Msg ) -> BasicError - { - BasicError { msg : msg.into() } - } - /// Message with description getter. - pub fn msg( &self ) -> &String - { - &self.msg - } - } +// /// +// /// Macro to generate an error descriptor. +// /// +// /// ### Basic use-case. +// /// ```rust +// /// # use error_tools::{ BasicError, err }; +// /// fn f1() -> BasicError +// /// { +// /// return err!( "No attr" ); +// /// } +// /// ``` +// /// +// +// #[ macro_export ] +// macro_rules! err +// { +// +// ( $msg : expr ) => +// { +// $crate::BasicError::new( $msg ).into() +// }; +// ( $msg : expr, $( $arg : expr ),+ $(,)? ) => +// { +// $crate::BasicError::new( format!( $msg, $( $arg ),+ ) ).into() +// }; +// +// } +// +// /// +// /// Macro to return an Err( error ) generating error descriptor. +// /// +// /// ### Basic use-case. +// /// ```rust +// /// # use error_tools::{ BasicError, return_err }; +// /// fn f1() -> Result< (), BasicError > +// /// { +// /// return_err!( "No attr" ); +// /// } +// /// ``` +// /// +// +// #[ macro_export ] +// macro_rules! return_err +// { +// +// ( $msg : expr ) => +// { +// return Result::Err( $crate::err!( $msg ) ) +// }; +// ( $msg : expr, $( $arg : expr ),+ $(,)? ) => +// { +// return Result::Err( $crate::err!( $msg, $( $arg ),+ ) ) +// }; +// +// } +// +// // zzz : review +// // xxx : rid of +// +// /// baic implementation of generic BasicError +// +// #[ derive( core::fmt::Debug, core::clone::Clone, core::cmp::PartialEq, core::cmp::Eq ) ] +// pub struct BasicError +// { +// msg : String, +// } +// +// impl BasicError +// { +// /// Constructor expecting message with description. +// pub fn new< Msg : Into< String > >( msg : Msg ) -> BasicError +// { +// BasicError { msg : msg.into() } +// } +// /// Message with description getter. +// pub fn msg( &self ) -> &String +// { +// &self.msg +// } +// } +// +// impl core::fmt::Display for BasicError +// { +// fn fmt(&self, f: &mut core::fmt::Formatter< '_ >) -> core::fmt::Result +// { +// write!( f, "{}", self.msg ) +// } +// } +// +// impl ErrorTrait for BasicError +// { +// fn description( &self ) -> &str +// { +// &self.msg +// } +// } +// +// impl< T > From< BasicError > for Result< T, BasicError > +// { +// /// Returns the argument unchanged. +// #[ inline( always ) ] +// fn from( src : BasicError ) -> Self +// { +// Result::Err( src ) +// } +// } +// +// pub use err; +// pub use return_err; - impl core::fmt::Display for BasicError - { - fn fmt(&self, f: &mut core::fmt::Formatter< '_ >) -> core::fmt::Result - { - write!( f, "{}", self.msg ) - } - } - - impl ErrorTrait for BasicError - { - fn description( &self ) -> &str - { - &self.msg - } - } + // qqq : write standard mod interface without using mod_interface /* aaa : Dmytro : added to each library file */ +} - impl< T > From< BasicError > for Result< T, BasicError > - { - /// Returns the argument unchanged. - #[ inline( always ) ] - fn from( src : BasicError ) -> Self - { - Result::Err( src ) - } - } +/// Assertions. +#[ cfg( feature = "enabled" ) ] +pub mod assert; - pub use err; - pub use return_err; +#[ cfg( feature = "enabled" ) ] +#[ cfg( feature = "error_typed" ) ] +/// Typed exceptions handling mechanism. +pub mod typed; - // qqq : write standard mod interface without using mod_interface /* aaa : Dmytro : added to each library file */ -} +#[ cfg( feature = "enabled" ) ] +#[ cfg( feature = "error_untyped" ) ] +/// Untyped exceptions handling mechanism. +pub mod untyped; +#[ cfg( feature = "enabled" ) ] #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use own::*; /// Own namespace of the module. +#[ cfg( feature = "enabled" ) ] #[ allow( unused_imports ) ] pub mod own { use super::*; + #[ doc( inline ) ] pub use orphan::*; + + #[ doc( inline ) ] + pub use assert::orphan::*; + + #[ cfg( feature = "error_untyped" ) ] + #[ doc( inline ) ] + pub use untyped::orphan::*; + + #[ cfg( feature = "error_typed" ) ] + #[ doc( inline ) ] + pub use typed::orphan::*; + + #[ doc( inline ) ] + pub use private:: + { + // err, + // return_err, + ErrorTrait, + // BasicError, + }; + + pub use super::assert; + #[ cfg( feature = "error_typed" ) ] + pub use super::typed; + #[ cfg( feature = "error_untyped" ) ] + pub use super::untyped; + } /// Shared with parent namespace of the module +#[ cfg( feature = "enabled" ) ] #[ allow( unused_imports ) ] pub mod orphan { @@ -231,11 +277,18 @@ pub mod orphan } /// Exposed namespace of the module. +#[ cfg( feature = "enabled" ) ] #[ allow( unused_imports ) ] pub mod exposed { use super::*; + #[ doc( inline ) ] + pub use prelude::*; + + // Expose itself. + pub use super::super::error; + #[ doc( inline ) ] pub use private:: { @@ -244,22 +297,43 @@ pub mod exposed }; #[ doc( inline ) ] - pub use prelude::*; + pub use assert::exposed::*; + + #[ cfg( feature = "error_untyped" ) ] + #[ doc( inline ) ] + pub use untyped::exposed::*; + + #[ cfg( feature = "error_typed" ) ] + #[ doc( inline ) ] + pub use typed::exposed::*; + } /// Prelude to use essentials: `use my_module::prelude::*`. +#[ cfg( feature = "enabled" ) ] #[ allow( unused_imports ) ] pub mod prelude { use super::*; + // #[ doc( inline ) ] + // pub use private:: + // { + // // err, + // // return_err, + // ErrorTrait, + // // BasicError, + // }; + #[ doc( inline ) ] - pub use private:: - { - err, - return_err, - ErrorTrait, - BasicError, - }; + pub use assert::prelude::*; + + #[ cfg( feature = "error_untyped" ) ] + #[ doc( inline ) ] + pub use untyped::prelude::*; + + #[ cfg( feature = "error_typed" ) ] + #[ doc( inline ) ] + pub use typed::prelude::*; } diff --git a/module/core/error_tools/src/typed.rs b/module/core/error_tools/src/error/typed.rs similarity index 94% rename from module/core/error_tools/src/typed.rs rename to module/core/error_tools/src/error/typed.rs index e4e341a586..074fb5b61a 100644 --- a/module/core/error_tools/src/typed.rs +++ b/module/core/error_tools/src/error/typed.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/core/error_tools/src/untyped.rs b/module/core/error_tools/src/error/untyped.rs similarity index 82% rename from module/core/error_tools/src/untyped.rs rename to module/core/error_tools/src/error/untyped.rs index df16162bab..8288f32866 100644 --- a/module/core/error_tools/src/untyped.rs +++ b/module/core/error_tools/src/error/untyped.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { @@ -13,6 +13,7 @@ pub use own::*; pub mod own { use super::*; + #[ doc( inline ) ] pub use orphan::*; @@ -24,6 +25,10 @@ pub mod own Error, Ok, Result, + format_err, + bail as return_err, + ensure, + bail, }; } @@ -39,13 +44,13 @@ pub mod orphan #[ doc( inline ) ] pub use exposed::*; - #[ doc( inline ) ] - pub use ::anyhow:: - { - format_err, - ensure, - bail, - }; + // #[ doc( inline ) ] + // pub use ::anyhow:: + // { + // format_err, + // ensure, + // bail, + // }; } diff --git a/module/core/error_tools/src/lib.rs b/module/core/error_tools/src/lib.rs index 30a25af03b..9ba2500d42 100644 --- a/module/core/error_tools/src/lib.rs +++ b/module/core/error_tools/src/lib.rs @@ -4,10 +4,6 @@ #![ doc( html_root_url = "https://docs.rs/error_tools/latest/error_tools/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -/// Assertions. -#[ cfg( feature = "enabled" ) ] -pub mod assert; - /// Alias for std::error::BasicError. #[ cfg( feature = "enabled" ) ] #[ cfg( not( feature = "no_std" ) ) ] @@ -19,27 +15,15 @@ pub mod dependency { #[ doc( inline ) ] - #[ allow( unused_imports ) ] #[ cfg( feature = "error_typed" ) ] pub use ::thiserror; #[ doc( inline ) ] - #[ allow( unused_imports ) ] #[ cfg( feature = "error_untyped" ) ] pub use ::anyhow; } -#[ cfg( feature = "enabled" ) ] -#[ cfg( feature = "error_typed" ) ] -/// Typed exceptions handling mechanism. -pub mod typed; - -#[ cfg( feature = "enabled" ) ] -#[ cfg( feature = "error_untyped" ) ] -/// Untyped exceptions handling mechanism. -pub mod untyped; - #[ cfg( feature = "enabled" ) ] #[ doc( inline ) ] #[ allow( unused_imports ) ] @@ -51,27 +35,9 @@ pub use own::*; pub mod own { use super::*; - #[ allow( unused_imports ) ] - use super::*; - - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use assert::orphan::*; - #[ cfg( not( feature = "no_std" ) ) ] #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use error::orphan::*; - - #[ cfg( feature = "error_untyped" ) ] - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use untyped::orphan::*; - - #[ cfg( feature = "error_typed" ) ] - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use typed::orphan::*; + pub use error::own::*; } @@ -85,6 +51,9 @@ pub mod orphan #[ doc( inline ) ] pub use exposed::*; + #[ doc( inline ) ] + pub use error::orphan::*; + } /// Exposed namespace of the module. @@ -95,28 +64,11 @@ pub mod exposed use super::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use prelude::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use assert::exposed::*; - - #[ cfg( not( feature = "no_std" ) ) ] - #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use error::exposed::*; - #[ cfg( feature = "error_untyped" ) ] - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use untyped::exposed::*; - - #[ cfg( feature = "error_typed" ) ] - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use typed::exposed::*; - } /// Prelude to use essentials: `use my_module::prelude::*`. @@ -125,26 +77,8 @@ pub mod exposed pub mod prelude { use super::*; - #[ allow( unused_imports ) ] - use super::*; - - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use assert::prelude::*; - #[ cfg( not( feature = "no_std" ) ) ] #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use error::prelude::*; - #[ cfg( feature = "error_untyped" ) ] - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use untyped::prelude::*; - - #[ cfg( feature = "error_typed" ) ] - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use typed::prelude::*; - } diff --git a/module/core/error_tools/src/result.rs b/module/core/error_tools/src/result.rs deleted file mode 100644 index ea5a3c3b48..0000000000 --- a/module/core/error_tools/src/result.rs +++ /dev/null @@ -1,43 +0,0 @@ -// /// Internal namespace. -// mod private -// { -// use crate::error::BasicError; -// -// /// Type alias for Result with BasicError. -// pub type Result< T, E = BasicError > = std::result::Result< T, E >; -// } -// -// /// Own namespace of the module. -// pub mod own -// { -// #[ doc( inline ) ] -// #[ allow( unused_imports ) ] -// pub use orphan::*; -// } -// -// #[ doc( inline ) ] -// #[ allow( unused_imports ) ] -// pub use own::*; -// -// /// Shared with parent namespace of the module -// pub mod orphan -// { -// #[ doc( inline ) ] -// #[ allow( unused_imports ) ] -// pub use exposed::*; -// } -// -// /// Exposed namespace of the module. -// pub mod exposed -// { -// #[ doc( inline ) ] -// #[ allow( unused_imports ) ] -// pub use prelude::*; -// } -// -// /// Prelude to use essentials: `use my_module::prelude::*`. -// pub mod prelude -// { -// pub use private::Result; -// } -// diff --git a/module/core/error_tools/tests/inc/basic_test.rs b/module/core/error_tools/tests/inc/basic_test.rs index 61462b17f9..32cb4c4bba 100644 --- a/module/core/error_tools/tests/inc/basic_test.rs +++ b/module/core/error_tools/tests/inc/basic_test.rs @@ -1,5 +1,5 @@ #![ allow( deprecated ) ] -#![ allow( unused_imports ) ] +// #![ allow( unused_imports ) ] use super::*; // @@ -7,117 +7,116 @@ use super::*; #[ cfg( not( feature = "no_std" ) ) ] tests_impls! { - fn basic() - { - use std::error::Error; - - // test.case( "basic" ); - - let err1 = the_module::BasicError::new( "Some error" ); - a_id!( err1.to_string(), "Some error" ); - a_id!( err1.description(), "Some error" ); - a_id!( err1.msg(), "Some error" ); - a_id!( format!( "err1 : {}", err1 ), "err1 : Some error" ); - - // test.case( "compare" ); - - let err1 = the_module::BasicError::new( "Some error" ); - let err2 = the_module::BasicError::new( "Some error" ); - a_id!( err1, err2 ); - a_id!( err1.description(), err2.description() ); - - // test.case( "clone" ); - - let err1 = the_module::BasicError::new( "Some error" ); - let err2 = err1.clone(); - a_id!( err1, err2 ); - a_id!( err1.description(), err2.description() ); - } - - // - - fn use1() - { - use std::error::Error as ErrorTrait; - use the_module::BasicError as Error; - - // test.case( "basic" ); - - let err1 = Error::new( "Some error" ); - a_id!( err1.to_string(), "Some error" ); - a_id!( err1.description(), "Some error" ); - a_id!( err1.msg(), "Some error" ); - a_id!( format!( "err1 : {}", err1 ), "err1 : Some error" ); - } - - // - - fn use2() - { - use the_module::{ BasicError, ErrorTrait }; - - // test.case( "basic" ); - - let err1 = BasicError::new( "Some error" ); - a_id!( err1.to_string(), "Some error" ); - a_id!( err1.description(), "Some error" ); - a_id!( err1.msg(), "Some error" ); - a_id!( format!( "err1 : {}", err1 ), "err1 : Some error" ); - } - - // - - fn use3() - { - use std::error::Error; - - // test.case( "basic" ); - - let err1 = the_module::BasicError::new( "Some error" ); - a_id!( err1.to_string(), "Some error" ); - a_id!( err1.description(), "Some error" ); - a_id!( err1.msg(), "Some error" ); - a_id!( format!( "err1 : {}", err1 ), "err1 : Some error" ); - } - - // - - fn err_basic() - { - // test.case( "basic" ); - let err : the_module::BasicError = the_module::err!( "abc" ); - a_id!( err.to_string(), "abc" ); - - // test.case( "with args" ); - let err : the_module::BasicError = the_module::err!( "abc{}{}", "def", "ghi" ); - a_id!( err.to_string(), "abcdefghi" ); - } +// fn basic() +// { +// use std::error::Error; +// +// // test.case( "basic" ); +// +// let err1 = the_module::BasicError::new( "Some error" ); +// a_id!( err1.to_string(), "Some error" ); +// a_id!( err1.description(), "Some error" ); +// a_id!( err1.msg(), "Some error" ); +// a_id!( format!( "err1 : {}", err1 ), "err1 : Some error" ); +// +// // test.case( "compare" ); +// +// let err1 = the_module::BasicError::new( "Some error" ); +// let err2 = the_module::BasicError::new( "Some error" ); +// a_id!( err1, err2 ); +// a_id!( err1.description(), err2.description() ); +// +// // test.case( "clone" ); +// +// let err1 = the_module::BasicError::new( "Some error" ); +// let err2 = err1.clone(); +// a_id!( err1, err2 ); +// a_id!( err1.description(), err2.description() ); +// } // - fn sample() - { - #[ cfg( not( feature = "no_std" ) ) ] - fn f1() -> the_module::untyped::Result< () > - { - let _read = std::fs::read_to_string( "Cargo.toml" )?; - Err( the_module::BasicError::new( "Some error" ).into() ) - // the_module::BasicError::new( "Some error" ).into() - // zzz : make it working maybe - } - - #[ cfg( not( feature = "no_std" ) ) ] - { - let err = f1(); - println!( "{err:#?}" ); - // < Err( - // < BasicError { - // < msg: "Some error", - // < }, - // < ) - } - } - +// fn use1() +// { +// use std::error::Error as ErrorTrait; +// use the_module::BasicError as Error; +// +// // test.case( "basic" ); +// +// let err1 = Error::new( "Some error" ); +// a_id!( err1.to_string(), "Some error" ); +// a_id!( err1.description(), "Some error" ); +// a_id!( err1.msg(), "Some error" ); +// a_id!( format!( "err1 : {}", err1 ), "err1 : Some error" ); +// } +// +// // +// +// fn use2() +// { +// use the_module::{ BasicError, ErrorTrait }; +// +// // test.case( "basic" ); +// +// let err1 = BasicError::new( "Some error" ); +// a_id!( err1.to_string(), "Some error" ); +// a_id!( err1.description(), "Some error" ); +// a_id!( err1.msg(), "Some error" ); +// a_id!( format!( "err1 : {}", err1 ), "err1 : Some error" ); +// } +// +// // +// +// fn use3() +// { +// use std::error::Error; +// +// // test.case( "basic" ); +// +// let err1 = the_module::BasicError::new( "Some error" ); +// a_id!( err1.to_string(), "Some error" ); +// a_id!( err1.description(), "Some error" ); +// a_id!( err1.msg(), "Some error" ); +// a_id!( format!( "err1 : {}", err1 ), "err1 : Some error" ); +// } +// +// // +// +// fn err_basic() +// { +// // test.case( "basic" ); +// let err : the_module::BasicError = the_module::err!( "abc" ); +// a_id!( err.to_string(), "abc" ); +// +// // test.case( "with args" ); +// let err : the_module::BasicError = the_module::err!( "abc{}{}", "def", "ghi" ); +// a_id!( err.to_string(), "abcdefghi" ); +// } +// +// // +// +// fn sample() +// { +// #[ cfg( not( feature = "no_std" ) ) ] +// fn f1() -> the_module::untyped::Result< () > +// { +// let _read = std::fs::read_to_string( "Cargo.toml" )?; +// Err( the_module::BasicError::new( "Some error" ).into() ) +// // the_module::BasicError::new( "Some error" ).into() +// // zzz : make it working maybe +// } +// +// #[ cfg( not( feature = "no_std" ) ) ] +// { +// let err = f1(); +// println!( "{err:#?}" ); +// // < Err( +// // < BasicError { +// // < msg: "Some error", +// // < }, +// // < ) +// } +// } } @@ -126,10 +125,10 @@ tests_impls! #[ cfg( not( feature = "no_std" ) ) ] tests_index! { - basic, - use1, - use2, - use3, - err_basic, - sample, + // basic, + // use1, + // use2, + // use3, + // err_basic, + // sample, } diff --git a/module/core/error_tools/tests/inc/mod.rs b/module/core/error_tools/tests/inc/mod.rs index 256c6e20bd..dc239e680e 100644 --- a/module/core/error_tools/tests/inc/mod.rs +++ b/module/core/error_tools/tests/inc/mod.rs @@ -1,8 +1,10 @@ #[ allow( unused_imports ) ] use super::*; -mod assert_test; mod basic_test; +mod namespace_test; + +mod assert_test; #[ cfg( not( feature = "no_std" ) ) ] mod err_with_test; mod untyped_test; diff --git a/module/core/error_tools/tests/inc/namespace_test.rs b/module/core/error_tools/tests/inc/namespace_test.rs new file mode 100644 index 0000000000..92e96b0610 --- /dev/null +++ b/module/core/error_tools/tests/inc/namespace_test.rs @@ -0,0 +1,12 @@ +use super::*; + +#[ test ] +fn exposed_main_namespace() +{ + + the_module::error::debug_assert_id!( 1, 1 ); + the_module::exposed::error::debug_assert_id!( 1, 1 ); + use the_module::exposed::*; + error::debug_assert_id!( 1, 1 ); + +} \ No newline at end of file diff --git a/module/core/error_tools/tests/tests.rs b/module/core/error_tools/tests/tests.rs index 0374c10521..f217bd0119 100644 --- a/module/core/error_tools/tests/tests.rs +++ b/module/core/error_tools/tests/tests.rs @@ -1,7 +1,6 @@ +#![ allow( unused_imports ) ] -#[ allow( unused_imports ) ] use error_tools as the_module; -#[ allow( unused_imports ) ] use test_tools::exposed::*; mod inc; diff --git a/module/core/for_each/Cargo.toml b/module/core/for_each/Cargo.toml index 877ccbe184..2e43d14153 100644 --- a/module/core/for_each/Cargo.toml +++ b/module/core/for_each/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "for_each" -version = "0.8.0" +version = "0.10.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/for_each/License b/module/core/for_each/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/for_each/License +++ b/module/core/for_each/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/for_each/src/lib.rs b/module/core/for_each/src/lib.rs index b106a5110b..00825e5b96 100644 --- a/module/core/for_each/src/lib.rs +++ b/module/core/for_each/src/lib.rs @@ -4,7 +4,7 @@ #![ doc( html_root_url = "https://docs.rs/for_each/latest/for_each/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -/// Internal namespace. +/// Define a private namespace for all its items. #[ cfg( feature = "enabled" ) ] mod private { diff --git a/module/core/format_tools/License b/module/core/format_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/format_tools/License +++ b/module/core/format_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/format_tools/Readme.md b/module/core/format_tools/Readme.md index 19543ef6f4..6fe6e41b5f 100644 --- a/module/core/format_tools/Readme.md +++ b/module/core/format_tools/Readme.md @@ -15,66 +15,70 @@ Using the `to_string_with_fallback` macro to convert values to strings with a pr ```rust fn main() { - // Import necessary traits and the macro from the `format_tools` crate. - use core::fmt; - use format_tools:: + #[ cfg( feature = "enabled" ) ] { - WithDebug, - WithDisplay, - to_string_with_fallback, - }; - // Define a struct that implements both Debug and Display traits. - struct Both; + // Import necessary traits and the macro from the `format_tools` crate. + use core::fmt; + use format_tools:: + { + WithDebug, + WithDisplay, + to_string_with_fallback, + }; - // Implement the Debug trait for the Both struct. - impl fmt::Debug for Both - { - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + // Define a struct that implements both Debug and Display traits. + struct Both; + + // Implement the Debug trait for the Both struct. + impl fmt::Debug for Both { - write!( f, "This is debug" ) + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + write!( f, "This is debug" ) + } } - } - // Implement the Display trait for the Both struct. - impl fmt::Display for Both - { - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + // Implement the Display trait for the Both struct. + impl fmt::Display for Both { - write!( f, "This is display" ) + 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; + // Define a struct that implements only the Debug trait. + struct OnlyDebug; - // Implement the Debug trait for the OnlyDebug struct. - impl fmt::Debug for OnlyDebug - { - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + // Implement the Debug trait for the OnlyDebug struct. + impl fmt::Debug for OnlyDebug { - write!( f, "This is debug" ) + 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; - // Convert the struct to a string using `to_string_with_fallback` macro. - // The primary formatting method WithDisplay is used. - let got = to_string_with_fallback!( WithDisplay, WithDebug, &src ); - let exp = "This is display".to_string(); - // Assert that the result matches the expected value. - assert_eq!( got, exp ); - - // Example usage: Using OnlyDebug which implements only Debug. - let src = OnlyDebug; - // Convert the struct to a string using `to_string_with_fallback` macro. - // The primary formatting method WithDisplay is not available, so the fallback WithDebug is used. - let got = to_string_with_fallback!( WithDisplay, WithDebug, &src ); - let exp = "This is debug".to_string(); - // Assert that the result matches the expected value. - assert_eq!( got, exp ); + // Example usage: Using Both which implements both Debug and Display. + let src = Both; + // Convert the struct to a string using `to_string_with_fallback` macro. + // The primary formatting method WithDisplay is used. + let got = to_string_with_fallback!( WithDisplay, WithDebug, &src ); + let exp = "This is display".to_string(); + // Assert that the result matches the expected value. + assert_eq!( got, exp ); + + // Example usage: Using OnlyDebug which implements only Debug. + let src = OnlyDebug; + // Convert the struct to a string using `to_string_with_fallback` macro. + // The primary formatting method WithDisplay is not available, so the fallback WithDebug is used. + let got = to_string_with_fallback!( WithDisplay, WithDebug, &src ); + let exp = "This is debug".to_string(); + // Assert that the result matches the expected value. + assert_eq!( got, exp ); + + } } ``` diff --git a/module/core/format_tools/examples/format_tools_trivial.rs b/module/core/format_tools/examples/format_tools_trivial.rs index 6683ab3f4a..bd7c7208c9 100644 --- a/module/core/format_tools/examples/format_tools_trivial.rs +++ b/module/core/format_tools/examples/format_tools_trivial.rs @@ -5,64 +5,68 @@ fn main() { - // Import necessary traits and the macro from the `format_tools` crate. - use core::fmt; - use format_tools:: + #[ cfg( feature = "enabled" ) ] { - WithDebug, - WithDisplay, - to_string_with_fallback, - }; - // Define a struct that implements both Debug and Display traits. - struct Both; + // Import necessary traits and the macro from the `format_tools` crate. + use core::fmt; + use format_tools:: + { + WithDebug, + WithDisplay, + to_string_with_fallback, + }; - // Implement the Debug trait for the Both struct. - impl fmt::Debug for Both - { - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + // Define a struct that implements both Debug and Display traits. + struct Both; + + // Implement the Debug trait for the Both struct. + impl fmt::Debug for Both { - write!( f, "This is debug" ) + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + write!( f, "This is debug" ) + } } - } - // Implement the Display trait for the Both struct. - impl fmt::Display for Both - { - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + // Implement the Display trait for the Both struct. + impl fmt::Display for Both { - write!( f, "This is display" ) + 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; + // Define a struct that implements only the Debug trait. + struct OnlyDebug; - // Implement the Debug trait for the OnlyDebug struct. - impl fmt::Debug for OnlyDebug - { - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + // Implement the Debug trait for the OnlyDebug struct. + impl fmt::Debug for OnlyDebug { - write!( f, "This is debug" ) + 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; - // Convert the struct to a string using `to_string_with_fallback` macro. - // The primary formatting method WithDisplay is used. - let got = to_string_with_fallback!( WithDisplay, WithDebug, &src ); - let exp = "This is display".to_string(); - // Assert that the result matches the expected value. - assert_eq!( got, exp ); - - // Example usage: Using OnlyDebug which implements only Debug. - let src = OnlyDebug; - // Convert the struct to a string using `to_string_with_fallback` macro. - // The primary formatting method WithDisplay is not available, so the fallback WithDebug is used. - let got = to_string_with_fallback!( WithDisplay, WithDebug, &src ); - let exp = "This is debug".to_string(); - // Assert that the result matches the expected value. - assert_eq!( got, exp ); + // Example usage: Using Both which implements both Debug and Display. + let src = Both; + // Convert the struct to a string using `to_string_with_fallback` macro. + // The primary formatting method WithDisplay is used. + let got = to_string_with_fallback!( WithDisplay, WithDebug, &src ); + let exp = "This is display".to_string(); + // Assert that the result matches the expected value. + assert_eq!( got, exp ); + // Example usage: Using OnlyDebug which implements only Debug. + let src = OnlyDebug; + // Convert the struct to a string using `to_string_with_fallback` macro. + // The primary formatting method WithDisplay is not available, so the fallback WithDebug is used. + let got = to_string_with_fallback!( WithDisplay, WithDebug, &src ); + let exp = "This is debug".to_string(); + // Assert that the result matches the expected value. + assert_eq!( got, exp ); + + } } \ No newline at end of file diff --git a/module/core/format_tools/src/format.rs b/module/core/format_tools/src/format.rs index 4e55517dcc..6200a4f5d8 100644 --- a/module/core/format_tools/src/format.rs +++ b/module/core/format_tools/src/format.rs @@ -2,7 +2,7 @@ //! Collection of mechanisms for formatting and serialization into string. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { @@ -17,8 +17,8 @@ mod private macro_rules! _field_with_key { ( + $path : expr, $key : ident, - $src : expr, $how : ty, $fallback1 : ty, $fallback2 : ty @@ -28,9 +28,10 @@ mod private {{ ( ::core::stringify!( $key ), - $crate::OptionalCow::< '_, str, $how >::from + // $crate::OptionalCow::< '_, str, $how >::from + Option::Some ( - $crate::to_string_with_fallback!( $how, $fallback1, $fallback2, $src ) + $crate::to_string_with_fallback!( $how, $fallback1, $fallback2, $path ) ), ) }}; @@ -47,32 +48,39 @@ mod private macro_rules! _field { - ( & $path:ident.$( $key:ident )+, $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => + // dst.push( field!( &self.id ) ); + ( ( & $pre:ident.$( $key:tt )+ ), $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => {{ - $crate::_field!( # ( & $path . ) ( $( $key )+ ) ( $how, $fallback1, $fallback2 ) ) + $crate::_field!( # ( & $pre . ) ( $( $key )+ ) ( $how, $fallback1, $fallback2 ) ) }}; - ( $path:ident.$( $key:ident )+, $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => + // dst.push( field!( self.id ) ); + ( ( $pre:ident.$( $key:tt )+ ), $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => {{ - $crate::_field!( # ( $path . ) ( $( $key )+ ) ( $how, $fallback1, $fallback2 ) ) + $crate::_field!( # ( $pre . ) ( $( $key )+ ) ( $how, $fallback1, $fallback2 ) ) }}; - ( & $key:ident, $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => + // dst.push( field!( &tools ) ); + ( ( & $key:ident ), $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => {{ - $crate::_field!( # () ( $key ) ( $how, $fallback1, $fallback2 ) ) + $crate::_field!( # () ( & $key ) ( $how, $fallback1, $fallback2 ) ) }}; - ( $key:ident, $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => + // dst.push( field!( tools ) ); + ( ( $key:ident ), $how : ty, $fallback1 : ty, $fallback2 : ty $(,)? ) => {{ $crate::_field!( # () ( $key ) ( $how, $fallback1, $fallback2 ) ) }}; // private + // ( a.b. ) + // ( c.d ) + // ( $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) ( # ( $( $prefix:tt )* ) - ( $prekey:ident.$( $field:ident )+ ) + ( $prekey:ident.$( $field:tt )+ ) ( $how : ty, $fallback1 : ty, $fallback2 : ty ) ) => @@ -80,6 +88,23 @@ mod private $crate::_field!( # ( $( $prefix )* $prekey . ) ( $( $field )+ ) ( $how, $fallback1, $fallback2 ) ) }}; + // ( a.b. ) + // ( 0.d ) + // ( $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) + ( + # + ( $( $prefix:tt )* ) + ( $prekey:tt.$( $field:tt )+ ) + ( $how : ty, $fallback1 : ty, $fallback2 : ty ) + ) + => + {{ + $crate::_field!( # ( $( $prefix )* $prekey . ) ( $( $field )+ ) ( $how, $fallback1, $fallback2 ) ) + }}; + + // ( a.b.c. ) + // ( d ) + // ( $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) ( # ( $( $prefix:tt )* ) @@ -91,6 +116,9 @@ mod private $crate::_field!( # # ( $( $prefix )* ) ( $key ) ( $how, $fallback1, $fallback2 ) ) }}; + // ( a.b.c ) + // ( d ) + // ( $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) ( # # ( $( $prefix:tt )* ) @@ -99,7 +127,8 @@ mod private ) => {{ - $crate::_field_with_key!( $key, $( $prefix )* $key, $how, $fallback1, $fallback2 ) + // _field_with_key!( id, &self. id, $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline ) + $crate::_field_with_key!( $( $prefix )* $key, $key, $how, $fallback1, $fallback2 ) }}; } @@ -129,7 +158,7 @@ mod private ) => {{ - $crate::_field_with_key!( $key, $src, $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline ) + $crate::_field_with_key!( $src, $key, $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline ) }}; } @@ -144,7 +173,7 @@ mod private ( $( $t:tt )+ ) => {{ - $crate::_field!( $( $t )+, $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline ) + $crate::_field!( ( $( $t )+ ), $crate::WithRef, $crate::WithDisplay, $crate::WithDebugMultiline ) }} } @@ -178,7 +207,7 @@ mod private ) => {{ - $crate::_field_with_key!( $key, $src, $crate::WithRef, $crate::WithDisplay, $crate::WithDebug ) + $crate::_field_with_key!( $src, $key, $crate::WithRef, $crate::WithDisplay, $crate::WithDebug ) }}; } @@ -193,7 +222,7 @@ mod private ( $( $t:tt )+ ) => {{ - $crate::_field!( $( $t )+, $crate::WithRef, $crate::WithDisplay, $crate::WithDebug ) + $crate::_field!( ( $( $t )+ ), $crate::WithRef, $crate::WithDisplay, $crate::WithDebug ) }} } @@ -226,7 +255,7 @@ mod private ) => {{ - $crate::_field_with_key!( $key, $src, $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) + $crate::_field_with_key!( $src, $key, $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) }}; } @@ -240,7 +269,7 @@ mod private ( $( $t:tt )+ ) => {{ - $crate::_field!( $( $t )+, $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) + $crate::_field!( ( $( $t )+ ), $crate::WithRef, $crate::WithDebug, $crate::WithDebug ) }} } @@ -260,6 +289,12 @@ pub mod string; pub mod table; pub mod to_string; pub mod to_string_with_fallback; +pub mod text_wrap; + +/// A strucutre for diagnostic and demonstration purpose. +#[ doc( hidden ) ] +#[ cfg( debug_assertions ) ] +pub mod test_object_without_impl; #[ doc( inline ) ] #[ allow( unused_imports ) ] @@ -283,6 +318,7 @@ pub mod own table::orphan::*, to_string::orphan::*, to_string_with_fallback::orphan::*, + text_wrap::orphan::*, }; } @@ -304,6 +340,14 @@ pub mod orphan ref_or_debug, }; + #[ doc( hidden ) ] + #[ cfg( debug_assertions ) ] + pub use test_object_without_impl:: + { + TestObjectWithoutImpl, + test_objects_gen, + }; + } /// Exposed namespace of the module. @@ -327,6 +371,7 @@ pub mod exposed table::exposed::*, to_string::exposed::*, to_string_with_fallback::exposed::*, + text_wrap::exposed::*, }; } @@ -349,6 +394,7 @@ pub mod prelude table::prelude::*, to_string::prelude::*, to_string_with_fallback::prelude::*, + text_wrap::prelude::*, }; } diff --git a/module/core/format_tools/src/format/as_table.rs b/module/core/format_tools/src/format/as_table.rs index 4e70ba233d..d269556525 100644 --- a/module/core/format_tools/src/format/as_table.rs +++ b/module/core/format_tools/src/format/as_table.rs @@ -2,7 +2,7 @@ //! Nice print's wrapper. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { @@ -21,29 +21,29 @@ mod private /// #[ repr( transparent ) ] #[ derive( Clone, Copy ) ] - pub struct AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + pub struct AsTable< 'table, Table, RowKey, Row, CellKey> ( &'table Table, ::core::marker::PhantomData <( &'table (), - fn() -> ( &'table RowKey, Row, &'table CellKey, CellRepr ), + fn() -> ( &'table RowKey, Row, &'table CellKey ), )>, ) where RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey >, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr + // CellRepr : table::CellRepr ; - impl< 'table, Table, RowKey, Row, CellKey, CellRepr > - AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + impl< 'table, Table, RowKey, Row, CellKey> + AsTable< 'table, Table, RowKey, Row, CellKey> where RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey >, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { /// Just a constructor. pub fn new( src : &'table Table ) -> Self @@ -52,13 +52,13 @@ mod private } } - impl< 'table, Table, RowKey, Row, CellKey, CellRepr > AsRef< Table > - for AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + impl< 'table, Table, RowKey, Row, CellKey> AsRef< Table > + for AsTable< 'table, Table, RowKey, Row, CellKey> where RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey >, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { fn as_ref( &self ) -> &Table { @@ -66,13 +66,13 @@ mod private } } - impl< 'table, Table, RowKey, Row, CellKey, CellRepr > Deref - for AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + impl< 'table, Table, RowKey, Row, CellKey> Deref + for AsTable< 'table, Table, RowKey, Row, CellKey> where RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey >, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { type Target = Table; @@ -82,13 +82,13 @@ mod private } } - impl< 'table, Table, RowKey, Row, CellKey, CellRepr > From< &'table Table > - for AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + impl< 'table, Table, RowKey, Row, CellKey> From< &'table Table > + for AsTable< 'table, Table, RowKey, Row, CellKey> where RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey >, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { fn from( table : &'table Table ) -> Self { @@ -96,14 +96,14 @@ mod private } } - impl< 'table, Table, RowKey, Row, CellKey, CellRepr > fmt::Debug - for AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + impl< 'table, Table, RowKey, Row, CellKey> fmt::Debug + for AsTable< 'table, Table, RowKey, Row, CellKey> where Table : fmt::Debug, RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey >, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { @@ -130,25 +130,25 @@ mod private type RowKey : table::RowKey; /// The type representing a row, must implement `Cells`. - type Row : Cells< Self::CellKey, Self::CellRepr >; + type Row : Cells< Self::CellKey >; /// The type used to identify cells within a row, must implement `Key` and can be unsized. type CellKey : table::CellKey + ?Sized; - /// The type representing the content of a cell, must implement `CellRepr`. - type CellRepr : table::CellRepr; + // /// The type representing the content of a cell, must implement `CellRepr`. + // type // CellRepr : table::CellRepr; /// Converts the data reference into an `AsTable` reference. - fn as_table( &self ) -> AsTable< '_, Self::Table, Self::RowKey, Self::Row, Self::CellKey, Self::CellRepr >; + fn as_table( &self ) -> AsTable< '_, Self::Table, Self::RowKey, Self::Row, Self::CellKey >; } - impl< 'table, Table, RowKey, Row, CellKey, CellRepr > IntoAsTable - for AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + impl< 'table, Table, RowKey, Row, CellKey> IntoAsTable + for AsTable< 'table, Table, RowKey, Row, CellKey> where RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey >, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, Self : Copy, { @@ -156,9 +156,9 @@ mod private type RowKey = RowKey; type Row = Row; type CellKey = CellKey; - type CellRepr = CellRepr; + // type CellRepr = CellRepr; - fn as_table( &self ) -> AsTable< '_, Self::Table, Self::RowKey, Self::Row, Self::CellKey, Self::CellRepr > + fn as_table( &self ) -> AsTable< '_, Self::Table, Self::RowKey, Self::Row, Self::CellKey > { *self } @@ -168,9 +168,9 @@ mod private // impl< Row > IntoAsTable // for Vec< Row > // where -// Row : Cells< Self::CellKey, Self::CellRepr >, +// Row : Cells< Self::CellKey >, // // CellKey : table::CellKey + ?Sized, -// // CellRepr : table::CellRepr, +// // // CellRepr : table::CellRepr, // { // // type Table = Self; @@ -179,14 +179,14 @@ mod private // type CellKey = str; // type CellRepr = WithRef; // -// fn as_table( &self ) -> AsTable< '_, Self::Table, Self::RowKey, Self::Row, Self::CellKey, Self::CellRepr > +// fn as_table( &self ) -> AsTable< '_, Self::Table, Self::RowKey, Self::Row, Self::CellKey > // { // AsTable::from( self ) // } // // } - // pub struct AsTable< 'table, Table, RowKey, Row, CellKey, CellRepr > + // pub struct AsTable< 'table, Table, RowKey, Row, CellKey> } diff --git a/module/core/format_tools/src/format/filter.rs b/module/core/format_tools/src/format/filter.rs index 191522e138..1551721570 100644 --- a/module/core/format_tools/src/format/filter.rs +++ b/module/core/format_tools/src/format/filter.rs @@ -2,7 +2,7 @@ //! Print data as table. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/core/format_tools/src/format/md_math.rs b/module/core/format_tools/src/format/md_math.rs index a53625fc21..9aa70022d0 100644 --- a/module/core/format_tools/src/format/md_math.rs +++ b/module/core/format_tools/src/format/md_math.rs @@ -3,7 +3,9 @@ //! Provides functionality for converting multidimensional indices into flat offsets, //! useful for operations involving multidimensional arrays or grids. -/// Internal namespace. +// xxx : use crate mdmath + +/// Define a private namespace for all its items. mod private { use core:: @@ -29,7 +31,20 @@ mod private /// # Returns /// /// A value of type `T` representing the flat offset. - fn md_offset( & self, md_index : [ T ; 3 ] ) -> T; + fn md_offset( & self, md_index : Self ) -> T; + } + + impl< T > MdOffset< T > for [ T ; 2 ] + where + T : Mul< T, Output = T > + Add< T, Output = T > + PartialOrd + Copy + fmt::Debug, + { + fn md_offset( & self, md_index : [ T ; 2 ] ) -> T + { + debug_assert!( md_index[ 0 ] < self[ 0 ], "md_index : {md_index:?} | md_size : {self:?}" ); + debug_assert!( md_index[ 1 ] < self[ 1 ], "md_index : {md_index:?} | md_size : {self:?}" ); + let m1 = self[ 0 ]; + md_index[ 0 ] + m1 * md_index[ 1 ] + } } impl< T > MdOffset< T > for [ T ; 3 ] diff --git a/module/core/format_tools/src/format/output_format.rs b/module/core/format_tools/src/format/output_format.rs index 511d12db79..1bf58b75e6 100644 --- a/module/core/format_tools/src/format/output_format.rs +++ b/module/core/format_tools/src/format/output_format.rs @@ -1,6 +1,6 @@ //! Customizable format of printing table. //! -//! # Example of ordinary format +//! # Example of table format //! //! ```text //! sid | sname | gap @@ -28,10 +28,12 @@ //! ``` //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { + use std::borrow::Cow; + use crate::*; use print:: { @@ -74,14 +76,45 @@ mod private #[ inline( always ) ] fn default() -> Self { - super::ordinary::Ordinary::instance() + super::table::Table::instance() } } + /// Print table, which is constructed with vectors and `Cow`s, with the + /// specified output formatter. + /// + /// This function is useful when you do not want to use `AsTable`, or implement `Fields`, and + /// other traits, but you just have string slices in vectors. + /// + /// `rows` should not contain header of the table, it will be automatically added if `has_header` + /// is true. + pub fn vector_table_write< 'data, 'context > + ( + column_names : Vec< Cow< 'data, str > >, + has_header : bool, + rows : Vec< Vec< Cow< 'data, str > > >, + c : &mut Context< 'context >, + ) -> fmt::Result + { + InputExtract::extract_from_raw_table + ( + column_names, + has_header, + rows, + c.printer.filter_col, + c.printer.filter_row, + | x | + { + c.printer.output_format.extract_write( x, c ) + } + ) + } + } -mod ordinary; +mod table; mod records; +mod keys; #[ allow( unused_imports ) ] pub use own::*; @@ -97,13 +130,15 @@ pub mod own #[ doc( inline ) ] pub use { - ordinary::Ordinary, + table::Table, records::Records, + keys::Keys, }; #[ doc( inline ) ] pub use private:: { + vector_table_write, }; } diff --git a/module/core/format_tools/src/format/output_format/keys.rs b/module/core/format_tools/src/format/output_format/keys.rs new file mode 100644 index 0000000000..55ee27b023 --- /dev/null +++ b/module/core/format_tools/src/format/output_format/keys.rs @@ -0,0 +1,107 @@ +//! Implement keys list output format. +//! +//! # Example +//! +//! ```text +//! ``` +//! + +use crate::*; +use print:: +{ + InputExtract, + Context, +}; +use core:: +{ + fmt, +}; +use std::sync::OnceLock; + +/// A struct representing the list of keys output format. +#[derive( Debug )] +pub struct Keys +{ + // /// Prefix added to each row. + // pub table_prefix : String, + // /// Postfix added to each row. + // pub table_postfix : String, + // /// Separator used between rows. + // pub table_separator : String, + // /// Prefix added to each row. + // pub row_prefix : String, + // /// Postfix added to each row. + // pub row_postfix : String, + // /// Separator used between rows. + // pub row_separator : String, + // /// Prefix added to each cell. + // pub cell_prefix : String, + // /// Postfix added to each cell. + // pub cell_postfix : String, + // /// Separator used between table columns. + // pub cell_separator : String, +} + +impl Keys +{ + /// Returns a reference to a static instance of `Keys`. + pub fn instance() -> &'static dyn TableOutputFormat + { + static INSTANCE : OnceLock< Keys > = OnceLock::new(); + INSTANCE.get_or_init( || Keys::default() ) + } +} + +impl Default for Keys +{ + fn default() -> Self + { + + // let cell_prefix = "".to_string(); + // let cell_postfix = "".to_string(); + // let cell_separator = " │ ".to_string(); + // let row_prefix = "│ ".to_string(); + // let row_postfix = " │".to_string(); + // let row_separator = "\n".to_string(); + // let table_prefix = "".to_string(); + // let table_postfix = "".to_string(); + // let table_separator = "\n".to_string(); + + Self + { + // table_prefix, + // table_postfix, + // table_separator, + // row_prefix, + // row_postfix, + // row_separator, + // cell_prefix, + // cell_postfix, + // cell_separator, + } + } +} + +impl TableOutputFormat for Keys +{ + + fn extract_write< 'buf, 'data >( + &self, + x : &InputExtract< 'data >, + c : &mut Context< 'buf >, + ) -> fmt::Result + { + + // dbg!( &x ); + + for col in &x.col_descriptors + { + write!( c.buf, " - {}\n", col.label )?; + } + + write!( c.buf, " {} fields\n", x.col_descriptors.len() )?; + + Ok(()) + } + +} diff --git a/module/core/format_tools/src/format/output_format/ordinary.rs b/module/core/format_tools/src/format/output_format/ordinary.rs deleted file mode 100644 index 23606111f3..0000000000 --- a/module/core/format_tools/src/format/output_format/ordinary.rs +++ /dev/null @@ -1,275 +0,0 @@ -//! Implement classic table output format. -//! -//! # Example -//! -//! ```text -//! sid | sname | gap -//! -----+-------+----- -//! 3 | Alice | 5 -//! 6 | Joe | 1 -//! 10 | Boris | 5 -//! ``` - -use crate::*; -use print:: -{ - InputExtract, - Context, -}; -use core:: -{ - fmt, -}; -use std::sync::OnceLock; - -/// A struct representing the classic table output format. -/// -/// `Ordinary` provides a standard implementation for table formatting, -/// supporting a classic style with default settings. -/// -/// # Example -/// -/// ```text -/// sid | sname | gap -/// -----+-------+----- -/// 3 | Alice | 5 -/// 6 | Joe | 1 -/// 10 | Boris | 5 -/// ``` -#[ derive( Debug ) ] -pub struct Ordinary -{ - /// Delimitting header with grid line or not. - pub delimitting_header : bool, - /// Prefix added to each cell. - pub cell_prefix : String, - /// Postfix added to each cell. - pub cell_postfix : String, - /// Separator used between table columns. - pub cell_separator : String, - /// Prefix added to each row. - pub row_prefix : String, - /// Postfix added to each row. - pub row_postfix : String, - /// Separator used between rows. - pub row_separator : String, - /// Horizontal line character. - pub h : char, - /// Vertical line character. - pub v : char, - /// Left T-junction character. - pub t_l : char, - /// Right T-junction character. - pub t_r : char, - /// Top T-junction character. - pub t_t : char, - /// Bottom T-junction character. - pub t_b : char, - /// Cross junction character. - pub cross : char, - /// Top-left corner character. - pub corner_lt : char, - /// Top-right corner character. - pub corner_rt : char, - /// Bottom-left corner character. - pub corner_lb : char, - /// Bottom-right corner character. - pub corner_rb : char, -} - -impl Default for Ordinary -{ - fn default() -> Self - { - - let delimitting_header = true; - - let cell_prefix = "".to_string(); - let cell_postfix = "".to_string(); - let cell_separator = " │ ".to_string(); - let row_prefix = "│ ".to_string(); - let row_postfix = " │".to_string(); - let row_separator = "\n".to_string(); - - let h = '─'; - let v = '|'; - let t_l = '├'; - let t_r = '┤'; - let t_t = '┬'; - let t_b = '┴'; - let cross = '┼'; - let corner_lt = '┌'; - let corner_rt = '┐'; - let corner_lb = '└'; - let corner_rb = '┘'; - - Self - { - delimitting_header, - cell_prefix, - cell_postfix, - cell_separator, - row_prefix, - row_postfix, - row_separator, - h, - v, - t_l, - t_r, - t_t, - t_b, - cross, - corner_lt, - corner_rt, - corner_lb, - corner_rb, - } - } -} - -impl Default for &'static Ordinary -{ - fn default() -> Self - { - // qqq : find a better solution - static STYLES : OnceLock< Ordinary > = OnceLock::new(); - STYLES.get_or_init( || - { - Ordinary::default() - }) - } -} - -impl Ordinary -{ - - /// Returns a reference to a static instance of `Ordinary`. - /// - /// This method provides access to a single shared instance of `Ordinary`, - /// ensuring efficient reuse of the classic table output format. - pub fn instance() -> & 'static dyn TableOutputFormat - { - - static INSTANCE : OnceLock< Ordinary > = OnceLock::new(); - INSTANCE.get_or_init( || - { - Self::default() - }) - - } -} - -impl TableOutputFormat for Ordinary -{ - fn extract_write< 'buf, 'data >( &self, x : &InputExtract< 'data >, c : &mut Context< 'buf > ) -> fmt::Result - { - use md_math::MdOffset; - - let cell_prefix = &self.cell_prefix; - let cell_postfix = &self.cell_postfix; - let cell_separator = &self.cell_separator; - let row_prefix = &self.row_prefix; - let row_postfix = &self.row_postfix; - let row_separator = &self.row_separator; - let h = self.h.to_string(); - - let mut delimitting_header = self.delimitting_header; - let row_width = if delimitting_header - { - let mut grid_width = x.mcells_vis[ 0 ] * ( cell_prefix.chars().count() + cell_postfix.chars().count() ); - grid_width += row_prefix.chars().count() + row_postfix.chars().count(); - if x.mcells_vis[ 0 ] > 0 - { - grid_width += ( x.mcells_vis[ 0 ] - 1 ) * ( cell_separator.chars().count() ); - } - x.mchars[ 0 ] + grid_width - } - else - { - 0 - }; - let mut prev_typ : Option< LineType > = None; - - // dbg!( x.row_descriptors.len() ); - - for ( irow, row ) in x.row_descriptors.iter().enumerate() - { - let height = row.height; - - if delimitting_header - { - if let Some( prev_typ ) = prev_typ - { - if prev_typ == LineType::Header && row.typ == LineType::Regular - { - write!( c.buf, "{}", row_separator )?; - write!( c.buf, "{}", h.repeat( row_width ) )?; - delimitting_header = false - } - } - if row.vis - { - prev_typ = Some( row.typ ); - } - } - - if !row.vis - { - continue; - } - - // dbg!( row.height ); - - for islice in 0..height - { - - if irow > 0 - { - write!( c.buf, "{}", row_separator )?; - } - - write!( c.buf, "{}", row_prefix )?; - - for icol in 0 .. x.col_descriptors.len() - { - let col = &x.col_descriptors[ icol ]; - let cell_width = x.data[ irow ][ icol ].1[0]; - let width = col.width; - let md_index = [ islice, icol, irow as usize ]; - let slice = x.slices[ x.slices_dim.md_offset( md_index ) ]; - - // println!( "md_index : {md_index:?} | md_offset : {} | slice : {slice}", x.slices_dim.md_offset( md_index ) ); - - if icol > 0 - { - write!( c.buf, "{}", cell_separator )?; - } - - write!( c.buf, "{}", cell_prefix )?; - - // println!( "icol : {icol} | irow : {irow} | width : {width} | cell_width : {cell_width}" ); - let lspaces = ( width - cell_width ) / 2; - let rspaces = ( width - cell_width + 1 ) / 2 + cell_width - slice.len(); - // println!( "icol : {icol} | irow : {irow} | width : {width} | cell_width : {cell_width} | lspaces : {lspaces} | rspaces : {rspaces}" ); - - if lspaces > 0 - { - write!( c.buf, "{: 0 - { - write!( c.buf, "{:>width$}", " ", width = rspaces )?; - } - - write!( c.buf, "{}", cell_postfix )?; - } - - write!( c.buf, "{}", row_postfix )?; - } - - } - - Ok(()) - } -} diff --git a/module/core/format_tools/src/format/output_format/records.rs b/module/core/format_tools/src/format/output_format/records.rs index 263177edb8..1c89f34038 100644 --- a/module/core/format_tools/src/format/output_format/records.rs +++ b/module/core/format_tools/src/format/output_format/records.rs @@ -22,12 +22,12 @@ //! use crate::*; -use md_math::MdOffset; use print:: { InputExtract, Context, }; +use std::borrow::Cow; use core:: { fmt, @@ -39,7 +39,51 @@ use std::sync::OnceLock; /// `Records` provides an implementation for table formatting that outputs /// each row as a separate table with 2 columns, first is name of column in the original data and second is cell value itself. #[derive( Debug )] -pub struct Records; +pub struct Records +{ + /// Prefix added to each row. + pub table_prefix : String, + /// Postfix added to each row. + pub table_postfix : String, + /// Separator used between rows. + pub table_separator : String, + /// Prefix added to each row. + pub row_prefix : String, + /// Postfix added to each row. + pub row_postfix : String, + /// Separator used between rows. + pub row_separator : String, + /// Prefix added to each cell. + pub cell_prefix : String, + /// Postfix added to each cell. + pub cell_postfix : String, + /// Separator used between table columns. + pub cell_separator : String, + /// Limit table width. If the value is zero, then no limitation. + pub max_width: usize, + // /// Horizontal line character. + // pub h : char, + // /// Vertical line character. + // pub v : char, + // /// Left T-junction character. + // pub t_l : char, + // /// Right T-junction character. + // pub t_r : char, + // /// Top T-junction character. + // pub t_t : char, + // /// Bottom T-junction character. + // pub t_b : char, + // /// Cross junction character. + // pub cross : char, + // /// Top-left corner character. + // pub corner_lt : char, + // /// Top-right corner character. + // pub corner_rt : char, + // /// Bottom-left corner character. + // pub corner_lb : char, + // /// Bottom-right corner character. + // pub corner_rb : char, +} impl Records { @@ -47,7 +91,26 @@ impl Records pub fn instance() -> & 'static dyn TableOutputFormat { static INSTANCE : OnceLock< Records > = OnceLock::new(); - INSTANCE.get_or_init( || Records ) + INSTANCE.get_or_init( || Records::default() ) + } + + /// Calculate how much space is minimally needed in order to generate an output with this output formatter. + /// It will be impossible to render tables smaller than the result of `min_width()`. + /// + /// This function is similar to `output_format::Table::min_width`, but it does not contain a + /// `column_count` as it always equal to 2, and it aslo uses the `output_format::Records` + /// style parameters. + pub fn min_width + ( + &self, + ) -> usize + { + // 2 is used here, because `Records` displays 2 columns: keys and values. + self.row_prefix.chars().count() + + self.row_postfix.chars().count() + + 2 * ( self.cell_postfix.chars().count() + self.cell_prefix.chars().count() ) + + self.cell_separator.chars().count() + + 2 } } @@ -55,36 +118,149 @@ impl Default for Records { fn default() -> Self { + + let cell_prefix = "".to_string(); + let cell_postfix = "".to_string(); + let cell_separator = " │ ".to_string(); + let row_prefix = "│ ".to_string(); + let row_postfix = " │".to_string(); + let row_separator = "\n".to_string(); + let table_prefix = "".to_string(); + let table_postfix = "".to_string(); + let table_separator = "\n".to_string(); + + let max_width = 0; + + // let h = '─'; + // let v = '|'; + // let t_l = '├'; + // let t_r = '┤'; + // let t_t = '┬'; + // let t_b = '┴'; + // let cross = '┼'; + // let corner_lt = '┌'; + // let corner_rt = '┐'; + // let corner_lb = '└'; + // let corner_rb = '┘'; + Self { + table_prefix, + table_postfix, + table_separator, + row_prefix, + row_postfix, + row_separator, + cell_prefix, + cell_postfix, + cell_separator, + max_width, + // h, + // v, + // t_l, + // t_r, + // t_t, + // t_b, + // cross, + // corner_lt, + // corner_rt, + // corner_lb, + // corner_rb, } } } impl TableOutputFormat for Records { - fn extract_write< 'buf, 'data > - ( + + fn extract_write< 'buf, 'data >( & self, x : & InputExtract< 'data >, c : & mut Context< 'buf >, ) -> fmt::Result { - for ( i, row ) in x.row_descriptors.iter().enumerate() + use format::text_wrap::{ text_wrap, width_calculate }; + + if self.max_width != 0 && self.max_width < self.min_width() + { + return Err( fmt::Error ); + } + + // 2 because there are only 2 columns: key and value. + let columns_max_width = if self.max_width == 0 { 0 } else { self.max_width - self.min_width() + 2 }; + + let keys : Vec< ( Cow< 'data, str >, [ usize; 2 ] ) > = x.header().collect(); + let keys_width = width_calculate( &keys ); + + write!( c.buf, "{}", self.table_prefix )?; + + let mut printed_tables_count = 0; + + for ( itable_descriptor, table_descriptor ) in x.row_descriptors.iter().enumerate() { - if !row.vis + if !table_descriptor.vis || ( x.has_header && itable_descriptor == 0 ) { continue; } - writeln!( c.buf, "-[ RECORD {} ]", i + 1 )?; - for ( icol, col ) in x.col_descriptors.iter().enumerate() + + if printed_tables_count > 0 { - // let cell_width = x.data[ i ][ icol ].1[ 0 ]; - let md_index = [ 0, icol, i ]; - let slice = x.slices[ x.slices_dim.md_offset( md_index ) ]; - writeln!( c.buf, "{} | {}", col.width, slice )?; + write!( c.buf, "{}", self.table_separator )?; + } + + printed_tables_count += 1; + + writeln!( c.buf, " = {}", table_descriptor.irow )?; + + let values = &x.data[ itable_descriptor ]; + let values_width = width_calculate( &values ); + + let table_for_wrapping : Vec< Vec< ( Cow< 'data, str >, [ usize; 2] ) > > = + keys.iter().enumerate().map( | ( ikey, key ) | + { + vec![ key.clone(), values[ ikey ].clone() ] + }).collect(); + + let wrapped_text = text_wrap + ( + table_for_wrapping.iter(), + &[ keys_width, values_width ], + columns_max_width, + keys_width + values_width, + ); + + for ( irow, cols ) in wrapped_text.data.into_iter().enumerate() + { + if irow != 0 + { + write!( c.buf, "{}", self.row_separator )?; + } + + let key = &cols[ 0 ]; + let value = &cols[ 1 ]; + + let key_width = wrapped_text.column_widthes[ 0 ]; + let value_width = wrapped_text.column_widthes[ 1 ]; + + write!( c.buf, "{}", self.row_prefix )?; + + write!( c.buf, "{}", self.cell_prefix )?; + write!( c.buf, "{: Self + { + + let delimitting_header = true; + + let cell_prefix = "".to_string(); + let cell_postfix = "".to_string(); + let cell_separator = " │ ".to_string(); + let row_prefix = "│ ".to_string(); + let row_postfix = " │".to_string(); + let row_separator = "\n".to_string(); + + let h = '─'; + let v = '|'; + let t_l = '├'; + let t_r = '┤'; + let t_t = '┬'; + let t_b = '┴'; + let cross = '┼'; + let corner_lt = '┌'; + let corner_rt = '┐'; + let corner_lb = '└'; + let corner_rb = '┘'; + let max_width = 0; + + Self + { + delimitting_header, + cell_prefix, + cell_postfix, + cell_separator, + row_prefix, + row_postfix, + row_separator, + h, + v, + t_l, + t_r, + t_t, + t_b, + cross, + corner_lt, + corner_rt, + corner_lb, + corner_rb, + max_width + } + } +} + +impl Default for &'static Table +{ + fn default() -> Self + { + // qqq : find a better solution + static STYLES : OnceLock< Table > = OnceLock::new(); + STYLES.get_or_init( || + { + Table::default() + }) + } +} + +impl Table +{ + + /// Returns a reference to a static instance of `Table`. + /// + /// This method provides access to a single shared instance of `Table`, + /// ensuring efficient reuse of the classic table output format. + pub fn instance() -> & 'static dyn TableOutputFormat + { + + static INSTANCE : OnceLock< Table > = OnceLock::new(); + INSTANCE.get_or_init( || + { + Self::default() + }) + + } + + /// Calculate how much space is minimally needed in order to generate a table output with the specified + /// number of columns. It will be impossible to render table smaller than the result of + /// `min_width()`. + /// + /// This function is similar to `output_format::Records::min_width`, but it contains a `column_count` + /// parameter, and it aslo uses the `output_format::Table` style parameters. + pub fn min_width + ( + &self, + column_count : usize, + ) -> usize + { + self.row_prefix.chars().count() + + self.row_postfix.chars().count() + + column_count * ( self.cell_postfix.chars().count() + self.cell_prefix.chars().count() ) + + if column_count == 0 { 0 } else { ( column_count - 1 ) * self.cell_separator.chars().count() } + + column_count + } +} + +impl TableOutputFormat for Table +{ + fn extract_write< 'buf, 'data >( &self, x : &InputExtract< 'data >, c : &mut Context< 'buf > ) -> fmt::Result + { + use format::text_wrap::text_wrap; + + let cell_prefix = &self.cell_prefix; + let cell_postfix = &self.cell_postfix; + let cell_separator = &self.cell_separator; + let row_prefix = &self.row_prefix; + let row_postfix = &self.row_postfix; + let row_separator = &self.row_separator; + let h = self.h.to_string(); + + let column_count = x.col_descriptors.len(); + + if self.max_width != 0 && ( self.min_width( column_count ) > self.max_width ) + { + return Err( fmt::Error ); + } + + let columns_nowrap_width = x.col_descriptors.iter().map( |c| c.width ).sum::(); + let visual_elements_width = self.min_width( column_count ) - column_count; + + let filtered_data = x.row_descriptors.iter().filter_map( | r | + { + if r.vis + { + Some( &x.data[ r.irow ] ) + } + else + { + None + } + }); + + let wrapped_text = text_wrap + ( + filtered_data, + x.col_descriptors.iter().map( | c | c.width ).collect::< Vec< usize > >(), + if self.max_width == 0 { 0 } else { self.max_width - visual_elements_width }, + columns_nowrap_width + ); + + let new_columns_widthes = wrapped_text.column_widthes.iter().sum::(); + let new_row_width = new_columns_widthes + visual_elements_width; + + let mut printed_row_count = 0; + + for row in wrapped_text.data.iter() + { + if printed_row_count == wrapped_text.first_row_height && x.has_header && self.delimitting_header + { + write!( c.buf, "{}", row_separator )?; + write!( c.buf, "{}", h.repeat( new_row_width ) )?; + } + + if printed_row_count > 0 + { + write!( c.buf, "{}", row_separator )?; + } + + printed_row_count += 1; + + write!( c.buf, "{}", row_prefix )?; + + for ( icol, col ) in row.iter().enumerate() + { + let cell_wrapped_width = col.wrap_width; + let column_width = wrapped_text.column_widthes[ icol ]; + let slice_width = col.content.chars().count(); + + if icol > 0 + { + write!( c.buf, "{}", cell_separator )?; + } + + write!( c.buf, "{}", cell_prefix )?; + + let lspaces = ( column_width - cell_wrapped_width ) / 2; + let rspaces = ( ( column_width - cell_wrapped_width ) as f32 / 2 as f32 ).round() as usize + cell_wrapped_width - slice_width; + + if lspaces > 0 + { + write!( c.buf, "{: 0 + { + write!( c.buf, "{:>width$}", " ", width = rspaces )?; + } + + write!( c.buf, "{}", cell_postfix )?; + } + + write!( c.buf, "{}", row_postfix )?; + } + + Ok(()) + } +} \ No newline at end of file diff --git a/module/core/format_tools/src/format/print.rs b/module/core/format_tools/src/format/print.rs index e02746d3dc..f1aa104c24 100644 --- a/module/core/format_tools/src/format/print.rs +++ b/module/core/format_tools/src/format/print.rs @@ -2,14 +2,14 @@ //! Print data as table. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; use std:: { - borrow::Cow, + borrow::{ Cow, Borrow }, collections::HashMap, }; use core:: @@ -41,6 +41,7 @@ mod private /// used to add a consistent end to each row. /// /// ``` + // xxx : enable // #[ derive( Debug, Former ) ] // #[ derive( Debug ) ] @@ -83,7 +84,7 @@ mod private // .field( "row_prefix", & self.row_prefix ) // .field( "row_postfix", & self.row_postfix ) // .field( "row_separator", & self.row_separator ) - // .field( "output_format", & format_args!( "{:?}", self.output_format ) ) // xxx + // .field( "output_format", & format_args!( "{:?}", self.output_format ) ) // .field( "filter_col", & format_args!( "{:?}", self.filter_col ) ) .finish() } @@ -164,7 +165,7 @@ mod private /// A `String` containing the formatted table. fn table_to_string( &'data self ) -> String { - self.table_to_string_with_format( &output_format::Ordinary::default() ) + self.table_to_string_with_format( &output_format::Table::default() ) } /// Converts the table to a string representation specifying printer. @@ -195,15 +196,15 @@ mod private } /// A trait for formatting tables. - impl< 'data, T, RowKey, Row, CellKey, CellRepr > TableFormatter< 'data > - for AsTable< 'data, T, RowKey, Row, CellKey, CellRepr > + impl< 'data, T, RowKey, Row, CellKey> TableFormatter< 'data > + for AsTable< 'data, T, RowKey, Row, CellKey> where - Self : TableRows< CellKey = CellKey, CellRepr = CellRepr, RowKey = RowKey, Row = Row >, + Self : TableRows< CellKey = CellKey, RowKey = RowKey, Row = Row >, Self : TableHeader< CellKey = CellKey >, RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr >, + Row : Cells< CellKey>, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { fn fmt< 'a >( &'data self, c : &mut Context< 'a > ) -> fmt::Result @@ -228,19 +229,27 @@ mod private #[ derive( Debug, Default ) ] pub struct RowDescriptor { + /// Index of the row. pub irow : usize, + /// Height of the row. pub height : usize, + /// Type of the line: header or regular. pub typ : LineType, + /// Visibility of the row. pub vis : bool, } /// A struct for extracting and organizing row of table data for formatting. #[ derive( Debug, Default ) ] - pub struct ColDescriptor + pub struct ColDescriptor< 'label > { + /// Index of the column. pub icol : usize, + /// Column width. pub width : usize, + /// Label of the column. + pub label : &'label str, } /// A struct for extracting and organizing table data for formatting. @@ -270,23 +279,14 @@ mod private /// Descriptors for each column, including optional title, width, and index. // width, index - // pub col_descriptors : Vec< ( usize, usize ) >, - pub col_descriptors : Vec< ColDescriptor >, + pub col_descriptors : Vec< ColDescriptor< 'data > >, /// Descriptors for each row, including height. - // height - // pub row_descriptors : Vec< ( usize, ) >, pub row_descriptors : Vec< RowDescriptor >, /// Extracted data for each cell, including string content and size. // string, size, - pub data : Vec< Vec< ( Cow< 'data, str >, [ usize ; 2 ] ) > >, - - /// Dimensions of slices for retrieving data from multi-matrix. - pub slices_dim : [ usize ; 3 ], - - /// Extracted slices or strings for further processing. - pub slices : Vec< &'data str >, + pub data : Vec< Vec< ( Cow< 'data, str >, [ usize ; 2 ] ) > >, // xxx : use maybe flat vector } @@ -295,45 +295,168 @@ mod private impl< 'data > InputExtract< 'data > { + /// Returns an iterator over the row descriptors, skipping the header if present. + /// + /// This function provides an iterator that yields each row descriptor along with its index. + /// If the table has a header, the first row is skipped, ensuring that iteration starts from + /// the first data row. + /// + /// # Returns + /// + /// An iterator over tuples containing: + /// - `usize`: The index of the row. + /// - `&RowDescriptor`: A reference to the row descriptor. + /// + pub fn rows( & self ) -> impl _IteratorTrait< Item = ( usize, &RowDescriptor ) > + { + self.row_descriptors + .iter() + .enumerate() + .skip( if self.has_header { 1 } else { 0 } ) + } + + /// Returns an iterator over the header cells, or a default value if no header is present. + /// + /// This function provides an iterator that yields each cell in the header row. If the table + /// does not have a header, it returns an iterator over default values, which are empty strings + /// with a size of `[0, 1]`. + /// + /// # Returns + /// + /// A boxed iterator yielding tuples containing: + /// - `Cow<'data, str>`: A clone-on-write string representing the cell content. + /// - `[usize; 2]`: An array representing the size of the cell. + /// + pub fn header( & self ) -> Box< dyn Iterator< Item = ( Cow< 'data, str >, [ usize ; 2 ] ) > + '_ > + { + if self.has_header + { + Box::new( self.data[ 0 ].iter().cloned() ) + } + else + { + Box::new( std::iter::repeat( ( Cow::Borrowed( "" ), [ 0, 1 ] ) ).take( self.mcells[ 0 ] ) ) + } + } + + /// Returns a slice from the header, or an empty string if no header is present. + /// + /// # Arguments + /// + /// - `icol`: The column index within the header row. + /// + /// # Returns + /// + /// A string slice representing the header content. + /// + pub fn header_slice( & self, icol : usize ) -> & str + { + if self.has_header + { + self.data[ 0 ][ icol ].0.borrow() + } + else + { + "" + } + } + + /// Extract input data from and collect it in a format consumable by output formatter. - pub fn extract< 't, 'context, Table, RowKey, Row, CellKey, CellRepr > + pub fn extract< 'context, Table, RowKey, Row, CellKey> ( - table : &'t Table, + table : &'data Table, filter_col : &'context ( dyn FilterCol + 'context ), filter_row : &'context ( dyn FilterRow + 'context ), callback : impl for< 'a2 > FnOnce( &'a2 InputExtract< 'a2 > ) -> fmt::Result, ) -> fmt::Result where - 'data : 't, - Table : TableRows< RowKey = RowKey, Row = Row, CellKey = CellKey, CellRepr = CellRepr >, + Table : TableRows< RowKey = RowKey, Row = Row, CellKey = CellKey >, Table : TableHeader< CellKey = CellKey >, RowKey : table::RowKey, - Row : Cells< CellKey, CellRepr > + 'data, + Row : Cells< CellKey > + 'data, + Row : Cells< CellKey > + 'data, CellKey : table::CellKey + ?Sized + 'data, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { - use md_math::MdOffset; + let mut key_to_ikey : HashMap< Cow< 'data, str >, usize > = HashMap::new(); + let mut keys_count = 0; + + let rows = table.rows().map( | r | + { + let mut unsorted : Vec< ( usize, Cow< 'data, str > ) > = r.cells().map( | ( key, c ) | + { + if !key_to_ikey.contains_key( key.borrow() ) + { + key_to_ikey.insert( key.borrow().into(), keys_count ); + keys_count += 1; + } + + ( key_to_ikey[ key.borrow() ], c.unwrap_or( Cow::from( "" ) ) ) + } ).collect(); + + unsorted.sort_by( | ( i1, _ ), ( i2, _ ) | i1.cmp(i2) ); + + unsorted.into_iter().map( | ( _, c ) | c).collect() + } ).collect(); + + let has_header = table.header().is_some(); + let column_names = match table.header() + { + Some( header ) => header.map( | ( k, _ ) | Cow::from( k.borrow() ) ).collect(), + + None => match table.rows().next() + { + Some( r ) => r.cells().map( | ( k, _ ) | Cow::from( k.borrow() ) ).collect(), + None => Vec::new() + } + }; + + Self::extract_from_raw_table + ( + column_names, + has_header, + rows, + filter_col, + filter_row, + callback, + ) + } + + /// Extract input data from a table that is constructed with vectors and `Cow`s and collect + /// it in a format consumable by output formatter. + /// + /// `rows` should not contain header of the table, it will be automatically added if `has_header` + /// is true. + pub fn extract_from_raw_table< 'context > + ( + column_names : Vec< Cow< 'data, str > >, + has_header : bool, + rows : Vec< Vec< Cow< 'data, str > > >, + filter_col : &'context ( dyn FilterCol + 'context ), + filter_row : &'context ( dyn FilterRow + 'context ), + callback : impl for< 'a2 > FnOnce( &'a2 InputExtract< 'a2 > ) -> fmt::Result, + ) -> fmt::Result + { // let mcells = table.mcells(); let mut mcells_vis = [ 0 ; 2 ]; let mut mcells = [ 0 ; 2 ]; let mut mchars = [ 0 ; 2 ]; // key width, index - let mut key_to_ikey : HashMap< &'t CellKey, usize > = HashMap::new(); + let mut key_to_ikey : HashMap< Cow< 'data, str >, usize > = HashMap::new(); - let mut col_descriptors : Vec< ColDescriptor > = Vec::with_capacity( mcells[ 0 ] ); + let mut col_descriptors : Vec< ColDescriptor< '_ > > = Vec::with_capacity( mcells[ 0 ] ); let mut row_descriptors : Vec< RowDescriptor > = Vec::with_capacity( mcells[ 1 ] ); - let mut has_header = false; - let mut data : Vec< Vec< ( Cow< 't, str >, [ usize ; 2 ] ) > > = Vec::new(); - let rows = table.rows(); + let mut data : Vec< Vec< ( Cow< 'data, str >, [ usize ; 2 ] ) > > = Vec::new(); let mut irow : usize = 0; let filter_col_need_args = filter_col.need_args(); // let filter_row_need_args = filter_row.need_args(); - let mut row_add = | row_iter : &'_ mut dyn _IteratorTrait< Item = ( &'t CellKey, Cow< 't, str > ) >, typ : LineType | + let mut row_add = | row_data : Vec< Cow< 'data, str > >, typ : LineType | { irow = row_descriptors.len(); @@ -343,18 +466,21 @@ mod private let mut ncol = 0; let mut ncol_vis = 0; - let fields : Vec< ( Cow< 't, str >, [ usize ; 2 ] ) > = row_iter + let fields : Vec< ( Cow< 'data, str >, [ usize ; 2 ] ) > = row_data + .into_iter() + .enumerate() .filter_map ( - | ( key, val ) | + | ( ikey, val ) | { + let key = &column_names[ ikey ]; let l = col_descriptors.len(); ncol += 1; if filter_col_need_args { - if !filter_col.filter_col( key.borrow() ) + if !filter_col.filter_col( key.as_ref() ) { return None; } @@ -372,17 +498,18 @@ mod private let sz = string::size( &val ); key_to_ikey - .entry( key ) + .entry( key.clone() ) .and_modify( | icol | { let col = &mut col_descriptors[ *icol ]; col.width = col.width.max( sz[ 0 ] ); + col.label = ""; }) .or_insert_with( || { let icol = l; let width = sz[ 0 ]; - let col = ColDescriptor { width, icol }; + let col = ColDescriptor { width, icol, label : "" }; col_descriptors.push( col ); icol }); @@ -410,18 +537,9 @@ mod private // process header first - if let Some( header ) = table.header() + if has_header { - rows.len().checked_add( 1 ).expect( "Table has too many rows" ); - // assert!( header.len() <= usize::MAX, "Header of a table has too many cells" ); - has_header = true; - - let mut row2 = header.map( | ( key, title ) | - { - ( key, Cow::Borrowed( title ) ) - }); - - row_add( &mut row2, LineType::Header ); + row_add( column_names.clone(), LineType::Header ); } // Collect rows @@ -430,53 +548,14 @@ mod private { // assert!( row.cells().len() <= usize::MAX, "Row of a table has too many cells" ); - let mut row2 = row - .cells() - .map - ( - | ( key, val ) | - { - - let val = match val.0 - { - Some( val ) => - { - val - } - None => - { - Cow::Borrowed( "" ) - } - }; - - return ( key, val ); - } - ); - - row_add( &mut row2, LineType::Regular ); + row_add( row, LineType::Regular ); } // calculate size in chars mchars[ 0 ] = col_descriptors.iter().fold( 0, | acc, col | acc + col.width ); mchars[ 1 ] = row_descriptors.iter().fold( 0, | acc, row | acc + if row.vis { row.height } else { 0 } ); - - // cook slices multi-matrix - - let mut slices_dim = [ 1, mcells[ 0 ], mcells[ 1 ] ]; - slices_dim[ 0 ] = row_descriptors - .iter() - .fold( 0, | acc : usize, row | acc.max( row.height ) ) - ; - - let slices_len = slices_dim[ 0 ] * slices_dim[ 1 ] * slices_dim[ 2 ]; - let slices : Vec< &str > = vec![ "" ; slices_len ]; - - // assert_eq!( mcells, mcells, r#"Incorrect multidimensional size of table - // mcells <> mcells - // {mcells:?} <> {mcells:?}"# ); - // println!( "mcells : {mcells:?} | mcells : {mcells:?} | mcells_vis : {mcells_vis:?}" ); - + let mut x = InputExtract::< '_ > { mcells, @@ -486,39 +565,16 @@ mod private row_descriptors, data, has_header, - slices_dim, - slices, }; - // extract slices - - let mut slices : Vec< &str > = vec![]; - std::mem::swap( &mut x.slices, &mut slices ); - - let mut irow : isize = -1; - - for row_data in x.data.iter() + if x.data.len() > 0 { - - irow += 1; - for icol in 0 .. x.col_descriptors.len() { - let cell = &row_data[ icol ]; - string::lines( cell.0.as_ref() ) - .enumerate() - .for_each( | ( layer, s ) | - { - let md_index = [ layer, icol, irow as usize ]; - slices[ x.slices_dim.md_offset( md_index ) ] = s; - }) - ; + x.col_descriptors[ icol ].label = x.data[ 0 ][ icol ].0.as_ref(); } - } - std::mem::swap( &mut x.slices, &mut slices ); - return callback( &x ); } @@ -543,6 +599,8 @@ pub mod own Context, Printer, InputExtract, + RowDescriptor, + ColDescriptor, }; } diff --git a/module/core/format_tools/src/format/string.rs b/module/core/format_tools/src/format/string.rs index 511f44c473..ee34e9e718 100644 --- a/module/core/format_tools/src/format/string.rs +++ b/module/core/format_tools/src/format/string.rs @@ -4,7 +4,7 @@ // xxx : move to crate string_tools -/// Internal namespace. +/// Define a private namespace for all its items. mod private { @@ -114,6 +114,47 @@ mod private Lines::new( src.as_ref() ) } + /// Returns an iterator over the lines of a string slice with text wrapping. + /// + /// This function provides an iterator that yields each line of the input string slice. + /// It is based on previous iterator `lines` but it also includes text wrapping that is + /// controlled via `limit_width` argument. If the string contains a trailing new line, + /// then an empty string will be yielded in this iterator. + /// + /// # Arguments + /// + /// * `src` - A reference to a type that can be converted to a string slice. This allows + /// for flexibility in passing various string-like types. + /// + /// * `limit_width` - text wrapping limit. Lines that are longer than this parameter will + // be split into smaller lines. + /// + /// # Returns + /// + /// An iterator of type `LinesWithLimit` that yields each line as a `&str`. + /// + /// # Examples + /// + /// ``` + /// let text = "Hello\nWorld\n"; + /// let mut lines = format_tools::string::lines_with_limit( text, 3 ); + /// assert_eq!( lines.next(), Some( "Hel" ) ); + /// assert_eq!( lines.next(), Some( "lo" ) ); + /// assert_eq!( lines.next(), Some( "Wor" ) ); + /// assert_eq!( lines.next(), Some( "ld" ) ); + /// assert_eq!( lines.next(), Some( "" ) ); + /// assert_eq!( lines.next(), None ); + /// ``` + pub fn lines_with_limit< S : AsRef< str > + ?Sized > + ( + src : & S, + limit_width : usize + ) + -> LinesWithLimit< '_ > + { + LinesWithLimit::new( src.as_ref(), limit_width ) + } + /// An iterator over the lines of a string slice. /// /// This struct implements the `Iterator` trait, allowing you to iterate over the lines @@ -128,6 +169,7 @@ mod private has_trailing_newline : bool, finished : bool, } + impl< 'a > Lines< 'a > { fn new( input : &'a str ) -> Self @@ -172,6 +214,70 @@ mod private } } + /// An iterator over the lines of a string slice with text wrapping. + /// + /// This struct implements the `Iterator` trait, allowing you to iterate over the parts + /// of a string. It uses `Lines` iterator and splits lines if they are longer that the + /// `limit_width` parameter. If the string contains a trailing new line, then an empty + /// string will be yielded in this iterator. + /// + /// If `limit_width` is equal to 0, then no wrapping is applied, and behaviour of this + /// iterator is equals to `Lines` iterator. + #[ derive( Debug ) ] + pub struct LinesWithLimit< 'a > + { + lines : Lines< 'a >, + limit_width : usize, + cur : Option< &'a str >, + } + + impl< 'a > LinesWithLimit< 'a > + { + fn new( input : &'a str, limit_width : usize ) -> Self + { + LinesWithLimit + { + lines : lines( input ), + limit_width, + cur : None, + } + } + } + + impl< 'a > Iterator for LinesWithLimit< 'a > + { + type Item = &'a str; + + fn next( &mut self ) -> Option< Self::Item > + { + if self.cur.is_none() || self.cur.is_some_and( str::is_empty ) + { + self.cur = self.lines.next(); + } + + match self.cur + { + None => return None, + + Some( cur ) => + { + if self.limit_width == 0 + { + self.cur = None; + Some( cur ) + } + else + { + let (chunk, rest) = cur.split_at(self.limit_width.min(cur.len())); + self.cur = Some( rest ); + + Some(chunk) + } + } + } + } + } + } #[ allow( unused_imports ) ] @@ -191,6 +297,8 @@ pub mod own size, lines, Lines, + lines_with_limit, + LinesWithLimit, }; } diff --git a/module/core/format_tools/src/format/table.rs b/module/core/format_tools/src/format/table.rs index 9ea6b1aecd..1fab2ab744 100644 --- a/module/core/format_tools/src/format/table.rs +++ b/module/core/format_tools/src/format/table.rs @@ -2,7 +2,7 @@ //! Table interface. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { @@ -12,7 +12,11 @@ mod private // fmt, borrow::Borrow, }; - // use std::borrow::Cow; + use std:: + { + borrow::Cow, + collections::HashMap, + }; use reflect_tools:: { IteratorTrait, @@ -72,26 +76,37 @@ mod private // = - /// Marker trait to tag structures for whcih table trait deducing should be done from trait Fields, which is reflection. + /// Marker trait to tag structures for which table trait deducing should be done from trait Fields, which is reflection. pub trait TableWithFields {} // = /// A trait for iterating over all cells of a row. - pub trait Cells< CellKey, CellRepr > + pub trait Cells< CellKey > where - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, CellKey : table::CellKey + ?Sized, { /// Returns an iterator over all cells of the row. - fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b CellKey, OptionalCow< 'b, str, CellRepr > ) > + // fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b CellKey, OptionalCow< 'b, str > ) > + fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b CellKey, Option< Cow< 'b, str > > ) > where 'a : 'b, CellKey : 'b, ; } - impl< Row, CellKey, CellRepr > Cells< CellKey, CellRepr > + impl Cells< str > for HashMap< String, String > + { + fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b str, Option< Cow< 'b, str > > ) > + where + 'a : 'b, + { + self.iter().map( | ( k, v ) | ( k.as_str(), Some( Cow::from( v ) ) ) ) + } + } + + impl< Row, CellKey > Cells< CellKey > for Row where CellKey : table::CellKey + ?Sized, @@ -99,14 +114,17 @@ mod private Row : TableWithFields + Fields < &'ckv CellKey, - OptionalCow< 'ckv, str, CellRepr >, + // OptionalCow< 'ckv, str >, + Option< Cow< 'ckv, str > >, Key< 'ckv > = &'ckv CellKey, - Val< 'ckv > = OptionalCow< 'ckv, str, CellRepr >, + // Val< 'ckv > = OptionalCow< 'ckv, str >, + Val< 'ckv > = Option< Cow< 'ckv, str > >, > + 'ckv, // xxx - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { - fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b CellKey, OptionalCow< 'b, str, CellRepr > ) > + // fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b CellKey, OptionalCow< 'b, str > ) > + fn cells< 'a, 'b >( &'a self ) -> impl IteratorTrait< Item = ( &'b CellKey, Option< Cow< 'b, str > > ) > where 'a : 'b, CellKey : 'b, @@ -154,15 +172,15 @@ mod private /// /// The type representing a row, which must implement `Cells` /// for the specified `CellKey` and `CellRepr`. - type Row : Cells< Self::CellKey, Self::CellRepr >; + type Row : Cells< Self::CellKey >; /// /// The type used to identify cells within a row, requiring /// implementation of the `Key` trait. type CellKey : table::CellKey + ?Sized; /// - /// The type representing the content of a cell, requiring - /// implementation of the `CellRepr` trait. - type CellRepr : table::CellRepr; + // /// The type representing the content of a cell, requiring + // /// implementation of the `CellRepr` trait. + // type // CellRepr : table::CellRepr; /// Returns an iterator over all rows of the table. fn rows( &self ) -> impl IteratorTrait< Item = &Self::Row >; @@ -171,9 +189,8 @@ mod private // Self::Row : 'a; } - impl< T, RowKey, Row, CellKey, CellRepr > - TableRows<> - for AsTable< '_, T, RowKey, Row, CellKey, CellRepr > + impl< T, RowKey, Row, CellKey > TableRows<> + for AsTable< '_, T, RowKey, Row, CellKey > where for< 'k, 'v > T : Fields @@ -185,14 +202,14 @@ mod private > + 'k + 'v, RowKey : table::RowKey, - Row : TableWithFields + Cells< CellKey, CellRepr >, + Row : Cells< CellKey >, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { type RowKey = RowKey; type Row = Row; type CellKey = CellKey; - type CellRepr = CellRepr; + // type CellRepr = CellRepr; fn rows( &self ) -> impl IteratorTrait< Item = &Self::Row > // fn rows< 'a >( &'a self ) -> impl IteratorTrait< Item = &'a Self::Row > @@ -217,14 +234,14 @@ mod private // fn mcells( &self ) -> [ usize ; 2 ]; // } // -// impl< T, RowKey, Row, CellKey, CellRepr > TableSize -// for AsTable< '_, T, RowKey, Row, CellKey, CellRepr > +// impl< T, RowKey, Row, CellKey > TableSize +// for AsTable< '_, T, RowKey, Row, CellKey > // where -// Self : TableRows< RowKey = RowKey, Row = Row, CellKey = CellKey, CellRepr = CellRepr >, +// Self : TableRows< RowKey = RowKey, Row = Row, CellKey = CellKey >, // RowKey : table::RowKey, -// Row : Cells< CellKey, CellRepr >, +// Row : Cells< CellKey >, // CellKey : table::CellKey + ?Sized, -// CellRepr : table::CellRepr, +// // CellRepr : table::CellRepr, // { // fn mcells( &self ) -> [ usize ; 2 ] // { @@ -256,14 +273,14 @@ mod private fn header( &self ) -> Option< impl IteratorTrait< Item = ( &Self::CellKey, &'_ str ) > >; } - impl< T, RowKey, Row, CellKey, CellRepr > TableHeader - for AsTable< '_, T, RowKey, Row, CellKey, CellRepr > + impl< T, RowKey, Row, CellKey > TableHeader + for AsTable< '_, T, RowKey, Row, CellKey > where - Self : TableRows< RowKey = RowKey, Row = Row, CellKey = CellKey, CellRepr = CellRepr >, + Self : TableRows< RowKey = RowKey, Row = Row, CellKey = CellKey >, RowKey : table::RowKey, - Row : TableWithFields + Cells< CellKey, CellRepr >, + Row : Cells< CellKey >, CellKey : table::CellKey + ?Sized, - CellRepr : table::CellRepr, + // CellRepr : table::CellRepr, { type CellKey = CellKey; diff --git a/module/core/format_tools/src/format/test_object_without_impl.rs b/module/core/format_tools/src/format/test_object_without_impl.rs new file mode 100644 index 0000000000..f61b3fe588 --- /dev/null +++ b/module/core/format_tools/src/format/test_object_without_impl.rs @@ -0,0 +1,155 @@ +//! A strucutre for diagnostic and demonstration purpose. + +// use super::*; + +// use crate:: +// { +// Fields, +// IteratorTrait, +// TableWithFields, +// WithRef, +// OptionalCow, +// }; + +use std:: +{ + collections::HashMap, + hash::Hasher, + hash::Hash, + cmp::Ordering, + // borrow::Cow, +}; + +/// Struct representing a test object with various fields. +#[ derive( Clone, Debug, PartialEq, Eq ) ] +pub struct TestObjectWithoutImpl +{ + pub id : String, + pub created_at : i64, + pub file_ids : Vec< String >, + pub tools : Option< Vec< HashMap< String, String > > >, +} + +// TableWithFields is not implemented for TestObjectWithoutImpl intentionally + +// impl TableWithFields for TestObjectWithoutImpl {} +// +// impl Fields< &'_ str, Option< Cow< '_, str > > > +// for TestObjectWithoutImpl +// { +// type Key< 'k > = &'k str; +// type Val< 'v > = Option< Cow< 'v, str > >; +// +// fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > +// { +// use format_tools::ref_or_display_or_debug_multiline::field; +// // use format_tools::ref_or_display_or_debug::field; +// let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new(); +// +// dst.push( field!( &self.id ) ); +// dst.push( field!( &self.created_at ) ); +// dst.push( field!( &self.file_ids ) ); +// +// if let Some( tools ) = &self.tools +// { +// dst.push( field!( tools ) ); +// } +// else +// { +// dst.push( ( "tools", Option::None ) ); +// } +// +// dst.into_iter() +// } +// +// } + +impl Hash for TestObjectWithoutImpl +{ + + fn hash< H: Hasher >( &self, state: &mut H ) + { + self.id.hash( state ); + self.created_at.hash( state ); + self.file_ids.hash( state ); + + if let Some( tools ) = &self.tools + { + for tool in tools + { + for ( key, value ) in tool + { + key.hash( state ); + value.hash( state ); + } + } + } + else + { + state.write_u8( 0 ); + } + } + +} + +impl PartialOrd for TestObjectWithoutImpl +{ + + fn partial_cmp( &self, other: &Self ) -> Option< Ordering > + { + Some( self.cmp( other ) ) + } + +} + +impl Ord for TestObjectWithoutImpl +{ + + fn cmp( &self, other: &Self ) -> Ordering + { + self.id + .cmp( &other.id ) + .then_with( | | self.created_at.cmp( &other.created_at ) ) + .then_with( | | self.file_ids.cmp( &other.file_ids ) ) + } + +} + +/// Generate a dynamic array of test objects. +pub fn test_objects_gen() -> Vec< TestObjectWithoutImpl > +{ + + vec! + [ + TestObjectWithoutImpl + { + id : "1".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".to_string() ], + tools : None + }, + TestObjectWithoutImpl + { + id : "2".to_string(), + created_at : 13, + file_ids : vec![ "file3".to_string(), "file4\nmore details".to_string() ], + tools : Some + ( + vec! + [ + { + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map + }, + { + let mut map = HashMap::new(); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + } + ] + ), + }, + ] + +} diff --git a/module/core/format_tools/src/format/text_wrap.rs b/module/core/format_tools/src/format/text_wrap.rs new file mode 100644 index 0000000000..695ac287cd --- /dev/null +++ b/module/core/format_tools/src/format/text_wrap.rs @@ -0,0 +1,256 @@ +//! +//! Text wrapping function. +//! + +/// Define a private namespace for all its items. +mod private +{ + + use std::borrow::Cow; + + use crate::*; + + /// Struct that represents a wrapped tabular data. It is similar to `InputExtract`, + /// but we cannot use it as it does not wrap the text and it contains wrong column + /// widthes and heights (as they are dependent on wrapping too). + #[ derive( Debug ) ] + pub struct WrappedInputExtract< 'data > + { + /// Tabular data of rows and columns. + /// Note: these cells does not represent the actual information cells in the + /// original table. These cells are wrapped and used only for displaying. This also + /// means that one row in original table can be represented here with one or more + /// rows. + pub data: Vec< Vec< WrappedCell< 'data > > >, + + /// New widthes of columns that include wrapping. + pub column_widthes : Vec< usize >, + + /// Size of the first row of the table. + /// This parameter is used in case header of the table should be displayed. + pub first_row_height : usize, + } + + /// Struct that represents a content of a wrapped cell. + /// It contains the slice of the cell as well as its original width. + /// + /// Parameter `wrap_width` is needed as text in `output_format::Table` is centered. + /// However it is centered according to whole cell size and not the size of wrapped + /// text slice. + /// + /// Example that depicts the importance of `wrap_width` parameter: + /// + /// 1) | [ | 2) | [ | + /// | line1, | | line1, | + /// | line2 | | line2 | + /// | ] | | ] | + /// + /// The first case seems to be properly formatted, while the second case took centering + /// too literally. That is why `wrap_width` is introduced, and additional spaces to the + /// right side should be included by the output formatter. + #[ derive( Debug ) ] + pub struct WrappedCell< 'data > + { + /// Width of the cell. In calculations use this width instead of slice length in order + /// to properly center the text. See example in the doc string of the parent struct. + pub wrap_width : usize, + + /// Actual content of the cell. + pub content : Cow< 'data, str > + } + + /// Wrap table cells. + /// + /// `InputExtract` contains cells with full content, so it represents the logical + /// structure of the table. `WrappedInputExtract` wraps original cells to smaller + /// cells. The resulting data is more low-level and corresponds to the table that + /// will be actually printed to the console (or other output type). + /// + /// `InputExtract` is not directly passed to this function, as it made to be general. + /// Instead you pass table cells in `data` argument and pass a vector of column widthes + /// in `columns_width_list` generated by `InputExtract`. + /// + /// `columns_width_list` is a slice, this is more effective and general than just a `Vec`. + /// In table style, there could be many columns, but in records style there will be + /// always 2 columns - this number is known at compile time, so we can use a slice object. + /// + /// Notice: + /// 1. Data passed to this function should contain only visible rows and columns. + /// It does not perform additional filtering. + /// 2. `data` parameters is **vector of rows of columns** (like and ordinary table). + /// This means that in styles like `Records` where headers and rows turned into columns + /// You have to transpose your data before passing it to this function. + /// + /// Wrapping is controlled by `columns_max_width` and `columns_nowrap_width` parameters. + /// + /// - `columns_max_width` is the size that is allowed to be occupied by columns. + /// It equals to maximum table width minus lengthes of visual elements (prefixes, + /// postfixes, separators, etc.). + /// + /// - `columns_nowrap_width` is the sum of column widthes of cells without wrapping (basically, + /// the sum of widthes of column descriptors in `InputExtract`). + /// + /// The function will perform wrapping and shrink the columns so that they occupy not + /// more than `columns_max_width`. + /// + /// If `columns_max_width` is equal to 0, then no wrapping will be performed. + pub fn text_wrap< 'data > + ( + data : impl Iterator< Item = &'data Vec< ( Cow< 'data, str >, [ usize; 2 ] ) > >, + columns_width_list : impl AsRef< [ usize ] >, + columns_max_width : usize, + columns_nowrap_width : usize, + ) + -> WrappedInputExtract< 'data > + { + let columns_width_list = columns_width_list.as_ref(); + + let mut first_row_height = 0; + let mut new_data = Vec::new(); + let mut column_widthes = Vec::new(); + + if columns_max_width == 0 || columns_max_width >= columns_nowrap_width + { + column_widthes.extend( columns_width_list.iter() ); + } + else + { + let shrink_factor : f32 = ( columns_max_width as f32 ) / ( columns_nowrap_width as f32 ); + + for ( icol, col_width ) in columns_width_list.iter().enumerate() + { + let col_limit_float = ( *col_width as f32 ) * shrink_factor; + let col_limit = col_limit_float.floor() as usize; + + let col_width_to_put = if icol == columns_width_list.len() - 1 + { + columns_max_width - column_widthes.iter().sum::() + } + else + { + col_limit.max(1) + }; + + column_widthes.push( col_width_to_put ); + } + } + + for ( irow, row ) in data.enumerate() + { + let mut wrapped_rows : Vec< Vec< Cow< 'data, str > > > = vec![]; + + for ( icol, col ) in row.iter().enumerate() + { + let col_limit = column_widthes[ icol ]; + let wrapped_col = string::lines_with_limit( col.0.as_ref(), col_limit ).map( Cow::from ).collect(); + wrapped_rows.push( wrapped_col ); + } + + let max_rows = wrapped_rows.iter().map( Vec::len ).max().unwrap_or(0); + + let mut transposed : Vec< Vec< WrappedCell< 'data > > > = Vec::new(); + + if max_rows == 0 + { + transposed.push( vec![] ); + } + + for i in 0..max_rows + { + let mut row_vec : Vec< WrappedCell< 'data > > = Vec::new(); + + for col_lines in &wrapped_rows + { + if col_lines.len() > i + { + let wrap_width = col_lines.iter().map( |c| c.len() ).max().unwrap_or(0); + row_vec.push( WrappedCell { wrap_width , content : col_lines[ i ].clone() } ); + } + else + { + row_vec.push( WrappedCell { wrap_width : 0, content : Cow::from( "" ) } ); + } + } + + transposed.push( row_vec ); + } + + if irow == 0 + { + first_row_height += transposed.len(); + } + + new_data.extend( transposed ); + } + + WrappedInputExtract + { + data: new_data, + first_row_height, + column_widthes + } + } + + /// Calculate width of the column without wrapping. + pub fn width_calculate< 'data > + ( + column : &'data Vec< ( Cow< 'data, str >, [ usize; 2 ] ) > + ) + -> usize + { + column.iter().map( |k| + { + string::lines( k.0.as_ref() ).map( |l| l.chars().count() ).max().unwrap_or( 0 ) + } ).max().unwrap_or( 0 ) + } + +} + +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; + #[ doc( inline ) ] + pub use orphan::*; + + #[ doc( inline ) ] + pub use + { + }; + + #[ doc( inline ) ] + pub use private:: + { + text_wrap, + width_calculate, + }; + +} + +/// Orphan namespace of the module. +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; + #[ doc( inline ) ] + pub use exposed::*; +} + +/// Exposed namespace of the module. +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + pub use super::super::output_format; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; +} diff --git a/module/core/format_tools/src/format/to_string.rs b/module/core/format_tools/src/format/to_string.rs index 6446e90fa2..8bc9bb538f 100644 --- a/module/core/format_tools/src/format/to_string.rs +++ b/module/core/format_tools/src/format/to_string.rs @@ -2,7 +2,7 @@ //! Flexible ToString augmentation. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { 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 index e79b827896..fb5966bf38 100644 --- a/module/core/format_tools/src/format/to_string_with_fallback.rs +++ b/module/core/format_tools/src/format/to_string_with_fallback.rs @@ -2,7 +2,7 @@ //! Flexible ToString augmentation. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/format_tools/tests/inc/collection_test.rs b/module/core/format_tools/tests/inc/collection_test.rs index 941f9a498b..0d066004e2 100644 --- a/module/core/format_tools/tests/inc/collection_test.rs +++ b/module/core/format_tools/tests/inc/collection_test.rs @@ -6,13 +6,12 @@ use the_module:: AsTable, TableRows, WithRef, - print, + // the_module::print, }; use std:: { collections::HashMap, - // borrow::Cow, }; use test_object::TestObject; @@ -57,14 +56,14 @@ fn dlist_basic() }; use the_module::TableFormatter; - let _as_table : AsTable< '_, Vec< TestObject >, &str, TestObject, str, WithRef > = AsTable::new( &data ); + let _as_table : AsTable< '_, Vec< TestObject >, &str, TestObject, str> = AsTable::new( &data ); let as_table = AsTable::new( &data ); let rows = TableRows::rows( &as_table ); assert_eq!( rows.len(), 2 ); let mut output = String::new(); - let mut context = print::Context::new( &mut output, Default::default() ); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); let got = as_table.table_to_string(); assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); @@ -113,14 +112,14 @@ fn hmap_basic() }; use the_module::TableFormatter; - let _as_table : AsTable< '_, HashMap< &str, TestObject >, &str, TestObject, str, WithRef > = AsTable::new( &data ); + let _as_table : AsTable< '_, HashMap< &str, TestObject >, &str, TestObject, str> = AsTable::new( &data ); let as_table = AsTable::new( &data ); let rows = TableRows::rows( &as_table ); assert_eq!( rows.len(), 2 ); let mut output = String::new(); - let mut context = print::Context::new( &mut output, Default::default() ); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); let got = as_table.table_to_string(); assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); @@ -169,14 +168,230 @@ fn bmap_basic() }; use the_module::TableFormatter; - let _as_table : AsTable< '_, Bmap< &str, TestObject >, &str, TestObject, str, WithRef > = AsTable::new( &data ); + let _as_table : AsTable< '_, Bmap< &str, TestObject >, &str, TestObject, str> = AsTable::new( &data ); let as_table = AsTable::new( &data ); let rows = TableRows::rows( &as_table ); assert_eq!( rows.len(), 2 ); let mut output = String::new(); - let mut context = print::Context::new( &mut output, Default::default() ); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); + let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); + let got = as_table.table_to_string(); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + +} + +#[ test ] +fn bset_basic() +{ + + let data : collection_tools::Bset< TestObject > = bset! + { + 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\nmore details".to_string() ], + tools : Some + ( + vec! + [ + { + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map + }, + { + let mut map = HashMap::new(); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + } + ] + ), + }, + }; + + use the_module::TableFormatter; + let _as_table : AsTable< '_, BTreeSet< TestObject >, &str, TestObject, str> = AsTable::new( &data ); + let as_table = AsTable::new( &data ); + + let rows = TableRows::rows( &as_table ); + assert_eq!( rows.len(), 2 ); + + let mut output = String::new(); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); + let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); + let got = as_table.table_to_string(); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + +} + +#[ test ] +fn deque_basic() +{ + + let data : collection_tools::Deque< TestObject > = deque! + { + 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\nmore details".to_string() ], + tools : Some + ( + vec! + [ + { + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map + }, + { + let mut map = HashMap::new(); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + } + ] + ), + }, + }; + + use the_module::TableFormatter; + let _as_table : AsTable< '_, VecDeque< TestObject >, &str, TestObject, str> = AsTable::new( &data ); + let as_table = AsTable::new( &data ); + + let rows = TableRows::rows( &as_table ); + assert_eq!( rows.len(), 2 ); + + let mut output = String::new(); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); + let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); + let got = as_table.table_to_string(); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + +} + +#[ test ] +fn hset_basic() +{ + + let data : collection_tools::Hset< TestObject > = hset! + { + 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\nmore details".to_string() ], + tools : Some + ( + vec! + [ + { + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map + }, + { + let mut map = HashMap::new(); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + } + ] + ), + }, + }; + + use the_module::TableFormatter; + let _as_table : AsTable< '_, HashSet< TestObject >, &str, TestObject, str> = AsTable::new( &data ); + let as_table = AsTable::new( &data ); + + let rows = TableRows::rows( &as_table ); + assert_eq!( rows.len(), 2 ); + + let mut output = String::new(); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); + let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); + let got = as_table.table_to_string(); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + +} + +#[ test ] +fn llist_basic() +{ + + let data : collection_tools::Llist< TestObject > = llist! + { + 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\nmore details".to_string() ], + tools : Some + ( + vec! + [ + { + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map + }, + { + let mut map = HashMap::new(); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + } + ] + ), + }, + }; + + use the_module::TableFormatter; + let _as_table : AsTable< '_, LinkedList< TestObject >, &str, TestObject, str> = AsTable::new( &data ); + let as_table = AsTable::new( &data ); + + let rows = TableRows::rows( &as_table ); + assert_eq!( rows.len(), 2 ); + + let mut output = String::new(); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); let got = as_table.table_to_string(); assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); @@ -186,3 +401,46 @@ fn bmap_basic() } // qqq : xxx : implement for other containers + +#[ test ] +fn vec_of_hashmap() +{ + let data : Vec< HashMap< String, String > > = vec! + [ + { + let mut map = HashMap::new(); + map.insert( "id".to_string(), "1".to_string() ); + map.insert( "created_at".to_string(), "1627845583".to_string() ); + map + }, + { + let mut map = HashMap::new(); + map.insert( "id".to_string(), "2".to_string() ); + map.insert( "created_at".to_string(), "13".to_string() ); + map + }, + ]; + + use std::borrow::Cow; + + use the_module::TableFormatter; + + let _as_table : AsTable< '_, Vec< HashMap< String, String > >, &str, HashMap< String, String >, str> = AsTable::new( &data ); + let as_table = AsTable::new( &data ); + + let rows = TableRows::rows( &as_table ); + assert_eq!( rows.len(), 2 ); + + let mut output = String::new(); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); + + let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); + + let got = as_table.table_to_string(); + + println!("{}", got); + + assert!( got.contains( "│ id │ created_at │" ) || got.contains( "│ created_at │ id │" ) ); + assert!( got.contains( "│ 1 │ 1627845583 │" ) || got.contains( "│ 1627845583 │ 1 │" ) ); + assert!( got.contains( "│ 2 │ 13 │" ) || got.contains( "│ 13 │ 2 │" ) ); +} \ No newline at end of file diff --git a/module/core/format_tools/tests/inc/fields_test.rs b/module/core/format_tools/tests/inc/fields_test.rs index 48ba295e20..32d921bed0 100644 --- a/module/core/format_tools/tests/inc/fields_test.rs +++ b/module/core/format_tools/tests/inc/fields_test.rs @@ -26,16 +26,16 @@ pub struct TestObject pub tools : Option< Vec< HashMap< String, String > > >, } -impl Fields< &'static str, OptionalCow< '_, str, WithRef > > +impl Fields< &'_ str, Option< Cow< '_, str > > > for TestObject { - type Key< 'k > = &'static str; - type Val< 'v > = OptionalCow< 'v, str, WithRef >; + type Key< 'k > = &'k str; + type Val< 'v > = Option< Cow< 'v, str > >; - fn fields( &self ) -> impl IteratorTrait< Item = ( &'static str, OptionalCow< '_, str, WithRef > ) > + fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > { use format_tools::ref_or_display_or_debug::field; - let mut dst : Vec< ( &'static str, OptionalCow< '_, str, WithRef > ) > = Vec::new(); + let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new(); dst.push( field!( &self.id ) ); dst.push( field!( &self.created_at ) ); @@ -47,11 +47,17 @@ for TestObject } else { - dst.push( ( "tools", OptionalCow::none() ) ); + dst.push( ( "tools", Option::None ) ); } dst.into_iter() } + +} + +pub fn is_borrowed( cow : &Option< Cow< '_, str > > ) -> bool +{ + matches!( cow, Some( Cow::Borrowed( _ ) ) ) } // @@ -76,16 +82,16 @@ fn basic_with_ref_display_debug() ), }; - let fields : Vec< ( &str, OptionalCow< '_, str, WithRef > ) > = - Fields::< &'static str, OptionalCow< '_, str, WithRef > >::fields( &test_object ).collect(); + let fields : Vec< ( &str, Option< Cow< '_, str > > ) > = + Fields::< &'static str, Option< Cow< '_, str > > >::fields( &test_object ).collect(); - // let fields : Vec< ( &str, OptionalCow< '_, str, WithRef > ) > = test_object.fields().collect(); + // let fields : Vec< ( &str, Option< Cow< '_, str > > ) > = test_object.fields().collect(); assert_eq!( fields.len(), 4 ); - assert!( fields[ 0 ].1.is_borrowed() ); - assert!( !fields[ 1 ].1.is_borrowed() ); - assert!( !fields[ 2 ].1.is_borrowed() ); - assert!( !fields[ 3 ].1.is_borrowed() ); + assert!( is_borrowed( &fields[ 0 ].1 ) ); + assert!( !is_borrowed( &fields[ 1 ].1 ) ); + assert!( !is_borrowed( &fields[ 2 ].1 ) ); + assert!( !is_borrowed( &fields[ 3 ].1 ) ); assert_eq!( fields[ 0 ], ( "id", Some( Cow::Borrowed( "12345" ) ).into() ) ); assert_eq!( fields[ 0 ], ( "id", Some( Cow::Owned( "12345".to_string() ) ).into() ) ); assert_eq!( fields[ 1 ], ( "created_at", Some( Cow::Owned( "1627845583".to_string() ) ).into() ) ); diff --git a/module/core/format_tools/tests/inc/format_records_test.rs b/module/core/format_tools/tests/inc/format_records_test.rs index c1e2cf2b26..77b8de7364 100644 --- a/module/core/format_tools/tests/inc/format_records_test.rs +++ b/module/core/format_tools/tests/inc/format_records_test.rs @@ -5,16 +5,16 @@ use the_module:: { AsTable, WithRef, - // filter, + filter, print, output_format, }; -// use std:: -// { -// // collections::HashMap, -// // borrow::Cow, -// }; +use std:: +{ + // collections::HashMap, + borrow::Cow, +}; // @@ -23,7 +23,7 @@ fn basic() { let test_objects = test_object::test_objects_gen(); - let _as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str, WithRef > = AsTable::new( &test_objects ); + let _as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str> = AsTable::new( &test_objects ); let as_table = AsTable::new( &test_objects ); let mut output = String::new(); @@ -34,287 +34,418 @@ fn basic() assert!( got.is_ok() ); println!( "{}", &output ); - // -[ RECORD 1 ] - // sid | 3 - // sname | Alice - // gap | 5 - // -[ RECORD 2 ] - // sid | 6 - // sname | Joe - // gap | 1 - // -[ RECORD 3 ] - // sid | 10 - // sname | Boris - // gap | 5 - - let exp = r#"xxx"#; - // a_id!( output.as_str(), exp ); + let exp = r#" = 1 +│ id │ 1 │ +│ created_at │ 1627845583 │ +│ file_ids │ [ │ +│ │ "file1", │ +│ │ "file2", │ +│ │ ] │ +│ tools │ │ + = 2 +│ id │ 2 │ +│ created_at │ 13 │ +│ file_ids │ [ │ +│ │ "file3", │ +│ │ "file4\nmore details", │ +│ │ ] │ +│ tools │ [ │ +│ │ { │ +│ │ "tool1": "value1", │ +│ │ }, │ +│ │ { │ +│ │ "tool2": "value2", │ +│ │ }, │ +│ │ ] │"#; + a_id!( output.as_str(), exp ); } // -// #[ test ] -// fn table_to_string() -// { -// use the_module::TableFormatter; -// let test_objects = test_object::test_objects_gen(); -// -// // with explicit arguments -// -// let as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str, WithRef > = AsTable::new( &test_objects ); -// let table_string = as_table.table_to_string(); -// println!( "\ntable_string\n{table_string}" ); -// assert!( table_string.contains( "id" ) ); -// assert!( table_string.contains( "created_at" ) ); -// assert!( table_string.contains( "file_ids" ) ); -// assert!( table_string.contains( "tools" ) ); -// -// // without explicit arguments -// -// println!( "" ); -// let as_table = 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" ) ); -// println!( "\ntable_string\n{table_string}" ); -// -// } -// -// // -// -// #[ test ] -// fn custom_format() -// { -// // use the_module::TableFormatter; -// let test_objects = test_object::test_objects_gen(); -// -// let mut format = output_format::Ordinary::default(); -// format.cell_prefix = "( ".into(); -// format.cell_postfix = " )".into(); -// format.cell_separator = "|".into(); -// format.row_prefix = ">".into(); -// format.row_postfix = "<".into(); -// format.row_separator = "\n".into(); -// -// let printer = print::Printer::with_format( &format ); -// let as_table = AsTable::new( &test_objects ); -// let mut output = String::new(); -// let mut context = print::Context::new( &mut output, printer ); -// let result = the_module::TableFormatter::fmt( &as_table, &mut context ); -// assert!( result.is_ok() ); -// -// println!( "\noutput\n{output}" ); -// assert!( output.contains( "id" ) ); -// assert!( output.contains( "created_at" ) ); -// assert!( output.contains( "file_ids" ) ); -// assert!( output.contains( "tools" ) ); -// -// let exp = r#">( id )|( created_at )|( file_ids )|( tools )< -// ───────────────────────────────────────────────────────────────────────────────────── -// >( 1 )|( 1627845583 )|( [ )|( )< -// >( )|( )|( "file1", )|( )< -// >( )|( )|( "file2", )|( )< -// >( )|( )|( ] )|( )< -// >( 2 )|( 13 )|( [ )|( [ )< -// >( )|( )|( "file3", )|( { )< -// >( )|( )|( "file4\nmore details", )|( "tool1": "value1", )< -// >( )|( )|( ] )|( }, )< -// >( )|( )|( )|( { )< -// >( )|( )|( )|( "tool2": "value2", )< -// >( )|( )|( )|( }, )< -// >( )|( )|( )|( ] )<"#; -// a_id!( output.as_str(), exp ); -// -// // using table_to_string_with_format -// -// use the_module::TableFormatter; -// -// let mut format = output_format::Ordinary::default(); -// format.cell_prefix = "( ".into(); -// format.cell_postfix = " )".into(); -// format.cell_separator = "|".into(); -// format.row_prefix = ">".into(); -// format.row_postfix = "<".into(); -// format.row_separator = "\n".into(); -// -// // let as_table = AsTable::new( &test_objects ); -// let got = AsTable::new( &test_objects ).table_to_string_with_format( &format ); -// let exp = r#">( id )|( created_at )|( file_ids )|( tools )< -// ───────────────────────────────────────────────────────────────────────────────────── -// >( 1 )|( 1627845583 )|( [ )|( )< -// >( )|( )|( "file1", )|( )< -// >( )|( )|( "file2", )|( )< -// >( )|( )|( ] )|( )< -// >( 2 )|( 13 )|( [ )|( [ )< -// >( )|( )|( "file3", )|( { )< -// >( )|( )|( "file4\nmore details", )|( "tool1": "value1", )< -// >( )|( )|( ] )|( }, )< -// >( )|( )|( )|( { )< -// >( )|( )|( )|( "tool2": "value2", )< -// >( )|( )|( )|( }, )< -// >( )|( )|( )|( ] )<"#; -// a_id!( got, exp ); -// -// } -// -// -// -// #[ test ] -// fn filter_col_none() -// { -// let test_objects = test_object::test_objects_gen(); -// -// let mut format = output_format::Ordinary::default(); -// format.cell_prefix = "( ".into(); -// format.cell_postfix = " )".into(); -// format.cell_separator = "|".into(); -// format.row_prefix = ">".into(); -// format.row_postfix = "<".into(); -// format.row_separator = "\n".into(); -// -// let mut printer = print::Printer::with_format( &format ); -// printer.filter_col = &filter::None; -// -// let as_table = AsTable::new( &test_objects ); -// let mut output = String::new(); -// let mut context = print::Context::new( &mut output, printer ); -// let result = the_module::TableFormatter::fmt( &as_table, &mut context ); -// assert!( result.is_ok() ); -// -// println!( "\noutput\n{output}" ); -// -// let exp = r#">< -// ── -// >< -// ><"#; -// -// a_id!( output.as_str(), exp ); -// -// } -// -// // -// -// #[ test ] -// fn filter_col_callback() -// { -// let test_objects = test_object::test_objects_gen(); -// -// let mut format = output_format::Ordinary::default(); -// format.cell_prefix = "( ".into(); -// format.cell_postfix = " )".into(); -// format.cell_separator = "|".into(); -// format.row_prefix = ">".into(); -// format.row_postfix = "<".into(); -// format.row_separator = "\n".into(); -// -// let mut printer = print::Printer::with_format( &format ); -// printer.filter_col = &| title : &str | -// { -// title != "tools" -// }; -// -// let as_table = AsTable::new( &test_objects ); -// let mut output = String::new(); -// let mut context = print::Context::new( &mut output, printer ); -// let result = the_module::TableFormatter::fmt( &as_table, &mut context ); -// assert!( result.is_ok() ); -// -// println!( "\noutput\n{output}" ); -// -// let exp = r#">( id )|( created_at )|( file_ids )< -// ────────────────────────────────────────────────────── -// >( 1 )|( 1627845583 )|( [ )< -// >( )|( )|( "file1", )< -// >( )|( )|( "file2", )< -// >( )|( )|( ] )< -// >( 2 )|( 13 )|( [ )< -// >( )|( )|( "file3", )< -// >( )|( )|( "file4\nmore details", )< -// >( )|( )|( ] )<"#; -// -// a_id!( output.as_str(), exp ); -// -// } -// -// // -// -// #[ test ] -// fn filter_row_none() -// { -// let test_objects = test_object::test_objects_gen(); -// -// let mut format = output_format::Ordinary::default(); -// format.cell_prefix = "( ".into(); -// format.cell_postfix = " )".into(); -// format.cell_separator = "|".into(); -// format.row_prefix = ">".into(); -// format.row_postfix = "<".into(); -// format.row_separator = "\n".into(); -// -// let mut printer = print::Printer::with_format( &format ); -// printer.filter_row = &filter::None; -// -// let as_table = AsTable::new( &test_objects ); -// let mut output = String::new(); -// let mut context = print::Context::new( &mut output, printer ); -// let result = the_module::TableFormatter::fmt( &as_table, &mut context ); -// assert!( result.is_ok() ); -// -// println!( "\noutput\n{output}" ); -// -// let exp = r#""#; -// -// a_id!( output.as_str(), exp ); -// -// } -// -// // -// -// #[ test ] -// fn filter_row_callback() -// { -// let test_objects = test_object::test_objects_gen(); -// -// let mut format = output_format::Ordinary::default(); -// format.cell_prefix = "( ".into(); -// format.cell_postfix = " )".into(); -// format.cell_separator = "|".into(); -// format.row_prefix = ">".into(); -// format.row_postfix = "<".into(); -// format.row_separator = "\n".into(); -// -// let mut printer = print::Printer::with_format( &format ); -// printer.filter_row = &| _typ, irow, _row : &[ ( Cow< '_, str >, [ usize ; 2 ] ) ] | -// { -// irow != 1 -// }; -// -// let as_table = AsTable::new( &test_objects ); -// let mut output = String::new(); -// let mut context = print::Context::new( &mut output, printer ); -// let result = the_module::TableFormatter::fmt( &as_table, &mut context ); -// assert!( result.is_ok() ); +#[ test ] +fn custom_format() +{ + // use the_module::TableFormatter; + let test_objects = test_object::test_objects_gen(); + + let mut format = output_format::Records::default(); + format.cell_prefix = "( ".into(); + format.cell_postfix = " )".into(); + format.cell_separator = "|".into(); + format.row_prefix = ">".into(); + format.row_postfix = "<".into(); + format.row_separator = "\n".into(); + + let printer = print::Printer::with_format( &format ); + let as_table = AsTable::new( &test_objects ); + let mut output = String::new(); + let mut context = print::Context::new( &mut output, printer ); + let result = the_module::TableFormatter::fmt( &as_table, &mut context ); + assert!( result.is_ok() ); + + println!( "\noutput\n{output}" ); + + let exp = r#" = 1 +>( id )|( 1 )< +>( created_at )|( 1627845583 )< +>( file_ids )|( [ )< +>( )|( "file1", )< +>( )|( "file2", )< +>( )|( ] )< +>( tools )|( )< + = 2 +>( id )|( 2 )< +>( created_at )|( 13 )< +>( file_ids )|( [ )< +>( )|( "file3", )< +>( )|( "file4\nmore details", )< +>( )|( ] )< +>( tools )|( [ )< +>( )|( { )< +>( )|( "tool1": "value1", )< +>( )|( }, )< +>( )|( { )< +>( )|( "tool2": "value2", )< +>( )|( }, )< +>( )|( ] )<"#; + a_id!( output.as_str(), exp ); + + // using table_to_string_with_format + + use the_module::TableFormatter; + + let mut format = output_format::Records::default(); + format.cell_prefix = "( ".into(); + format.cell_postfix = " )".into(); + format.cell_separator = "|".into(); + format.row_prefix = ">".into(); + format.row_postfix = "<".into(); + format.row_separator = "\n".into(); + + // let as_table = AsTable::new( &test_objects ); + let got = AsTable::new( &test_objects ).table_to_string_with_format( &format ); + let exp = r#" = 1 +>( id )|( 1 )< +>( created_at )|( 1627845583 )< +>( file_ids )|( [ )< +>( )|( "file1", )< +>( )|( "file2", )< +>( )|( ] )< +>( tools )|( )< + = 2 +>( id )|( 2 )< +>( created_at )|( 13 )< +>( file_ids )|( [ )< +>( )|( "file3", )< +>( )|( "file4\nmore details", )< +>( )|( ] )< +>( tools )|( [ )< +>( )|( { )< +>( )|( "tool1": "value1", )< +>( )|( }, )< +>( )|( { )< +>( )|( "tool2": "value2", )< +>( )|( }, )< +>( )|( ] )<"#; + a_id!( got, exp ); + +} + // -// println!( "\noutput\n{output}" ); + +#[ test ] +fn filter_col_none() +{ + let test_objects = test_object::test_objects_gen(); + + let mut format = output_format::Records::default(); + format.cell_prefix = "( ".into(); + format.cell_postfix = " )".into(); + format.cell_separator = "|".into(); + format.row_prefix = ">".into(); + format.row_postfix = "<".into(); + format.row_separator = "\n".into(); + + let mut printer = print::Printer::with_format( &format ); + printer.filter_col = &filter::None; + + let as_table = AsTable::new( &test_objects ); + let mut output = String::new(); + let mut context = print::Context::new( &mut output, printer ); + let result = the_module::TableFormatter::fmt( &as_table, &mut context ); + assert!( result.is_ok() ); + println!( "\noutput\n{output}" ); + + let exp = r#" = 1 + + = 2 +"#; + + a_id!( output.as_str(), exp ); + +} + // -// let exp = r#">( id )|( created_at )|( file_ids )|( tools )< -// ───────────────────────────────────────────────────────────────────────────────────── -// >( 2 )|( 13 )|( [ )|( [ )< -// >( )|( )|( "file3", )|( { )< -// >( )|( )|( "file4\nmore details", )|( "tool1": "value1", )< -// >( )|( )|( ] )|( }, )< -// >( )|( )|( )|( { )< -// >( )|( )|( )|( "tool2": "value2", )< -// >( )|( )|( )|( }, )< -// >( )|( )|( )|( ] )<"#; + +#[ test ] +fn filter_col_callback() +{ + let test_objects = test_object::test_objects_gen(); + + let mut format = output_format::Records::default(); + format.cell_prefix = "( ".into(); + format.cell_postfix = " )".into(); + format.cell_separator = "|".into(); + format.row_prefix = ">".into(); + format.row_postfix = "<".into(); + format.row_separator = "\n".into(); + + let mut printer = print::Printer::with_format( &format ); + printer.filter_col = &| title : &str | + { + title != "tools" + }; + + let as_table = AsTable::new( &test_objects ); + let mut output = String::new(); + let mut context = print::Context::new( &mut output, printer ); + let result = the_module::TableFormatter::fmt( &as_table, &mut context ); + assert!( result.is_ok() ); + println!( "\noutput\n{output}" ); + + let exp = r#" = 1 +>( id )|( 1 )< +>( created_at )|( 1627845583 )< +>( file_ids )|( [ )< +>( )|( "file1", )< +>( )|( "file2", )< +>( )|( ] )< + = 2 +>( id )|( 2 )< +>( created_at )|( 13 )< +>( file_ids )|( [ )< +>( )|( "file3", )< +>( )|( "file4\nmore details", )< +>( )|( ] )<"#; + + a_id!( output.as_str(), exp ); + +} + // -// a_id!( output.as_str(), exp ); + +#[ test ] +fn filter_row_none() +{ + let test_objects = test_object::test_objects_gen(); + + let mut format = output_format::Records::default(); + format.cell_prefix = "( ".into(); + format.cell_postfix = " )".into(); + format.cell_separator = "|".into(); + format.row_prefix = ">".into(); + format.row_postfix = "<".into(); + format.row_separator = "\n".into(); + + let mut printer = print::Printer::with_format( &format ); + printer.filter_row = &filter::None; + + let as_table = AsTable::new( &test_objects ); + let mut output = String::new(); + let mut context = print::Context::new( &mut output, printer ); + let result = the_module::TableFormatter::fmt( &as_table, &mut context ); + assert!( result.is_ok() ); + + println!( "\noutput\n{output}" ); + + let exp = r#""#; + + a_id!( output.as_str(), exp ); + +} + // -// } + +#[ test ] +fn filter_row_callback() +{ + let test_objects = test_object::test_objects_gen(); + + let mut format = output_format::Records::default(); + format.cell_prefix = "( ".into(); + format.cell_postfix = " )".into(); + format.cell_separator = "|".into(); + format.row_prefix = ">".into(); + format.row_postfix = "<".into(); + format.row_separator = "\n".into(); + + let mut printer = print::Printer::with_format( &format ); + printer.filter_row = &| _typ, irow, _row : &[ ( Cow< '_, str >, [ usize ; 2 ] ) ] | + { + irow != 1 + }; + + let as_table = AsTable::new( &test_objects ); + let mut output = String::new(); + let mut context = print::Context::new( &mut output, printer ); + let result = the_module::TableFormatter::fmt( &as_table, &mut context ); + assert!( result.is_ok() ); + + println!( "\noutput\n{output}" ); + + let exp = r#" = 2 +>( id )|( 2 )< +>( created_at )|( 13 )< +>( file_ids )|( [ )< +>( )|( "file3", )< +>( )|( "file4\nmore details", )< +>( )|( ] )< +>( tools )|( [ )< +>( )|( { )< +>( )|( "tool1": "value1", )< +>( )|( }, )< +>( )|( { )< +>( )|( "tool2": "value2", )< +>( )|( }, )< +>( )|( ] )<"#; + + a_id!( output.as_str(), exp ); + +} + // -// // -// xxx : enable \ No newline at end of file +// xxx : enable + +#[ test ] +fn test_width_limiting() +{ + use the_module::string; + + for width in min_width()..max_width() + { + println!("width: {}", width); + + let test_objects = test_object::test_objects_gen(); + let as_table = AsTable::new( &test_objects ); + + let mut format = output_format::Records::default(); + format.max_width = width; + + let mut output = String::new(); + let printer = print::Printer::with_format( &format ); + let mut context = print::Context::new( &mut output, printer ); + + let got = the_module::TableFormatter::fmt( &as_table, &mut context ); + + assert!( got.is_ok() ); + + for line in string::lines( &output ) + { + if line.starts_with(" = ") + { + continue; + } + + if line.chars().count() > width + { + println!("{}", output); + } + + assert!( line.chars().count() <= width ); + } + } +} + +#[ test ] +fn test_error_on_unsatisfiable_limit() +{ + // 0 is a special value that signifies no limit. + for width in 1..( min_width() ) + { + println!( "width: {}", width ); + + let test_objects = test_object::test_objects_gen(); + let as_table = AsTable::new( &test_objects ); + + let mut format = output_format::Records::default(); + format.max_width = width; + + let mut output = String::new(); + let printer = print::Printer::with_format( &format ); + let mut context = print::Context::new( &mut output, printer ); + + let got = the_module::TableFormatter::fmt( &as_table, &mut context ); + + assert!( got.is_err() ); + } +} + +#[ test ] +fn test_table_not_grows() +{ + use the_module::string; + + let expected_width = max_width(); + + // The upper bound was chosen arbitrarily. + for width in ( expected_width + 1 )..500 + { + println!( "width: {}", width ); + + let test_objects = test_object::test_objects_gen(); + let as_table = AsTable::new( &test_objects ); + + let mut format = output_format::Records::default(); + format.max_width = width; + + let mut output = String::new(); + let printer = print::Printer::with_format( &format ); + let mut context = print::Context::new( &mut output, printer ); + + let got = the_module::TableFormatter::fmt( &as_table, &mut context ); + + assert!( got.is_ok() ); + println!("{}", output); + + for line in string::lines( &output ) + { + if line.starts_with(" = ") + { + continue; + } + + assert!( line.chars().count() <= expected_width ); + } + } +} + +/// Utility function for calculating minimum table width with `test_objects_gen()` with +/// the default table style. +fn min_width() -> usize +{ + let format = output_format::Records::default(); + format.min_width() +} + +/// Utility function for calculating default table width with `test_objects_gen()` with +/// the default table style with table width limit equals to 0. +fn max_width() -> usize +{ + use the_module::string; + + let test_objects = test_object::test_objects_gen(); + let as_table = AsTable::new( &test_objects ); + + let format = output_format::Records::default(); + + let mut output = String::new(); + let printer = print::Printer::with_format( &format ); + let mut context = print::Context::new( &mut output, printer ); + + let got = the_module::TableFormatter::fmt( &as_table, &mut context ); + assert!( got.is_ok() ); + + string::lines( &output ).map( |s| s.chars().count() ).max().unwrap_or(0) +} \ No newline at end of file diff --git a/module/core/format_tools/tests/inc/format_ordinary_test.rs b/module/core/format_tools/tests/inc/format_table_test.rs similarity index 74% rename from module/core/format_tools/tests/inc/format_ordinary_test.rs rename to module/core/format_tools/tests/inc/format_table_test.rs index f0854cd6c0..945696f572 100644 --- a/module/core/format_tools/tests/inc/format_ordinary_test.rs +++ b/module/core/format_tools/tests/inc/format_table_test.rs @@ -23,7 +23,7 @@ fn basic() { let test_objects = test_object::test_objects_gen(); - let _as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str, WithRef > = AsTable::new( &test_objects ); + let _as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str> = AsTable::new( &test_objects ); let as_table = AsTable::new( &test_objects ); let mut output = String::new(); @@ -70,7 +70,7 @@ fn table_to_string() // with explicit arguments - let as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str, WithRef > = AsTable::new( &test_objects ); + let as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str> = AsTable::new( &test_objects ); let table_string = as_table.table_to_string(); println!( "\ntable_string\n{table_string}" ); assert!( table_string.contains( "id" ) ); @@ -99,7 +99,7 @@ fn custom_format() // use the_module::TableFormatter; let test_objects = test_object::test_objects_gen(); - let mut format = output_format::Ordinary::default(); + let mut format = output_format::Table::default(); format.cell_prefix = "( ".into(); format.cell_postfix = " )".into(); format.cell_separator = "|".into(); @@ -140,7 +140,7 @@ fn custom_format() use the_module::TableFormatter; - let mut format = output_format::Ordinary::default(); + let mut format = output_format::Table::default(); format.cell_prefix = "( ".into(); format.cell_postfix = " )".into(); format.cell_separator = "|".into(); @@ -175,7 +175,7 @@ fn filter_col_none() { let test_objects = test_object::test_objects_gen(); - let mut format = output_format::Ordinary::default(); + let mut format = output_format::Table::default(); format.cell_prefix = "( ".into(); format.cell_postfix = " )".into(); format.cell_separator = "|".into(); @@ -210,7 +210,7 @@ fn filter_col_callback() { let test_objects = test_object::test_objects_gen(); - let mut format = output_format::Ordinary::default(); + let mut format = output_format::Table::default(); format.cell_prefix = "( ".into(); format.cell_postfix = " )".into(); format.cell_separator = "|".into(); @@ -254,7 +254,7 @@ fn filter_row_none() { let test_objects = test_object::test_objects_gen(); - let mut format = output_format::Ordinary::default(); + let mut format = output_format::Table::default(); format.cell_prefix = "( ".into(); format.cell_postfix = " )".into(); format.cell_separator = "|".into(); @@ -286,7 +286,7 @@ fn filter_row_callback() { let test_objects = test_object::test_objects_gen(); - let mut format = output_format::Ordinary::default(); + let mut format = output_format::Table::default(); format.cell_prefix = "( ".into(); format.cell_postfix = " )".into(); format.cell_separator = "|".into(); @@ -324,3 +324,150 @@ fn filter_row_callback() } // + +// xxx : implement test for vector of vectors + +// + +#[ test ] +fn no_subtract_with_overflow() +{ + let test_objects = test_object::test_objects_gen_with_unicode(); + + let format = output_format::Table::default(); + let printer = print::Printer::with_format( &format ); + + let as_table = AsTable::new( &test_objects ); + let mut output = String::new(); + let mut context = print::Context::new( &mut output, printer ); + + let result = the_module::TableFormatter::fmt( &as_table, &mut context ); + + assert!( result.is_ok() ); +} + +#[ test ] +fn test_width_limiting() +{ + use the_module::string; + + for max_width in min_width()..max_width() + { + println!("max_width: {}", max_width); + + let test_objects = test_object::test_objects_gen(); + let as_table = AsTable::new( &test_objects ); + + let mut format = output_format::Table::default(); + format.max_width = max_width; + + let mut output = String::new(); + let printer = print::Printer::with_format( &format ); + let mut context = print::Context::new( &mut output, printer ); + + let got = the_module::TableFormatter::fmt( &as_table, &mut context ); + + assert!( got.is_ok() ); + + for line in string::lines( &output ) + { + assert_eq!( max_width, line.chars().count() ); + } + } +} + +#[ test ] +fn test_error_on_unsatisfiable_limit() +{ + // 0 is a special value that signifies no limit. Therefore, the lower bound is 1. + for max_width in 1..( min_width() ) + { + println!( "max_width: {}", max_width ); + + let test_objects = test_object::test_objects_gen(); + let as_table = AsTable::new( &test_objects ); + + let mut format = output_format::Table::default(); + format.max_width = max_width; + + let mut output = String::new(); + let printer = print::Printer::with_format( &format ); + let mut context = print::Context::new( &mut output, printer ); + + let got = the_module::TableFormatter::fmt( &as_table, &mut context ); + + assert!( got.is_err() ); + } +} + +#[ test ] +fn test_table_not_grows() +{ + use the_module::string; + + let expected_width = max_width(); + + // The upper bound was chosen arbitrarily. + for max_width in ( expected_width + 1 )..500 + { + println!( "max_width: {}", max_width ); + + let test_objects = test_object::test_objects_gen(); + let as_table = AsTable::new( &test_objects ); + + let mut format = output_format::Table::default(); + format.max_width = max_width; + + let mut output = String::new(); + let printer = print::Printer::with_format( &format ); + let mut context = print::Context::new( &mut output, printer ); + + let got = the_module::TableFormatter::fmt( &as_table, &mut context ); + + assert!( got.is_ok() ); + + for line in string::lines( &output ) + { + assert_eq!( expected_width, line.chars().count() ); + } + } +} + +/// Utility function for calculating minimum table width with `test_objects_gen()` with +/// the default table style. +fn min_width() -> usize +{ + use the_module::Fields; + + let format = output_format::Table::default(); + let test_objects = test_object::test_objects_gen(); + let col_count = test_objects[0].fields().count(); + + format.min_width( col_count ) +} + +/// Utility function for calculating default table width with `test_objects_gen()` with +/// the default table style without any maximum width. +fn max_width() -> usize +{ + use the_module::string; + + let test_objects = test_object::test_objects_gen(); + let as_table = AsTable::new( &test_objects ); + + let format = output_format::Table::default(); + + let mut output = String::new(); + let printer = print::Printer::with_format( &format ); + let mut context = print::Context::new( &mut output, printer ); + + let got = the_module::TableFormatter::fmt( &as_table, &mut context ); + assert!( got.is_ok() ); + + for line in string::lines( &output ) + { + return line.chars().count(); + } + + 0 +} \ No newline at end of file diff --git a/module/core/format_tools/tests/inc/mod.rs b/module/core/format_tools/tests/inc/mod.rs index 5188190547..5f35b24fcc 100644 --- a/module/core/format_tools/tests/inc/mod.rs +++ b/module/core/format_tools/tests/inc/mod.rs @@ -1,18 +1,19 @@ -#[ allow( unused_imports ) ] use super::*; #[ cfg( feature = "enabled" ) ] #[ path = "." ] mod fundamental { - #[ allow( unused_imports ) ] use super::*; mod test_object; mod table_test; - mod format_ordinary_test; + mod tabe_foreign_test; + + mod format_table_test; mod format_records_test; + // mod format_keys_test; // qqq : xxx : implement mod collection_test; mod fields_test; diff --git a/module/core/format_tools/tests/inc/tabe_foreign_test.rs b/module/core/format_tools/tests/inc/tabe_foreign_test.rs new file mode 100644 index 0000000000..6cbfd68249 --- /dev/null +++ b/module/core/format_tools/tests/inc/tabe_foreign_test.rs @@ -0,0 +1,131 @@ +use super::*; + +use the_module:: +{ + AsTable, + Cells, + TableRows, + TableHeader, + WithRef, +}; + +use std:: +{ + borrow::Cow, +}; + +// + +#[ test ] +fn iterator_over_objects_without_impl() +{ + use the_module::TestObjectWithoutImpl as TestObjectWithoutImpl; + use the_module:: + { + Fields, + IteratorTrait, + TableWithFields, + WithRef, + OptionalCow, + output_format, + }; + + // xxx : Clone should not be required + #[ derive( Debug, Clone ) ] + pub struct TestObjecWrap( TestObjectWithoutImpl ); + + impl TableWithFields for TestObjecWrap {} + impl Fields< &'_ str, Option< Cow< '_, str > > > + for TestObjecWrap + { + type Key< 'k > = &'k str; + type Val< 'v > = Option< Cow< 'v, str > >; + + fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > + { + use format_tools::ref_or_display_or_debug_multiline::field; + let mut dst = Vec::new(); + + dst.push( field!( &self.0.id ) ); + dst.push( field!( &self.0.created_at ) ); + dst.push( field!( &self.0.file_ids ) ); + + if let Some( tools ) = &self.0.tools + { + dst.push( field!( tools ) ); + } + else + { + dst.push( ( "tools", Option::None ) ); + } + + dst.into_iter() + } + + } + + let data : collection_tools::Vec< TestObjecWrap > = the_module::test_objects_gen() + .into_iter() + .map( | e | TestObjecWrap( e ) ) + .collect() + ; + + use the_module::TableFormatter; + let _as_table : AsTable< '_, Vec< TestObjecWrap >, &str, TestObjecWrap, str > = AsTable::new( &data ); + let as_table = AsTable::new( &data ); + + let rows = TableRows::rows( &as_table ); + assert_eq!( rows.len(), 2 ); + + let mut output = String::new(); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); + let _result = the_module::TableFormatter::fmt( &as_table, &mut context ); + + // = output as table + + let got = as_table.table_to_string(); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + + let got = AsTable::new( &data ).table_to_string(); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + + let got = AsTable::new( &data ).table_to_string_with_format( &output_format::Table::default() ); + println!( "{}", &got ); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + + // = output as records + + // let format = output_format::Records::default(); + let mut output = String::new(); + let format = the_module::output_format::Records::default(); + let printer = the_module::print::Printer::with_format( &format ); + let mut context = the_module::print::Context::new( &mut output, printer ); + let got = the_module::TableFormatter::fmt( &as_table, &mut context ); + assert!( got.is_ok() ); + + let got = AsTable::new( &data ).table_to_string_with_format( &output_format::Records::default() ); + println!( "{}", &got ); + assert!( got.contains( "│ id │ 1 │" ) ); + assert!( got.contains( "│ created_at │ 1627845583 │" ) ); + assert!( got.contains( "│ id │ 2 │" ) ); + assert!( got.contains( "│ created_at │ 13 │" ) ); + + // = output as keys + + let got = AsTable::new( &data ).table_to_string_with_format( &output_format::Keys::default() ); + println!( "{}", &got ); + assert!( got.contains( "- id" ) ); + assert!( got.contains( "- created_at" ) ); + assert!( got.contains( "- file_ids" ) ); + assert!( got.contains( "- tools" ) ); + assert!( got.contains( "4 fields" ) ); + + // assert!( false ); + +} diff --git a/module/core/format_tools/tests/inc/table_test.rs b/module/core/format_tools/tests/inc/table_test.rs index 2357d44aea..af57655085 100644 --- a/module/core/format_tools/tests/inc/table_test.rs +++ b/module/core/format_tools/tests/inc/table_test.rs @@ -10,6 +10,11 @@ use the_module:: WithRef, }; +use std:: +{ + borrow::Cow, +}; + // #[ test ] @@ -19,13 +24,13 @@ fn basic() { let test_objects = test_object::test_objects_gen(); - let cells = Cells::< str, WithRef >::cells( &test_objects[ 0 ] ); + let cells = Cells::< str>::cells( &test_objects[ 0 ] ); assert_eq!( cells.len(), 4 ); - let cells = Cells::< str, WithRef >::cells( &test_objects[ 1 ] ); + let cells = Cells::< str>::cells( &test_objects[ 1 ] ); assert_eq!( cells.len(), 4 ); drop( cells ); - let as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str, WithRef > = AsTable::new( &test_objects ); + let as_table : AsTable< '_, Vec< test_object::TestObject >, usize, test_object::TestObject, str> = AsTable::new( &test_objects ); // let mcells = TableSize::mcells( &as_table ); // assert_eq!( mcells, [ 4, 3 ] ); let rows = TableRows::rows( &as_table ); @@ -45,3 +50,310 @@ fn basic() dbg!( header.collect::< Vec< _ > >() ); } + +// + +#[ test ] +fn iterator_over_optional_cow() +{ + // use test_object::TestObject2 as TestObject2; + use the_module:: + { + Fields, + IteratorTrait, + TableWithFields, + WithRef, + OptionalCow, + }; + + /// Struct representing a test object with various fields. + #[ derive( Clone, Debug, PartialEq, Eq ) ] + pub struct TestObject2 + { + pub id : String, + pub created_at : i64, + pub file_ids : Vec< String >, + pub tools : Option< Vec< HashMap< String, String > > >, + } + + impl TableWithFields for TestObject2 {} + + impl Fields< &'_ str, Option< Cow< '_, str > > > + for TestObject2 + { + type Key< 'k > = &'k str; + type Val< 'v > = Option< Cow< 'v, str > >; + + fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > + { + use format_tools::ref_or_display_or_debug_multiline::field; + // use format_tools::ref_or_display_or_debug::field; + let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new(); + + // trace_macros!( true ); + dst.push( field!( &self.id ) ); + // trace_macros!( false ); + + dst.push( field!( &self.created_at ) ); + dst.push( field!( &self.file_ids ) ); + + if let Some( tools ) = &self.tools + { + dst.push( field!( tools ) ); + } + else + { + dst.push( ( "tools", Option::None ) ); + } + + dst.into_iter() + } + + } + + let data : collection_tools::Vec< TestObject2 > = dlist! + { + TestObject2 + { + id : "1".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".to_string() ], + tools : None + }, + TestObject2 + { + id : "2".to_string(), + created_at : 13, + file_ids : vec![ "file3".to_string(), "file4\nmore details".to_string() ], + tools : Some + ( + vec! + [ + { + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map + }, + { + let mut map = HashMap::new(); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + } + ] + ), + }, + }; + + use the_module::TableFormatter; + let _as_table : AsTable< '_, Vec< TestObject2 >, &str, TestObject2, str> = AsTable::new( &data ); + let as_table = AsTable::new( &data ); + + let rows = TableRows::rows( &as_table ); + assert_eq!( rows.len(), 2 ); + + let mut output = String::new(); + let mut context = the_module::print::Context::new( &mut output, Default::default() ); + let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); + let got = as_table.table_to_string(); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + + let got = AsTable::new( &data ).table_to_string(); + assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); + assert!( got.contains( "│ 13 │ [ │ [ │" ) ); + assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + +} + +// + +#[ test ] +fn iterator_over_strings() +{ + + fn to_owned< 'a, T1 >( src : ( T1, Option< Cow< 'a, str > > ) ) -> ( T1, String ) + { + let val = match src.1 + { + Some( c ) => c.into_owned(), + None => String::default(), + }; + ( src.0, val ) + } + + // fn into< 'a, T1, T2 : Copy >( src : ( T1, OptionalCow< 'a, str, T2 > ) ) -> ( T1, Option< Cow< 'a, str > > ) + // { + // ( src.0, src.1.into() ) + // } + + // use test_object::TestObject as TestObject3; + use the_module:: + { + Fields, + IteratorTrait, + TableWithFields, + WithRef, + OptionalCow, + }; + + use std::borrow::Cow; + + /// Struct representing a test object with various fields. + #[ derive( Clone, Debug, PartialEq, Eq ) ] + pub struct TestObject3 + { + pub id : String, + pub created_at : i64, + pub file_ids : Vec< String >, + pub tools : Option< Vec< HashMap< String, String > > >, + } + + impl TableWithFields for TestObject3 {} + + impl Fields< &'_ str, String > + for TestObject3 + { + type Key< 'k > = &'k str; + type Val< 'v > = String; + + fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, String ) > + { + use format_tools::ref_or_display_or_debug_multiline::field; + // use format_tools::ref_or_display_or_debug::field; + let mut dst : Vec< ( &'_ str, String ) > = Vec::new(); + + dst.push( to_owned( field!( &self.id ) ) ); + + dst.push( to_owned( field!( &self.created_at ) ) ); + dst.push( to_owned( field!( &self.file_ids ) ) ); + + if let Some( tools ) = &self.tools + { + dst.push( to_owned( field!( tools ) ) ); + } + else + { + dst.push( ( "tools", String::default() ) ); + } + + dst.into_iter() + } + + } + + let _data : collection_tools::Vec< TestObject3 > = dlist! + { + TestObject3 + { + id : "1".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".to_string() ], + tools : None + }, + TestObject3 + { + id : "2".to_string(), + created_at : 13, + file_ids : vec![ "file3".to_string(), "file4\nmore details".to_string() ], + tools : Some + ( + vec! + [ + { + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map + }, + { + let mut map = HashMap::new(); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + } + ] + ), + }, + }; + + // no variability in what Fields iterate over by design! + + // use the_module::TableFormatter; + // let _as_table : AsTable< '_, Vec< TestObject3 >, &str, TestObject3, str> = AsTable::new( &data ); + // let as_table = AsTable::new( &data ); + +// let rows = TableRows::rows( &as_table ); +// assert_eq!( rows.len(), 2 ); +// +// let mut output = String::new(); +// let mut context = the_module::print::Context::new( &mut output, Default::default() ); +// let _got = the_module::TableFormatter::fmt( &as_table, &mut context ); +// let got = as_table.table_to_string(); +// assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); +// assert!( got.contains( "│ 13 │ [ │ [ │" ) ); +// assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + +// let got = AsTable::new( &data ).table_to_string(); +// assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) ); +// assert!( got.contains( "│ 13 │ [ │ [ │" ) ); +// assert!( got.contains( "│ 1627845583 │ [ │ │" ) ); + +} + +#[ test ] +fn test_vector_table() +{ + let column_names : Vec< Cow< 'static, str > > = vec![ + "id".into(), + "created_at".into(), + "file_ids".into(), + "tools".into(), + ]; + + let rows : Vec< Vec< Cow< 'static, str > > > = vec! + [ + vec! + [ + "1".into(), + "1627845583".into(), + "[ file1, file2 ]".into(), + "".into(), + ], + + vec! + [ + "2".into(), + "13".into(), + "[ file3, file4 ]".into(), + "[ tool1 ]".into(), + ], + ]; + + use the_module:: + { + output_format, + filter, + print, + }; + + let mut output = String::new(); + let mut context = print::Context::new( &mut output, Default::default() ); + + let res = output_format::vector_table_write + ( + column_names, + true, + rows, + &mut context, + ); + + assert!( res.is_ok() ); + + println!( "{}", output ); + + let exp = r#"│ id │ created_at │ file_ids │ tools │ +────────────────────────────────────────────────── +│ 1 │ 1627845583 │ [ file1, file2 ] │ │ +│ 2 │ 13 │ [ file3, file4 ] │ [ tool1 ] │"#; + + a_id!( output.as_str(), exp ); +} \ No newline at end of file diff --git a/module/core/format_tools/tests/inc/test_object.rs b/module/core/format_tools/tests/inc/test_object.rs index 729a96fa85..70c702d035 100644 --- a/module/core/format_tools/tests/inc/test_object.rs +++ b/module/core/format_tools/tests/inc/test_object.rs @@ -13,11 +13,14 @@ use the_module:: use std:: { collections::HashMap, - // borrow::Cow, + hash::Hasher, + hash::Hash, + cmp::Ordering, + borrow::Cow, }; /// Struct representing a test object with various fields. -#[ derive( Clone, Debug ) ] +#[ derive( Clone, Debug, PartialEq, Eq ) ] pub struct TestObject { pub id : String, @@ -28,19 +31,51 @@ pub struct TestObject impl TableWithFields for TestObject {} -impl Fields< &'_ str, OptionalCow< '_, str, WithRef > > +// impl Fields< &'_ str, Option< Cow< '_, str > > > +// for TestObject +// { +// type Key< 'k > = &'k str; +// type Val< 'v > = OptionalCow< 'v, str>; +// +// fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > +// { +// use format_tools::ref_or_display_or_debug_multiline::field; +// // use format_tools::ref_or_display_or_debug::field; +// let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new(); +// +// dst.push( field!( &self.id ) ); +// dst.push( field!( &self.created_at ) ); +// dst.push( field!( &self.file_ids ) ); +// +// if let Some( tools ) = &self.tools +// { +// dst.push( field!( tools ) ); +// } +// else +// { +// dst.push( ( "tools", OptionalCow::none() ) ); +// } +// +// dst.into_iter() +// } +// +// } + +impl Fields< &'_ str, Option< Cow< '_, str > > > for TestObject { type Key< 'k > = &'k str; - type Val< 'v > = OptionalCow< 'v, str, WithRef >; + type Val< 'v > = Option< Cow< 'v, str > >; - fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, OptionalCow< '_, str, WithRef > ) > + fn fields( &self ) -> impl IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > { use format_tools::ref_or_display_or_debug_multiline::field; // use format_tools::ref_or_display_or_debug::field; - let mut dst : Vec< ( &'_ str, OptionalCow< '_, str, WithRef > ) > = Vec::new(); + let mut dst : Vec< ( &'_ str, Option< Cow< '_, str > > ) > = Vec::new(); + // trace_macros!( true ); dst.push( field!( &self.id ) ); + // trace_macros!( false ); dst.push( field!( &self.created_at ) ); dst.push( field!( &self.file_ids ) ); @@ -50,7 +85,7 @@ for TestObject } else { - dst.push( ( "tools", OptionalCow::none() ) ); + dst.push( ( "tools", Option::None ) ); } dst.into_iter() @@ -58,6 +93,74 @@ for TestObject } +impl Hash for TestObject +{ + + fn hash< H: Hasher >( &self, state: &mut H ) + { + self.id.hash( state ); + self.created_at.hash( state ); + self.file_ids.hash( state ); + + if let Some( tools ) = &self.tools + { + for tool in tools + { + for ( key, value ) in tool + { + key.hash( state ); + value.hash( state ); + } + } + } + else + { + state.write_u8( 0 ); + } + } + +} + +// impl PartialEq for TestObject +// { +// +// fn eq( &self, other: &Self ) -> bool +// { +// self.id == other.id && +// self.created_at == other.created_at && +// self.file_ids == other.file_ids && +// self.tools == other.tools +// } +// +// } +// +// impl Eq for TestObject +// { +// } + +impl PartialOrd for TestObject +{ + + fn partial_cmp( &self, other: &Self ) -> Option< Ordering > + { + Some( self.cmp( other ) ) + } + +} + +impl Ord for TestObject +{ + + fn cmp( &self, other: &Self ) -> Ordering + { + self.id + .cmp( &other.id ) + .then_with( | | self.created_at.cmp( &other.created_at ) ) + .then_with( | | self.file_ids.cmp( &other.file_ids ) ) + } + +} + // pub fn test_objects_gen() -> Vec< TestObject > @@ -97,3 +200,17 @@ pub fn test_objects_gen() -> Vec< TestObject > ] } + +pub fn test_objects_gen_with_unicode() -> Vec< TestObject > +{ + vec! + [ + TestObject + { + id : "Юнікод".to_string(), + created_at : 100, + file_ids : vec![], + tools : None, + } + ] +} \ No newline at end of file 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 index bd9947cd71..e0c39527c3 100644 --- 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 @@ -9,12 +9,12 @@ use the_module:: WithDebug, WithDisplay, // the_module::to_string_with_fallback::Ref, - to_string_with_fallback, + to_string_with_fallback }; use std:: { - // fmt, + fmt, // collections::HashMap, borrow::Cow, }; diff --git a/module/core/format_tools/tests/smoke_test.rs b/module/core/format_tools/tests/smoke_test.rs index 828e9b016b..cd7b1f36a8 100644 --- a/module/core/format_tools/tests/smoke_test.rs +++ b/module/core/format_tools/tests/smoke_test.rs @@ -1,12 +1,13 @@ +//! Smoke tests. - +/// Smoke test of local version of the crate. #[ test ] fn local_smoke_test() { ::test_tools::smoke_test_for_local_run(); } - +/// Smoke test of published version of the crate. #[ test ] fn published_smoke_test() { diff --git a/module/core/format_tools/tests/tests.rs b/module/core/format_tools/tests/tests.rs index eae1668ea0..c8e636300b 100644 --- a/module/core/format_tools/tests/tests.rs +++ b/module/core/format_tools/tests/tests.rs @@ -1,10 +1,10 @@ +//! Primary tests. + // #![ feature( trace_macros ) ] +#![ allow( unused_imports ) ] -#[ allow( unused_imports ) ] use format_tools as the_module; -#[ allow( unused_imports ) ] use test_tools::exposed::*; #[ cfg( feature = "enabled" ) ] mod inc; - diff --git a/module/core/former/Cargo.toml b/module/core/former/Cargo.toml index 255f72c486..df2a419b2b 100644 --- a/module/core/former/Cargo.toml +++ b/module/core/former/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former" -version = "2.8.0" +version = "2.11.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -65,5 +65,5 @@ former_types = { workspace = true } [dev-dependencies] -test_tools = { workspace = true, features = [ "full" ] } +test_tools = { workspace = true } collection_tools = { workspace = true, features = [ "collection_constructors" ] } diff --git a/module/core/former/License b/module/core/former/License index e3e9e057cf..c32986cee3 100644 --- a/module/core/former/License +++ b/module/core/former/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/former_meta/Cargo.toml b/module/core/former_meta/Cargo.toml index 537a170711..38845bc3f1 100644 --- a/module/core/former_meta/Cargo.toml +++ b/module/core/former_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former_meta" -version = "2.8.0" +version = "2.11.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -57,4 +57,4 @@ iter_tools = { workspace = true } convert_case = { version = "0.6.0", default-features = false, optional = true, features = [] } [dev-dependencies] -test_tools = { workspace = true, features = [ "full" ] } +test_tools = { workspace = true } diff --git a/module/core/former_meta/License b/module/core/former_meta/License index e3e9e057cf..c32986cee3 100644 --- a/module/core/former_meta/License +++ b/module/core/former_meta/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/former_types/Cargo.toml b/module/core/former_types/Cargo.toml index 75ae5bce43..1049a6c8bd 100644 --- a/module/core/former_types/Cargo.toml +++ b/module/core/former_types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former_types" -version = "2.7.0" +version = "2.12.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -50,4 +50,4 @@ collection_tools = { workspace = true, features = [ "collection_constructors" ] [dev-dependencies] -test_tools = { workspace = true, features = [ "full" ] } +test_tools = { workspace = true } diff --git a/module/core/former_types/License b/module/core/former_types/License index e3e9e057cf..c32986cee3 100644 --- a/module/core/former_types/License +++ b/module/core/former_types/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/former_types/src/collection.rs b/module/core/former_types/src/collection.rs index c740510fb3..c7b25889b7 100644 --- a/module/core/former_types/src/collection.rs +++ b/module/core/former_types/src/collection.rs @@ -5,7 +5,7 @@ //! such as vectors, hash maps, and custom collection implementations. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/core/fs_tools/License b/module/core/fs_tools/License index e3e9e057cf..c32986cee3 100644 --- a/module/core/fs_tools/License +++ b/module/core/fs_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/fs_tools/src/fs/fs.rs b/module/core/fs_tools/src/fs/fs.rs index 25f60b2592..a10288843c 100644 --- a/module/core/fs_tools/src/fs/fs.rs +++ b/module/core/fs_tools/src/fs/fs.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/core/implements/Cargo.toml b/module/core/implements/Cargo.toml index 44a51ad680..8c468c0b60 100644 --- a/module/core/implements/Cargo.toml +++ b/module/core/implements/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "implements" -version = "0.8.0" +version = "0.10.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/implements/License b/module/core/implements/License index e3e9e057cf..c32986cee3 100644 --- a/module/core/implements/License +++ b/module/core/implements/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/implements/src/lib.rs b/module/core/implements/src/lib.rs index 7bdfba2035..989d5e528e 100644 --- a/module/core/implements/src/lib.rs +++ b/module/core/implements/src/lib.rs @@ -16,7 +16,7 @@ #[ cfg( feature = "enabled" ) ] mod implements_impl; -/// Internal namespace. +/// Define a private namespace for all its items. #[ cfg( feature = "enabled" ) ] mod private { diff --git a/module/core/impls_index/Cargo.toml b/module/core/impls_index/Cargo.toml index ea67dfa107..392f5bf2f0 100644 --- a/module/core/impls_index/Cargo.toml +++ b/module/core/impls_index/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "impls_index" -version = "0.7.0" +version = "0.9.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -27,8 +27,6 @@ all-features = false [features] default = [ "enabled" ] full = [ "enabled" ] -no_std = [] -use_alloc = [ "no_std" ] enabled = [ "impls_index_meta/enabled" ] [dependencies] @@ -36,4 +34,4 @@ impls_index_meta = { workspace = true } [dev-dependencies] test_tools = { workspace = true } -tempdir = { version = "0.3.7" } +tempdir = { workspace = true } diff --git a/module/core/impls_index/License b/module/core/impls_index/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/impls_index/License +++ b/module/core/impls_index/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/impls_index/src/impls_index/func.rs b/module/core/impls_index/src/impls_index/func.rs index 21448b2ef8..da33da0127 100644 --- a/module/core/impls_index/src/impls_index/func.rs +++ b/module/core/impls_index/src/impls_index/func.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/core/impls_index/src/impls_index/impls.rs b/module/core/impls_index/src/impls_index/impls.rs index 18d81346a8..b10b4498e3 100644 --- a/module/core/impls_index/src/impls_index/impls.rs +++ b/module/core/impls_index/src/impls_index/impls.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { @@ -382,14 +382,7 @@ pub mod exposed use super::*; #[ doc( inline ) ] pub use prelude::*; -} - -/// Prelude to use essentials: `use my_module::prelude::*`. -#[ allow( unused_imports ) ] -pub mod prelude -{ - use super::*; #[ doc( inline ) ] pub use private:: { @@ -403,9 +396,15 @@ pub mod prelude _impls_callback, }; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use ::impls_index_meta::impls3; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use impls3 as impls; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; } diff --git a/module/core/impls_index/src/impls_index/mod.rs b/module/core/impls_index/src/impls_index/mod.rs index f0d3a5f74f..5b54558d8d 100644 --- a/module/core/impls_index/src/impls_index/mod.rs +++ b/module/core/impls_index/src/impls_index/mod.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { @@ -31,6 +31,8 @@ pub mod own use super::*; #[ doc( inline ) ] pub use orphan::*; + #[ doc( inline ) ] + pub use ::impls_index_meta::*; } /// Shared with parent namespace of the module @@ -40,7 +42,6 @@ pub mod orphan use super::*; #[ doc( inline ) ] pub use exposed::*; - // pub use super::dependency; } /// Exposed namespace of the module. @@ -51,11 +52,9 @@ pub mod exposed #[ doc( inline ) ] pub use prelude::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::impls::exposed::*; + pub use impls::exposed::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::func::exposed::*; + pub use func::exposed::*; } /// Prelude to use essentials: `use my_module::prelude::*`. @@ -64,13 +63,7 @@ pub mod prelude { use super::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::impls::prelude::*; + pub use impls::prelude::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::func::prelude::*; - // #[ cfg( any( feature = "meta", feature = "impls_index_meta" ) ) ] - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use ::impls_index_meta::*; + pub use func::prelude::*; } diff --git a/module/core/impls_index/src/lib.rs b/module/core/impls_index/src/lib.rs index ec229443d8..ac0f33af0a 100644 --- a/module/core/impls_index/src/lib.rs +++ b/module/core/impls_index/src/lib.rs @@ -1,4 +1,4 @@ -#![ cfg_attr( feature = "no_std", no_std ) ] +#![ no_std ] #![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] #![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] #![ doc( html_root_url = "https://docs.rs/impls_index/latest/impls_index/" ) ] @@ -30,7 +30,6 @@ pub mod own #[ doc( inline ) ] pub use orphan::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::impls_index::orphan::*; } @@ -53,7 +52,6 @@ pub mod exposed #[ doc( inline ) ] pub use prelude::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::impls_index::exposed::*; } @@ -64,6 +62,5 @@ pub mod prelude { use super::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::impls_index::prelude::*; } diff --git a/module/core/impls_index/tests/inc/func_test.rs b/module/core/impls_index/tests/inc/func_test.rs index 7408b5b3ff..7b5d74bbcc 100644 --- a/module/core/impls_index/tests/inc/func_test.rs +++ b/module/core/impls_index/tests/inc/func_test.rs @@ -2,7 +2,7 @@ use super::*; #[ allow ( unused_imports ) ] -use the_module::prelude::*; +use the_module::exposed::*; // use test_tools::exposed::*; // diff --git a/module/core/impls_index/tests/inc/impls1_test.rs b/module/core/impls_index/tests/inc/impls1_test.rs index c8df2ca220..b49e010b01 100644 --- a/module/core/impls_index/tests/inc/impls1_test.rs +++ b/module/core/impls_index/tests/inc/impls1_test.rs @@ -1,120 +1,118 @@ // use test_tools::exposed::*; use super::*; -use the_module::prelude::impls1; +use the_module::exposed::impls1; +// use the_module::exposed::{ index }; // -tests_impls! +#[ test ] +fn impls_basic() { - fn impls_basic() + // test.case( "impls1 basic" ); { - // test.case( "impls1 basic" ); + impls1! { - - impls1! + fn f1() { - fn f1() - { - println!( "f1" ); - } - pub fn f2() - { - println!( "f2" ); - } - }; + println!( "f1" ); + } + pub fn f2() + { + println!( "f2" ); + } + }; - // trace_macros!( true ); - f1!(); - f2!(); - // trace_macros!( false ); + // trace_macros!( true ); + f1!(); + f2!(); + // trace_macros!( false ); - f1(); - f2(); + f1(); + f2(); - } + } + +// // test.case( "impls1 as" ); +// { +// +// impls1! +// { +// fn f1() +// { +// println!( "f1" ); +// } +// pub fn f2() +// { +// println!( "f2" ); +// } +// }; +// +// // trace_macros!( true ); +// f1!( as f1b ); +// f2!( as f2b ); +// // trace_macros!( false ); +// +// f1b(); +// f2b(); +// +// } +// +// // test.case( "impls1 as index" ); +// { +// +// impls1! +// { +// fn f1() +// { +// println!( "f1" ); +// } +// pub fn f2() +// { +// println!( "f2" ); +// } +// }; +// +// // trace_macros!( true ); +// index! +// { +// f1, +// f2 as f2b, +// } +// // trace_macros!( false ); +// +// f1(); +// f2b(); +// +// } - // // test.case( "impls1 as" ); - // { - // - // impls1! - // { - // fn f1() - // { - // println!( "f1" ); - // } - // pub fn f2() - // { - // println!( "f2" ); - // } - // }; - // - // // trace_macros!( true ); - // f1!( as f1b ); - // f2!( as f2b ); - // // trace_macros!( false ); - // - // f1b(); - // f2b(); - // - // } - // - // // test.case( "impls1 as index" ); - // { - // - // impls1! - // { - // fn f1() - // { - // println!( "f1" ); - // } - // pub fn f2() - // { - // println!( "f2" ); - // } - // }; - // - // // trace_macros!( true ); - // index! - // { - // f1, - // f2 as f2b, - // } - // // trace_macros!( false ); - // - // f1(); - // f2b(); - // - // } + // test.case( "macro" ); + { - // test.case( "macro" ); + impls1! { - - impls1! + fn f1() { - fn f1() + macro_rules! macro1 { - macro_rules! macro1 - { - ( $( $Arg : tt )* ) => { }; - } - macro1!(); + ( $( $Arg : tt )* ) => { }; } + macro1!(); } - - // trace_macros!( true ); - f1!(); - // trace_macros!( false ); - } + // trace_macros!( true ); + f1!(); + // trace_macros!( false ); + } + } // -tests_index! -{ - impls_basic, -} +// tests_index! +// { +// impls_basic, +// } diff --git a/module/core/impls_index/tests/inc/impls2_test.rs b/module/core/impls_index/tests/inc/impls2_test.rs index bb5d16eaab..20b83f0731 100644 --- a/module/core/impls_index/tests/inc/impls2_test.rs +++ b/module/core/impls_index/tests/inc/impls2_test.rs @@ -1,121 +1,119 @@ // use test_tools::exposed::*; use super::*; -use the_module::prelude::impls2; +use the_module::exposed::impls2; +use the_module::exposed::{ index }; // -tests_impls! +#[ test ] +fn impls_basic() { - fn impls_basic() + // test.case( "impls2 basic" ); { - // test.case( "impls2 basic" ); + impls2! { - - impls2! + fn f1() { - fn f1() - { - println!( "f1" ); - } - pub fn f2() - { - println!( "f2" ); - } - }; + println!( "f1" ); + } + pub fn f2() + { + println!( "f2" ); + } + }; - // trace_macros!( true ); - f1!(); - f2!(); - // trace_macros!( false ); + // trace_macros!( true ); + f1!(); + f2!(); + // trace_macros!( false ); - f1(); - f2(); + f1(); + f2(); - } + } - // test.case( "impls2 as" ); - { + // test.case( "impls2 as" ); + { - impls2! + impls2! + { + fn f1() { - fn f1() - { - println!( "f1" ); - } - pub fn f2() - { - println!( "f2" ); - } - }; + println!( "f1" ); + } + pub fn f2() + { + println!( "f2" ); + } + }; - // trace_macros!( true ); - f1!( as f1b ); - f2!( as f2b ); - // trace_macros!( false ); + // trace_macros!( true ); + f1!( as f1b ); + f2!( as f2b ); + // trace_macros!( false ); - f1b(); - f2b(); + f1b(); + f2b(); - } + } - // test.case( "impls2 as index" ); - { + // test.case( "impls2 as index" ); + { - impls2! + impls2! + { + fn f1() { - fn f1() - { - println!( "f1" ); - } - pub fn f2() - { - println!( "f2" ); - } - }; - - // trace_macros!( true ); - index! + println!( "f1" ); + } + pub fn f2() { - f1, - f2 as f2b, + println!( "f2" ); } - // trace_macros!( false ); - - f1(); - f2b(); + }; + // trace_macros!( true ); + index! + { + f1, + f2 as f2b, } + // trace_macros!( false ); - // test.case( "macro" ); - { + f1(); + f2b(); - impls2! + } + + // test.case( "macro" ); + { + + impls2! + { + fn f1() { - fn f1() + macro_rules! macro1 { - macro_rules! macro1 - { - ( $( $Arg : tt )* ) => { }; - } - macro1!(); + ( $( $Arg : tt )* ) => { }; } + macro1!(); } - - // trace_macros!( true ); - f1!(); - // trace_macros!( false ); - } + // trace_macros!( true ); + f1!(); + // trace_macros!( false ); + } + } // -tests_index! -{ - // fns, - impls_basic, -} +// tests_index! +// { +// // fns, +// impls_basic, +// } diff --git a/module/core/impls_index/tests/inc/impls3_test.rs b/module/core/impls_index/tests/inc/impls3_test.rs index 860acd126a..1fe454dfc7 100644 --- a/module/core/impls_index/tests/inc/impls3_test.rs +++ b/module/core/impls_index/tests/inc/impls3_test.rs @@ -1,5 +1,6 @@ use super::*; -use the_module::prelude::impls3; +use the_module::exposed::impls3; +use the_module::exposed::{ index }; // @@ -7,7 +8,7 @@ use the_module::prelude::impls3; fn basic() { - impls! + impls3! { fn f1() { diff --git a/module/core/impls_index/tests/inc/impls_basic_test.rs b/module/core/impls_index/tests/inc/impls_basic_test.rs index c488aec5a2..8a9ef8df85 100644 --- a/module/core/impls_index/tests/inc/impls_basic_test.rs +++ b/module/core/impls_index/tests/inc/impls_basic_test.rs @@ -1,6 +1,5 @@ use super::*; -#[ allow( unused_imports ) ] -use the_module::prelude::*; +use the_module::exposed::*; // trace_macros!( true ); tests_impls! diff --git a/module/core/impls_index/tests/inc/index_test.rs b/module/core/impls_index/tests/inc/index_test.rs index de1ed0d9be..561e1ba8ac 100644 --- a/module/core/impls_index/tests/inc/index_test.rs +++ b/module/core/impls_index/tests/inc/index_test.rs @@ -1,155 +1,151 @@ // use test_tools::exposed::*; use super::*; -use the_module::prelude::impls1; +use the_module::exposed::impls1; +use the_module::exposed::{ index }; // -tests_impls! +#[ test ] +fn empty_with_comma() { - - fn empty_with_comma() + // test.case( "impls1 basic" ); { - // test.case( "impls1 basic" ); - { - - impls1!(); - index!(); - - } + impls1!(); + index!(); } +} + +#[ test ] +fn empty_without_comma() +{ - fn empty_without_comma() + // test.case( "impls1 basic" ); { - // test.case( "impls1 basic" ); + impls1! { + }; - impls1! - { - }; - - index! - { - } - + index! + { } } +} + +#[ test ] +fn with_comma() +{ - fn with_comma() + // test.case( "impls1 basic" ); { - // test.case( "impls1 basic" ); + impls1! { - - impls1! + fn f1() -> i32 { - fn f1() -> i32 - { - println!( "f1" ); - 13 - } - }; - - index! - { - f1, + println!( "f1" ); + 13 } + }; - a_id!( f1(), 13 ); + index! + { + f1, } + a_id!( f1(), 13 ); } +} + +#[ test ] +fn without_comma() +{ - fn without_comma() + // test.case( "impls1 basic" ); { - // test.case( "impls1 basic" ); + impls1! { - - impls1! - { - fn f1() -> i32 - { - println!( "f1" ); - 13 - } - }; - - index! + fn f1() -> i32 { - f1 + println!( "f1" ); + 13 } + }; - a_id!( f1(), 13 ); + index! + { + f1 } + a_id!( f1(), 13 ); } +} + +#[ test ] +fn parentheses_with_comma() +{ - fn parentheses_with_comma() + // test.case( "impls1 basic" ); { - // test.case( "impls1 basic" ); + impls1! { - - impls1! + fn f1() -> i32 { - fn f1() -> i32 - { - println!( "f1" ); - 13 - } - }; - - index!( f1, ); + println!( "f1" ); + 13 + } + }; - a_id!( f1(), 13 ); - } + index!( f1, ); + a_id!( f1(), 13 ); } +} - fn parentheses_without_comma() +#[ test ] +fn parentheses_without_comma() +{ + + // test.case( "impls1 basic" ); { - // test.case( "impls1 basic" ); + impls1! { - - impls1! + fn f1() -> i32 { - fn f1() -> i32 - { - println!( "f1" ); - 13 - } - }; - - index!( f1 ); + println!( "f1" ); + 13 + } + }; - a_id!( f1(), 13 ); - } + index!( f1 ); + a_id!( f1(), 13 ); } } // -tests_index! -{ - - empty_with_comma, - empty_without_comma, - with_comma, - without_comma, - parentheses_with_comma, - parentheses_without_comma, - -} +// tests_index! +// { +// +// empty_with_comma, +// empty_without_comma, +// with_comma, +// without_comma, +// parentheses_with_comma, +// parentheses_without_comma, +// +// } diff --git a/module/core/impls_index/tests/inc/mod.rs b/module/core/impls_index/tests/inc/mod.rs index d7b9687e2f..105f2928cd 100644 --- a/module/core/impls_index/tests/inc/mod.rs +++ b/module/core/impls_index/tests/inc/mod.rs @@ -1,5 +1,10 @@ -use super::*; +use super:: +{ + the_module, + only_for_terminal_module, + a_id, +}; mod func_test; mod impls_basic_test; diff --git a/module/core/impls_index/tests/inc/tests_index_test.rs b/module/core/impls_index/tests/inc/tests_index_test.rs index 9c684d5a68..d6cbf4e3c6 100644 --- a/module/core/impls_index/tests/inc/tests_index_test.rs +++ b/module/core/impls_index/tests/inc/tests_index_test.rs @@ -1,155 +1,151 @@ // use test_tools::exposed::*; use super::*; -use the_module::prelude::impls1; +use the_module::exposed::impls1; +use the_module::exposed::{ tests_index }; // -tests_impls! +#[ test ] +fn empty_with_comma() { - - fn empty_with_comma() + // test.case( "impls1 basic" ); { - // test.case( "impls1 basic" ); - { - - impls1!(); - tests_index!(); - - } + impls1!(); + tests_index!(); } +} + +#[ test ] +fn empty_without_comma() +{ - fn empty_without_comma() + // test.case( "impls1 basic" ); { - // test.case( "impls1 basic" ); + impls1! { + }; - impls1! - { - }; - - tests_index! - { - } - + tests_index! + { } } +} + +#[ test ] +fn with_comma() +{ - fn with_comma() + // test.case( "impls1 basic" ); { - // test.case( "impls1 basic" ); + impls1! { - - impls1! + fn f1() -> i32 { - fn f1() -> i32 - { - println!( "f1" ); - 13 - } - }; - - tests_index! - { - f1, + println!( "f1" ); + 13 } + }; - a_id!( f1(), 13 ); + tests_index! + { + f1, } + a_id!( f1(), 13 ); } +} + +#[ test ] +fn without_comma() +{ - fn without_comma() + // test.case( "impls1 basic" ); { - // test.case( "impls1 basic" ); + impls1! { - - impls1! - { - fn f1() -> i32 - { - println!( "f1" ); - 13 - } - }; - - tests_index! + fn f1() -> i32 { - f1 + println!( "f1" ); + 13 } + }; - a_id!( f1(), 13 ); + tests_index! + { + f1 } + a_id!( f1(), 13 ); } +} + +#[ test ] +fn parentheses_with_comma() +{ - fn parentheses_with_comma() + // test.case( "impls1 basic" ); { - // test.case( "impls1 basic" ); + impls1! { - - impls1! + fn f1() -> i32 { - fn f1() -> i32 - { - println!( "f1" ); - 13 - } - }; - - tests_index!( f1, ); + println!( "f1" ); + 13 + } + }; - a_id!( f1(), 13 ); - } + tests_index!( f1, ); + a_id!( f1(), 13 ); } +} - fn parentheses_without_comma() +#[ test ] +fn parentheses_without_comma() +{ + + // test.case( "impls1 basic" ); { - // test.case( "impls1 basic" ); + impls1! { - - impls1! + fn f1() -> i32 { - fn f1() -> i32 - { - println!( "f1" ); - 13 - } - }; - - tests_index!( f1 ); + println!( "f1" ); + 13 + } + }; - a_id!( f1(), 13 ); - } + tests_index!( f1 ); + a_id!( f1(), 13 ); } } // -tests_index! -{ - - empty_with_comma, - empty_without_comma, - with_comma, - without_comma, - parentheses_with_comma, - parentheses_without_comma, - -} +// tests_index! +// { +// +// empty_with_comma, +// empty_without_comma, +// with_comma, +// without_comma, +// parentheses_with_comma, +// parentheses_without_comma, +// +// } diff --git a/module/core/impls_index/tests/tests.rs b/module/core/impls_index/tests/tests.rs index 7d4038e715..b96684ac4a 100644 --- a/module/core/impls_index/tests/tests.rs +++ b/module/core/impls_index/tests/tests.rs @@ -1,3 +1,4 @@ +#![ allow( unused_imports ) ] include!( "../../../../module/step/meta/src/module/terminal.rs" ); diff --git a/module/core/impls_index_meta/Cargo.toml b/module/core/impls_index_meta/Cargo.toml index ce629d78b3..036c5a03d0 100644 --- a/module/core/impls_index_meta/Cargo.toml +++ b/module/core/impls_index_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "impls_index_meta" -version = "0.7.0" +version = "0.9.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/impls_index_meta/License b/module/core/impls_index_meta/License index e3e9e057cf..c32986cee3 100644 --- a/module/core/impls_index_meta/License +++ b/module/core/impls_index_meta/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/include_md/License b/module/core/include_md/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/include_md/License +++ b/module/core/include_md/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/inspect_type/Cargo.toml b/module/core/inspect_type/Cargo.toml index cebba6d857..260320b11b 100644 --- a/module/core/inspect_type/Cargo.toml +++ b/module/core/inspect_type/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "inspect_type" -version = "0.10.0" +version = "0.12.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/inspect_type/License b/module/core/inspect_type/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/inspect_type/License +++ b/module/core/inspect_type/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/inspect_type/src/lib.rs b/module/core/inspect_type/src/lib.rs index 27e60ce850..8f65d3fb63 100644 --- a/module/core/inspect_type/src/lib.rs +++ b/module/core/inspect_type/src/lib.rs @@ -2,7 +2,9 @@ #![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] #![ doc( html_root_url = "https://docs.rs/inspect_type/latest/inspect_type/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] +#![ allow( unexpected_cfgs ) ] +// #[ allow( unexpected_cfgs ) ] // #[ cfg( RUSTC_IS_NIGHTLY ) ] #[ cfg( not( RUSTC_IS_STABLE ) ) ] mod nightly diff --git a/module/core/inspect_type/tests/inc/inspect_type_test.rs b/module/core/inspect_type/tests/inc/inspect_type_test.rs index 58eb0b82b1..01445f74c4 100644 --- a/module/core/inspect_type/tests/inc/inspect_type_test.rs +++ b/module/core/inspect_type/tests/inc/inspect_type_test.rs @@ -1,3 +1,4 @@ + #[ allow( unused_imports ) ] use super::*; diff --git a/module/core/inspect_type/tests/tests.rs b/module/core/inspect_type/tests/tests.rs index 1b4624edf8..8e5818a1f9 100644 --- a/module/core/inspect_type/tests/tests.rs +++ b/module/core/inspect_type/tests/tests.rs @@ -1,3 +1,5 @@ +// #![ allow( unexpected_cfgs ) ] + // #![ no_std ] // #![ cfg_attr( feature = "no_std", no_std ) ] diff --git a/module/core/interval_adapter/Cargo.toml b/module/core/interval_adapter/Cargo.toml index 40b7639448..787fac61c8 100644 --- a/module/core/interval_adapter/Cargo.toml +++ b/module/core/interval_adapter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "interval_adapter" -version = "0.23.0" +version = "0.27.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/interval_adapter/License b/module/core/interval_adapter/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/interval_adapter/License +++ b/module/core/interval_adapter/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/interval_adapter/src/lib.rs b/module/core/interval_adapter/src/lib.rs index 4684d69850..3fcc39e3f1 100644 --- a/module/core/interval_adapter/src/lib.rs +++ b/module/core/interval_adapter/src/lib.rs @@ -4,7 +4,7 @@ #![ doc( html_root_url = "https://docs.rs/winterval/latest/winterval/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -/// Internal namespace. +/// Define a private namespace for all its items. #[ cfg( feature = "enabled" ) ] mod private { diff --git a/module/core/is_slice/Cargo.toml b/module/core/is_slice/Cargo.toml index b0945c3613..2854cf37cd 100644 --- a/module/core/is_slice/Cargo.toml +++ b/module/core/is_slice/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "is_slice" -version = "0.9.0" +version = "0.11.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/is_slice/License b/module/core/is_slice/License index e3e9e057cf..c32986cee3 100644 --- a/module/core/is_slice/License +++ b/module/core/is_slice/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/iter_tools/Cargo.toml b/module/core/iter_tools/Cargo.toml index ea0b221df3..7e4dcad983 100644 --- a/module/core/iter_tools/Cargo.toml +++ b/module/core/iter_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iter_tools" -version = "0.20.0" +version = "0.24.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/iter_tools/License b/module/core/iter_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/iter_tools/License +++ b/module/core/iter_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/iter_tools/src/iter.rs b/module/core/iter_tools/src/iter.rs index 86fbda3f33..727e18409f 100644 --- a/module/core/iter_tools/src/iter.rs +++ b/module/core/iter_tools/src/iter.rs @@ -5,6 +5,8 @@ mod private #[ allow( unused_imports ) ] use crate::*; // use ::itertools::process_results; + + #[ cfg( feature = "iter_trait" ) ] use clone_dyn_types::CloneDyn; /// Trait that encapsulates an iterator with specific characteristics and implemetning `CloneDyn`. diff --git a/module/core/macro_tools/Cargo.toml b/module/core/macro_tools/Cargo.toml index cb1e7be33e..99877d2e6f 100644 --- a/module/core/macro_tools/Cargo.toml +++ b/module/core/macro_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "macro_tools" -version = "0.39.0" +version = "0.44.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -108,5 +108,5 @@ iter_tools = { workspace = true, features = [ "iter_trait" ] } clone_dyn_types = { workspace = true, features = [] } former_types = { workspace = true, features = [ "types_component_assign" ] } -[dev-dependencies] -test_tools = { workspace = true } +# [dev-dependencies] +# test_tools = { workspace = true } diff --git a/module/core/macro_tools/License b/module/core/macro_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/macro_tools/License +++ b/module/core/macro_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/macro_tools/src/attr.rs b/module/core/macro_tools/src/attr.rs index d87c7865b2..15c0d1e69d 100644 --- a/module/core/macro_tools/src/attr.rs +++ b/module/core/macro_tools/src/attr.rs @@ -2,7 +2,7 @@ //! Attributes analyzys and manipulation. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/macro_tools/src/attr_prop.rs b/module/core/macro_tools/src/attr_prop.rs index a5e3aeaecd..8ffa3d9cab 100644 --- a/module/core/macro_tools/src/attr_prop.rs +++ b/module/core/macro_tools/src/attr_prop.rs @@ -102,7 +102,7 @@ mod boolean_optional; mod syn; mod syn_optional; -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::*; diff --git a/module/core/macro_tools/src/components.rs b/module/core/macro_tools/src/components.rs index 5ff8c6fbe5..4e8b2ccf20 100644 --- a/module/core/macro_tools/src/components.rs +++ b/module/core/macro_tools/src/components.rs @@ -2,7 +2,7 @@ //! Type-based assigning. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { } diff --git a/module/core/macro_tools/src/container_kind.rs b/module/core/macro_tools/src/container_kind.rs index b7cedc6149..6dc2719925 100644 --- a/module/core/macro_tools/src/container_kind.rs +++ b/module/core/macro_tools/src/container_kind.rs @@ -2,7 +2,7 @@ //! Determine kind of a container. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/macro_tools/src/ct.rs b/module/core/macro_tools/src/ct.rs index dd3778e29b..1264aea393 100644 --- a/module/core/macro_tools/src/ct.rs +++ b/module/core/macro_tools/src/ct.rs @@ -2,7 +2,7 @@ //! Compile-time tools. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { } diff --git a/module/core/macro_tools/src/derive.rs b/module/core/macro_tools/src/derive.rs index 84ab933fb4..dacf84f8e7 100644 --- a/module/core/macro_tools/src/derive.rs +++ b/module/core/macro_tools/src/derive.rs @@ -2,7 +2,7 @@ //! Macro helpers around derive macro and structure [`syn::DeriveInput`]. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/macro_tools/src/diag.rs b/module/core/macro_tools/src/diag.rs index 0f8fa6f6e8..81138cd382 100644 --- a/module/core/macro_tools/src/diag.rs +++ b/module/core/macro_tools/src/diag.rs @@ -2,7 +2,7 @@ //! Macro helpers. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/macro_tools/src/equation.rs b/module/core/macro_tools/src/equation.rs index 6a419dfe07..3d89aa4ba4 100644 --- a/module/core/macro_tools/src/equation.rs +++ b/module/core/macro_tools/src/equation.rs @@ -2,7 +2,7 @@ //! Attributes analyzys and manipulation. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/macro_tools/src/generic_args.rs b/module/core/macro_tools/src/generic_args.rs index 16636e8ac0..1cd40e8f7a 100644 --- a/module/core/macro_tools/src/generic_args.rs +++ b/module/core/macro_tools/src/generic_args.rs @@ -2,7 +2,7 @@ //! This module provides utilities to handle and manipulate generic arguments using the `syn` crate. It includes traits and functions for transforming, merging, and managing generic parameters within procedural macros, enabling seamless syntactic analysis and code generation. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index 599b5ca7cb..fac0859aa1 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -2,7 +2,7 @@ //! Functions and structures to handle and manipulate generic parameters using the `syn` crate. It's designed to support macro-driven code generation by simplifying, merging, extracting, and decomposing `syn::Generics`. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/macro_tools/src/item.rs b/module/core/macro_tools/src/item.rs index 605124e8a5..d82f484847 100644 --- a/module/core/macro_tools/src/item.rs +++ b/module/core/macro_tools/src/item.rs @@ -3,7 +3,7 @@ //! to manipulate the structure of items, handle different kinds of fields, and provide a structured approach to //! organizing the codebase into different access levels. -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/macro_tools/src/item_struct.rs b/module/core/macro_tools/src/item_struct.rs index 1855fa67b3..dd8f31f739 100644 --- a/module/core/macro_tools/src/item_struct.rs +++ b/module/core/macro_tools/src/item_struct.rs @@ -2,7 +2,7 @@ //! Parse structures, like `struct { a : i32 }`. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/macro_tools/src/iter.rs b/module/core/macro_tools/src/iter.rs index 6ad9773801..71bf438658 100644 --- a/module/core/macro_tools/src/iter.rs +++ b/module/core/macro_tools/src/iter.rs @@ -2,7 +2,7 @@ //! Tailored iterator. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { } diff --git a/module/core/macro_tools/src/kw.rs b/module/core/macro_tools/src/kw.rs index c7910e7571..4a29a6879d 100644 --- a/module/core/macro_tools/src/kw.rs +++ b/module/core/macro_tools/src/kw.rs @@ -2,7 +2,7 @@ //! Keywords //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::*; diff --git a/module/core/macro_tools/src/lib.rs b/module/core/macro_tools/src/lib.rs index a11fdf7f69..8f20b5d77b 100644 --- a/module/core/macro_tools/src/lib.rs +++ b/module/core/macro_tools/src/lib.rs @@ -4,7 +4,7 @@ #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -/// Internal namespace. +/// Define a private namespace for all its items. #[ cfg( feature = "enabled" ) ] mod private { diff --git a/module/core/macro_tools/src/name.rs b/module/core/macro_tools/src/name.rs index a9f53887b0..a5185ea8c4 100644 --- a/module/core/macro_tools/src/name.rs +++ b/module/core/macro_tools/src/name.rs @@ -2,7 +2,7 @@ //! Tait to getn name of an Item. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/core/macro_tools/src/phantom.rs b/module/core/macro_tools/src/phantom.rs index f4bc1ec350..507a7fe0d1 100644 --- a/module/core/macro_tools/src/phantom.rs +++ b/module/core/macro_tools/src/phantom.rs @@ -4,7 +4,7 @@ //! Functions and structures to handle and manipulate `PhantomData` fields in structs using the `syn` crate. These utilities ensure that generic parameters are correctly accounted for in type checking, even if they are not directly used in the struct's fields. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/macro_tools/src/punctuated.rs b/module/core/macro_tools/src/punctuated.rs index 2257904a81..893e8459fb 100644 --- a/module/core/macro_tools/src/punctuated.rs +++ b/module/core/macro_tools/src/punctuated.rs @@ -4,7 +4,7 @@ //! This module provides functionality to manipulate and ensure correct punctuation in `syn::punctuated::Punctuated` collections, commonly used in procedural macros to represent sequences of elements separated by punctuation marks, such as commas. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/core/macro_tools/src/quantifier.rs b/module/core/macro_tools/src/quantifier.rs index 379c38e9a4..a1c3cb7833 100644 --- a/module/core/macro_tools/src/quantifier.rs +++ b/module/core/macro_tools/src/quantifier.rs @@ -2,7 +2,7 @@ //! Quantifiers like Pair and Many. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/macro_tools/src/struct_like.rs b/module/core/macro_tools/src/struct_like.rs index 1ec494be89..5b9652b506 100644 --- a/module/core/macro_tools/src/struct_like.rs +++ b/module/core/macro_tools/src/struct_like.rs @@ -2,7 +2,7 @@ //! Parse structures, like `struct { a : i32 }`. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/macro_tools/src/tokens.rs b/module/core/macro_tools/src/tokens.rs index 0d7fd568e8..4785c8dfc8 100644 --- a/module/core/macro_tools/src/tokens.rs +++ b/module/core/macro_tools/src/tokens.rs @@ -2,7 +2,7 @@ //! Attributes analyzys and manipulation. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/macro_tools/src/typ.rs b/module/core/macro_tools/src/typ.rs index 03b535081e..1c1f0e39e5 100644 --- a/module/core/macro_tools/src/typ.rs +++ b/module/core/macro_tools/src/typ.rs @@ -2,7 +2,7 @@ //! Advanced syntax elements. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/macro_tools/src/typed.rs b/module/core/macro_tools/src/typed.rs index 3eeeba271f..5e75476fb1 100644 --- a/module/core/macro_tools/src/typed.rs +++ b/module/core/macro_tools/src/typed.rs @@ -2,7 +2,7 @@ //! Typed parsing. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::*; diff --git a/module/core/mem_tools/Cargo.toml b/module/core/mem_tools/Cargo.toml index fd90f9d727..ba71b5759a 100644 --- a/module/core/mem_tools/Cargo.toml +++ b/module/core/mem_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mem_tools" -version = "0.6.0" +version = "0.8.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -24,7 +24,6 @@ workspace = true features = [ "full" ] all-features = false - include = [ "/rust/impl/mem", "/Cargo.toml", diff --git a/module/core/mem_tools/License b/module/core/mem_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/mem_tools/License +++ b/module/core/mem_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/mem_tools/src/lib.rs b/module/core/mem_tools/src/lib.rs index 03270e0a05..141da61a9d 100644 --- a/module/core/mem_tools/src/lib.rs +++ b/module/core/mem_tools/src/lib.rs @@ -37,7 +37,6 @@ pub mod own #[ doc( inline ) ] pub use orphan::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::mem::orphan::*; } @@ -60,7 +59,6 @@ pub mod exposed #[ doc( inline ) ] pub use prelude::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::mem::exposed::*; } @@ -71,6 +69,5 @@ pub mod prelude { use super::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::mem::prelude::*; } diff --git a/module/core/mem_tools/src/mem.rs b/module/core/mem_tools/src/mem.rs index e35cb611cd..3a48ddad8b 100644 --- a/module/core/mem_tools/src/mem.rs +++ b/module/core/mem_tools/src/mem.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; @@ -64,30 +64,28 @@ mod private } +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + /// Own namespace of the module. #[ allow( unused_imports ) ] pub mod own { use super::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super:: { orphan::*, }; } -#[ doc( inline ) ] -#[ allow( unused_imports ) ] -pub use own::*; - /// Orphan namespace of the module. #[ allow( unused_imports ) ] pub mod orphan { use super::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super:: { exposed::*, @@ -103,6 +101,9 @@ pub mod orphan pub mod exposed { use super::*; + // Expose itself. + pub use super::super::mem; + #[ doc( inline ) ] pub use prelude::*; } diff --git a/module/core/meta_tools/Cargo.toml b/module/core/meta_tools/Cargo.toml index 282db2f43f..ec2054076a 100644 --- a/module/core/meta_tools/Cargo.toml +++ b/module/core/meta_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "meta_tools" -version = "0.10.0" +version = "0.12.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -24,47 +24,45 @@ workspace = true features = [ "full" ] all-features = false - - [features] default = [ "enabled", "meta_for_each", "meta_impls_index", - # "meta_mod_interface", - "meta_constructors", + "mod_interface", "meta_idents_concat", ] full = [ "enabled", "meta_for_each", "meta_impls_index", - # "meta_mod_interface", - "meta_constructors", + "mod_interface", "meta_idents_concat", ] no_std = [] use_alloc = [ "no_std" ] -enabled = [] +enabled = [ + "for_each/enabled", + "impls_index/enabled", + "mod_interface/enabled", +] -meta_for_each = [ "for_each/enabled" ] -meta_impls_index = [ "impls_index/enabled" ] -meta_mod_interface = [ "mod_interface/enabled" ] -# xxx : qqq : make mod_interface optional maybe +meta_for_each = [ "for_each/enabled", "dep:for_each" ] +meta_impls_index = [ "impls_index/enabled", "dep:impls_index" ] +mod_interface = [ "mod_interface/enabled", "dep:mod_interface" ] -meta_constructors = [ "literally" ] -meta_idents_concat = [ "paste" ] +# meta_constructors = [ "literally" ] +meta_idents_concat = [ "dep:paste" ] [dependencies] -## external -literally = { version = "~0.1.3", optional = true, default-features = false } -paste = { version = "~1.0.14", optional = true, default-features = false } +# ## external +paste = { workspace = true, optional = true, default-features = false } ## internal -impls_index = { workspace = true } -for_each = { workspace = true } -mod_interface = { workspace = true, features = [ "default" ] } +for_each = { workspace = true, optional = true } +impls_index = { workspace = true, optional = true } +mod_interface = { workspace = true, optional = true } [dev-dependencies] test_tools = { workspace = true } diff --git a/module/core/meta_tools/License b/module/core/meta_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/meta_tools/License +++ b/module/core/meta_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/meta_tools/Readme.md b/module/core/meta_tools/Readme.md index 0d472b069f..c43c980e94 100644 --- a/module/core/meta_tools/Readme.md +++ b/module/core/meta_tools/Readme.md @@ -7,21 +7,6 @@ Collection of general purpose meta tools. -### Basic use-case :: variadic constructor of collections - -Among other useful meta tools the module aggregates variadic constructors of collections. For example macro `hmap!` for constructing a hash map. - - - -```rust -use meta_tools::*; - -let meta_map = hmap! { 3 => 13 }; -let mut std_map = std::collections::HashMap::new(); -std_map.insert( 3, 13 ); -assert_eq!( meta_map, std_map ); -``` - ### Basic Use Case :: function-style call Apply a macro for each element of a list. diff --git a/module/core/meta_tools/examples/meta_tools_trivial.rs b/module/core/meta_tools/examples/meta_tools_trivial.rs index 75d17ddace..983e55c9d6 100644 --- a/module/core/meta_tools/examples/meta_tools_trivial.rs +++ b/module/core/meta_tools/examples/meta_tools_trivial.rs @@ -3,8 +3,10 @@ use meta_tools::*; fn main() { - let meta_map = hmap! { 3 => 13 }; - let mut std_map = std::collections::HashMap::new(); - std_map.insert( 3, 13 ); - assert_eq!( meta_map, std_map ); + for_each!( dbg, "a", "b", "c" ); + + // generates + dbg!( "a" ); + dbg!( "b" ); + dbg!( "c" ); } diff --git a/module/core/meta_tools/src/lib.rs b/module/core/meta_tools/src/lib.rs index cd49c9841e..e31d911ffe 100644 --- a/module/core/meta_tools/src/lib.rs +++ b/module/core/meta_tools/src/lib.rs @@ -10,32 +10,69 @@ pub mod dependency { - // #[ cfg( feature = "meta_mod_interface" ) ] pub use ::mod_interface; #[ cfg( feature = "meta_for_each" ) ] pub use ::for_each; #[ cfg( feature = "meta_impls_index" ) ] pub use ::impls_index; - - #[ cfg( feature = "meta_constructors" ) ] - pub use ::literally; #[ cfg( feature = "meta_idents_concat" ) ] pub use ::paste; - // #[ cfg( feature = "former" ) ] - // pub use ::former; - // #[ cfg( feature = "options" ) ] - // pub use ::woptions; - } +mod private {} + +// + +// // qqq : meta interface should be optional dependancy. please fix writing equivalent code manually +// #[ cfg( feature = "enabled" ) ] +// mod_interface::mod_interface! +// { +// // #![ debug ] // +// layer meta; +// +// } + +pub mod meta; -// qqq : meta interface should be optional dependancy. please fix writing equivalent code manually #[ cfg( feature = "enabled" ) ] -mod_interface::mod_interface! +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod own { + use super::*; + pub use meta::orphan::*; +} - layer meta; +/// Orphan namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; + pub use exposed::*; +} +/// Exposed namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + pub use prelude::*; + pub use meta::exposed::*; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; + pub use meta::prelude::*; } diff --git a/module/core/meta_tools/src/meta.rs b/module/core/meta_tools/src/meta.rs index e05ad7deec..1047857beb 100644 --- a/module/core/meta_tools/src/meta.rs +++ b/module/core/meta_tools/src/meta.rs @@ -2,39 +2,82 @@ //! Collection of general purpose meta tools. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { } // +// #[ cfg( feature = "enabled" ) ] +// mod_interface::mod_interface! +// { +// #![ debug ] +// +// #[ cfg( feature = "meta_impls_index" ) ] +// use ::impls_index; +// #[ cfg( feature = "meta_for_each" ) ] +// use ::for_each; +// // #[ cfg( feature = "meta_mod_interface" ) ] +// use ::mod_interface; +// // #[ cfg( feature = "meta_mod_interface" ) ] +// prelude use ::mod_interface::mod_interface; +// +// #[ cfg( feature = "meta_idents_concat" ) ] +// prelude use ::paste::paste as meta_idents_concat; +// +// } + +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ cfg( feature = "enabled" ) ] +pub mod own +{ + use super::*; + pub use ::impls_index::orphan::*; + pub use ::for_each::orphan::*; + pub use ::mod_interface::orphan::*; + pub use orphan::*; +} + +/// Orphan namespace of the module. #[ cfg( feature = "enabled" ) ] -mod_interface::mod_interface! +#[ allow( unused_imports ) ] +pub mod orphan { + use super::*; + + // pub use ::impls_index; + // pub use ::for_each; + // pub use ::mod_interface; - #[ cfg( feature = "meta_impls_index" ) ] - use ::impls_index; - #[ cfg( feature = "meta_for_each" ) ] - use ::for_each; - // #[ cfg( feature = "meta_mod_interface" ) ] - use ::mod_interface; - // #[ cfg( feature = "meta_mod_interface" ) ] - prelude use ::mod_interface::mod_interface; - - #[ cfg( feature = "meta_constructors" ) ] - prelude use ::literally::*; - #[ cfg( feature = "meta_idents_concat" ) ] - prelude use ::paste::paste as meta_idents_concat; - - // #[ cfg( feature = "options" ) ] - // use ::woptions; - // #[ cfg( feature = "options" ) ] - // prelude use ::woptions as options; - - // #[ cfg( feature = "former" ) ] - // use ::former; - // #[ cfg( feature = "former" ) ] - // prelude use ::former as former; + pub use exposed::*; +} +/// Exposed namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + pub use prelude::*; + pub use super::super::meta; + pub use ::impls_index::exposed::*; + pub use ::for_each::exposed::*; + pub use ::mod_interface::exposed::*; + pub use ::paste::paste as meta_idents_concat; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; + pub use ::impls_index::prelude::*; + pub use ::for_each::prelude::*; + pub use ::mod_interface::prelude::*; } diff --git a/module/core/meta_tools/tests/inc/meta_constructor_test.rs b/module/core/meta_tools/tests/inc/meta_constructor_test.rs index acee680259..d4cffdf307 100644 --- a/module/core/meta_tools/tests/inc/meta_constructor_test.rs +++ b/module/core/meta_tools/tests/inc/meta_constructor_test.rs @@ -1,50 +1,50 @@ -use super::*; - -// - -tests_impls! -{ - - fn hash_map() - { - - // test.case( "empty" ); - let got : std::collections::HashMap< i32, i32 > = the_module::hmap!{}; - let exp = std::collections::HashMap::new(); - a_id!( got, exp ); - - // test.case( "single entry" ); - let got = the_module::hmap!{ 3 => 13 }; - let mut exp = std::collections::HashMap::new(); - exp.insert( 3, 13 ); - a_id!( got, exp ); - - } - - // - - - fn hash_set() - { - - // test.case( "empty" ); - let got : std::collections::HashSet< i32 > = the_module::hset!{}; - let exp = std::collections::HashSet::new(); - a_id!( got, exp ); - - // test.case( "single entry" ); - let got = the_module::hset!{ 13 }; - let mut exp = std::collections::HashSet::new(); - exp.insert( 13 ); - a_id!( got, exp ); - - } -} - -// - -tests_index! -{ - hash_map, - hash_set, -} +// use super::*; +// +// // +// +// tests_impls! +// { +// +// fn hash_map() +// { +// +// // test.case( "empty" ); +// let got : std::collections::HashMap< i32, i32 > = the_module::hmap!{}; +// let exp = std::collections::HashMap::new(); +// a_id!( got, exp ); +// +// // test.case( "single entry" ); +// let got = the_module::hmap!{ 3 => 13 }; +// let mut exp = std::collections::HashMap::new(); +// exp.insert( 3, 13 ); +// a_id!( got, exp ); +// +// } +// +// // +// +// +// fn hash_set() +// { +// +// // test.case( "empty" ); +// let got : std::collections::HashSet< i32 > = the_module::hset!{}; +// let exp = std::collections::HashSet::new(); +// a_id!( got, exp ); +// +// // test.case( "single entry" ); +// let got = the_module::hset!{ 13 }; +// let mut exp = std::collections::HashSet::new(); +// exp.insert( 13 ); +// a_id!( got, exp ); +// +// } +// } +// +// // +// +// tests_index! +// { +// hash_map, +// hash_set, +// } diff --git a/module/core/meta_tools/tests/inc/mod.rs b/module/core/meta_tools/tests/inc/mod.rs index 9fc942d2c2..98e402d4c3 100644 --- a/module/core/meta_tools/tests/inc/mod.rs +++ b/module/core/meta_tools/tests/inc/mod.rs @@ -1,17 +1,17 @@ #[ allow( unused_imports ) ] use super::*; -#[ cfg( any( feature = "meta_constructors", feature = "meta_constructors" ) ) ] -mod meta_constructor_test; +// #[ cfg( any( feature = "meta_constructors", feature = "meta_constructors" ) ) ] +// mod meta_constructor_test; #[ cfg( any( feature = "meta_idents_concat", feature = "meta_idents_concat" ) ) ] mod indents_concat_test; -#[ cfg( any( feature = "for_each", feature = "meta_for_each" ) ) ] +#[ cfg( any( feature = "meta_for_each" ) ) ] #[ path = "../../../for_each/tests/inc/mod.rs" ] mod for_each_test; -#[ cfg( any( feature = "impls_index", feature = "meta_impls_index" ) ) ] +#[ cfg( any( feature = "meta_impls_index" ) ) ] #[ path = "../../../impls_index/tests/inc/mod.rs" ] mod impls_index; diff --git a/module/core/mod_interface/Cargo.toml b/module/core/mod_interface/Cargo.toml index 38f56efef2..8f3e3f76f4 100644 --- a/module/core/mod_interface/Cargo.toml +++ b/module/core/mod_interface/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mod_interface" -version = "0.23.0" +version = "0.30.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -28,8 +28,6 @@ all-features = false [features] default = [ "enabled" ] full = [ "enabled" ] -no_std = [] -use_alloc = [ "no_std" ] enabled = [ "mod_interface_meta/enabled" ] # keep these examples in directories diff --git a/module/core/mod_interface/License b/module/core/mod_interface/License index e3e9e057cf..c32986cee3 100644 --- a/module/core/mod_interface/License +++ b/module/core/mod_interface/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/mod_interface/Readme.md b/module/core/mod_interface/Readme.md index 72573cc881..0bb7e9b255 100644 --- a/module/core/mod_interface/Readme.md +++ b/module/core/mod_interface/Readme.md @@ -5,109 +5,199 @@ [![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_mod_interface_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_mod_interface_push.yml) [![docs.rs](https://img.shields.io/docsrs/mod_interface?color=e3e8f0&logo=docs.rs)](https://docs.rs/mod_interface) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) -Protocol of modularity unifying interface of a module and introducing layers. +Protocol of modularity unifying interface. -### Basic use-case +### Problem Solved -Library file with code `inner.rs`: +The `mod_interface` crate provides a structured approach to modularity, addressing two key challenges in software development: -```rust ignore -mod private +1. **Meaningful Namespace Structuring**: The crate enables developers to organize program entities into meaningful namespaces ( read modules ) without additional development overhead. This is achieved through a set of auto-importing rules and a flexible inversion of control mechanism, allowing parent layers ( namespaces or modules ) to delegate control over its items to child layers. This approach ensures that each namespace is self-contained and meaningful, promoting better organization and modularity. + +2. **Enhanced Readability and Tooling Independence**: By requiring a `mod private` section that lists all items ( read functions, structures, traits, types ) the `mod_interface` macro encourages developers to create a concise list of items at the beginning or end of a file. This improves readability, encourages refactoring, and reduces cognitive load by providing a clear, high-level grouping of items. Code tooling is not always reliable and can sometimes be counterproductive by automating tasks that should be done manually to achieve more concise code. While code tooling like `rust_analyzer` are useful, this approach minimizes reliance on them, making the program's structure easier to understand and manage. + +While some may argue that inversion of control over namespaces may not always achieve the desired outcome, and code tooling can be sufficient, the `mod_interface` crate offers a cathartic solution for designing complex systems where tooling and triditional structuring often fall short. By promoting a clear and organized structure, it helps developers grasp the semantics of their programs more holistically. + +### Basic Concepts + +In the `mod_interface` crate, the concepts of layers and namespaces are central to its modularity approach. Here's a refined explanation: + +- **Namespaces**: These are standard Rust modules that help organize code into logical groups. +- **Layers**: A layer is a specialized module that contains a set of predefined submodules, referred to as chapters. These chapters dictate how the contents of the module are propagated to parent layers. + +The chapters within a layer are: + +- **Private Chapter (`private`)**: This is where all the code and entities are initially defined. It is not accessible outside the module. +- **Public Chapter (`own`)**: Contains items that are not propagated to any parent layers. They remain within the module. +- **Public Chapter (`orphan`)**: Shares its contents with the immediate parent layer only. +- **Public Chapter (`exposed`)**: Propagates its contents to all parent layers, making them accessible throughout the hierarchy. +- **Public Chapter (`prelude`)**: Similar to `exposed`, but also serves as a recommendation for other crates to implicitly import its contents, akin to the prelude in the [Rust standard library](https://doc.rust-lang.org/std/prelude/index.html). + +Developers should define all entities within the `private` chapter and then re-export them through the other four chapters based on the desired propagation strategy. + +### Syntax of `mod_interface` Macro + +The `mod_interface` macro provides several directives to manage the relationships between layers and entities: + +- **`layer `**: Establishes a relationship where the current layer uses a child layer. +- **`use `**: Allows the current layer to use another layer defined elsewhere. +- **`reuse `**: Enables the current layer to reuse a layer defined anywhere, promoting code reuse. +- **` use `**: Allows the current layer to use an entity defined anywhere, with the specified promotion stategy (``). + +These directives provide flexibility in organizing and managing the modular structure of a Rust program, enhancing both readability and maintainability. + +### Example: Using Layers and Entities + +In this example, we demonstrate the basic use case of one layer utilizing another layer. For a module to be used as a layer, it must contain all the necessary chapters: `orphan`, `exposed`, and `prelude`. Generally, a layer should also have the `own` and `private` chapters, but these are typically not modified directly by the user unless explicitly defined, with the `private` chapter remaining inaccessible from outside the module. + +Below is a simple example where a parent layer imports a `child` layer. The `child` layer defines several functions, each with a different propagation strategy, resulting in each function being placed in a different chapter of the parent layer, while some functions do not reach the parent layer at all. + +```rust +use mod_interface::mod_interface; + +// Define a module named `child`. +pub mod child { - /// Routine of inner module. - pub fn inner_is() -> bool + + // Define a private namespace for all its items. + mod private { - true + /// Only my thing. + pub fn my_thing() -> bool { true } + /// Parent module should also has this thing. + pub fn orphan_thing() -> bool { true } + /// This thing should be exposed. + pub fn exposed_thing() -> bool { true } + /// This thing should be in prelude. + pub fn prelude_thing() -> bool { true } } -} -// + // -mod_interface::mod_interface! -{ - prelude use inner_is; -} -``` + crate::mod_interface! + { + own use my_thing; + orphan use orphan_thing; + exposed use exposed_thing; + prelude use prelude_thing; + } -Main file that generates modules and namespaces `main.rs` : +} -```rust ignore -use mod_interface::mod_interface; +// Priave namespaces is necessary. +mod private {} -// +crate::mod_interface! +{ + /// Inner. + use super::child; +} fn main() { - assert_eq!( prelude::inner_is(), inner::prelude::inner_is() ); -} -// + assert!( child::prelude_thing(), "prelude thing of child is there" ); + assert!( prelude_thing(), "and here" ); + assert!( own::prelude_thing(), "and here" ); + assert!( orphan::prelude_thing(), "and here" ); + assert!( exposed::prelude_thing(), "and here" ); + assert!( prelude::prelude_thing(), "and here" ); + + assert!( child::exposed_thing(), "exposed thing of child is there" ); + assert!( exposed_thing(), "and here" ); + assert!( own::exposed_thing(), "and here" ); + assert!( orphan::exposed_thing(), "and here" ); + assert!( exposed::exposed_thing(), "and here" ); + // assert!( prelude::exposed_thing(), "but not here" ); + + assert!( child::orphan_thing(), "orphan thing of child is there" ); + assert!( orphan_thing(), "orphan thing of child is here" ); + assert!( own::orphan_thing(), "and here" ); + // assert!( orphan::orphan_thing(), "but not here" ); + // assert!( exposed::orphan_thing(), "and not here" ); + // assert!( prelude::orphan_thing(), "and not here" ); + + assert!( child::my_thing(), "own thing of child is only there" ); + // assert!( my_thing(), "and not here" ); + // assert!( own::my_thing(), "and not here" ); + // assert!( orphan::my_thing(), "and not here" ); + // assert!( exposed::my_thing(), "and not here" ); + // assert!( prelude::my_thing(), "and not here" ); -mod_interface::mod_interface! -{ - /// Inner. - layer inner; } + ``` -It generates code : +
+The code above will be expanded to this ```rust use mod_interface::mod_interface; -// - -fn main() -{ - assert_eq!( prelude::inner_is(), inner::prelude::inner_is() ); -} - -// - -/// Inner. -pub mod inner +// Define a module named `child` +pub mod child { + // Define a private namespace for all its items. mod private { - /// Routine of inner module. - pub fn inner_is() -> bool { true } + /// Only my thing. + pub fn my_thing() -> bool { true } + /// Parent module should also has this thing. + pub fn orphan_thing() -> bool { true } + /// This thing should be exposed. + pub fn exposed_thing() -> bool { true } + /// This thing should be in prelude. + pub fn prelude_thing() -> bool { true } } + pub use own::*; + /// Own namespace of the module. pub mod own { + use super::*; pub use orphan::*; + pub use private::my_thing; } - pub use own::*; /// Orphan namespace of the module. pub mod orphan { + use super::*; pub use exposed::*; + pub use private::orphan_thing; } /// Exposed namespace of the module. pub mod exposed { + use super::*; pub use prelude::*; + pub use private::exposed_thing; } /// Prelude to use essentials: `use my_module::prelude::*`. pub mod prelude { - pub use private::inner_is; + use super::*; + pub use private::prelude_thing; } + } +// Priave namespaces is necessary. +mod private {} + +pub use own::*; + /// Own namespace of the module. #[ allow( unused_imports ) ] pub mod own { use super::*; pub use orphan::*; - pub use super::inner::orphan::*; + pub use child::orphan::*; + pub use super::child; } -pub use own::*; /// Orphan namespace of the module. #[ allow( unused_imports ) ] @@ -123,7 +213,7 @@ pub mod exposed { use super::*; pub use prelude::*; - pub use super::inner::exposed::*; + pub use child::exposed::*; } /// Prelude to use essentials: `use my_module::prelude::*`. @@ -131,10 +221,83 @@ pub mod exposed pub mod prelude { use super::*; - pub use super::inner::prelude::*; + pub use child::prelude::*; } + +// + +fn main() +{ + + assert!( child::prelude_thing(), "prelude thing of child is there" ); + assert!( prelude_thing(), "and here" ); + assert!( own::prelude_thing(), "and here" ); + assert!( orphan::prelude_thing(), "and here" ); + assert!( exposed::prelude_thing(), "and here" ); + assert!( prelude::prelude_thing(), "and here" ); + + assert!( child::exposed_thing(), "exposed thing of child is there" ); + assert!( exposed_thing(), "and here" ); + assert!( own::exposed_thing(), "and here" ); + assert!( orphan::exposed_thing(), "and here" ); + assert!( exposed::exposed_thing(), "and here" ); + // assert!( prelude::exposed_thing(), "but not here" ); + + assert!( child::orphan_thing(), "orphan thing of child is there" ); + assert!( orphan_thing(), "orphan thing of child is here" ); + assert!( own::orphan_thing(), "and here" ); + // assert!( orphan::orphan_thing(), "but not here" ); + // assert!( exposed::orphan_thing(), "and not here" ); + // assert!( prelude::orphan_thing(), "and not here" ); + + assert!( child::my_thing(), "own thing of child is only there" ); + // assert!( my_thing(), "and not here" ); + // assert!( own::my_thing(), "and not here" ); + // assert!( orphan::my_thing(), "and not here" ); + // assert!( exposed::my_thing(), "and not here" ); + // assert!( prelude::my_thing(), "and not here" ); + +} + ``` +
+ +As you can see: + +- The content of the `prelude` chapter is automatically propagated into the `exposed` chapter of the same layer. +- The content of the `exposed` chapter is automatically propagated into the `orphan` chapter of the same layer. +- The content of the `orphan` chapter is automatically propagated into the `own` chapter of the same layer. +- The content of the `own` chapter is not automatically propagated anywhere. + +### `layer ` vs `use ` + +The `use ;` syntax is used to import a layer from anywhere within the project or even from external crates. This provides flexibility in how layers are organized, as the layer being used does not need to be a direct submodule of the current module. It allows you to bring any accessible layer into the current scope without enforcing a specific file structure. The visibility of the imported layer remains as it is defined in its original location, and this syntax does not inherently change that visibility. + +In contrast, the `layer ` syntax is used to establish a hierarchical relationship where the current module uses a child layer. This requires the child layer to be a direct submodule, meaning it must be physically present in the file structure as a submodule. The `layer ` syntax implies `pub mod layer1`, making the child layer publicly accessible as a submodule. This enforces a specific organizational structure, where the child layer is part of the current module's hierarchy, and its contents are directly accessible according to the defined propagation strategies. + +Thus, `layer ` acts as a shortcut, combining the definition of a reference to a module file and using it, while `use ` uses a module that is already defined somewhere, not necessarily in the same crate. + +### `reuse ` vs `use ` + +The `reuse ` syntax treats the child layer as an integral part of the parent layer, so the normal rules of propagation do not apply to the content of the child layer. Specifically, the `own` chapter of the child layer is imported into the `own` chapter of the parent layer, and the `orphan` chapter of the child layer is imported into the `orphan` chapter of the parent layer. + +In contrast, `use ` follows the standard propagation rules: + +- `child::own` is not propagated. +- `child::orphan` is imported into `parent::own`. +- `child::exposed` is imported into `parent::exposed`. +- `child::prelude` is imported into `parent::prelude`. + +For `reuse `, the propagation is as follows: + +- `child::own` is imported into `parent::own`. +- `child::orphan` is imported into `parent::orphan`. +- `child::exposed` is imported into `parent::exposed`. +- `child::prelude` is imported into `parent::prelude`. + +`reusing` does not impact parent of parent or child of child. + ### Debugging To debug module interface use directive `#![ debug ]` in macro `mod_interface`. Let's update the main file of the example : @@ -144,7 +307,7 @@ mod_interface::mod_interface! { #![ debug ] /// Inner. - layer inner; + layer child; } ``` diff --git a/module/core/mod_interface/examples/mod_interface_debug/Readme.md b/module/core/mod_interface/examples/mod_interface_debug/Readme.md index 6cc31966fb..d57023c6a5 100644 --- a/module/core/mod_interface/examples/mod_interface_debug/Readme.md +++ b/module/core/mod_interface/examples/mod_interface_debug/Readme.md @@ -6,8 +6,10 @@ A sample demonstrates basic usage of macro `mod_interface`. -In file `inner.rs` demonstrated how to generate module interface from namespace `private` and its public routine. +In file `child.rs` demonstrated how to generate module interface from namespace `private` and its public routine. In file `main.rs` demonstrated how to generate module interface from layer ( file with full module interface ). The directive `#![ debug ]` in declaration of macro `mod_interface` allow to show generated module interface as the standard output in compile time. + + \ No newline at end of file diff --git a/module/core/mod_interface/examples/mod_interface_debug/src/inner.rs b/module/core/mod_interface/examples/mod_interface_debug/src/child.rs similarity index 80% rename from module/core/mod_interface/examples/mod_interface_debug/src/inner.rs rename to module/core/mod_interface/examples/mod_interface_debug/src/child.rs index cc62b2c56b..dd734212d9 100644 --- a/module/core/mod_interface/examples/mod_interface_debug/src/inner.rs +++ b/module/core/mod_interface/examples/mod_interface_debug/src/child.rs @@ -1,6 +1,6 @@ mod private { - /// Routine of inner module. + /// Routine of child module. pub fn inner_is() -> bool { true diff --git a/module/core/mod_interface/examples/mod_interface_debug/src/main.rs b/module/core/mod_interface/examples/mod_interface_debug/src/main.rs index e316b7acd6..985f4f49f7 100644 --- a/module/core/mod_interface/examples/mod_interface_debug/src/main.rs +++ b/module/core/mod_interface/examples/mod_interface_debug/src/main.rs @@ -3,16 +3,18 @@ use mod_interface::mod_interface; // -fn main() +mod private {} +mod_interface! { - assert_eq!( prelude::inner_is(), inner::prelude::inner_is() ); + // Uncomment to see expanded code. + // #![ debug ] + /// Child. + layer child; } // -mod_interface! +fn main() { - #![ debug ] - /// Inner. - layer inner; + assert_eq!( prelude::inner_is(), child::prelude::inner_is() ); } diff --git a/module/core/mod_interface/examples/mod_interface_trivial/Readme.md b/module/core/mod_interface/examples/mod_interface_trivial/Readme.md index 343322a31c..e7b67c25d1 100644 --- a/module/core/mod_interface/examples/mod_interface_trivial/Readme.md +++ b/module/core/mod_interface/examples/mod_interface_trivial/Readme.md @@ -1,11 +1,9 @@ -# Sample +### Example: Using Layers and Entities [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) [![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%2Frust%2Fmod_interface_trivial,SAMPLE_FILE=.%2Fsrc%2Fmain.rs/https://github.com/Wandalen/wTools) [![docs.rs](https://raster.shields.io/static/v1?label=docs&message=online&color=eee&logo=docsdotrs&logoColor=eee)](https://docs.rs/mod_interface) -A sample demonstrates basic usage of macro `mod_interface`. +In this example, we demonstrate the basic use case of one layer utilizing another layer. For a module to be used as a layer, it must contain all the necessary chapters: `orphan`, `exposed`, and `prelude`. Generally, a layer should also have the `own` and `private` chapters, but these are typically not modified directly by the user unless explicitly defined, with the `private` chapter remaining inaccessible from outside the module. -In file `inner.rs` demonstrated how to generate module interface from namespace `private` and its public routine. - -In file `main.rs` demonstrated how to generate module interface from layer ( file with full module interface ). +Below is a simple example where a parent layer imports a `child` layer. The `child` layer defines several functions, each with a different propagation strategy, resulting in each function being placed in a different chapter of the parent layer, while some functions do not reach the parent layer at all. diff --git a/module/core/mod_interface/examples/mod_interface_trivial/src/child.rs b/module/core/mod_interface/examples/mod_interface_trivial/src/child.rs new file mode 100644 index 0000000000..4ea0121559 --- /dev/null +++ b/module/core/mod_interface/examples/mod_interface_trivial/src/child.rs @@ -0,0 +1,23 @@ + +// Define a private namespace for all its items. +mod private +{ + /// Only my thing. + pub fn my_thing() -> bool { true } + /// Parent module should also has this thing. + pub fn orphan_thing() -> bool { true } + /// This thing should be exposed. + pub fn exposed_thing() -> bool { true } + /// This thing should be in prelude. + pub fn prelude_thing() -> bool { true } +} + +// + +crate::mod_interface! +{ + own use my_thing; + orphan use orphan_thing; + exposed use exposed_thing; + prelude use prelude_thing; +} diff --git a/module/core/mod_interface/examples/mod_interface_trivial/src/inner.rs b/module/core/mod_interface/examples/mod_interface_trivial/src/inner.rs deleted file mode 100644 index cc62b2c56b..0000000000 --- a/module/core/mod_interface/examples/mod_interface_trivial/src/inner.rs +++ /dev/null @@ -1,15 +0,0 @@ -mod private -{ - /// Routine of inner module. - pub fn inner_is() -> bool - { - true - } -} - -// - -mod_interface::mod_interface! -{ - prelude use inner_is; -} diff --git a/module/core/mod_interface/examples/mod_interface_trivial/src/main.rs b/module/core/mod_interface/examples/mod_interface_trivial/src/main.rs index 03b8905594..f834f8b12f 100644 --- a/module/core/mod_interface/examples/mod_interface_trivial/src/main.rs +++ b/module/core/mod_interface/examples/mod_interface_trivial/src/main.rs @@ -1,21 +1,49 @@ -//! qqq : write proper descriptionuse mod_interface::mod_interface; - -// +//! This example demonstrates how to use the `mod_interface` crate to organize a Rust program into structured namespaces. The code is divided into a library file (`child.rs`) and a main function. The library file defines a module with private functions and uses the `mod_interface` macro to specify which functions should be exposed in different namespaces. The main function then tests the visibility and accessibility of these functions. use mod_interface::mod_interface; -fn main() -{ - assert_eq!( prelude::inner_is(), prelude::inner_is() ); -} +/// Children. +pub mod child; -// +// Priave namespaces is necessary. +mod private {} -mod_interface! +crate::mod_interface! { /// Inner. - layer inner; + use super::child; } -// qqq : rewrite sample -/* aaa : Dmytro : sample with layer */ + +fn main() +{ + + assert!( child::prelude_thing(), "prelude thing of child is there" ); + assert!( prelude_thing(), "and here" ); + assert!( own::prelude_thing(), "and here" ); + assert!( orphan::prelude_thing(), "and here" ); + assert!( exposed::prelude_thing(), "and here" ); + assert!( prelude::prelude_thing(), "and here" ); + + assert!( child::exposed_thing(), "exposed thing of child is there" ); + assert!( exposed_thing(), "and here" ); + assert!( own::exposed_thing(), "and here" ); + assert!( orphan::exposed_thing(), "and here" ); + assert!( exposed::exposed_thing(), "and here" ); + // assert!( prelude::exposed_thing(), "but not here" ); + + assert!( child::orphan_thing(), "orphan thing of child is there" ); + assert!( orphan_thing(), "orphan thing of child is here" ); + assert!( own::orphan_thing(), "and here" ); + // assert!( orphan::orphan_thing(), "but not here" ); + // assert!( exposed::orphan_thing(), "and not here" ); + // assert!( prelude::orphan_thing(), "and not here" ); + + assert!( child::my_thing(), "own thing of child is only there" ); + // assert!( my_thing(), "and not here" ); + // assert!( own::my_thing(), "and not here" ); + // assert!( orphan::my_thing(), "and not here" ); + // assert!( exposed::my_thing(), "and not here" ); + // assert!( prelude::my_thing(), "and not here" ); + +} diff --git a/module/core/mod_interface/src/lib.rs b/module/core/mod_interface/src/lib.rs index 30c7731f89..726b166188 100644 --- a/module/core/mod_interface/src/lib.rs +++ b/module/core/mod_interface/src/lib.rs @@ -1,4 +1,4 @@ -#![ cfg_attr( feature = "no_std", no_std ) ] +#![ no_std ] #![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] #![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] #![ doc( html_root_url = "https://docs.rs/mod_interface/latest/mod_interface/" ) ] diff --git a/module/core/mod_interface/tests/inc/derive/attr_debug/mod.rs b/module/core/mod_interface/tests/inc/derive/attr_debug/mod.rs index 939ebcdfb3..7b425682cc 100644 --- a/module/core/mod_interface/tests/inc/derive/attr_debug/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/attr_debug/mod.rs @@ -1,9 +1,11 @@ use super::*; -mod_interface! +mod private {} + +the_module::mod_interface! { - #![ debug ] + // #![ debug ] /// layer_a layer layer_a; diff --git a/module/core/mod_interface/tests/inc/derive/layer/mod.rs b/module/core/mod_interface/tests/inc/derive/layer/mod.rs index d8e79fb20b..8a567560f7 100644 --- a/module/core/mod_interface/tests/inc/derive/layer/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/layer/mod.rs @@ -6,7 +6,7 @@ mod private { } -mod_interface! +the_module::mod_interface! { /// layer_a diff --git a/module/core/mod_interface/tests/inc/derive/layer_have_layer/layer_a.rs b/module/core/mod_interface/tests/inc/derive/layer_have_layer/layer_a.rs index dfffa8d8a8..082005e6be 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_have_layer/layer_a.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_have_layer/layer_a.rs @@ -33,7 +33,7 @@ mod private // -mod_interface! +the_module::mod_interface! { // orphan use super::private:: diff --git a/module/core/mod_interface/tests/inc/derive/layer_have_layer/layer_b.rs b/module/core/mod_interface/tests/inc/derive/layer_have_layer/layer_b.rs index 9f17f61637..1d265d3c4f 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_have_layer/layer_b.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_have_layer/layer_b.rs @@ -39,7 +39,7 @@ pub struct SubStruct2 // -mod_interface! +the_module::mod_interface! { own use layer_b_own; diff --git a/module/core/mod_interface/tests/inc/derive/layer_have_layer/mod.rs b/module/core/mod_interface/tests/inc/derive/layer_have_layer/mod.rs index 6cf3f6db29..219360f435 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_have_layer/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_have_layer/mod.rs @@ -11,7 +11,7 @@ mod private { } -mod_interface! +the_module::mod_interface! { /// layer_a diff --git a/module/core/mod_interface/tests/inc/derive/layer_have_layer_cfg/layer_a.rs b/module/core/mod_interface/tests/inc/derive/layer_have_layer_cfg/layer_a.rs index dfffa8d8a8..082005e6be 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_have_layer_cfg/layer_a.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_have_layer_cfg/layer_a.rs @@ -33,7 +33,7 @@ mod private // -mod_interface! +the_module::mod_interface! { // orphan use super::private:: diff --git a/module/core/mod_interface/tests/inc/derive/layer_have_layer_cfg/layer_b.rs b/module/core/mod_interface/tests/inc/derive/layer_have_layer_cfg/layer_b.rs index 9f17f61637..1d265d3c4f 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_have_layer_cfg/layer_b.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_have_layer_cfg/layer_b.rs @@ -39,7 +39,7 @@ pub struct SubStruct2 // -mod_interface! +the_module::mod_interface! { own use layer_b_own; diff --git a/module/core/mod_interface/tests/inc/derive/layer_have_layer_cfg/mod.rs b/module/core/mod_interface/tests/inc/derive/layer_have_layer_cfg/mod.rs index 09c564f64b..b0fc4d5d70 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_have_layer_cfg/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_have_layer_cfg/mod.rs @@ -11,7 +11,7 @@ mod private { } -mod_interface! +the_module::mod_interface! { /// layer_a diff --git a/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use/layer_a.rs b/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use/layer_a.rs index 8d8d6b1faf..c71e0af7d2 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use/layer_a.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use/layer_a.rs @@ -33,7 +33,7 @@ mod private // -mod_interface! +the_module::mod_interface! { own use { layer_a_own }; diff --git a/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use/layer_b.rs b/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use/layer_b.rs index 9f17f61637..1d265d3c4f 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use/layer_b.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use/layer_b.rs @@ -39,7 +39,7 @@ pub struct SubStruct2 // -mod_interface! +the_module::mod_interface! { own use layer_b_own; diff --git a/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use/mod.rs b/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use/mod.rs index c34df1c831..0d2ec22d26 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use/mod.rs @@ -12,11 +12,11 @@ mod private } /// layer_a -mod layer_a; +pub mod layer_a; /// layer_b -mod layer_b; +pub mod layer_b; -mod_interface! +the_module::mod_interface! { /// layer_a diff --git a/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use_two/layer_a.rs b/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use_two/layer_a.rs index 8d8d6b1faf..c71e0af7d2 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use_two/layer_a.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use_two/layer_a.rs @@ -33,7 +33,7 @@ mod private // -mod_interface! +the_module::mod_interface! { own use { layer_a_own }; diff --git a/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use_two/layer_b.rs b/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use_two/layer_b.rs index 9f17f61637..1d265d3c4f 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use_two/layer_b.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use_two/layer_b.rs @@ -39,7 +39,7 @@ pub struct SubStruct2 // -mod_interface! +the_module::mod_interface! { own use layer_b_own; diff --git a/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use_two/mod.rs b/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use_two/mod.rs index 4774b23347..c20f8d770a 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use_two/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_have_layer_separate_use_two/mod.rs @@ -12,11 +12,11 @@ mod private } /// layer_a -mod layer_a; +pub mod layer_a; /// layer_b -mod layer_b; +pub mod layer_b; -mod_interface! +the_module::mod_interface! { // zzz : test with `layer { layer_a, layer_a };` diff --git a/module/core/mod_interface/tests/inc/derive/layer_have_mod_cfg/mod.rs b/module/core/mod_interface/tests/inc/derive/layer_have_mod_cfg/mod.rs index 2188f4a6b3..38ff58d0eb 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_have_mod_cfg/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_have_mod_cfg/mod.rs @@ -11,7 +11,7 @@ mod private { } -mod_interface! +the_module::mod_interface! { /// mod_a diff --git a/module/core/mod_interface/tests/inc/derive/layer_unknown_vis/trybuild.stderr b/module/core/mod_interface/tests/inc/derive/layer_unknown_vis/trybuild.stderr index 2d2aa78ea8..125e29bbdb 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_unknown_vis/trybuild.stderr +++ b/module/core/mod_interface/tests/inc/derive/layer_unknown_vis/trybuild.stderr @@ -1,4 +1,4 @@ -error: expected one of: `mod`, `use`, `layer` +error: expected one of: `mod`, `use`, `layer`, `reuse` --> tests/inc/derive/layer_unknown_vis/mod.rs | | xyz layer layer_a; diff --git a/module/core/mod_interface/tests/inc/derive/layer_use_cfg/layer_a.rs b/module/core/mod_interface/tests/inc/derive/layer_use_cfg/layer_a.rs index dfffa8d8a8..082005e6be 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_use_cfg/layer_a.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_use_cfg/layer_a.rs @@ -33,7 +33,7 @@ mod private // -mod_interface! +the_module::mod_interface! { // orphan use super::private:: diff --git a/module/core/mod_interface/tests/inc/derive/layer_use_cfg/layer_b.rs b/module/core/mod_interface/tests/inc/derive/layer_use_cfg/layer_b.rs index 9f17f61637..1d265d3c4f 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_use_cfg/layer_b.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_use_cfg/layer_b.rs @@ -39,7 +39,7 @@ pub struct SubStruct2 // -mod_interface! +the_module::mod_interface! { own use layer_b_own; diff --git a/module/core/mod_interface/tests/inc/derive/layer_use_cfg/mod.rs b/module/core/mod_interface/tests/inc/derive/layer_use_cfg/mod.rs index 0c730db3a7..d9eedf0a3e 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_use_cfg/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_use_cfg/mod.rs @@ -12,12 +12,13 @@ mod private } /// layer_a -mod layer_a; +pub mod layer_a; /// layer_b -mod layer_b; +pub mod layer_b; -mod_interface! +the_module::mod_interface! { + // #![ debug ] /// layer_a use super::layer_a; @@ -33,4 +34,3 @@ mod_interface! // include!( "../../only_test/layer_simple_only_test.rs" ); - diff --git a/module/core/mod_interface/tests/inc/derive/layer_use_macro/layer_a.rs b/module/core/mod_interface/tests/inc/derive/layer_use_macro/layer_a.rs index 12db22ecfc..b37c839cd0 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_use_macro/layer_a.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_use_macro/layer_a.rs @@ -35,7 +35,7 @@ mod private // -mod_interface! +the_module::mod_interface! { // exposed( crate ) use macro1; diff --git a/module/core/mod_interface/tests/inc/derive/layer_use_macro/mod.rs b/module/core/mod_interface/tests/inc/derive/layer_use_macro/mod.rs index 1bb9569c90..67a972b145 100644 --- a/module/core/mod_interface/tests/inc/derive/layer_use_macro/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/layer_use_macro/mod.rs @@ -11,7 +11,7 @@ mod private { } -mod_interface! +the_module::mod_interface! { /// layer_a diff --git a/module/core/mod_interface/tests/inc/derive/micro_modules/mod.rs b/module/core/mod_interface/tests/inc/derive/micro_modules/mod.rs index 09c94a139e..57adff6ff2 100644 --- a/module/core/mod_interface/tests/inc/derive/micro_modules/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/micro_modules/mod.rs @@ -6,8 +6,9 @@ mod private { } -mod_interface! +the_module::mod_interface! { + // #![ debug ] /// mod_own own mod mod_own; diff --git a/module/core/mod_interface/tests/inc/derive/micro_modules/mod_protected.rs b/module/core/mod_interface/tests/inc/derive/micro_modules/mod_own.rs similarity index 100% rename from module/core/mod_interface/tests/inc/derive/micro_modules/mod_protected.rs rename to module/core/mod_interface/tests/inc/derive/micro_modules/mod_own.rs diff --git a/module/core/mod_interface/tests/inc/derive/micro_modules_bad_vis/trybuild.stderr b/module/core/mod_interface/tests/inc/derive/micro_modules_bad_vis/trybuild.stderr index b84160eec0..d73c3c374c 100644 --- a/module/core/mod_interface/tests/inc/derive/micro_modules_bad_vis/trybuild.stderr +++ b/module/core/mod_interface/tests/inc/derive/micro_modules_bad_vis/trybuild.stderr @@ -1,4 +1,4 @@ -error: To include a non-standard module use either [ private, protected, orphan, exposed, prelude ] visibility: +error: To include a non-standard module use either [ private, own, orphan, exposed, prelude ] visibility: #[doc = " mod_exposed"] pub mod mod_exposed; --> tests/inc/derive/micro_modules_bad_vis/mod.rs | diff --git a/module/core/mod_interface/tests/inc/manual/micro_modules/mod_protected.rs b/module/core/mod_interface/tests/inc/derive/micro_modules_glob/child.rs similarity index 100% rename from module/core/mod_interface/tests/inc/manual/micro_modules/mod_protected.rs rename to module/core/mod_interface/tests/inc/derive/micro_modules_glob/child.rs diff --git a/module/core/mod_interface/tests/inc/derive/micro_modules_glob/mod.rs b/module/core/mod_interface/tests/inc/derive/micro_modules_glob/mod.rs new file mode 100644 index 0000000000..f567778739 --- /dev/null +++ b/module/core/mod_interface/tests/inc/derive/micro_modules_glob/mod.rs @@ -0,0 +1,28 @@ + +// use super::*; + +/// Define a private namespace for all its items. +mod private +{ + pub struct Struct1; + pub struct Struct2; +} + +// + +crate::the_module::mod_interface! +{ + own use + { + * + }; +} + +// + +#[ test ] +fn basic() +{ + let _s1 = Struct1; + let _s2 = Struct2; +} diff --git a/module/core/mod_interface/tests/inc/derive/micro_modules_two/mod.rs b/module/core/mod_interface/tests/inc/derive/micro_modules_two/mod.rs index 9071caf2d1..c62e6f7e18 100644 --- a/module/core/mod_interface/tests/inc/derive/micro_modules_two/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/micro_modules_two/mod.rs @@ -6,7 +6,7 @@ mod private { } -mod_interface! +the_module::mod_interface! { /// mod_own1 diff --git a/module/core/mod_interface/tests/inc/derive/micro_modules_two/mod_protected1.rs b/module/core/mod_interface/tests/inc/derive/micro_modules_two/mod_own1.rs similarity index 100% rename from module/core/mod_interface/tests/inc/derive/micro_modules_two/mod_protected1.rs rename to module/core/mod_interface/tests/inc/derive/micro_modules_two/mod_own1.rs diff --git a/module/core/mod_interface/tests/inc/derive/micro_modules_two/mod_protected2.rs b/module/core/mod_interface/tests/inc/derive/micro_modules_two/mod_own2.rs similarity index 100% rename from module/core/mod_interface/tests/inc/derive/micro_modules_two/mod_protected2.rs rename to module/core/mod_interface/tests/inc/derive/micro_modules_two/mod_own2.rs diff --git a/module/core/mod_interface/tests/inc/derive/micro_modules_two_joined/mod.rs b/module/core/mod_interface/tests/inc/derive/micro_modules_two_joined/mod.rs index ced5712479..de2d1c2e88 100644 --- a/module/core/mod_interface/tests/inc/derive/micro_modules_two_joined/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/micro_modules_two_joined/mod.rs @@ -6,7 +6,7 @@ mod private { } -mod_interface! +the_module::mod_interface! { own mod diff --git a/module/core/mod_interface/tests/inc/derive/micro_modules_two_joined/mod_protected1.rs b/module/core/mod_interface/tests/inc/derive/micro_modules_two_joined/mod_own1.rs similarity index 100% rename from module/core/mod_interface/tests/inc/derive/micro_modules_two_joined/mod_protected1.rs rename to module/core/mod_interface/tests/inc/derive/micro_modules_two_joined/mod_own1.rs diff --git a/module/core/mod_interface/tests/inc/derive/micro_modules_two_joined/mod_protected2.rs b/module/core/mod_interface/tests/inc/derive/micro_modules_two_joined/mod_own2.rs similarity index 100% rename from module/core/mod_interface/tests/inc/derive/micro_modules_two_joined/mod_protected2.rs rename to module/core/mod_interface/tests/inc/derive/micro_modules_two_joined/mod_own2.rs diff --git a/module/core/mod_interface/tests/inc/derive/micro_modules_unknown_vis/trybuild.stderr b/module/core/mod_interface/tests/inc/derive/micro_modules_unknown_vis/trybuild.stderr index 8df4ef8899..0fd927c7e0 100644 --- a/module/core/mod_interface/tests/inc/derive/micro_modules_unknown_vis/trybuild.stderr +++ b/module/core/mod_interface/tests/inc/derive/micro_modules_unknown_vis/trybuild.stderr @@ -1,4 +1,4 @@ -error: expected one of: `mod`, `use`, `layer` +error: expected one of: `mod`, `use`, `layer`, `reuse` --> tests/inc/derive/micro_modules_unknown_vis/mod.rs | | not_vis mod mod_exposed; diff --git a/module/core/mod_interface/tests/inc/derive/reuse_basic/child.rs b/module/core/mod_interface/tests/inc/derive/reuse_basic/child.rs new file mode 100644 index 0000000000..19fcd7abde --- /dev/null +++ b/module/core/mod_interface/tests/inc/derive/reuse_basic/child.rs @@ -0,0 +1,15 @@ +mod private +{ + pub struct Own; + pub struct Orphan; + pub struct Exposed; + pub struct Prelude; +} + +crate::the_module::mod_interface! +{ + own use Own; + orphan use Orphan; + exposed use Exposed; + prelude use Prelude; +} diff --git a/module/core/mod_interface/tests/inc/derive/reuse_basic/mod.rs b/module/core/mod_interface/tests/inc/derive/reuse_basic/mod.rs new file mode 100644 index 0000000000..8ee5259142 --- /dev/null +++ b/module/core/mod_interface/tests/inc/derive/reuse_basic/mod.rs @@ -0,0 +1,34 @@ + +// use super::*; + +/// Define a private namespace for all its items. +mod private +{ +} + +mod child; + +// + +crate::the_module::mod_interface! +{ + reuse child; +} + +// + +#[ test ] +fn basic() +{ + + let _ = child::Own; + let _ = child::Orphan; + let _ = child::Exposed; + let _ = child::Prelude; + + let _ = Own; + let _ = Orphan; + let _ = Exposed; + let _ = Prelude; + +} diff --git a/module/core/mod_interface/tests/inc/derive/use_as/derive.rs b/module/core/mod_interface/tests/inc/derive/use_as/derive.rs index 4c452702b0..1d0b464591 100644 --- a/module/core/mod_interface/tests/inc/derive/use_as/derive.rs +++ b/module/core/mod_interface/tests/inc/derive/use_as/derive.rs @@ -4,7 +4,9 @@ use super::*; /// Layer X pub mod layer_x; -mod_interface! +mod private {} + +the_module::mod_interface! { // #![ debug ] @@ -13,7 +15,7 @@ mod_interface! // /// layer_a // pub use super::layer_x as layer_a; - // xxx : make that working + // zzz : make that working } diff --git a/module/core/mod_interface/tests/inc/derive/use_as/manual_only.rs b/module/core/mod_interface/tests/inc/derive/use_as/manual_only.rs index f6fcb2f162..9ce347e8fb 100644 --- a/module/core/mod_interface/tests/inc/derive/use_as/manual_only.rs +++ b/module/core/mod_interface/tests/inc/derive/use_as/manual_only.rs @@ -3,7 +3,7 @@ use layer_x as layer_a; #[doc(inline)] #[allow(unused_imports)] -pub use protected :: * ; +pub use own :: * ; #[doc = r" Own namespace of the module."] #[ allow( unused_imports ) ] diff --git a/module/core/mod_interface/tests/inc/derive/use_bad_vis/trybuild.stderr b/module/core/mod_interface/tests/inc/derive/use_bad_vis/trybuild.stderr index b63d146f04..cb5d08876c 100644 --- a/module/core/mod_interface/tests/inc/derive/use_bad_vis/trybuild.stderr +++ b/module/core/mod_interface/tests/inc/derive/use_bad_vis/trybuild.stderr @@ -1,4 +1,4 @@ -error: Use either [ private, protected, orphan, exposed, prelude ] visibility: +error: Use either [ private, own, orphan, exposed, prelude ] visibility: #[doc = " layer_a"] pub use; --> tests/inc/derive/use_bad_vis/mod.rs | diff --git a/module/core/mod_interface/tests/inc/derive/use_basic/mod.rs b/module/core/mod_interface/tests/inc/derive/use_basic/mod.rs index 3cfbb3ad53..4afc8262c6 100644 --- a/module/core/mod_interface/tests/inc/derive/use_basic/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/use_basic/mod.rs @@ -1,10 +1,14 @@ use super::*; -mod layer_a; -mod layer_b; +// private layer +pub mod layer_a; +// private layer +pub mod layer_b; -mod_interface! +mod private {} + +the_module::mod_interface! { /// layer_a diff --git a/module/core/mod_interface/tests/inc/derive/use_layer/layer_a.rs b/module/core/mod_interface/tests/inc/derive/use_layer/layer_a.rs index 14ecb25b3e..1b892a03b1 100644 --- a/module/core/mod_interface/tests/inc/derive/use_layer/layer_a.rs +++ b/module/core/mod_interface/tests/inc/derive/use_layer/layer_a.rs @@ -34,7 +34,7 @@ pub struct SubStruct4 // -mod_interface! +the_module::mod_interface! { orphan use ::std::vec::Vec; diff --git a/module/core/mod_interface/tests/inc/derive/use_layer/mod.rs b/module/core/mod_interface/tests/inc/derive/use_layer/mod.rs index 17247d2d07..4b4bfaa581 100644 --- a/module/core/mod_interface/tests/inc/derive/use_layer/mod.rs +++ b/module/core/mod_interface/tests/inc/derive/use_layer/mod.rs @@ -6,12 +6,7 @@ mod tools pub use super::super::*; } -// /// Private namespace of the module. -// mod private -// { -// } - -mod layer_a; +pub mod layer_a; /// SuperStruct1. #[ derive( Debug, PartialEq ) ] @@ -19,7 +14,9 @@ pub struct SuperStruct1 { } -mod_interface! +mod private {} + +the_module::mod_interface! { /// layer_a diff --git a/module/core/mod_interface/tests/inc/derive/use_private_layers/layer_a.rs b/module/core/mod_interface/tests/inc/derive/use_private_layers/layer_a.rs new file mode 100644 index 0000000000..8c49982711 --- /dev/null +++ b/module/core/mod_interface/tests/inc/derive/use_private_layers/layer_a.rs @@ -0,0 +1,63 @@ + +/// Private namespace of the module. +mod private +{ +} + +/// Own namespace of the module. +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; + #[ doc( inline ) ] + pub use orphan::*; + /// layer_a_own + pub fn layer_a_own() -> bool + { + true + } +} + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Orphan namespace of the module. +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; + #[ doc( inline ) ] + pub use exposed::*; + /// layer_a_orphan + pub fn layer_a_orphan() -> bool + { + true + } +} + +/// Exposed namespace of the module. +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + #[ doc( inline ) ] + pub use prelude::*; + /// layer_a_exposed + pub fn layer_a_exposed() -> bool + { + true + } +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; + /// layer_a_prelude + pub fn layer_a_prelude() -> bool + { + true + } +} diff --git a/module/core/mod_interface/tests/inc/derive/use_private_layers/layer_b.rs b/module/core/mod_interface/tests/inc/derive/use_private_layers/layer_b.rs new file mode 100644 index 0000000000..1e15689f05 --- /dev/null +++ b/module/core/mod_interface/tests/inc/derive/use_private_layers/layer_b.rs @@ -0,0 +1,63 @@ + +/// Private namespace of the module. +mod private +{ +} + +/// Own namespace of the module. +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; + #[ doc( inline ) ] + pub use orphan::*; + /// layer_b_own + pub fn layer_b_own() -> bool + { + true + } +} + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Orphan namespace of the module. +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; + #[ doc( inline ) ] + pub use exposed::*; + /// layer_b_orphan + pub fn layer_b_orphan() -> bool + { + true + } +} + +/// Exposed namespace of the module. +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + #[ doc( inline ) ] + pub use prelude::*; + /// layer_b_exposed + pub fn layer_b_exposed() -> bool + { + true + } +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; + /// layer_b_prelude + pub fn layer_b_prelude() -> bool + { + true + } +} diff --git a/module/core/mod_interface/tests/inc/derive/use_private_layers/mod.rs b/module/core/mod_interface/tests/inc/derive/use_private_layers/mod.rs new file mode 100644 index 0000000000..531513253f --- /dev/null +++ b/module/core/mod_interface/tests/inc/derive/use_private_layers/mod.rs @@ -0,0 +1,28 @@ +#![ allow( dead_code ) ] +#![ allow( unused_imports ) ] + +use super::*; + +// private layer +mod layer_a; +// private layer +mod layer_b; + +mod private {} + +// xxx : qqq : make it working + +// the_module::mod_interface! +// { +// +// /// layer_a +// priv use super::layer_a; +// +// /// layer_b +// priv use super::layer_b; +// +// } +// +// // +// +// include!( "../../only_test/layer_simple_only_test.rs" ); diff --git a/module/core/mod_interface/tests/inc/derive/use_unknown_vis/trybuild.stderr b/module/core/mod_interface/tests/inc/derive/use_unknown_vis/trybuild.stderr index 530570d39a..0dc9fb08bc 100644 --- a/module/core/mod_interface/tests/inc/derive/use_unknown_vis/trybuild.stderr +++ b/module/core/mod_interface/tests/inc/derive/use_unknown_vis/trybuild.stderr @@ -1,4 +1,4 @@ -error: expected one of: `mod`, `use`, `layer` +error: expected one of: `mod`, `use`, `layer`, `reuse` --> tests/inc/derive/use_unknown_vis/mod.rs | | xyz use f1; diff --git a/module/core/mod_interface/tests/inc/manual/layer/mod.rs b/module/core/mod_interface/tests/inc/manual/layer/mod.rs index 044ff08dbf..adb8be65df 100644 --- a/module/core/mod_interface/tests/inc/manual/layer/mod.rs +++ b/module/core/mod_interface/tests/inc/manual/layer/mod.rs @@ -19,11 +19,13 @@ pub mod own #[ doc( inline ) ] pub use orphan::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::layer_a::orphan::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::layer_b::orphan::*; + #[ doc( inline ) ] + pub use super::layer_a; + #[ doc( inline ) ] + pub use super::layer_b; } #[ doc( inline ) ] diff --git a/module/core/mod_interface/tests/inc/manual/micro_modules/mod.rs b/module/core/mod_interface/tests/inc/manual/micro_modules/mod.rs index 65ba341ba1..5aa53251a1 100644 --- a/module/core/mod_interface/tests/inc/manual/micro_modules/mod.rs +++ b/module/core/mod_interface/tests/inc/manual/micro_modules/mod.rs @@ -1,3 +1,4 @@ +#![ allow( dead_code ) ] use super::*; diff --git a/module/core/mod_interface/tests/inc/manual/micro_modules/mod_own.rs b/module/core/mod_interface/tests/inc/manual/micro_modules/mod_own.rs new file mode 100644 index 0000000000..a6619cc0c4 --- /dev/null +++ b/module/core/mod_interface/tests/inc/manual/micro_modules/mod_own.rs @@ -0,0 +1,5 @@ +/// has_own +pub fn has_own() -> bool +{ + true +} \ No newline at end of file diff --git a/module/core/mod_interface/tests/inc/manual/micro_modules_two/mod_protected1.rs b/module/core/mod_interface/tests/inc/manual/micro_modules_two/mod_own1.rs similarity index 100% rename from module/core/mod_interface/tests/inc/manual/micro_modules_two/mod_protected1.rs rename to module/core/mod_interface/tests/inc/manual/micro_modules_two/mod_own1.rs diff --git a/module/core/mod_interface/tests/inc/manual/micro_modules_two/mod_protected2.rs b/module/core/mod_interface/tests/inc/manual/micro_modules_two/mod_own2.rs similarity index 100% rename from module/core/mod_interface/tests/inc/manual/micro_modules_two/mod_protected2.rs rename to module/core/mod_interface/tests/inc/manual/micro_modules_two/mod_own2.rs diff --git a/module/core/mod_interface/tests/inc/manual/layer_use/layer_a.rs b/module/core/mod_interface/tests/inc/manual/use_layer/layer_a.rs similarity index 100% rename from module/core/mod_interface/tests/inc/manual/layer_use/layer_a.rs rename to module/core/mod_interface/tests/inc/manual/use_layer/layer_a.rs diff --git a/module/core/mod_interface/tests/inc/manual/layer_use/layer_b.rs b/module/core/mod_interface/tests/inc/manual/use_layer/layer_b.rs similarity index 100% rename from module/core/mod_interface/tests/inc/manual/layer_use/layer_b.rs rename to module/core/mod_interface/tests/inc/manual/use_layer/layer_b.rs diff --git a/module/core/mod_interface/tests/inc/manual/layer_use/mod.rs b/module/core/mod_interface/tests/inc/manual/use_layer/mod.rs similarity index 93% rename from module/core/mod_interface/tests/inc/manual/layer_use/mod.rs rename to module/core/mod_interface/tests/inc/manual/use_layer/mod.rs index 044ff08dbf..43622260c8 100644 --- a/module/core/mod_interface/tests/inc/manual/layer_use/mod.rs +++ b/module/core/mod_interface/tests/inc/manual/use_layer/mod.rs @@ -24,6 +24,10 @@ pub mod own #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::layer_b::orphan::*; + #[ doc( inline ) ] + pub use super::layer_a; + #[ doc( inline ) ] + pub use super::layer_b; } #[ doc( inline ) ] diff --git a/module/core/mod_interface/tests/inc/mod.rs b/module/core/mod_interface/tests/inc/mod.rs index 5d8aaa7045..1809e2f2e8 100644 --- a/module/core/mod_interface/tests/inc/mod.rs +++ b/module/core/mod_interface/tests/inc/mod.rs @@ -9,7 +9,7 @@ mod manual mod micro_modules; mod micro_modules_two; mod layer; - mod layer_use; + mod use_layer; } @@ -22,6 +22,7 @@ mod derive mod micro_modules; mod micro_modules_two; mod micro_modules_two_joined; + mod micro_modules_glob; // layer mod layer; @@ -33,16 +34,23 @@ mod derive mod layer_use_cfg; mod layer_use_macro; + // use mod use_layer; mod use_basic; + mod use_private_layers; #[ path = "./use_as/derive.rs" ] mod use_as_derive; #[ path = "./use_as/manual.rs" ] mod use_as_manual; + // reuse + mod reuse_basic; + // attr mod attr_debug; } mod trybuild_test; + +// xxx : enable \ No newline at end of file diff --git a/module/core/mod_interface/tests/inc/only_test/layer_simple_only_test.rs b/module/core/mod_interface/tests/inc/only_test/layer_simple_only_test.rs index 93b1190705..f62756f61a 100644 --- a/module/core/mod_interface/tests/inc/only_test/layer_simple_only_test.rs +++ b/module/core/mod_interface/tests/inc/only_test/layer_simple_only_test.rs @@ -7,6 +7,12 @@ tests_impls! fn basic() { + /* test.case( "layers themself" ); */ + { + a_id!( own::layer_a::layer_a_own(), true ); + a_id!( own::layer_b::layer_b_own(), true ); + } + /* test.case( "root" ); */ { a_id!( layer_a::layer_a_own(), true ); diff --git a/module/core/mod_interface/tests/inc/trybuild_test.rs b/module/core/mod_interface/tests/inc/trybuild_test.rs index 5acc2a4f29..f5dbbbaece 100644 --- a/module/core/mod_interface/tests/inc/trybuild_test.rs +++ b/module/core/mod_interface/tests/inc/trybuild_test.rs @@ -5,6 +5,8 @@ use super::*; // #[ cfg_attr( feature = "enabled", module_mod_interface ) ] +// xxx : qqq : enable it + // #[ cfg( module_mod_interface ) ] // #[ cfg( module_is_terminal ) ] #[ test_tools::nightly ] @@ -12,50 +14,49 @@ use super::*; fn trybuild_tests() { // qqq : fix test : if run its test with --target-dir flag it's fall (for example : cargo test --target-dir C:\foo\bar ) - // // use test_tools::dependency::trybuild; - // println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); - // // let t = trybuild::TestCases::new(); - // let t = test_tools::compiletime::TestCases::new(); - // - // let current_exe_path = std::env::current_exe().expect( "No such file or directory" ); - // - // let exe_directory = dbg!(current_exe_path.parent().expect("No such file or directory")); - // fn find_workspace_root( start_path : &std::path::Path ) -> Option< &std::path::Path > - // { - // start_path - // .ancestors() - // .find( |path| path.join( "Cargo.toml" ).exists() ) - // } - // - // let workspace_root = find_workspace_root( exe_directory ).expect( "No such file or directory" ); - // let current_dir = workspace_root.join( "module/core/mod_interface" ); - // - // // micro module - // - // t.pass( current_dir.join( "tests/inc/derive/micro_modules/trybuild.rs" ) ); - // t.pass( current_dir.join( "tests/inc/derive/micro_modules_two/trybuild.rs" ) ); - // t.pass( current_dir.join( "tests/inc/derive/micro_modules_two_joined/trybuild.rs" ) ); - // - // // layer - // - // t.pass( current_dir.join( "tests/inc/derive/layer/trybuild.rs" ) ); - // t.pass( current_dir.join( "tests/inc/derive/layer_have_layer/trybuild.rs" ) ); - // t.pass( current_dir.join( "tests/inc/derive/layer_have_layer_separate_use/trybuild.rs" ) ); - // t.pass( current_dir.join( "tests/inc/derive/layer_have_layer_separate_use_two/trybuild.rs" ) ); - // t.pass( current_dir.join( "tests/inc/derive/layer_have_layer_cfg/trybuild.rs" ) ); - // t.pass( current_dir.join( "tests/inc/derive/layer_use_cfg/trybuild.rs" ) ); - // t.pass( current_dir.join( "tests/inc/derive/layer_have_mod_cfg/trybuild.rs" ) ); - // t.pass( current_dir.join( "tests/inc/derive/layer_use_macro/trybuild.rs" ) ); - // - // // use - // - // t.pass( current_dir.join( "tests/inc/derive/use_basic/trybuild.rs" ) ); - // t.pass( current_dir.join( "tests/inc/derive/use_layer/trybuild.rs" ) ); - // t.pass( current_dir.join( "tests/inc/derive/use_as/trybuild.rs" ) ); - // - // // attr - // - // t.pass( current_dir.join( "tests/inc/derive/attr_debug/trybuild.rs" ) ); + // use test_tools::dependency::trybuild; + println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); + let t = test_tools::compiletime::TestCases::new(); + + let current_exe_path = std::env::current_exe().expect( "No such file or directory" ); + + let exe_directory = dbg!(current_exe_path.parent().expect("No such file or directory")); + fn find_workspace_root( start_path : &std::path::Path ) -> Option< &std::path::Path > + { + start_path + .ancestors() + .find( |path| path.join( "Cargo.toml" ).exists() ) + } + + let workspace_root = find_workspace_root( exe_directory ).expect( "No such file or directory" ); + let current_dir = workspace_root.join( "module/core/mod_interface" ); + + // micro module + + t.pass( current_dir.join( "tests/inc/derive/micro_modules/trybuild.rs" ) ); + t.pass( current_dir.join( "tests/inc/derive/micro_modules_two/trybuild.rs" ) ); + t.pass( current_dir.join( "tests/inc/derive/micro_modules_two_joined/trybuild.rs" ) ); + + // layer + + t.pass( current_dir.join( "tests/inc/derive/layer/trybuild.rs" ) ); + t.pass( current_dir.join( "tests/inc/derive/layer_have_layer/trybuild.rs" ) ); + t.pass( current_dir.join( "tests/inc/derive/layer_have_layer_separate_use/trybuild.rs" ) ); + t.pass( current_dir.join( "tests/inc/derive/layer_have_layer_separate_use_two/trybuild.rs" ) ); + t.pass( current_dir.join( "tests/inc/derive/layer_have_layer_cfg/trybuild.rs" ) ); + t.pass( current_dir.join( "tests/inc/derive/layer_use_cfg/trybuild.rs" ) ); + t.pass( current_dir.join( "tests/inc/derive/layer_have_mod_cfg/trybuild.rs" ) ); + t.pass( current_dir.join( "tests/inc/derive/layer_use_macro/trybuild.rs" ) ); + + // use + + t.pass( current_dir.join( "tests/inc/derive/use_basic/trybuild.rs" ) ); + t.pass( current_dir.join( "tests/inc/derive/use_layer/trybuild.rs" ) ); + t.pass( current_dir.join( "tests/inc/derive/use_as/trybuild.rs" ) ); + + // attr + + t.pass( current_dir.join( "tests/inc/derive/attr_debug/trybuild.rs" ) ); // } @@ -69,29 +70,28 @@ only_for_terminal_module! fn cta_trybuild_tests() { // qqq : fix test : if run its test with --target-dir flag it's fall (for example : cargo test --target-dir C:\foo\bar ) - // use test_tools::dependency::trybuild; - // println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); - // // let t = trybuild::TestCases::new(); - // let t = test_tools::compiletime::TestCases::new(); - // - // let current_exe_path = std::env::current_exe().expect( "No such file or directory" ); - // - // let exe_directory = current_exe_path.parent().expect( "No such file or directory" ); - // fn find_workspace_root( start_path : &std::path::Path ) -> Option< &std::path::Path > - // { - // start_path - // .ancestors() - // .find( |path| path.join( "Cargo.toml" ).exists() ) - // } - // - // let workspace_root = find_workspace_root( exe_directory ).expect( "No such file or directory" ); - // let current_dir = workspace_root.join( "module/core/mod_interface" ); - // - // t.compile_fail( current_dir.join( "tests/inc/derive/micro_modules_bad_vis/trybuild.rs" ) ); - // t.compile_fail( current_dir.join( "tests/inc/derive/micro_modules_unknown_vis/trybuild.rs" ) ); - // t.compile_fail( current_dir.join( "tests/inc/derive/layer_bad_vis/trybuild.rs" ) ); - // t.compile_fail( current_dir.join( "tests/inc/derive/layer_unknown_vis/trybuild.rs" ) ); - // t.compile_fail( current_dir.join( "tests/inc/derive/use_bad_vis/trybuild.rs" ) ); - // t.compile_fail( current_dir.join( "tests/inc/derive/use_unknown_vis/trybuild.rs" ) ); + use test_tools::dependency::trybuild; + println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); + let t = test_tools::compiletime::TestCases::new(); + + let current_exe_path = std::env::current_exe().expect( "No such file or directory" ); + + let exe_directory = current_exe_path.parent().expect( "No such file or directory" ); + fn find_workspace_root( start_path : &std::path::Path ) -> Option< &std::path::Path > + { + start_path + .ancestors() + .find( |path| path.join( "Cargo.toml" ).exists() ) + } + + let workspace_root = find_workspace_root( exe_directory ).expect( "No such file or directory" ); + let current_dir = workspace_root.join( "module/core/mod_interface" ); + + t.compile_fail( current_dir.join( "tests/inc/derive/micro_modules_bad_vis/trybuild.rs" ) ); + t.compile_fail( current_dir.join( "tests/inc/derive/micro_modules_unknown_vis/trybuild.rs" ) ); + t.compile_fail( current_dir.join( "tests/inc/derive/layer_bad_vis/trybuild.rs" ) ); + t.compile_fail( current_dir.join( "tests/inc/derive/layer_unknown_vis/trybuild.rs" ) ); + t.compile_fail( current_dir.join( "tests/inc/derive/use_bad_vis/trybuild.rs" ) ); + t.compile_fail( current_dir.join( "tests/inc/derive/use_unknown_vis/trybuild.rs" ) ); } } diff --git a/module/core/mod_interface/tests/smoke_test.rs b/module/core/mod_interface/tests/smoke_test.rs index 828e9b016b..d826b0e72a 100644 --- a/module/core/mod_interface/tests/smoke_test.rs +++ b/module/core/mod_interface/tests/smoke_test.rs @@ -1,4 +1,4 @@ - +//! Smoke tests #[ test ] fn local_smoke_test() @@ -6,7 +6,6 @@ fn local_smoke_test() ::test_tools::smoke_test_for_local_run(); } - #[ test ] fn published_smoke_test() { diff --git a/module/core/mod_interface/tests/tests.rs b/module/core/mod_interface/tests/tests.rs index 33120affda..7736531699 100644 --- a/module/core/mod_interface/tests/tests.rs +++ b/module/core/mod_interface/tests/tests.rs @@ -1,3 +1,5 @@ +//! Main tests +#![ allow( unused_imports ) ] /// A struct for testing purpose. #[ derive( Debug, PartialEq ) ] @@ -5,9 +7,7 @@ pub struct CrateStructForTesting1 { } -#[ allow( unused_imports ) ] use ::mod_interface as the_module; -#[ allow( unused_imports ) ] use test_tools::exposed::*; #[ path="../../../../module/step/meta/src/module/terminal.rs" ] mod terminal; diff --git a/module/core/mod_interface_meta/Cargo.toml b/module/core/mod_interface_meta/Cargo.toml index 05f0bbf285..ab3e6c709c 100644 --- a/module/core/mod_interface_meta/Cargo.toml +++ b/module/core/mod_interface_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mod_interface_meta" -version = "0.23.0" +version = "0.29.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/mod_interface_meta/License b/module/core/mod_interface_meta/License index e3e9e057cf..c32986cee3 100644 --- a/module/core/mod_interface_meta/License +++ b/module/core/mod_interface_meta/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/mod_interface_meta/src/impls.rs b/module/core/mod_interface_meta/src/impls.rs index 737dab4d78..81c6cec066 100644 --- a/module/core/mod_interface_meta/src/impls.rs +++ b/module/core/mod_interface_meta/src/impls.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; @@ -16,7 +16,7 @@ mod private // = ? // x - // protected protected1; + // own own1; // orphan orphan1; // exposed exposed1; // prelude prelude1; @@ -33,7 +33,7 @@ mod private // x // orphan macromod mod_orphan1; - // : protected -> protected + // : own -> own // : orphan -> orphan // : exposed -> orphan // : prelude -> orphan @@ -42,14 +42,14 @@ mod private // x // prelude exposed macromod mod_own1; - // : protected -> exposed + // : own -> exposed // : orphan -> exposed // : exposed -> exposed // : prelude -> prelude // x - // prelude protected macromod mod_exposed1; - // : protected -> protected + // prelude own macromod mod_exposed1; + // : own -> own // : orphan -> orphan // : exposed -> exposed // : prelude -> prelude @@ -58,14 +58,14 @@ mod private // x // exposed exposed macromod mod_exposed1; - // : protected -> exposed + // : own -> exposed // : orphan -> exposed // : exposed -> exposed // : prelude -> exposed // x // exposed orphan macromod mod_exposed1; - // : protected -> orphan + // : own -> orphan // : orphan -> orphan // : exposed -> exposed // : prelude -> exposed @@ -102,12 +102,10 @@ mod private /// /// Handle record "use" with implicit visibility. /// - #[ allow ( dead_code ) ] - fn record_use_implicit + fn record_reuse_implicit ( record : &Record, c : &'_ mut RecordContext< '_ >, - // clauses_map : &mut HashMap< u32, Vec< proc_macro2::TokenStream > >, ) -> syn::Result< () > @@ -115,35 +113,88 @@ mod private let attrs1 = &record.attrs; let path = record.use_elements.as_ref().unwrap(); - // let vis = record.vis.clone(); - // if vis == Visibility::Inherited + let path = if let Some( rename ) = &path.rename + { + let pure_path = path.pure_without_super_path()?; + c.clauses_map.get_mut( &ClauseImmediates::Kind() ).unwrap().push( qt! + { + pub use #pure_path as #rename; + }); + parse_qt!{ #rename } + } + else + { + path.clone() + }; - // xxx + let adjsuted_path = path.prefixed_with_all(); - // let _path; - // let path2 = if path.prefix_is_needed() - // { - // _path = parse_qt!{ super::private::#path }; - // &_path - // } - // else - // { - // path - // }; + c.clauses_map.get_mut( &VisOwn::Kind() ).unwrap().push( qt! + { + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + #attrs1 + pub use #adjsuted_path::own::*; + }); - let adjsuted_path = path.adjsuted_implicit_path()?; + c.clauses_map.get_mut( &VisOrphan::Kind() ).unwrap().push( qt! + { + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + #attrs1 + pub use #adjsuted_path::orphan::*; + }); - // println!( "adjsuted_path : {}", qt!{ #adjsuted_path } ); + c.clauses_map.get_mut( &VisExposed::Kind() ).unwrap().push( qt! + { + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + #attrs1 + pub use #adjsuted_path::exposed::*; + }); - if let Some( rename ) = &path.rename + c.clauses_map.get_mut( &VisPrelude::Kind() ).unwrap().push( qt! + { + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + #attrs1 + pub use #adjsuted_path::prelude::*; + }); + + Ok( () ) + } + + /// + /// Handle record "use" with implicit visibility. + /// + fn record_use_implicit + ( + record : &Record, + c : &'_ mut RecordContext< '_ >, + ) + -> + syn::Result< () > + { + + let attrs1 = &record.attrs; + let path = record.use_elements.as_ref().unwrap(); + + let path = if let Some( rename ) = &path.rename { let pure_path = path.pure_without_super_path()?; c.clauses_map.get_mut( &ClauseImmediates::Kind() ).unwrap().push( qt! { pub use #pure_path as #rename; }); + parse_qt!{ #rename } } + else + { + path.clone() + }; + + let adjsuted_path = path.prefixed_with_all(); c.clauses_map.get_mut( &VisOwn::Kind() ).unwrap().push( qt! { @@ -153,6 +204,16 @@ mod private pub use #adjsuted_path::orphan::*; }); + // export layer as own field of current layer + let prefixed_with_super_maybe = path.prefixed_with_super_maybe(); + c.clauses_map.get_mut( &VisOwn::Kind() ).unwrap().push( qt! + { + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + #attrs1 + pub use #prefixed_with_super_maybe; + }); + c.clauses_map.get_mut( &VisExposed::Kind() ).unwrap().push( qt! { #[ doc( inline ) ] @@ -175,12 +236,10 @@ mod private /// /// Handle record "use" with explicit visibility. /// - #[ allow ( dead_code ) ] fn record_use_explicit ( record : &Record, c : &'_ mut RecordContext< '_ >, - // clauses_map : &mut HashMap< u32, Vec< proc_macro2::TokenStream > >, ) -> syn::Result< () > @@ -200,8 +259,7 @@ mod private )); } - let adjsuted_path = path.adjsuted_explicit_path(); - + let adjsuted_path = path.prefixed_with_all(); let vis2 = if vis.restriction().is_some() { qt!{ pub( crate ) } @@ -248,13 +306,16 @@ mod private if !record.vis.valid_sub_namespace() { - return Err( syn_err! + return Err ( - record, - "To include a non-standard module use either {} visibility:\n {}", - VALID_VISIBILITY_LIST_STR, - qt!{ #record }, - )); + syn_err! + ( + record, + "To include a non-standard module use either {} visibility:\n {}", + VALID_VISIBILITY_LIST_STR, + qt!{ #record }, + ) + ); } c.clauses_map.get_mut( &record.vis.kind() ).unwrap().push( qt! @@ -263,7 +324,8 @@ mod private #[ allow( unused_imports ) ] #attrs1 #attrs2 - pub use #path; + pub use __all__::#path; + // pub use super::#path; // xxx : remove super? }); @@ -310,7 +372,17 @@ mod private #[ allow( unused_imports ) ] #attrs1 #attrs2 - pub use #path::orphan::*; + pub use __all__::#path::orphan::*; + }); + + // export layer as own field of current layer + // let prefixed_with_super_maybe = path.prefixed_with_super_maybe(); + c.clauses_map.get_mut( &VisOwn::Kind() ).unwrap().push( qt! + { + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + #attrs1 + pub use super::#path; }); c.clauses_map.get_mut( &VisExposed::Kind() ).unwrap().push( qt! @@ -319,7 +391,7 @@ mod private #[ allow( unused_imports ) ] #attrs1 #attrs2 - pub use #path::exposed::*; + pub use __all__::#path::exposed::*; }); c.clauses_map.get_mut( &VisPrelude::Kind() ).unwrap().push( qt! @@ -328,7 +400,7 @@ mod private #[ allow( unused_imports ) ] #attrs1 #attrs2 - pub use #path::prelude::*; + pub use __all__::#path::prelude::*; }); Ok( () ) @@ -383,6 +455,23 @@ mod private record_use_explicit( record, &mut record_context )?; } }, + Reuse( _ ) => + { + let vis = &record.vis; + if vis == &Visibility::Inherited + { + record_reuse_implicit( record, &mut record_context )?; + } + else + { + return Err( syn_err! + ( + record, + "Using visibility usesd before `reuse` is illegal\n{}", + qt!{ #record }, + )); + } + }, _ => { record.elements.iter().try_for_each( | element | -> syn::Result::< () > @@ -397,8 +486,9 @@ mod private { record_layer( record, element, &mut record_context )?; }, - Use( _ ) => + _ => { + panic!( "Unexpected" ) }, } syn::Result::Ok( () ) @@ -410,7 +500,7 @@ mod private })?; let immediates_clause = clauses_map.get( &ClauseImmediates::Kind() ).unwrap(); - let protected_clause = clauses_map.get( &VisOwn::Kind() ).unwrap(); + let own_clause = clauses_map.get( &VisOwn::Kind() ).unwrap(); let orphan_clause = clauses_map.get( &VisOrphan::Kind() ).unwrap(); let exposed_clause = clauses_map.get( &VisExposed::Kind() ).unwrap(); let prelude_clause = clauses_map.get( &VisPrelude::Kind() ).unwrap(); @@ -420,6 +510,8 @@ mod private #( #immediates_clause )* + // use private as __private__; // this line is necessary for readable error in case private namespace is not present + #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use own::*; @@ -428,19 +520,34 @@ mod private #[ allow( unused_imports ) ] pub mod own { - use super::*; + // There must be internal private namespace + // Because it's not possible to direcly make `use super::*;` + // Because then items from super can't be exposed publicly complaining: + // `error[E0428]: the name `mod1` is defined multiple times` + // use super::*; + use super::private; // this line is necessary for readable error in case private namespace is not present + mod __all__ + { + pub use super::super::*; + pub use super::super::private::*; + } #[ doc( inline ) ] - pub use orphan::*; - #( #protected_clause )* + pub use super::orphan::*; + #( #own_clause )* } /// Orphan namespace of the module. #[ allow( unused_imports ) ] pub mod orphan { - use super::*; + // use super::*; + mod __all__ + { + pub use super::super::*; + pub use super::super::private::*; + } #[ doc( inline ) ] - pub use exposed::*; + pub use super::exposed::*; #( #orphan_clause )* } @@ -448,9 +555,14 @@ mod private #[ allow( unused_imports ) ] pub mod exposed { - use super::*; + // use super::*; + mod __all__ + { + pub use super::super::*; + pub use super::super::private::*; + } #[ doc( inline ) ] - pub use prelude::*; + pub use super::prelude::*; #( #exposed_clause )* } @@ -458,7 +570,12 @@ mod private #[ allow( unused_imports ) ] pub mod prelude { - use super::*; + // use super::*; + mod __all__ + { + pub use super::super::*; + pub use super::super::private::*; + } #( #prelude_clause )* } diff --git a/module/core/mod_interface_meta/src/lib.rs b/module/core/mod_interface_meta/src/lib.rs index bb595ba9a2..70dc68878e 100644 --- a/module/core/mod_interface_meta/src/lib.rs +++ b/module/core/mod_interface_meta/src/lib.rs @@ -1,9 +1,23 @@ #![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] #![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] #![ doc( html_root_url = "https://docs.rs/mod_interface_meta/latest/mod_interface_meta/" ) ] -#![ deny( dead_code ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] +#![ warn( dead_code ) ] + +// /// Derives. +// layer derive; +// own use super::derive; +// // xxx : change to remove need to write explicitly that + +// xxx : change to remove need to write explicitly that +// crate::mod_interface! +// { +// /// Derives. +// layer derive; +// own use super::derive; // xxx : change to remove need to write explicitly that +// } + // xxx : clean up, ad solve problems // - example based on simpified version of test::layer_have_layer with single sublayer // - example with attribute `#![ debug ]` @@ -29,7 +43,7 @@ // }; // } -// xxx : make use proper_path_tools::own::path working +// xxx : make use pth::own::path working // xxx : put modular files into a namespace `file` maybe // #[ cfg( feature = "enabled" ) ] diff --git a/module/core/mod_interface_meta/src/record.rs b/module/core/mod_interface_meta/src/record.rs index c60b0bb55c..aeb6a696eb 100644 --- a/module/core/mod_interface_meta/src/record.rs +++ b/module/core/mod_interface_meta/src/record.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; @@ -11,6 +11,7 @@ mod private pub mod kw { super::syn::custom_keyword!( layer ); + super::syn::custom_keyword!( reuse ); } /// @@ -23,6 +24,7 @@ mod private MicroModule( syn::token::Mod ), Layer( kw::layer ), Use( syn::token::Use ), + Reuse( kw::reuse ), } // @@ -47,6 +49,10 @@ mod private { ElementType::Layer( input.parse()? ) }, + _case if lookahead.peek( kw::reuse ) => + { + ElementType::Reuse( input.parse()? ) + }, _default => { return Err( lookahead.error() ) @@ -69,6 +75,7 @@ mod private MicroModule( e ) => e.to_tokens( tokens ), Use( e ) => e.to_tokens( tokens ), Layer( e ) => e.to_tokens( tokens ), + Reuse( e ) => e.to_tokens( tokens ), } } } @@ -104,7 +111,7 @@ mod private match element_type { - ElementType::Use( _ ) => + ElementType::Use( _ ) | ElementType::Reuse( _ ) => { use_elements = Some( input.parse()? ); elements = syn::punctuated::Punctuated::new(); diff --git a/module/core/mod_interface_meta/src/use_tree.rs b/module/core/mod_interface_meta/src/use_tree.rs index f87ee133ad..3f51fccc22 100644 --- a/module/core/mod_interface_meta/src/use_tree.rs +++ b/module/core/mod_interface_meta/src/use_tree.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use macro_tools::prelude::*; @@ -24,12 +24,12 @@ mod private /// Is adding prefix to the tree path required? /// Add `super::private::` to path unless it starts from `::` or `super` or `crate`. - pub fn prefix_is_needed( &self ) -> bool + pub fn private_prefix_is_needed( &self ) -> bool { use syn::UseTree::*; - // println!( "prefix_is_needed : {:?}", self ); - // println!( "prefix_is_needed : self.leading_colon : {:?}", self.leading_colon ); + // println!( "private_prefix_is_needed : {:?}", self ); + // println!( "private_prefix_is_needed : self.leading_colon : {:?}", self.leading_colon ); if self.leading_colon.is_some() { @@ -105,32 +105,34 @@ mod private Ok( path ) } - /// Adjusted path. - /// Add `super::private::` to path unless it starts from `::` or `super` or `crate`. - pub fn adjsuted_implicit_path( &self ) -> syn::Result< syn::punctuated::Punctuated< syn::Ident, Token![::] > > + /// Prefix path with __all__ if it's appropriate. + pub fn prefixed_with_all( &self ) -> Self { + // use syn::UseTree::*; - let pure_path = self.pure_path()?; - if self.prefix_is_needed() + if self.private_prefix_is_needed() { - Ok( parse_qt!{ super::private::#pure_path } ) + let mut clone = self.clone(); + let tree = parse_qt!{ __all__::#self }; + clone.tree = tree; + clone } else { - Ok( pure_path ) + self.clone() } + } - /// Adjusted path. - /// Add `super::private::` to path unless it starts from `::` or `super` or `crate`. - // pub fn adjsuted_explicit_path( &self ) -> syn::UseTree - pub fn adjsuted_explicit_path( &self ) -> Self + /// Prefix path with `super::` if it's appropriate to avoid "re-export of crate public `child`" problem. + pub fn prefixed_with_super_maybe( &self ) -> Self { + // use syn::UseTree::*; - if self.prefix_is_needed() + if self.private_prefix_is_needed() { let mut clone = self.clone(); - let tree = parse_qt!{ super::private::#self }; + let tree = parse_qt!{ super::#self }; clone.tree = tree; clone } @@ -138,6 +140,7 @@ mod private { self.clone() } + } } diff --git a/module/core/mod_interface_meta/src/visibility.rs b/module/core/mod_interface_meta/src/visibility.rs index acece0cb4f..4e229ed21c 100644 --- a/module/core/mod_interface_meta/src/visibility.rs +++ b/module/core/mod_interface_meta/src/visibility.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use macro_tools::prelude::*; diff --git a/module/core/process_tools/Cargo.toml b/module/core/process_tools/Cargo.toml index 8b43896373..e358031ef1 100644 --- a/module/core/process_tools/Cargo.toml +++ b/module/core/process_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "process_tools" -version = "0.8.0" +version = "0.12.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -31,7 +31,7 @@ full = [ "default" ] enabled = [ "mod_interface/enabled", "former/enabled", - "proper_path_tools/enabled", + "pth/enabled", "error_tools/enabled", "iter_tools/enabled", ] @@ -42,7 +42,7 @@ process_environment_is_cicd = [] [dependencies] mod_interface = { workspace = true } former = { workspace = true, features = [ "derive_former" ] } -proper_path_tools = { workspace = true } +pth = { workspace = true } error_tools = { workspace = true, features = [ "error_untyped" ] } iter_tools = { workspace = true } diff --git a/module/core/process_tools/License b/module/core/process_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/process_tools/License +++ b/module/core/process_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/process_tools/src/environment.rs b/module/core/process_tools/src/environment.rs index 6ba4ba20fd..31d20aa9f0 100644 --- a/module/core/process_tools/src/environment.rs +++ b/module/core/process_tools/src/environment.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/core/process_tools/src/lib.rs b/module/core/process_tools/src/lib.rs index ceb35389ea..2f91e2f714 100644 --- a/module/core/process_tools/src/lib.rs +++ b/module/core/process_tools/src/lib.rs @@ -7,6 +7,8 @@ #[ cfg( feature = "enabled" ) ] use mod_interface::mod_interface; +mod private {} + #[ cfg( feature = "enabled" ) ] mod_interface! { diff --git a/module/core/process_tools/src/process.rs b/module/core/process_tools/src/process.rs index 8636c628b5..d58e95455a 100644 --- a/module/core/process_tools/src/process.rs +++ b/module/core/process_tools/src/process.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::*; diff --git a/module/core/program_tools/Cargo.toml b/module/core/program_tools/Cargo.toml index 1ba2675334..a5e28c9202 100644 --- a/module/core/program_tools/Cargo.toml +++ b/module/core/program_tools/Cargo.toml @@ -36,7 +36,7 @@ full = [ enabled = [ "mod_interface/enabled", "former/enabled", - "proper_path_tools/enabled", + "pth/enabled", "error_tools/enabled", "iter_tools/enabled", ] @@ -44,7 +44,7 @@ enabled = [ [dependencies] mod_interface = { workspace = true } former = { workspace = true, features = [ "derive_former" ] } -proper_path_tools = { workspace = true } +pth = { workspace = true } error_tools = { workspace = true, features = [ "error_untyped" ] } # qqq : xxx : rid of error_untyped iter_tools = { workspace = true } diff --git a/module/core/program_tools/License b/module/core/program_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/program_tools/License +++ b/module/core/program_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/program_tools/src/program.rs b/module/core/program_tools/src/program.rs index 70d66a7ead..90737df823 100644 --- a/module/core/program_tools/src/program.rs +++ b/module/core/program_tools/src/program.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/core/proper_path_tools/Readme.md b/module/core/proper_path_tools/Readme.md deleted file mode 100644 index d142018019..0000000000 --- a/module/core/proper_path_tools/Readme.md +++ /dev/null @@ -1,35 +0,0 @@ - - -# Module :: proper_path_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_proper_path_tools_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_proper_path_tools_push.yml) [![docs.rs](https://img.shields.io/docsrs/proper_path_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/proper_path_tools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) - - -Collection of algorithms and structures to handle paths properly. - -All functions in the crate don't touch file system, but only process paths. - - diff --git a/module/core/proper_path_tools/Cargo.toml b/module/core/pth/Cargo.toml similarity index 88% rename from module/core/proper_path_tools/Cargo.toml rename to module/core/pth/Cargo.toml index a9de7e5f46..79a2141441 100644 --- a/module/core/proper_path_tools/Cargo.toml +++ b/module/core/pth/Cargo.toml @@ -1,15 +1,15 @@ [package] -name = "proper_path_tools" -version = "0.9.0" +name = "pth" +version = "0.21.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", ] license = "MIT" readme = "Readme.md" -documentation = "https://docs.rs/proper_path_tools" -repository = "https://github.com/Wandalen/wTools/tree/master/module/core/proper_path_tools" -homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/proper_path_tools" +documentation = "https://docs.rs/pth" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/pth" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/pth" description = """ Collection of algorithms and structures to handle paths properly. """ @@ -35,6 +35,8 @@ full = [ "path_utf8", ] no_std = [] +# qqq : xxx : negate no_std +# use_std = [] use_alloc = [ "no_std" ] enabled = [ "mod_interface/enabled" ] diff --git a/module/core/pth/License b/module/core/pth/License new file mode 100644 index 0000000000..0804aed8e3 --- /dev/null +++ b/module/core/pth/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/core/pth/Readme.md b/module/core/pth/Readme.md new file mode 100644 index 0000000000..a6f4c2f04d --- /dev/null +++ b/module/core/pth/Readme.md @@ -0,0 +1,51 @@ + + +# Module :: pth + + [![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_pth_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_pth_push.yml) [![docs.rs](https://img.shields.io/docsrs/pth?color=e3e8f0&logo=docs.rs)](https://docs.rs/pth) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + + +Collection of algorithms and structures to handle paths properly. + +All functions in the crate don't touch file system, but only process paths. + +### Type `AbsolutePath` + +The AbsolutePath type ensures that paths are absolute, which helps reduce issues and maintenance costs associated with relative paths. Relative paths can be problematic as they introduce additional variables and complexities, making code analysis, integration, refactoring, and testing more difficult. By using absolute paths, software architecture can be improved, similar to how avoiding global variables can enhance code quality. It is recommended to use relative paths only at the outskirts of an application. + +### Trait `AsPath` + +This trait is used to avoid redundant allocation of memory by providing a reference to a Path. It is implemented only for types that can either be referenced or are references to Path itself. Unlike `TryIntoPath`, it does not allocate memory on the heap. However, `TryIntoPath` is implemented for a wider range of types because it is not restricted from allocating memory. Unlike `AsRef< Path >`, `AsPath` is implemented for a wider number of types, including those that are not directly convertible to a Path using `AsRef`. This is because `AsPath` is designed to provide a more flexible interface for path-like types, accommodating various representations that can logically be treated as paths. + +### Trait `TryIntoPath` + +This trait is used to convert any path-like type into an owned PathBuf. Unlike `TryIntoCowPath`, it always returns an owned PathBuf, so there is no need to differentiate between borrowed and owned paths at runtime. Unlike `AsPath`, it is implemented for a wider range of path-like types, similar to `TryIntoCowPath`. + +### Trait `TryIntoCowPath` + +This trait is designed to avoid redundant memory allocation. Unlike TryIntoPath, it does not allocate memory on the heap if it’s not necessary. Unlike `AsPath`, it is implemented for a wider number of path-like types, similar to TryIntoPath. The drawback is the necessity to differentiate borrowed and owned paths at runtime. + + diff --git a/module/core/pth/src/as_path.rs b/module/core/pth/src/as_path.rs new file mode 100644 index 0000000000..693532a081 --- /dev/null +++ b/module/core/pth/src/as_path.rs @@ -0,0 +1,71 @@ +/// Define a private namespace for all its items. +mod private +{ + #[ allow( unused_imports ) ] + use crate::*; + #[ cfg( feature = "no_std" ) ] + extern crate std; + + use std::path::Path; + + /// A trait for converting various types into a reference to a `Path`. + /// + /// This trait is used to avoid redundant allocation of memory by providing a reference to a `Path`. + /// It is implemented only for types that can either be referenced or are references to `Path` itself. + /// Unlike `TryIntoPath`, it does not allocate memory on the heap. However, `TryIntoPath` is implemented for a wider range of types because it is not restricted from allocating memory. + /// Unlike `AsRef`, `AsPath` is implemented for a wider number of types, including those that are not directly convertible to a `Path` using `AsRef`. + /// This is because `AsPath` is designed to provide a more flexible interface for path-like types, accommodating various representations that can logically be treated as paths. + pub trait AsPath + { + /// Converts the implementing type into a reference to a `Path`. + /// + /// # Returns + /// + /// A reference to a `Path`. + fn as_path( &self ) -> &Path; + } + + /// Implementation of `AsPath` for `str`. + impl AsPath for str + { + fn as_path( &self ) -> &Path + { + Path::new( self ) + } + } + + /// Implementation of `AsPath` for `Path`. + impl AsPath for Path + { + fn as_path( &self ) -> &Path + { + self + } + } + + /// Implementation of `AsPath` for `Utf8Path`. + #[cfg( feature = "path_utf8" )] + impl AsPath for Utf8Path + { + fn as_path( &self ) -> &Path + { + self.as_std_path() + } + } + + /// Blanket implementation of `AsPath` for all types that implement `AsRef`. + impl< T > AsPath for T + where + T : AsRef< Path >, + { + fn as_path( &self ) -> &Path + { + self.as_ref() + } + } +} + +crate::mod_interface! +{ + orphan use AsPath; +} \ No newline at end of file diff --git a/module/core/proper_path_tools/src/lib.rs b/module/core/pth/src/lib.rs similarity index 62% rename from module/core/proper_path_tools/src/lib.rs rename to module/core/pth/src/lib.rs index 1ac23b4abd..223020ac00 100644 --- a/module/core/proper_path_tools/src/lib.rs +++ b/module/core/pth/src/lib.rs @@ -1,7 +1,7 @@ #![ 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/proper_path_tools/latest/proper_path_tools/" ) ] +#![ doc( html_root_url = "https://docs.rs/pth/latest/pth/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] #[ cfg( feature = "enabled" ) ] @@ -11,6 +11,8 @@ use mod_interface::mod_interface; #[ macro_use ] extern crate alloc; +mod private {} + #[ cfg( feature = "enabled" ) ] mod_interface! { @@ -18,11 +20,26 @@ mod_interface! /// Basic functionality. layer path; + /// AsPath trait. + layer as_path; + /// TryIntoPath trait. + layer try_into_path; + /// TryIntoPath trait. + layer try_into_cow_path; + /// Transitive TryFrom and TryInto. layer transitive; #[ cfg( feature = "path_utf8" ) ] own use ::camino::{ Utf8Path, Utf8PathBuf }; - own use ::std::path::{ PathBuf, Path }; + + // #[ cfg( not( feature = "no_std" ) ) ] + // own use ::std::path::{ PathBuf, Path, Component }; + + #[ cfg( not( feature = "no_std" ) ) ] + own use ::std::path::*; + + #[ cfg( not( feature = "no_std" ) ) ] + own use ::std::borrow::Cow; } diff --git a/module/core/proper_path_tools/src/path.rs b/module/core/pth/src/path.rs similarity index 95% rename from module/core/proper_path_tools/src/path.rs rename to module/core/pth/src/path.rs index b11df6f466..504dcdd25f 100644 --- a/module/core/proper_path_tools/src/path.rs +++ b/module/core/pth/src/path.rs @@ -1,7 +1,9 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { + use crate::*; + #[ cfg( feature = "no_std" ) ] extern crate std; @@ -25,7 +27,7 @@ mod private /// # Examples: /// /// ``` - /// use proper_path_tools::path; + /// use pth::path; /// /// assert_eq!( path::is_glob( "file.txt" ), false ); // No glob patterns /// assert_eq!( path::is_glob( "*.txt" ), true ); // Contains unescaped glob character * @@ -110,7 +112,7 @@ mod private /// /// ``` /// use std::path::{ Path, PathBuf }; - /// use proper_path_tools::path as path; + /// use pth::path as path; /// /// let path = Path::new( "/a/b/./c/../d" ); /// let normalized_path = path::normalize( path ); @@ -260,7 +262,7 @@ mod private /// # Examples /// /// ``` - /// use proper_path_tools::path::unique_folder_name; + /// use pth::path::unique_folder_name; /// let folder_name = unique_folder_name().unwrap(); /// println!( "Generated folder name: {}", folder_name ); /// ``` @@ -299,6 +301,7 @@ mod private Ok( std::format!( "{}_{}_{}_{}", timestamp, pid, tid, count ) ) } + /// Joins a list of file system paths into a single absolute path. /// /// This function takes a list of file system paths and joins them into a single path, @@ -308,23 +311,22 @@ mod private /// /// ``` /// use std::path::PathBuf; - /// use proper_path_tools::path; + /// use pth::path; /// /// let paths = vec![ PathBuf::from( "a/b/c" ), PathBuf::from( "/d/e" ), PathBuf::from( "f/g" ) ]; - /// let joined = path::join_paths( paths.iter().map( | p | p.as_path() ) ); + /// let joined = path::iter_join( paths.iter().map( | p | p.as_path() ) ); /// assert_eq!( joined, std::path::PathBuf::from( "/d/e/f/g" ) ); /// /// let paths = vec![ PathBuf::from( "" ), PathBuf::from( "a/b" ), PathBuf::from( "" ), PathBuf::from( "c" ), PathBuf::from( "" ) ]; - /// let joined = path::join_paths( paths.iter().map( | p | p.as_path() ) ); + /// let joined = path::iter_join( paths.iter().map( | p | p.as_path() ) ); /// assert_eq!( joined, std::path::PathBuf::from( PathBuf::from( "/a/b/c" ) ) ); /// /// ``` // qqq : make macro paths_join!( ... ) - pub fn join_paths< 'a, I >( paths : I ) -> std::path::PathBuf + pub fn iter_join< 'a ,I, P >( paths : I ) -> PathBuf where - // AsPath : AsRef< std::path::Path >, - // I : Iterator< Item = AsPath >, - I : Iterator< Item = &'a std::path::Path >, + I : Iterator< Item = P >, + P : TryIntoCowPath< 'a >, { #[ cfg( feature = "no_std" ) ] extern crate alloc; @@ -337,8 +339,12 @@ mod private for path in paths { - let mut path = path.to_string_lossy().replace( '\\', "/" ); - path = path.replace( ':', "" ); + // let mut path = path.to_string_lossy().replace( '\\', "/" ); + // qqq : xxx : avoid unwrap + let path = path.try_into_cow_path().unwrap().to_string_lossy().replace( '\\', "/" ); + // qqq : xxx : avoid converting to String, keep it Path + + // path = path.replace( ':', "" ); // qqq : this is a bug let mut added_slah = false; @@ -449,7 +455,7 @@ mod private /// # Examples /// /// ``` - /// use proper_path_tools::path::exts; + /// use pth::path::exts; /// /// let path = "/path/to/file.tar.gz"; /// let extensions = exts( path ); @@ -457,7 +463,7 @@ mod private /// ``` /// /// ``` - /// use proper_path_tools::path::exts; + /// use pth::path::exts; /// /// let empty_path = ""; /// let extensions = exts( empty_path ); @@ -512,7 +518,7 @@ mod private /// /// ``` /// use std::path::PathBuf; - /// use proper_path_tools::path::without_ext; + /// use pth::path::without_ext; /// /// let path = "/path/to/file.txt"; /// let modified_path = without_ext(path); @@ -521,7 +527,7 @@ mod private /// /// ``` /// use std::path::PathBuf; - /// use proper_path_tools::path::without_ext; + /// use pth::path::without_ext; /// /// let empty_path = ""; /// let modified_path = without_ext(empty_path); @@ -591,7 +597,7 @@ mod private /// /// ``` /// use std::path::PathBuf; - /// use proper_path_tools::path::change_ext; + /// use pth::path::change_ext; /// /// let path = "/path/to/file.txt"; /// let modified_path = change_ext( path, "json" ); @@ -600,7 +606,7 @@ mod private /// /// ``` /// use std::path::PathBuf; - /// use proper_path_tools::path::change_ext; + /// use pth::path::change_ext; /// /// let empty_path = ""; /// let modified_path = change_ext( empty_path, "txt" ); @@ -642,7 +648,7 @@ mod private /// # Examples /// /// ``` - /// use proper_path_tools::path::path_common; + /// use pth::path::path_common; /// /// let paths = vec![ "/a/b/c", "/a/b/d", "/a/b/e" ]; /// let common_path = path_common( paths.into_iter() ); @@ -834,7 +840,7 @@ mod private /// /// let file_path = "/home/user/documents/file.txt"; /// let new_path = "/mnt/storage"; - /// let rebased_path = proper_path_tools::path::rebase( file_path, new_path, None ).unwrap(); + /// let rebased_path = pth::path::rebase( file_path, new_path, None ).unwrap(); /// assert_eq!( rebased_path, PathBuf::from( "/mnt/storage/home/user/documents/file.txt" ) ); /// ``` /// @@ -846,7 +852,7 @@ mod private /// let file_path = "/home/user/documents/file.txt"; /// let new_path = "/mnt/storage"; /// let old_path = "/home/user"; - /// let rebased_path = proper_path_tools::path::rebase( file_path, new_path, Some( old_path ) ).unwrap(); + /// let rebased_path = pth::path::rebase( file_path, new_path, Some( old_path ) ).unwrap(); /// assert_eq!( rebased_path, PathBuf::from( "/mnt/storage/documents/file.txt" ) ); /// ``` /// @@ -900,7 +906,7 @@ mod private /// /// let from = "/a/b"; /// let to = "/a/c/d"; - /// let relative_path = proper_path_tools::path::path_relative( from, to ); + /// let relative_path = pth::path::path_relative( from, to ); /// assert_eq!( relative_path, PathBuf::from( "../c/d" ) ); /// ``` pub fn path_relative< T : AsRef< std::path::Path > >( from : T, to : T ) -> std::path::PathBuf @@ -1008,7 +1014,7 @@ mod private /// # Examples /// /// ``` - /// use proper_path_tools::path::ext; + /// use pth::path::ext; /// /// let path = "/path/to/file.txt"; /// let extension = ext( path ); @@ -1016,7 +1022,7 @@ mod private /// ``` /// /// ``` - /// use proper_path_tools::path::ext; + /// use pth::path::ext; /// /// let empty_path = ""; /// let extension = ext( empty_path ); @@ -1047,17 +1053,20 @@ mod private crate::mod_interface! { - orphan use ext; - orphan use exts; - orphan use change_ext; - orphan use path_relative; - orphan use rebase; - orphan use path_common; - orphan use join_paths; - orphan use without_ext; - orphan use is_glob; - orphan use normalize; - orphan use canonicalize; + orphan use + { + ext, + exts, + change_ext, + path_relative, + rebase, + path_common, + iter_join, + without_ext, + is_glob, + normalize, + canonicalize, + }; #[ cfg( feature = "path_unique_folder_name" ) ] orphan use unique_folder_name; @@ -1071,4 +1080,7 @@ crate::mod_interface! /// Describe native path. Use to pass path to the platfrom. layer native_path; + /// Convenient joining. + layer joining; + } diff --git a/module/core/proper_path_tools/src/path/absolute_path.rs b/module/core/pth/src/path/absolute_path.rs similarity index 53% rename from module/core/proper_path_tools/src/path/absolute_path.rs rename to module/core/pth/src/path/absolute_path.rs index 60a3587a81..c80f0ce2c1 100644 --- a/module/core/proper_path_tools/src/path/absolute_path.rs +++ b/module/core/pth/src/path/absolute_path.rs @@ -1,52 +1,49 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { - use crate::*; - use std:: { - // borrow::Cow, path::{ Path, PathBuf }, io, }; - use core:: { fmt, - ops:: - { - Deref, - DerefMut, - }, + ops::{ Deref, DerefMut }, }; - - #[cfg(feature="no_std")] + #[ cfg( feature = "no_std" ) ] extern crate std; - + #[ cfg( feature = "no_std" ) ] + use alloc::string::String; #[ cfg( feature = "derive_serde" ) ] use serde::{ Serialize, Deserialize }; - #[ cfg( feature = "path_utf8" ) ] - use camino::{ Utf8Path, Utf8PathBuf }; + // #[ cfg( feature = "path_utf8" ) ] + // use camino::{ Utf8Path, Utf8PathBuf }; - /// Absolute path. + /// A new type representing an absolute path. + /// + /// The `AbsolutePath` type ensures that paths are absolute, which helps reduce issues and maintenance costs associated with relative paths. + /// Relative paths can be problematic as they introduce additional variables and complexities, making code analysis, integration, refactoring, and testing more difficult. + /// By using absolute paths, software architecture can be improved, similar to how avoiding global variables can enhance code quality. + /// It is recommended to use relative paths only at the outskirts of an application. #[ cfg_attr( feature = "derive_serde", derive( Serialize, Deserialize ) ) ] #[ derive( Debug, Default, Clone, Ord, PartialOrd, Eq, PartialEq, Hash ) ] pub struct AbsolutePath( PathBuf ); impl AbsolutePath { - - /// Returns the Path without its final component, if there is one. - /// Returns None if the path terminates in a root or prefix, or if it's the empty string. + /// Returns the parent directory as an `AbsolutePath`, if it exists. + /// + /// Returns `None` if the path terminates in a root or prefix, or if it's the empty string. #[ inline ] pub fn parent( &self ) -> Option< AbsolutePath > { self.0.parent().map( PathBuf::from ).map( AbsolutePath ) } - /// Creates an owned `AbsolutePath` with path adjoined to self. + /// Creates an owned `AbsolutePath` by joining a given path to `self`. #[ inline ] pub fn join< P >( &self, path : P ) -> AbsolutePath where @@ -55,13 +52,7 @@ mod private Self::try_from( self.0.join( path ) ).unwrap() } - // /// Converts a `AbsolutePath` to a `Cow` - // pub fn to_string_lossy( &self ) -> Cow< '_, str > - // { - // self.0.to_string_lossy() - // } - - /// Determines whether base is a prefix of self. + /// Checks if the path starts with a given base path. /// /// Only considers whole path components to match. #[ inline ] @@ -70,13 +61,52 @@ mod private self.0.starts_with( base ) } - /// Returns inner type which is PathBuf. - #[ inline( always ) ] + /// Returns the inner `PathBuf`. + #[inline(always)] pub fn inner( self ) -> PathBuf { self.0 } + /// Creates an `AbsolutePath` from an iterator over items that implement `TryIntoCowPath`. + /// + /// This function joins all path segments into a single path and attempts to convert it + /// into an `AbsolutePath`. The resulting path must be absolute. + /// + /// # Arguments + /// + /// * `iter` - An iterator over path segments. + /// + /// # Returns + /// + /// * `Ok(AbsolutePath)` if the joined path is absolute. + /// * `Err(io::Error)` if the joined path is not absolute. + pub fn from_iter< 'a, I, P >( iter : I ) -> Result< Self, io::Error > + where + I : Iterator< Item = P >, + P : TryIntoCowPath< 'a >, + { + let joined_path = iter_join( iter ); + AbsolutePath::try_from( joined_path ) + } + + /// Joins path components into a `PathBuf`. + /// + /// This function leverages the `PathJoined` trait to join multiple path components into a single `PathBuf`. + /// + /// # Arguments + /// + /// * `paths` - A tuple of path components implementing the `PathJoined` trait. + /// + /// # Returns + /// + /// * `Ok(PathBuf)` - The joined path as a `PathBuf`. + /// * `Err(io::Error)` - An error if any component fails to convert. + pub fn from_paths< Paths : PathJoined >( paths : Paths ) -> Result< Self, io::Error > + { + Self::try_from( paths.iter_join()? ) + } + } impl fmt::Display for AbsolutePath @@ -91,8 +121,6 @@ mod private #[ inline ] fn is_absolute( path : &Path ) -> bool { - // None - not absolute - // with `.` or `..` at the first component - not absolute !path.components().next().is_some_and( | c | c.as_os_str() == "." || c.as_os_str() == ".." ) } @@ -118,7 +146,6 @@ mod private } } - // xxx : qqq : use Into< Path > impl TryFrom< &Path > for AbsolutePath { type Error = std::io::Error; @@ -126,13 +153,11 @@ mod private #[ inline ] fn try_from( src : &Path ) -> Result< Self, Self::Error > { - // < Self as TryFrom< &str > >::try_from( src.to_string_lossy() ) let path = path::canonicalize( src )?; - // xxx if !is_absolute( &path ) { - return Err( io::Error::new( io::ErrorKind::InvalidData, "Path expected to be absolute, but it's not {path}" ) ) + return Err( io::Error::new( io::ErrorKind::Other, format!( "Path expected to be absolute, but it's not {path:?}" ) ) ); } Ok( Self( path ) ) @@ -150,19 +175,29 @@ mod private } } -// impl TryFrom< &str > for AbsolutePath -// { -// type Error = std::io::Error; -// // type Error = PathError; -// -// #[ inline( always ) ] -// fn try_from( src : &str ) -> Result< Self, Self::Error > -// { -// Self::try_from( AbsolutePath::try_from( src )? ) -// } -// } - - #[ cfg( feature = "path_utf8" ) ] + impl< 'a > TryFrom< &'a String > for AbsolutePath + { + type Error = std::io::Error; + + #[ inline ] + fn try_from( src : &'a String ) -> Result< Self, Self::Error > + { + < Self as TryFrom< &Path > >::try_from( src.as_ref() ) + } + } + + impl< 'a > TryFrom< String > for AbsolutePath + { + type Error = std::io::Error; + + #[ inline ] + fn try_from( src : String ) -> Result< Self, Self::Error > + { + < Self as TryFrom< &Path > >::try_from( src.as_ref() ) + } + } + + #[cfg( feature = "path_utf8" )] impl TryFrom< Utf8PathBuf > for AbsolutePath { type Error = std::io::Error; @@ -174,7 +209,7 @@ mod private } } - #[ cfg( feature = "path_utf8" ) ] + #[cfg( feature = "path_utf8" )] impl TryFrom< &Utf8PathBuf > for AbsolutePath { type Error = std::io::Error; @@ -186,7 +221,7 @@ mod private } } - #[ cfg( feature = "path_utf8" ) ] + #[cfg( feature = "path_utf8" )] impl TryFrom< &Utf8Path > for AbsolutePath { type Error = std::io::Error; @@ -210,21 +245,18 @@ mod private impl< 'a > TryFrom< &'a AbsolutePath > for &'a str { type Error = std::io::Error; + #[ inline ] fn try_from( src : &'a AbsolutePath ) -> Result< &'a str, Self::Error > { - src - .to_str() - .ok_or_else - ( - move || io::Error::new( io::ErrorKind::Other, format!( "Can't convert &PathBuf into &str {src}" ) ) - ) + src.to_str().ok_or_else( || io::Error::new( io::ErrorKind::Other, format!( "Can't convert &PathBuf into &str {src}" ) ) ) } } impl TryFrom< &AbsolutePath > for String { type Error = std::io::Error; + #[ inline ] fn try_from( src : &AbsolutePath ) -> Result< String, Self::Error > { @@ -233,34 +265,23 @@ mod private } } -// impl TryFrom< Utf8PathBuf > for AbsolutePath -// { -// type Error = std::io::Error; -// -// fn try_from( src : Utf8PathBuf ) -> Result< Self, Self::Error > -// { -// AbsolutePath::try_from( src.as_std_path() ) -// } -// } - -// impl TryFrom< &Utf8Path > for AbsolutePath -// { -// type Error = std::io::Error; -// -// fn try_from( src : &Utf8Path ) -> Result< Self, Self::Error > -// { -// AbsolutePath::try_from( src.as_std_path() ) -// } -// } - - // // xxx : use derives - // impl AsRef< Path > for AbsolutePath - // { - // fn as_ref( &self ) -> &Path - // { - // self.0.as_ref() - // } - // } + impl TryIntoPath for AbsolutePath + { + #[ inline ] + fn try_into_path( self ) -> Result< PathBuf, io::Error > + { + Ok( self.0 ) + } + } + + impl< 'a > TryIntoCowPath< 'a > for AbsolutePath + { + #[ inline ] + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error > + { + Ok( Cow::Owned( self.0 ) ) + } + } impl AsRef< Path > for AbsolutePath { @@ -283,6 +304,7 @@ mod private impl Deref for AbsolutePath { type Target = Path; + #[ inline ] fn deref( &self ) -> &Self::Target { @@ -298,42 +320,9 @@ mod private &mut self.0 } } - -// /// Convertable into absolute path entity should implement the trait. -// pub trait TryIntoAbsolutePath -// { -// /// Error returned if conversion is failed. -// type Error; -// /// Method to convert the type into absolute path. -// fn into_absolute_path( self ) -> Result< AbsolutePath, Self::Error >; -// } -// -// // impl TryIntoAbsolutePath for AbsolutePath -// // { -// // type Error = std::io::Error; -// // #[ inline ] -// // fn into_absolute_path( self ) -> Result< AbsolutePath, Self::Error > -// // { -// // Ok( self ) -// // } -// // } -// -// impl< TryIntoAbsolutePathType > TryIntoAbsolutePath for TryIntoAbsolutePathType -// where -// TryIntoAbsolutePathType : TryInto< AbsolutePath >, -// { -// type Error = < Self as TryInto< AbsolutePath > >::Error; -// #[ inline ] -// fn into_absolute_path( self ) -> Result< AbsolutePath, Self::Error > -// { -// self.try_into() -// } -// } - } crate::mod_interface! { exposed use AbsolutePath; - // exposed use TryIntoAbsolutePath; -} +} \ No newline at end of file diff --git a/module/core/proper_path_tools/src/path/canonical_path.rs b/module/core/pth/src/path/canonical_path.rs similarity index 83% rename from module/core/proper_path_tools/src/path/canonical_path.rs rename to module/core/pth/src/path/canonical_path.rs index 45886ded78..dd8a6957c6 100644 --- a/module/core/proper_path_tools/src/path/canonical_path.rs +++ b/module/core/pth/src/path/canonical_path.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { @@ -21,14 +21,18 @@ mod private }, }; - #[cfg(feature="no_std")] + // qqq : xxx : redo + #[ cfg( feature="no_std" ) ] extern crate std; + #[ cfg( feature="no_std" ) ] + use alloc::string::String; + #[ cfg( feature = "derive_serde" ) ] use serde::{ Serialize, Deserialize }; - #[ cfg( feature = "path_utf8" ) ] - use camino::{ Utf8Path, Utf8PathBuf }; + // #[ cfg( feature = "path_utf8" ) ] + // use camino::{ Utf8Path, Utf8PathBuf }; /// Caninical path. #[ cfg_attr( feature = "derive_serde", derive( Serialize, Deserialize ) ) ] @@ -111,6 +115,28 @@ mod private } } + impl< 'a > TryFrom< &'a String > for CanonicalPath + { + type Error = std::io::Error; + + #[ inline ] + fn try_from( src : &'a String ) -> Result< Self, Self::Error > + { + < Self as TryFrom< &Path > >::try_from( src.as_ref() ) + } + } + + impl< 'a > TryFrom< String > for CanonicalPath + { + type Error = std::io::Error; + + #[ inline ] + fn try_from( src : String ) -> Result< Self, Self::Error > + { + < Self as TryFrom< &Path > >::try_from( src.as_ref() ) + } + } + impl TryFrom< PathBuf > for CanonicalPath { type Error = std::io::Error; @@ -213,6 +239,32 @@ mod private } } + impl TryIntoPath for CanonicalPath + { + #[ inline ] + fn try_into_path( self ) -> Result< PathBuf, io::Error > + { + Ok( self.0 ) + } + } + + impl< 'a > TryIntoCowPath< 'a > for CanonicalPath + { + #[ inline ] + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error > + { + Ok( Cow::Owned( self.0 ) ) + } + } + + // impl AsPath for CanonicalPath + // { + // fn as_path( &self ) -> &Path + // { + // self.0.as_path() + // } + // } + // impl TryFrom< Utf8PathBuf > for CanonicalPath // { // type Error = std::io::Error; diff --git a/module/core/proper_path_tools/src/path/current_path.rs b/module/core/pth/src/path/current_path.rs similarity index 50% rename from module/core/proper_path_tools/src/path/current_path.rs rename to module/core/pth/src/path/current_path.rs index f9e5a83293..8ddf322b2a 100644 --- a/module/core/proper_path_tools/src/path/current_path.rs +++ b/module/core/pth/src/path/current_path.rs @@ -1,17 +1,24 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; - use std::env; + #[ cfg( not( feature = "no_std" ) ) ] + use std:: + { + env, + io, + }; /// Symbolize current path. #[ derive( Clone, Copy, Debug, Default, PartialEq, Eq ) ] pub struct CurrentPath; #[ cfg( feature = "path_utf8" ) ] + #[ cfg( not( feature = "no_std" ) ) ] impl TryFrom< CurrentPath > for Utf8PathBuf { + #[ cfg( not( feature = "no_std" ) ) ] type Error = std::io::Error; #[ inline ] @@ -22,6 +29,7 @@ mod private ( | err | { + #[ cfg( not( feature = "no_std" ) ) ] std::io::Error::new ( std::io::ErrorKind::NotFound, @@ -32,8 +40,10 @@ mod private } } + #[ cfg( not( feature = "no_std" ) ) ] impl TryFrom< CurrentPath > for PathBuf { + #[ cfg( not( feature = "no_std" ) ) ] type Error = std::io::Error; #[ inline ] @@ -43,8 +53,10 @@ mod private } } + #[ cfg( not( feature = "no_std" ) ) ] impl TryFrom< CurrentPath > for AbsolutePath { + #[ cfg( not( feature = "no_std" ) ) ] type Error = std::io::Error; #[ inline ] @@ -54,6 +66,39 @@ mod private } } + impl TryIntoPath for &CurrentPath + { + fn try_into_path( self ) -> Result< PathBuf, io::Error > + { + env::current_dir() + } + } + + impl TryIntoPath for CurrentPath + { + fn try_into_path( self ) -> Result< PathBuf, io::Error > + { + env::current_dir() + } + } + + impl< 'a > TryIntoCowPath< 'a > for CurrentPath + { + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error > + { + let current_dir = env::current_dir()?; + Ok( Cow::Owned( current_dir ) ) + } + } + + impl< 'a > TryIntoCowPath< 'a > for &CurrentPath + { + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error > + { + TryIntoCowPath::try_into_cow_path( *self ) + } + } + } crate::mod_interface! diff --git a/module/core/pth/src/path/joining.rs b/module/core/pth/src/path/joining.rs new file mode 100644 index 0000000000..6e8c0a1ddf --- /dev/null +++ b/module/core/pth/src/path/joining.rs @@ -0,0 +1,191 @@ +mod private +{ + use crate::*; + use std::{ io, path::PathBuf }; + + /// Joins path components into a `PathBuf`. + /// + /// This function leverages the `PathJoined` trait to join multiple path components into a single `PathBuf`. + /// + /// # Arguments + /// + /// * `paths` - A tuple of path components implementing the `PathJoined` trait. + /// + /// # Returns + /// + /// * `Ok(PathBuf)` - The joined path as a `PathBuf`. + /// * `Err(io::Error)` - An error if any component fails to convert. + pub fn join< Paths : PathJoined >( paths : Paths ) -> Result< PathBuf, io::Error > + { + paths.iter_join() + } + + /// A trait for joining path components into a `PathBuf`. + /// + /// This trait provides a method to join multiple path components into a single `PathBuf`. + /// It is implemented for tuples of varying lengths, allowing for flexible combinations of path components. + /// Each component must implement the `TryIntoCowPath` trait, enabling conversion into a `Cow`. + pub trait PathJoined + { + /// Joins the path components into a single `PathBuf`. + /// + /// # Returns + /// + /// * `Ok(PathBuf)` - The joined path as a `PathBuf`. + /// * `Err(io::Error)` - An error if any component fails to convert. + fn iter_join( self ) -> Result< PathBuf, io::Error >; + } + + // // Implementation for an Iterator over items implementing TryIntoCowPath + // impl< 'a, I, T > PathJoined for I + // where + // I : Iterator< Item = T >, + // T : TryIntoCowPath< 'a >, + // { + // fn iter_join( self ) -> Result< PathBuf, io::Error > + // { + // let mut result = PathBuf::new(); + // for item in self + // { + // result.push( item.try_into_cow_path()?.as_ref() ); + // } + // Ok( result ) + // } + // } + + // Implementation for a tuple of length 1 + impl< 'a, T1 > PathJoined for ( T1, ) + where + T1 : TryIntoCowPath< 'a >, + { + #[ inline ] + fn iter_join( self ) -> Result< PathBuf, io::Error > + { + let ( p1, ) = self; + let mut result = PathBuf::new(); + result.push( p1.try_into_cow_path()?.as_ref() ); + Ok( result ) + } + } + + // Implementation for a tuple of length 2 + impl< 'a, T1, T2 > PathJoined for ( T1, T2 ) + where + T1 : TryIntoCowPath< 'a >, + T2 : TryIntoCowPath< 'a >, + { + #[ inline ] + fn iter_join( self ) -> Result< PathBuf, io::Error > + { + let ( p1, p2 ) = self; + let mut result = PathBuf::new(); + result.push( p1.try_into_cow_path()?.as_ref() ); + result.push( p2.try_into_cow_path()?.as_ref() ); + Ok( result ) + } + } + + // Implementation for a tuple of length 3 + impl< 'a, T1, T2, T3 > PathJoined for ( T1, T2, T3 ) + where + T1 : TryIntoCowPath< 'a >, + T2 : TryIntoCowPath< 'a >, + T3 : TryIntoCowPath< 'a >, + { + #[ inline ] + fn iter_join( self ) -> Result< PathBuf, io::Error > + { + let ( p1, p2, p3 ) = self; + let mut result = PathBuf::new(); + result.push( p1.try_into_cow_path()?.as_ref() ); + result.push( p2.try_into_cow_path()?.as_ref() ); + result.push( p3.try_into_cow_path()?.as_ref() ); + Ok( result ) + } + } + + // Implementation for a tuple of length 4 + impl< 'a, T1, T2, T3, T4 > PathJoined for ( T1, T2, T3, T4 ) + where + T1 : TryIntoCowPath< 'a >, + T2 : TryIntoCowPath< 'a >, + T3 : TryIntoCowPath< 'a >, + T4 : TryIntoCowPath< 'a >, + { + #[ inline ] + fn iter_join( self ) -> Result< PathBuf, io::Error > + { + let ( p1, p2, p3, p4 ) = self; + let mut result = PathBuf::new(); + result.push( p1.try_into_cow_path()?.as_ref() ); + result.push( p2.try_into_cow_path()?.as_ref() ); + result.push( p3.try_into_cow_path()?.as_ref() ); + result.push( p4.try_into_cow_path()?.as_ref() ); + Ok( result ) + } + } + + // Implementation for a tuple of length 5 + impl< 'a, T1, T2, T3, T4, T5 > PathJoined for ( T1, T2, T3, T4, T5 ) + where + T1 : TryIntoCowPath< 'a >, + T2 : TryIntoCowPath< 'a >, + T3 : TryIntoCowPath< 'a >, + T4 : TryIntoCowPath< 'a >, + T5 : TryIntoCowPath< 'a >, + { + #[ inline ] + fn iter_join( self ) -> Result< PathBuf, io::Error > + { + let ( p1, p2, p3, p4, p5 ) = self; + let mut result = PathBuf::new(); + result.push( p1.try_into_cow_path()?.as_ref() ); + result.push( p2.try_into_cow_path()?.as_ref() ); + result.push( p3.try_into_cow_path()?.as_ref() ); + result.push( p4.try_into_cow_path()?.as_ref() ); + result.push( p5.try_into_cow_path()?.as_ref() ); + Ok( result ) + } + } + + // Implementation for slices + impl< 'a, T > PathJoined for &'a [ T ] + where + T : TryIntoCowPath< 'a > + Clone, + { + #[ inline ] + fn iter_join( self ) -> Result< PathBuf, io::Error > + { + let mut result = PathBuf::new(); + for item in self + { + result.push( item.clone().try_into_cow_path()?.as_ref() ); + } + Ok( result ) + } + } + + // Implementation for arrays + impl< 'a, T, const N : usize > PathJoined for [ T; N ] + where + T : TryIntoCowPath< 'a > + Clone, + { + #[ inline ] + fn iter_join( self ) -> Result< PathBuf, io::Error > + { + let mut result = PathBuf::new(); + for item in &self + { + result.push( item.clone().try_into_cow_path()?.as_ref() ); + } + Ok( result ) + } + } + +} + +crate::mod_interface! +{ + orphan use join; + exposed use PathJoined; +} diff --git a/module/core/proper_path_tools/src/path/native_path.rs b/module/core/pth/src/path/native_path.rs similarity index 84% rename from module/core/proper_path_tools/src/path/native_path.rs rename to module/core/pth/src/path/native_path.rs index df2e7ca559..80b75715b2 100644 --- a/module/core/proper_path_tools/src/path/native_path.rs +++ b/module/core/pth/src/path/native_path.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { @@ -21,14 +21,17 @@ mod private }, }; - #[cfg(feature="no_std")] + #[ cfg( feature="no_std" ) ] extern crate std; + #[ cfg( feature="no_std" ) ] + use alloc::string::String; + #[ cfg( feature = "derive_serde" ) ] use serde::{ Serialize, Deserialize }; - #[ cfg( feature = "path_utf8" ) ] - use camino::{ Utf8Path, Utf8PathBuf }; + // #[ cfg( feature = "path_utf8" ) ] + // use camino::{ Utf8Path, Utf8PathBuf }; /// Caninical path. #[ cfg_attr( feature = "derive_serde", derive( Serialize, Deserialize ) ) ] @@ -111,6 +114,28 @@ mod private } } + impl< 'a > TryFrom< &'a String > for NativePath + { + type Error = std::io::Error; + + #[ inline ] + fn try_from( src : &'a String ) -> Result< Self, Self::Error > + { + < Self as TryFrom< &Path > >::try_from( src.as_ref() ) + } + } + + impl< 'a > TryFrom< String > for NativePath + { + type Error = std::io::Error; + + #[ inline ] + fn try_from( src : String ) -> Result< Self, Self::Error > + { + < Self as TryFrom< &Path > >::try_from( src.as_ref() ) + } + } + impl TryFrom< PathBuf > for NativePath { type Error = std::io::Error; @@ -228,6 +253,32 @@ mod private } } + impl TryIntoPath for NativePath + { + #[ inline ] + fn try_into_path( self ) -> Result< PathBuf, io::Error > + { + Ok( self.0 ) + } + } + + impl< 'a > TryIntoCowPath< 'a > for NativePath + { + #[ inline ] + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error > + { + Ok( Cow::Owned( self.0 ) ) + } + } + + // impl AsPath for NativePath + // { + // fn as_path( &self ) -> &Path + // { + // self.0.as_path() + // } + // } + // impl TryFrom< Utf8PathBuf > for NativePath // { // type Error = std::io::Error; diff --git a/module/core/proper_path_tools/src/transitive.rs b/module/core/pth/src/transitive.rs similarity index 98% rename from module/core/proper_path_tools/src/transitive.rs rename to module/core/pth/src/transitive.rs index 9de7eef34b..ce1f366765 100644 --- a/module/core/proper_path_tools/src/transitive.rs +++ b/module/core/pth/src/transitive.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // xxx : move to derive_tools @@ -49,7 +49,7 @@ mod private /// # Example /// /// ```rust - /// use proper_path_tools::TransitiveTryFrom; + /// use pth::TransitiveTryFrom; /// use std::convert::TryFrom; /// /// struct InitialType; @@ -132,7 +132,7 @@ mod private /// # Example /// /// ```rust - /// use proper_path_tools::TransitiveTryInto; + /// use pth::TransitiveTryInto; /// use std::convert::TryInto; /// /// struct InitialType; diff --git a/module/core/pth/src/try_into_cow_path.rs b/module/core/pth/src/try_into_cow_path.rs new file mode 100644 index 0000000000..af03344f74 --- /dev/null +++ b/module/core/pth/src/try_into_cow_path.rs @@ -0,0 +1,111 @@ +/// Define a private namespace for all its items. +mod private +{ + use crate::*; + use std:: + { + borrow::Cow, + io, + path::{ Component, Path, PathBuf }, + }; + // use camino::{ Utf8Path, Utf8PathBuf }; + + /// A trait for converting various types into a `Cow`. + /// + /// This trait is designed to avoid redundant memory allocation. + /// Unlike `TryIntoPath`, it does not allocate memory on the heap if it's not necessary. + /// Unlike `AsPath`, it is implemented for a wider number of path-like types, similar to `TryIntoPath`. + /// The drawback is the necessity to differentiate borrowed and owned paths at runtime. + pub trait TryIntoCowPath<'a> + { + /// Converts the implementing type into a `Cow`. + /// + /// # Returns + /// + /// * `Ok(Cow)` - A `Cow` that may be either borrowed or owned, depending on the input type. + /// * `Err(io::Error)` - An error if the conversion fails. + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error >; + } + + /// Implementation of `TryIntoCowPath` for `String`. + impl<'a> TryIntoCowPath<'a> for &'a str + { + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error > + { + Ok( Cow::Borrowed( self.as_path() ) ) + } + } + + /// Implementation of `TryIntoCowPath` for `String`. + impl<'a> TryIntoCowPath<'a> for String + { + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error > + { + Ok( Cow::Owned( PathBuf::from( self ) ) ) + } + } + + /// Implementation of `TryIntoCowPath` for `PathBuf`. + impl<'a> TryIntoCowPath<'a> for PathBuf + { + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error > + { + Ok( Cow::Owned( self ) ) + } + } + + /// Implementation of `TryIntoCowPath` for a reference to `Path`. + impl<'a> TryIntoCowPath<'a> for &'a Path + { + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error > + { + Ok( Cow::Borrowed( self ) ) + } + } + + /// Implementation of `TryIntoCowPath` for a reference to `Utf8Path`. + #[cfg( feature = "path_utf8" )] + impl< 'a > TryIntoCowPath< 'a > for &'a Utf8Path + { + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error > + { + Ok( Cow::Borrowed( self.as_std_path() ) ) + } + } + + /// Implementation of `TryIntoCowPath` for `Utf8PathBuf`. + #[cfg( feature = "path_utf8" )] + impl<'a> TryIntoCowPath<'a> for Utf8PathBuf + { + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error > + { + Ok( Cow::Owned( self.as_std_path().to_path_buf() ) ) + } + } + + /// Implementation of `TryIntoCowPath` for `std::path::Component`. + impl<'a> TryIntoCowPath<'a> for Component<'a> + { + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error > + { + Ok( Cow::Owned( PathBuf::from( self.as_os_str() ) ) ) + } + } + + /// Blanket implementation of `TryIntoCowPath` for references to types implementing `AsPath`. + impl<'a, T> TryIntoCowPath< 'a > for &'a T + where + T : AsPath, + { + fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error > + { + Ok( Cow::Borrowed( self.as_path() ) ) + } + } + +} + +crate::mod_interface! +{ + orphan use TryIntoCowPath; +} \ No newline at end of file diff --git a/module/core/pth/src/try_into_path.rs b/module/core/pth/src/try_into_path.rs new file mode 100644 index 0000000000..979ee754f9 --- /dev/null +++ b/module/core/pth/src/try_into_path.rs @@ -0,0 +1,109 @@ +/// Define a private namespace for all its items. +mod private +{ + #[ allow( unused_imports ) ] + use crate::*; + use std:: + { + io, + path::{ Component, Path, PathBuf }, + }; + // use camino::{ Utf8Path, Utf8PathBuf }; + + /// A trait for converting various types into a `PathBuf`. + /// + /// This trait is used to convert any path-like type into an owned `PathBuf`. + /// Unlike `TryIntoCowPath`, it always returns an owned `PathBuf`, so there is no need to differentiate between borrowed and owned paths at runtime. + /// Unlike `AsPath`, it is implemented for a wider range of path-like types, similar to `TryIntoCowPath`. + pub trait TryIntoPath + { + /// Converts the implementing type into a `PathBuf`. + /// + /// # Returns + /// + /// * `Ok(PathBuf)` - The owned path buffer. + /// * `Err(io::Error)` - An error if the conversion fails. + fn try_into_path( self ) -> Result< PathBuf, io::Error >; + } + + /// Implementation of `TryIntoPath` for `&str`. + impl TryIntoPath for &str + { + fn try_into_path( self ) -> Result< PathBuf, io::Error > + { + Ok( PathBuf::from( self ) ) + } + } + + /// Implementation of `TryIntoPath` for `String`. + impl TryIntoPath for String + { + fn try_into_path( self ) -> Result< PathBuf, io::Error > + { + Ok( PathBuf::from( self ) ) + } + } + + /// Implementation of `TryIntoPath` for a reference to `Path`. + impl TryIntoPath for &Path + { + fn try_into_path( self ) -> Result< PathBuf, io::Error > + { + Ok( self.to_path_buf() ) + } + } + + /// Implementation of `TryIntoPath` for `PathBuf`. + impl TryIntoPath for PathBuf + { + fn try_into_path( self ) -> Result< PathBuf, io::Error > + { + Ok( self ) + } + } + + /// Implementation of `TryIntoPath` for a reference to `Utf8Path`. + #[cfg( feature = "path_utf8" )] + impl TryIntoPath for &Utf8Path + { + fn try_into_path( self ) -> Result< PathBuf, io::Error > + { + Ok( self.as_std_path().to_path_buf() ) + } + } + + /// Implementation of `TryIntoPath` for `Utf8PathBuf`. + #[cfg( feature = "path_utf8" )] + impl TryIntoPath for Utf8PathBuf + { + fn try_into_path( self ) -> Result< PathBuf, io::Error > + { + Ok( self.as_std_path().to_path_buf() ) + } + } + + /// Implementation of `TryIntoPath` for `std::path::Component`. + impl TryIntoPath for Component<'_> + { + fn try_into_path( self ) -> Result< PathBuf, io::Error > + { + Ok( self.as_os_str().into() ) + } + } + + /// Blanket implementation of `TryIntoPath` for references to types implementing `AsRef`. + impl< T > TryIntoPath for &T + where + T : AsRef< Path >, + { + fn try_into_path( self ) -> Result< PathBuf, io::Error > + { + Ok( self.as_ref().to_path_buf() ) + } + } +} + +crate::mod_interface! +{ + orphan use TryIntoPath; +} \ No newline at end of file diff --git a/module/core/proper_path_tools/tests/experiment.rs b/module/core/pth/tests/experiment.rs similarity index 94% rename from module/core/proper_path_tools/tests/experiment.rs rename to module/core/pth/tests/experiment.rs index 29e2cd3eba..60e36f8879 100644 --- a/module/core/proper_path_tools/tests/experiment.rs +++ b/module/core/pth/tests/experiment.rs @@ -2,7 +2,7 @@ include!( "../../../../module/step/meta/src/module/terminal.rs" ); #[ allow( unused_imports ) ] -use proper_path_tools as the_module; +use pth as the_module; #[ allow( unused_imports ) ] use test_tools::exposed::*; diff --git a/module/core/pth/tests/inc/absolute_path_test.rs b/module/core/pth/tests/inc/absolute_path_test.rs new file mode 100644 index 0000000000..6d15a1fb2b --- /dev/null +++ b/module/core/pth/tests/inc/absolute_path_test.rs @@ -0,0 +1,5 @@ +use super::*; + +mod basic_test; +mod from_paths_test; +mod try_from_test; diff --git a/module/core/proper_path_tools/tests/inc/absolute_path.rs b/module/core/pth/tests/inc/absolute_path_test/basic_test.rs similarity index 95% rename from module/core/proper_path_tools/tests/inc/absolute_path.rs rename to module/core/pth/tests/inc/absolute_path_test/basic_test.rs index 247be8c4b4..3f8a254ba0 100644 --- a/module/core/proper_path_tools/tests/inc/absolute_path.rs +++ b/module/core/pth/tests/inc/absolute_path_test/basic_test.rs @@ -1,4 +1,3 @@ -#[ allow( unused_imports ) ] use super::*; use the_module:: @@ -8,9 +7,6 @@ use the_module:: PathBuf, }; -// #[ cfg( feature = "path_utf8" ) ] -// use the_module::Utf8PathBuf; - #[ test ] fn basic() { @@ -37,6 +33,7 @@ fn test_to_string_lossy_hard() } #[test] +#[ cfg( not( feature="no_std" ) ) ] fn test_try_from_pathbuf() { @@ -46,6 +43,7 @@ fn test_try_from_pathbuf() } #[test] +#[ cfg( not( feature="no_std" ) ) ] fn test_try_from_path() { let path = Path::new( "/path/to/some/file.txt" ); @@ -69,7 +67,6 @@ fn test_join() assert_eq!( joined_path.to_string_lossy(), "/path/to/some/file.txt" ); } - #[test] fn test_relative_path_try_from_str() { @@ -79,6 +76,7 @@ fn test_relative_path_try_from_str() } #[test] +#[ cfg( not( feature="no_std" ) ) ] fn test_relative_path_try_from_pathbuf() { let rel_path_buf = PathBuf::from( "src/main.rs" ); @@ -87,6 +85,7 @@ fn test_relative_path_try_from_pathbuf() } #[test] +#[ cfg( not( feature="no_std" ) ) ] fn test_relative_path_try_from_path() { let rel_path = Path::new( "src/main.rs" ); diff --git a/module/core/pth/tests/inc/absolute_path_test/from_paths_test.rs b/module/core/pth/tests/inc/absolute_path_test/from_paths_test.rs new file mode 100644 index 0000000000..3e5bd05dd4 --- /dev/null +++ b/module/core/pth/tests/inc/absolute_path_test/from_paths_test.rs @@ -0,0 +1,92 @@ +use super::*; + +// xxx : make it working + +#[ test ] +fn test_from_paths_single_absolute_segment() +{ + use the_module::AbsolutePath; + use std::convert::TryFrom; + + let segments = vec![ "/single" ]; + let got = AbsolutePath::from_iter( segments.iter().map( |s| *s ) ).unwrap(); + let exp = AbsolutePath::try_from( "/single" ).unwrap(); + + assert_eq!( got, exp ); +} + +#[ test ] +fn test_from_paths_multiple_segments() +{ + use the_module::AbsolutePath; + use std::convert::TryFrom; + + let segments = vec![ "/path", "to", "file" ]; + let got = AbsolutePath::from_iter( segments.iter().map( |s| *s ) ).unwrap(); + let exp = AbsolutePath::try_from( "/path/to/file" ).unwrap(); + + assert_eq!( got, exp ); +} + +#[ test ] +fn test_from_paths_empty_segments() +{ + use the_module::AbsolutePath; + + let segments : Vec< &str > = vec![]; + let result = AbsolutePath::from_iter( segments.iter().map( | s | *s ) ); + + assert!( result.is_err(), "Expected an error for empty segments" ); +} + +#[ test ] +fn test_from_paths_with_dot_segments() +{ + use the_module::AbsolutePath; + use std::convert::TryFrom; + + let segments = vec![ "/path", ".", "to", "file" ]; + let got = AbsolutePath::from_iter( segments.iter().map( |s| *s ) ).unwrap(); + let exp = AbsolutePath::try_from( "/path/to/file" ).unwrap(); + + assert_eq!( got, exp ); +} + +#[ test ] +fn test_from_paths_with_dotdot_segments() +{ + use the_module::AbsolutePath; + use std::convert::TryFrom; + + let segments = vec![ "/path", "to", "..", "file" ]; + let got = AbsolutePath::from_iter( segments.iter().map( |s| *s ) ).unwrap(); + let exp = AbsolutePath::try_from( "/path/file" ).unwrap(); + + assert_eq!( got, exp ); +} + +#[ test ] +fn test_from_paths_with_trailing_slash() +{ + use the_module::AbsolutePath; + use std::convert::TryFrom; + + let segments = vec![ "/path", "to", "file/" ]; + let got = AbsolutePath::from_iter( segments.iter().map( |s| *s ) ).unwrap(); + let exp = AbsolutePath::try_from( "/path/to/file/" ).unwrap(); + + assert_eq!( got, exp ); +} + +#[ test ] +fn test_from_paths_with_mixed_slashes() +{ + use the_module::AbsolutePath; + use std::convert::TryFrom; + + let segments = vec![ "/path\\to", "file" ]; + let got = AbsolutePath::from_iter( segments.iter().map( |s| *s ) ).unwrap(); + let exp = AbsolutePath::try_from( "/path/to/file" ).unwrap(); + + assert_eq!( got, exp ); +} diff --git a/module/core/pth/tests/inc/absolute_path_test/try_from_test.rs b/module/core/pth/tests/inc/absolute_path_test/try_from_test.rs new file mode 100644 index 0000000000..ee1aa2b3a1 --- /dev/null +++ b/module/core/pth/tests/inc/absolute_path_test/try_from_test.rs @@ -0,0 +1,55 @@ +use super::*; +use std::convert::TryFrom; + +#[ test ] +fn try_from_absolute_path_test() +{ + use std::path::{ Path, PathBuf }; + use the_module::AbsolutePath; + + // Create an AbsolutePath instance + let absolute_path = AbsolutePath::try_from( "/absolute/path" ).unwrap(); + + // Test conversion to &str + let path_str : &str = TryFrom::try_from( &absolute_path ).unwrap(); + println!( "&str from AbsolutePath: {:?}", path_str ); + assert_eq!( path_str, "/absolute/path" ); + + // Test conversion to String + let path_string : String = TryFrom::try_from( &absolute_path ).unwrap(); + println!( "String from AbsolutePath: {:?}", path_string ); + assert_eq!( path_string, "/absolute/path" ); + + // Test conversion to PathBuf + let path_buf : PathBuf = TryFrom::try_from( absolute_path.clone() ).unwrap(); + println!( "PathBuf from AbsolutePath: {:?}", path_buf ); + assert_eq!( path_buf, PathBuf::from( "/absolute/path" ) ); + + // Test conversion to &Path + let path_ref : &Path = absolute_path.as_ref(); + println!( "&Path from AbsolutePath: {:?}", path_ref ); + assert_eq!( path_ref, Path::new( "/absolute/path" ) ); + + // Test conversion from &String + let string_path : String = String::from( "/absolute/path" ); + let absolute_path_from_string : AbsolutePath = TryFrom::try_from( &string_path ).unwrap(); + println!( "AbsolutePath from &String: {:?}", absolute_path_from_string ); + assert_eq!( absolute_path_from_string, absolute_path ); + + // Test conversion from String + let absolute_path_from_owned_string : AbsolutePath = TryFrom::try_from( string_path.clone() ).unwrap(); + println!( "AbsolutePath from String: {:?}", absolute_path_from_owned_string ); + assert_eq!( absolute_path_from_owned_string, absolute_path ); + + // Test conversion from &Path + let path_ref : &Path = Path::new( "/absolute/path" ); + let absolute_path_from_path_ref : AbsolutePath = TryFrom::try_from( path_ref ).unwrap(); + println!( "AbsolutePath from &Path: {:?}", absolute_path_from_path_ref ); + assert_eq!( absolute_path_from_path_ref, absolute_path ); + + // Test conversion from PathBuf + let path_buf_instance : PathBuf = PathBuf::from( "/absolute/path" ); + let absolute_path_from_path_buf : AbsolutePath = TryFrom::try_from( path_buf_instance.clone() ).unwrap(); + println!( "AbsolutePath from PathBuf: {:?}", absolute_path_from_path_buf ); + assert_eq!( absolute_path_from_path_buf, absolute_path ); +} \ No newline at end of file diff --git a/module/core/pth/tests/inc/as_path_test.rs b/module/core/pth/tests/inc/as_path_test.rs new file mode 100644 index 0000000000..340a6540ca --- /dev/null +++ b/module/core/pth/tests/inc/as_path_test.rs @@ -0,0 +1,103 @@ +use super::*; + +#[ test ] +fn as_path_test() +{ + use std::path::{ Component, Path, PathBuf }; + #[ cfg( feature = "path_utf8" ) ] + use the_module::{ Utf8Path, Utf8PathBuf }; + use the_module::{ AsPath, AbsolutePath, CanonicalPath, NativePath, CurrentPath }; + + // Test with &str + let path_str : &str = "/some/path"; + let path : &Path = AsPath::as_path( path_str ); + println!( "Path from &str: {:?}", path ); + + // Test with &String + let string_path : String = String::from( "/another/path" ); + let path : &Path = AsPath::as_path( &string_path ); + println!( "Path from &String: {:?}", path ); + + // Test with String + let path : &Path = AsPath::as_path( &string_path ); + println!( "Path from String: {:?}", path ); + + // Test with &Path + let path_ref : &Path = Path::new( "/yet/another/path" ); + let path : &Path = AsPath::as_path( path_ref ); + println!( "Path from &Path: {:?}", path ); + + // Test with &PathBuf + let path_buf : PathBuf = PathBuf::from( "/yet/another/path" ); + let path : &Path = AsPath::as_path( &path_buf ); + println!( "Path from &PathBuf: {:?}", path ); + + // Test with PathBuf + let path : &Path = AsPath::as_path( &path_buf ); + println!( "Path from PathBuf: {:?}", path ); + + // Test with &AbsolutePath + let absolute_path : AbsolutePath = AbsolutePath::try_from( "/absolute/path" ).unwrap(); + let path : &Path = AsPath::as_path( &absolute_path ); + println!( "Path from &AbsolutePath: {:?}", path ); + + // Test with AbsolutePath + let path : &Path = AsPath::as_path( &absolute_path ); + println!( "Path from AbsolutePath: {:?}", path ); + + // Test with &CanonicalPath + let canonical_path = CanonicalPath::try_from( "/canonical/path" ).unwrap(); + let path : &Path = AsPath::as_path( &canonical_path ); + println!( "Path from &CanonicalPath: {:?}", path ); + + // Test with CanonicalPath + let path : &Path = AsPath::as_path( &canonical_path ); + println!( "Path from CanonicalPath: {:?}", path ); + + // Test with &NativePath + let native_path = NativePath::try_from( PathBuf::from( "/native/path" ) ).unwrap(); + let path : &Path = AsPath::as_path( &native_path ); + println!( "Path from &NativePath: {:?}", path ); + + // Test with NativePath + let path : &Path = AsPath::as_path( &native_path ); + println!( "Path from NativePath: {:?}", path ); + + // Test with &Component + let root_component : Component< '_ > = Component::RootDir; + let path : &Path = AsPath::as_path( &root_component ); + println!( "Path from &Component: {:?}", path ); + + // Test with Component + let path : &Path = AsPath::as_path( &root_component ); + println!( "Path from Component: {:?}", path ); + + // Test with Component + let path = Path::new( "/component/path" ); + for component in path.components() + { + let path : &Path = AsPath::as_path( &component ); + println!( "Path from Component: {:?}", path ); + } + + #[ cfg( feature = "path_utf8" ) ] + { + // Test with &Utf8Path + let utf8_path = Utf8Path::new( "/utf8/path" ); + let path : &Path = AsPath::as_path( &utf8_path ); + println!( "Path from &Utf8Path: {:?}", path ); + + // Test with Utf8Path + let path : &Path = AsPath::as_path( &utf8_path ); + println!( "Path from Utf8Path: {:?}", path ); + + // Test with &Utf8PathBuf + let utf8_path_buf = Utf8PathBuf::from( "/utf8/pathbuf" ); + let path : &Path = AsPath::as_path( &utf8_path_buf ); + println!( "Path from &Utf8PathBuf: {:?}", path ); + + // Test with Utf8PathBuf + let path : &Path = AsPath::as_path( &utf8_path_buf ); + println!( "Path from Utf8PathBuf: {:?}", path ); + } +} diff --git a/module/core/proper_path_tools/tests/inc/current_path.rs b/module/core/pth/tests/inc/current_path.rs similarity index 85% rename from module/core/proper_path_tools/tests/inc/current_path.rs rename to module/core/pth/tests/inc/current_path.rs index 628873a346..88703f0ec6 100644 --- a/module/core/proper_path_tools/tests/inc/current_path.rs +++ b/module/core/pth/tests/inc/current_path.rs @@ -1,6 +1,7 @@ #[ allow( unused_imports ) ] use super::*; +#[ cfg( not( feature="no_std" ) ) ] use the_module:: { AbsolutePath, @@ -12,6 +13,7 @@ use the_module:: use the_module::Utf8PathBuf; #[ test ] +#[ cfg( not( feature="no_std" ) ) ] fn basic() { @@ -24,6 +26,7 @@ fn basic() println!( "absolute_path : {absolute_path:?}" ); #[ cfg( feature = "path_utf8" ) ] + #[ cfg( not( feature="no_std" ) ) ] { let cd = the_module::CurrentPath; let utf8_path : Utf8PathBuf = cd.try_into().unwrap(); diff --git a/module/core/proper_path_tools/tests/inc/mod.rs b/module/core/pth/tests/inc/mod.rs similarity index 57% rename from module/core/proper_path_tools/tests/inc/mod.rs rename to module/core/pth/tests/inc/mod.rs index 58e8721710..8026b293ba 100644 --- a/module/core/proper_path_tools/tests/inc/mod.rs +++ b/module/core/pth/tests/inc/mod.rs @@ -1,8 +1,14 @@ -#[allow(unused_imports)] use super::*; -mod absolute_path; +mod as_path_test; +mod try_into_path_test; +mod try_into_cow_path_test; + +mod absolute_path_test; +mod path_join_fn_test; +mod path_join_trait_test; + mod current_path; mod path_canonicalize; mod path_change_ext; @@ -10,12 +16,11 @@ mod path_common; mod path_ext; mod path_exts; mod path_is_glob; -mod path_join; mod path_normalize; mod path_relative; mod rebase_path; mod transitive; mod without_ext; -#[cfg(feature = "path_unique_folder_name")] +#[ cfg( feature = "path_unique_folder_name" ) ] mod path_unique_folder_name; diff --git a/module/core/proper_path_tools/tests/inc/path_canonicalize.rs b/module/core/pth/tests/inc/path_canonicalize.rs similarity index 66% rename from module/core/proper_path_tools/tests/inc/path_canonicalize.rs rename to module/core/pth/tests/inc/path_canonicalize.rs index 64cd4665f2..ae94013a4c 100644 --- a/module/core/proper_path_tools/tests/inc/path_canonicalize.rs +++ b/module/core/pth/tests/inc/path_canonicalize.rs @@ -7,10 +7,10 @@ use the_module::path; fn assumptions() { - assert_eq!( PathBuf::from( "c:/src/" ).is_absolute(), true ); - assert_eq!( PathBuf::from( "/c/src/" ).is_absolute(), false ); - assert_eq!( PathBuf::from( "/c:/src/" ).is_absolute(), false ); - assert_eq!( PathBuf::from( "/c/src/" ).is_absolute(), false ); + // assert_eq!( PathBuf::from( "c:/src/" ).is_absolute(), false ); // qqq : xxx : this assumption is false on linux + // assert_eq!( PathBuf::from( "/c/src/" ).is_absolute(), true ); // qqq : xxx : this assumption is false, seems + // assert_eq!( PathBuf::from( "/c:/src/" ).is_absolute(), true ); // qqq : xxx : this assumption is false, too + // assert_eq!( PathBuf::from( "/c/src/" ).is_absolute(), true ); // qqq : xxx : this assumption is false, too } @@ -23,11 +23,11 @@ fn basic() assert_eq!( got.unwrap(), exp ); let got = path::canonicalize( PathBuf::from( "\\src" ) ); - let exp = PathBuf::from( "/src" ); + let exp = PathBuf::from( "\\src" ); assert_eq!( got.unwrap(), exp ); let got = path::canonicalize( PathBuf::from( "\\src\\" ) ); - let exp = PathBuf::from( "/src/" ); + let exp = PathBuf::from( "\\src\\" ); assert_eq!( got.unwrap(), exp ); let got = path::canonicalize( PathBuf::from( "/src" ) ); diff --git a/module/core/proper_path_tools/tests/inc/path_change_ext.rs b/module/core/pth/tests/inc/path_change_ext.rs similarity index 100% rename from module/core/proper_path_tools/tests/inc/path_change_ext.rs rename to module/core/pth/tests/inc/path_change_ext.rs diff --git a/module/core/proper_path_tools/tests/inc/path_common.rs b/module/core/pth/tests/inc/path_common.rs similarity index 100% rename from module/core/proper_path_tools/tests/inc/path_common.rs rename to module/core/pth/tests/inc/path_common.rs diff --git a/module/core/proper_path_tools/tests/inc/path_ext.rs b/module/core/pth/tests/inc/path_ext.rs similarity index 100% rename from module/core/proper_path_tools/tests/inc/path_ext.rs rename to module/core/pth/tests/inc/path_ext.rs diff --git a/module/core/proper_path_tools/tests/inc/path_exts.rs b/module/core/pth/tests/inc/path_exts.rs similarity index 100% rename from module/core/proper_path_tools/tests/inc/path_exts.rs rename to module/core/pth/tests/inc/path_exts.rs diff --git a/module/core/proper_path_tools/tests/inc/path_is_glob.rs b/module/core/pth/tests/inc/path_is_glob.rs similarity index 100% rename from module/core/proper_path_tools/tests/inc/path_is_glob.rs rename to module/core/pth/tests/inc/path_is_glob.rs diff --git a/module/core/proper_path_tools/tests/inc/path_join.rs b/module/core/pth/tests/inc/path_join_fn_test.rs similarity index 76% rename from module/core/proper_path_tools/tests/inc/path_join.rs rename to module/core/pth/tests/inc/path_join_fn_test.rs index fa526ee19d..f5a2acd005 100644 --- a/module/core/proper_path_tools/tests/inc/path_join.rs +++ b/module/core/pth/tests/inc/path_join_fn_test.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; fn join_empty() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "".into(), vec![ "".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -21,7 +21,7 @@ fn join_empty() fn join_several_empties() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "".into(), vec![ "".into(), "".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -37,7 +37,7 @@ fn join_several_empties() fn root_with_absolute() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/b".into(), vec![ "/".into(), "/a/b".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -53,7 +53,7 @@ fn root_with_absolute() fn root_with_relative() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/b".into(), vec![ "/".into(), "a/b".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -69,7 +69,7 @@ fn root_with_relative() fn dir_with_absolute() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/b".into(), vec![ "/dir".into(), "/a/b".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -85,7 +85,7 @@ fn dir_with_absolute() fn dir_with_relative() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/dir/a/b".into(), vec![ "/dir".into(), "a/b".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -101,7 +101,7 @@ fn dir_with_relative() fn trailed_dir_with_absolute() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/b".into(), vec![ "/dir/".into(), "/a/b".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -117,7 +117,7 @@ fn trailed_dir_with_absolute() fn trailed_dir_with_relative() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/dir/a/b".into(), vec![ "/dir/".into(), "a/b".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -133,7 +133,7 @@ fn trailed_dir_with_relative() fn dir_with_down() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/b".into(), vec![ "/dir".into(), "../a/b".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -149,7 +149,7 @@ fn dir_with_down() fn trailed_dir_with_down() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/dir/a/b".into(), vec![ "/dir/".into(), "../a/b".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -165,7 +165,7 @@ fn trailed_dir_with_down() fn dir_with_several_down() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/b".into(), vec![ "/dir/dir2".into(), "../../a/b".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -181,7 +181,7 @@ fn dir_with_several_down() fn trailed_dir_with_several_down() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/b".into(), vec![ "/dir/".into(), "../../a/b".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -197,7 +197,7 @@ fn trailed_dir_with_several_down() fn dir_with_several_down_go_out_of_root() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/../a/b".into(), vec![ "/dir".into(), "../../a/b".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -213,7 +213,7 @@ fn dir_with_several_down_go_out_of_root() fn trailed_absolute_with_trailed_down() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/b/".into(), vec![ "/a/b/".into(), "../".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -229,7 +229,7 @@ fn trailed_absolute_with_trailed_down() fn absolute_with_trailed_down() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/".into(), vec![ "/a/b".into(), "../".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -245,7 +245,7 @@ fn absolute_with_trailed_down() fn trailed_absolute_with_down() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/b".into(), vec![ "/a/b/".into(), "..".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -261,7 +261,7 @@ fn trailed_absolute_with_down() fn trailed_absolute_with_trailed_here() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/b/".into(), vec![ "/a/b/".into(), "./".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -277,7 +277,7 @@ fn trailed_absolute_with_trailed_here() fn absolute_with_trailed_here() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/b/".into(), vec![ "/a/b".into(), "./".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -293,7 +293,7 @@ fn absolute_with_trailed_here() fn trailed_absolute_with_here() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/b".into(), vec![ "/a/b/".into(), ".".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -309,7 +309,7 @@ fn trailed_absolute_with_here() fn join_with_empty() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/a/b/c".into(), vec![ "".into(), "a/b".into(), "".into(), "c".into(), "".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -324,8 +324,8 @@ fn join_with_empty() #[ test ] fn join_windows_os_paths() { - let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/c/foo/bar/".into(), vec![ "c:\\".into(), "foo\\".into(), "bar\\".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/c:/foo/bar/".into(), vec![ "c:\\".into(), "foo\\".into(), "bar\\".into() ] ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -341,7 +341,7 @@ fn join_windows_os_paths() fn join_unix_os_paths() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/baz/foo".into(), vec![ "/bar/".into(), "/baz".into(), "foo/".into(), ".".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -357,7 +357,7 @@ fn join_unix_os_paths() fn join_unix_os_paths_2() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/baz/foo/z".into(), vec![ "/bar/".into(), "/baz".into(), "foo/".into(), ".".into(), "z".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -373,7 +373,7 @@ fn join_unix_os_paths_2() fn more_complicated_cases_1() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/aa/bb//cc".into(), vec![ "/aa".into(), "bb//".into(), "cc".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -389,7 +389,7 @@ fn more_complicated_cases_1() fn more_complicated_cases_2() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/bb/cc".into(), vec![ "/aa".into(), "/bb".into(), "cc".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -405,7 +405,7 @@ fn more_complicated_cases_2() fn more_complicated_cases_3() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "//aa/bb//cc//".into(), vec![ "//aa".into(), "bb//".into(), "cc//".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -421,7 +421,7 @@ fn more_complicated_cases_3() fn more_complicated_cases_4() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "/aa/bb//cc".into(), vec![ "/aa".into(), "bb//".into(), "cc".into(), ".".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, @@ -437,7 +437,7 @@ fn more_complicated_cases_4() fn more_complicated_cases_5() { let ( expected, paths ) : ( PathBuf, Vec< PathBuf > ) = ( "//b//d/..e".into(), vec![ "/".into(), "a".into(), "//b//".into(), "././c".into(), "../d".into(), "..e".into() ] ); - let result = the_module::path::join_paths( paths.iter().map( |p| p.as_path() ) ); + let result = the_module::path::iter_join( paths.iter().map( |p| p.as_path() ) ); assert_eq! ( result, diff --git a/module/core/pth/tests/inc/path_join_trait_test.rs b/module/core/pth/tests/inc/path_join_trait_test.rs new file mode 100644 index 0000000000..74f302166b --- /dev/null +++ b/module/core/pth/tests/inc/path_join_trait_test.rs @@ -0,0 +1,206 @@ +use super::*; +use std:: +{ + borrow::Cow, + io, + path::{ Path, PathBuf }, +}; + +#[ test ] +fn basic() -> Result< (), io::Error > +{ + use the_module::PathJoined; + use std::path::PathBuf; + + let path1 : &str = "/some"; + let path2 : String = "path".into(); + let path3 : PathBuf = "to/file".into(); + let path4 : &str = "extra"; + let path5 : String = "components".into(); + + // Test with a tuple of length 1 + let joined1 : PathBuf = ( path1, ).iter_join()?; + println!( "Joined PathBuf (1): {:?}", joined1 ); + + // Test with a tuple of length 2 + let joined2 : PathBuf = ( path1, path2.clone() ).iter_join()?; + println!( "Joined PathBuf (2): {:?}", joined2 ); + + // Test with a tuple of length 3 + let joined3 : PathBuf = ( path1, path2.clone(), path3.clone() ).iter_join()?; + println!( "Joined PathBuf (3): {:?}", joined3 ); + + // Test with a tuple of length 4 + let joined4 : PathBuf = ( path1, path2.clone(), path3.clone(), path4 ).iter_join()?; + println!( "Joined PathBuf (4): {:?}", joined4 ); + + // Test with a tuple of length 5 + let joined5 : PathBuf = ( path1, path2, path3, path4, path5 ).iter_join()?; + println!( "Joined PathBuf (5): {:?}", joined5 ); + + Ok( () ) +} + +#[ test ] +fn array_join_paths_test() -> Result< (), io::Error > +{ + use the_module::{ PathJoined, TryIntoCowPath }; + use std::path::PathBuf; + + // Define a slice of path components + let path_components : [ &str; 3 ] = [ "/some", "path", "to/file" ]; + // Join the path components into a PathBuf + let joined : PathBuf = path_components.iter_join()?; + println!( "Joined PathBuf from slice: {:?}", joined ); + let expected = PathBuf::from( "/some/path/to/file" ); + assert_eq!( joined, expected ); + + Ok( () ) +} + +#[ test ] +fn slice_join_paths_test() -> Result< (), io::Error > +{ + use the_module::{ PathJoined, TryIntoCowPath }; + use std::path::PathBuf; + + // Define a slice of path components + let path_components : [ &str; 3 ] = [ "/some", "path", "to/file" ]; + let slice : &[ &str ] = &path_components[ .. ]; + // Join the path components into a PathBuf + let joined : PathBuf = slice.iter_join()?; + println!( "Joined PathBuf from slice: {:?}", joined ); + let expected = PathBuf::from( "/some/path/to/file" ); + assert_eq!( joined, expected ); + + Ok( () ) +} + +#[ test ] +fn all_types() -> Result< (), io::Error > +{ + use std::path::Path; + use the_module::{ AbsolutePath, CanonicalPath, NativePath, CurrentPath }; + use the_module::{ PathJoined, AsPath, TryIntoPath }; + + // AbsolutePath and CurrentPath + { + let absolute_path = AbsolutePath::try_from( "/absolute/path" ).unwrap(); + let current_path = CurrentPath; + let joined = ( absolute_path.clone(), current_path ).iter_join()?; + let expected = current_path.try_into_path()?; + println!( "Joined PathBuf: {:?}", joined ); + assert_eq!( joined, expected ); + } + + // // CurrentPath and AbsolutePath + // { + // let absolute_path = AbsolutePath::try_from( "/absolute/path" ).unwrap(); + // let current_path = CurrentPath; + // let joined = ( current_path, absolute_path.clone() ).iter_join()?; + // let expected = absolute_path.as_path().to_path_buf(); + // println!( "Joined PathBuf: {:?}", joined ); + // assert_eq!( joined, expected ); + // } + // // qqq : qqq2 : for Denys : bad + + // AbsolutePath and Component + { + let absolute_path = AbsolutePath::try_from( "/absolute/path" ).unwrap(); + let component = Path::new( "/component/path" ).components().next().unwrap(); + println!( "component : {component:?}" ); + let joined = ( absolute_path, component ).iter_join()?; + let expected = component.as_path(); + println!( "Joined PathBuf: {:?}", joined ); + assert_eq!( joined, expected ); + } + + // AbsolutePath and &str + { + let absolute_path = AbsolutePath::try_from( "/absolute/path" ).unwrap(); + let path_str : &str = "additional/str"; + let joined = ( absolute_path, path_str ).iter_join()?; + let expected = PathBuf::from( "/absolute/path/additional/str" ); + println!( "Joined PathBuf: {:?}", joined ); + assert_eq!( joined, expected ); + } + + // AbsolutePath and NativePath + { + let absolute_path = AbsolutePath::try_from( "/absolute/path" ).unwrap(); + let native_path = NativePath::try_from( PathBuf::from( "/native/path" ) ).unwrap(); + let joined = ( absolute_path, native_path ).iter_join()?; + let expected = PathBuf::from( "/native/path" ); + println!( "Joined PathBuf: {:?}", joined ); + assert_eq!( joined, expected ); + } + + // AbsolutePath and CanonicalPath + { + let absolute_path = AbsolutePath::try_from( "/absolute/path" ).unwrap(); + let canonical_path = CanonicalPath::try_from( "/canonical/path" ).unwrap(); + let joined = ( absolute_path, canonical_path ).iter_join()?; + let expected = PathBuf::from( "/canonical/path" ); + println!( "Joined PathBuf: {:?}", joined ); + assert_eq!( joined, expected ); + } + + // NativePath and CurrentPath + { + let native_path = NativePath::try_from( PathBuf::from( "/native/path" ) ).unwrap(); + let current_path = CurrentPath; + let joined = ( native_path, current_path ).iter_join()?; + let expected = current_path.try_into_path()?; + println!( "Joined PathBuf: {:?}", joined ); + assert_eq!( joined, expected ); + } + + // CanonicalPath and Component + { + let canonical_path = CanonicalPath::try_from( "/canonical/path" ).unwrap(); + let component = Path::new( "/component/path" ).components().next().unwrap(); + println!( "component : {component:?}" ); + let joined = ( canonical_path, component ).iter_join()?; + let expected = component.as_path(); + // let expected = PathBuf::from( "/canonical/component" ); + println!( "Joined PathBuf: {:?}", joined ); + assert_eq!( joined, expected ); + } + + Ok( () ) +} + +#[ test ] +fn join_function_test() -> Result< (), io::Error > +{ + use the_module::path; + use std::path::PathBuf; + + // Test joining a tuple of path components + let path1 : &str = "/some"; + let path2 : String = "path".into(); + let path3 : PathBuf = "to/file".into(); + + // Use the join function to join the path components + let joined : PathBuf = path::join( ( path1, path2.clone(), path3.clone() ) )?; + println!( "Joined PathBuf: {:?}", joined ); + // Verify the expected outcome + let expected = PathBuf::from( "/some/path/to/file" ); + assert_eq!( joined, expected ); + + // Test joining a tuple of length 2 + let joined : PathBuf = path::join( ( path1, path2.clone() ) )?; + println!( "Joined PathBuf (2 components): {:?}", joined ); + // Verify the expected outcome + let expected = PathBuf::from( "/some/path" ); + assert_eq!( joined, expected ); + + // Test joining a tuple of length 1 + let joined : PathBuf = path::join( ( path1, ) )?; + println!( "Joined PathBuf (1 component): {:?}", joined ); + // Verify the expected outcome + let expected = PathBuf::from( "/some" ); + assert_eq!( joined, expected ); + + Ok( () ) +} \ No newline at end of file diff --git a/module/core/proper_path_tools/tests/inc/path_normalize.rs b/module/core/pth/tests/inc/path_normalize.rs similarity index 100% rename from module/core/proper_path_tools/tests/inc/path_normalize.rs rename to module/core/pth/tests/inc/path_normalize.rs diff --git a/module/core/proper_path_tools/tests/inc/path_relative.rs b/module/core/pth/tests/inc/path_relative.rs similarity index 100% rename from module/core/proper_path_tools/tests/inc/path_relative.rs rename to module/core/pth/tests/inc/path_relative.rs diff --git a/module/core/proper_path_tools/tests/inc/path_unique_folder_name.rs b/module/core/pth/tests/inc/path_unique_folder_name.rs similarity index 100% rename from module/core/proper_path_tools/tests/inc/path_unique_folder_name.rs rename to module/core/pth/tests/inc/path_unique_folder_name.rs diff --git a/module/core/proper_path_tools/tests/inc/rebase_path.rs b/module/core/pth/tests/inc/rebase_path.rs similarity index 100% rename from module/core/proper_path_tools/tests/inc/rebase_path.rs rename to module/core/pth/tests/inc/rebase_path.rs diff --git a/module/core/proper_path_tools/tests/inc/transitive.rs b/module/core/pth/tests/inc/transitive.rs similarity index 96% rename from module/core/proper_path_tools/tests/inc/transitive.rs rename to module/core/pth/tests/inc/transitive.rs index e0b2da7acc..8224024e5b 100644 --- a/module/core/proper_path_tools/tests/inc/transitive.rs +++ b/module/core/pth/tests/inc/transitive.rs @@ -4,7 +4,7 @@ use super::*; #[ test ] fn basic_from() { - use proper_path_tools::TransitiveTryFrom; + use pth::TransitiveTryFrom; use std::convert::TryFrom; struct InitialType; @@ -42,7 +42,7 @@ fn basic_from() #[ test ] fn test_transitive_try_into() { - use proper_path_tools::TransitiveTryInto; + use pth::TransitiveTryInto; // Define NewType1 wrapping a String #[ derive( Debug, PartialEq ) ] diff --git a/module/core/pth/tests/inc/try_into_cow_path_test.rs b/module/core/pth/tests/inc/try_into_cow_path_test.rs new file mode 100644 index 0000000000..73a3910c52 --- /dev/null +++ b/module/core/pth/tests/inc/try_into_cow_path_test.rs @@ -0,0 +1,124 @@ +use super::*; + +#[ test ] +fn try_into_cow_path_test() +{ + use std:: + { + borrow::Cow, + path::{ Component, Path, PathBuf }, + }; + #[ cfg( feature = "path_utf8" ) ] + use the_module::{ Utf8Path, Utf8PathBuf }; + use the_module:: + { + TryIntoCowPath, AbsolutePath, CanonicalPath, NativePath, CurrentPath, + }; + + // Test with &str + let path_str : &str = "/some/path"; + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( path_str ).unwrap(); + println!( "Cow from &str: {:?}", cow_path ); + + // Test with &String + let string_path : String = String::from( "/another/path" ); + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( &string_path ).unwrap(); + println!( "Cow from &String: {:?}", cow_path ); + + // Test with String + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( string_path.clone() ).unwrap(); + println!( "Cow from String: {:?}", cow_path ); + + // Test with &Path + let path : &Path = Path::new( "/yet/another/path" ); + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( path ).unwrap(); + println!( "Cow from &Path: {:?}", cow_path ); + + // Test with &PathBuf + let path_buf : PathBuf = PathBuf::from( "/yet/another/path" ); + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( &path_buf ).unwrap(); + println!( "Cow from &PathBuf: {:?}", cow_path ); + + // Test with PathBuf + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( path_buf.clone() ).unwrap(); + println!( "Cow from PathBuf: {:?}", cow_path ); + + // Test with &AbsolutePath + let absolute_path : AbsolutePath = AbsolutePath::try_from( "/absolute/path" ).unwrap(); + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( &absolute_path ).unwrap(); + println!( "Cow from &AbsolutePath: {:?}", cow_path ); + + // Test with AbsolutePath + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( absolute_path.clone() ).unwrap(); + println!( "Cow from AbsolutePath: {:?}", cow_path ); + + // Test with &CanonicalPath + let canonical_path = CanonicalPath::try_from( "/canonical/path" ).unwrap(); + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( &canonical_path ).unwrap(); + println!( "Cow from &CanonicalPath: {:?}", cow_path ); + + // Test with CanonicalPath + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( canonical_path.clone() ).unwrap(); + println!( "Cow from CanonicalPath: {:?}", cow_path ); + + // Test with &NativePath + let native_path = NativePath::try_from( PathBuf::from( "/native/path" ) ).unwrap(); + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( &native_path ).unwrap(); + println!( "Cow from &NativePath: {:?}", cow_path ); + + // Test with NativePath + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( native_path.clone() ).unwrap(); + println!( "Cow from NativePath: {:?}", cow_path ); + + // Test with &CurrentPath + let current_path = CurrentPath; + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( ¤t_path ).unwrap(); + println!( "Cow from &CurrentPath: {:?}", cow_path ); + assert!( cow_path.to_string_lossy().len() > 1 ); + + // Test with CurrentPath + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( current_path ).unwrap(); + println!( "Cow from CurrentPath: {:?}", cow_path ); + assert!( cow_path.to_string_lossy().len() > 1 ); + + // Test with &Component + let root_component : Component< '_ > = Component::RootDir; + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( &root_component ).unwrap(); + println!( "Cow from &Component: {:?}", cow_path ); + assert!( cow_path.to_string_lossy().len() >= 1 ); + + // Test with Component + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( root_component ).unwrap(); + println!( "Cow from Component: {:?}", cow_path ); + assert!( cow_path.to_string_lossy().len() >= 1 ); + + // Test with Component + let path = Path::new( "/component/path" ); + for component in path.components() + { + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( component ).unwrap(); + println!( "Cow from Component: {:?}", cow_path ); + assert!( cow_path.to_string_lossy().len() >= 1 ); + } + + #[ cfg( feature = "path_utf8" ) ] + { + // Test with &Utf8Path + let utf8_path = Utf8Path::new( "/utf8/path" ); + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( &utf8_path ).unwrap(); + println!( "Cow from &Utf8Path: {:?}", cow_path ); + + // Test with Utf8Path + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( utf8_path ).unwrap(); + println!( "Cow from Utf8Path: {:?}", cow_path ); + + // Test with &Utf8PathBuf + let utf8_path_buf = Utf8PathBuf::from( "/utf8/pathbuf" ); + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( &utf8_path_buf ).unwrap(); + println!( "Cow from &Utf8PathBuf: {:?}", cow_path ); + + // Test with Utf8PathBuf + let cow_path : Cow< '_ , Path > = TryIntoCowPath::try_into_cow_path( utf8_path_buf.clone() ).unwrap(); + println!( "Cow from Utf8PathBuf: {:?}", cow_path ); + } +} diff --git a/module/core/pth/tests/inc/try_into_path_test.rs b/module/core/pth/tests/inc/try_into_path_test.rs new file mode 100644 index 0000000000..b7623d5c60 --- /dev/null +++ b/module/core/pth/tests/inc/try_into_path_test.rs @@ -0,0 +1,117 @@ +use super::*; + +#[ test ] +fn try_into_path_test() +{ + use std::path::{ Component, Path, PathBuf }; + #[ cfg( feature = "path_utf8" ) ] + use the_module::{ Utf8Path, Utf8PathBuf }; + use the_module::{ TryIntoPath, AbsolutePath, CanonicalPath, NativePath, CurrentPath }; + + // Test with &str + let path_str : &str = "/some/path"; + let path_buf : PathBuf = TryIntoPath::try_into_path( path_str ).unwrap(); + println!( "PathBuf from &str: {:?}", path_buf ); + + // Test with &String + let string_path : String = String::from( "/another/path" ); + let path_buf : PathBuf = TryIntoPath::try_into_path( &string_path ).unwrap(); + println!( "PathBuf from &String: {:?}", path_buf ); + + // Test with String + let path_buf : PathBuf = TryIntoPath::try_into_path( string_path.clone() ).unwrap(); + println!( "PathBuf from String: {:?}", path_buf ); + + // Test with &Path + let path : &Path = Path::new( "/yet/another/path" ); + let path_buf : PathBuf = TryIntoPath::try_into_path( path ).unwrap(); + println!( "PathBuf from &Path: {:?}", path_buf ); + + // Test with &PathBuf + let path_buf_instance : PathBuf = PathBuf::from( "/yet/another/path" ); + let path_buf : PathBuf = TryIntoPath::try_into_path( &path_buf_instance ).unwrap(); + println!( "PathBuf from &PathBuf: {:?}", path_buf ); + + // Test with PathBuf + let path_buf : PathBuf = TryIntoPath::try_into_path( path_buf_instance.clone() ).unwrap(); + println!( "PathBuf from PathBuf: {:?}", path_buf ); + + // Test with &AbsolutePath + let absolute_path : AbsolutePath = AbsolutePath::try_from( "/absolute/path" ).unwrap(); + let path_buf : PathBuf = TryIntoPath::try_into_path( &absolute_path ).unwrap(); + println!( "PathBuf from &AbsolutePath: {:?}", path_buf ); + + // Test with AbsolutePath + let path_buf : PathBuf = TryIntoPath::try_into_path( absolute_path.clone() ).unwrap(); + println!( "PathBuf from AbsolutePath: {:?}", path_buf ); + + // Test with &CanonicalPath + let canonical_path = CanonicalPath::try_from( "/canonical/path" ).unwrap(); + let path_buf : PathBuf = TryIntoPath::try_into_path( &canonical_path ).unwrap(); + println!( "PathBuf from &CanonicalPath: {:?}", path_buf ); + + // Test with CanonicalPath + let path_buf : PathBuf = TryIntoPath::try_into_path( canonical_path.clone() ).unwrap(); + println!( "PathBuf from CanonicalPath: {:?}", path_buf ); + + // Test with &NativePath + let native_path = NativePath::try_from( PathBuf::from( "/native/path" ) ).unwrap(); + let path_buf : PathBuf = TryIntoPath::try_into_path( &native_path ).unwrap(); + println!( "PathBuf from &NativePath: {:?}", path_buf ); + + // Test with NativePath + let path_buf : PathBuf = TryIntoPath::try_into_path( native_path.clone() ).unwrap(); + println!( "PathBuf from NativePath: {:?}", path_buf ); + + // Test with &CurrentPath + let current_path = CurrentPath; + let path_buf : PathBuf = TryIntoPath::try_into_path( ¤t_path ).unwrap(); + println!( "PathBuf from &CurrentPath: {:?}", path_buf ); + assert!( path_buf.to_string_lossy().len() > 1 ); + + // Test with CurrentPath + let path_buf : PathBuf = TryIntoPath::try_into_path( current_path ).unwrap(); + println!( "PathBuf from CurrentPath: {:?}", path_buf ); + assert!( path_buf.to_string_lossy().len() > 1 ); + + // Test with &Component + let root_component : Component< '_ > = Component::RootDir; + let path_buf : PathBuf = TryIntoPath::try_into_path( &root_component ).unwrap(); + println!( "PathBuf from &Component: {:?}", path_buf ); + assert!( path_buf.to_string_lossy().len() >= 1 ); + + // Test with Component + let path_buf : PathBuf = TryIntoPath::try_into_path( root_component ).unwrap(); + println!( "PathBuf from Component: {:?}", path_buf ); + assert!( path_buf.to_string_lossy().len() >= 1 ); + + // Test with Component + let path = Path::new( "/component/path" ); + for component in path.components() + { + let path_buf : PathBuf = TryIntoPath::try_into_path( component ).unwrap(); + println!( "PathBuf from Component: {:?}", path_buf ); + assert!( path_buf.to_string_lossy().len() >= 1 ); + } + + #[ cfg( feature = "path_utf8" ) ] + { + // Test with &Utf8Path + let utf8_path = Utf8Path::new( "/utf8/path" ); + let path_buf : PathBuf = TryIntoPath::try_into_path( &utf8_path ).unwrap(); + println!( "PathBuf from &Utf8Path: {:?}", path_buf ); + + // Test with Utf8Path + let path_buf : PathBuf = TryIntoPath::try_into_path( utf8_path ).unwrap(); + println!( "PathBuf from Utf8Path: {:?}", path_buf ); + + // Test with &Utf8PathBuf + let utf8_path_buf = Utf8PathBuf::from( "/utf8/pathbuf" ); + let path_buf : PathBuf = TryIntoPath::try_into_path( &utf8_path_buf ).unwrap(); + println!( "PathBuf from &Utf8PathBuf: {:?}", path_buf ); + + // Test with Utf8PathBuf + let path_buf : PathBuf = TryIntoPath::try_into_path( utf8_path_buf.clone() ).unwrap(); + println!( "PathBuf from Utf8PathBuf: {:?}", path_buf ); + } +} diff --git a/module/core/proper_path_tools/tests/inc/without_ext.rs b/module/core/pth/tests/inc/without_ext.rs similarity index 100% rename from module/core/proper_path_tools/tests/inc/without_ext.rs rename to module/core/pth/tests/inc/without_ext.rs diff --git a/module/core/pth/tests/smoke_test.rs b/module/core/pth/tests/smoke_test.rs new file mode 100644 index 0000000000..828e9b016b --- /dev/null +++ b/module/core/pth/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/pth/tests/tests.rs b/module/core/pth/tests/tests.rs new file mode 100644 index 0000000000..49fa343161 --- /dev/null +++ b/module/core/pth/tests/tests.rs @@ -0,0 +1,9 @@ +#![ allow( unused_imports ) ] + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +use pth as the_module; +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/core/reflect_tools/License b/module/core/reflect_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/reflect_tools/License +++ b/module/core/reflect_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/reflect_tools/src/reflect.rs b/module/core/reflect_tools/src/reflect.rs index 0cde174ac9..3d363b1c09 100644 --- a/module/core/reflect_tools/src/reflect.rs +++ b/module/core/reflect_tools/src/reflect.rs @@ -52,7 +52,7 @@ // qqq : make the example working. use tests for inpsisrations -/// Internal namespace. +/// Define a private namespace for all its items. mod private { } diff --git a/module/core/reflect_tools/src/reflect/axiomatic.rs b/module/core/reflect_tools/src/reflect/axiomatic.rs index dcc6f044c8..2a092dfd0b 100644 --- a/module/core/reflect_tools/src/reflect/axiomatic.rs +++ b/module/core/reflect_tools/src/reflect/axiomatic.rs @@ -4,7 +4,7 @@ use super::*; -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use super::*; diff --git a/module/core/reflect_tools/src/reflect/entity_array.rs b/module/core/reflect_tools/src/reflect/entity_array.rs index afe3363b7c..3a9e592116 100644 --- a/module/core/reflect_tools/src/reflect/entity_array.rs +++ b/module/core/reflect_tools/src/reflect/entity_array.rs @@ -4,7 +4,7 @@ use super::*; -/// Internal namespace. +/// Define a private namespace for all its items. pub mod private { use super::*; diff --git a/module/core/reflect_tools/src/reflect/entity_hashmap.rs b/module/core/reflect_tools/src/reflect/entity_hashmap.rs index 97d9a821c9..21f7a04f35 100644 --- a/module/core/reflect_tools/src/reflect/entity_hashmap.rs +++ b/module/core/reflect_tools/src/reflect/entity_hashmap.rs @@ -4,7 +4,7 @@ use super::*; -/// Internal namespace. +/// Define a private namespace for all its items. pub mod private { use super::*; diff --git a/module/core/reflect_tools/src/reflect/entity_hashset.rs b/module/core/reflect_tools/src/reflect/entity_hashset.rs index ba48a7a189..84803f0c77 100644 --- a/module/core/reflect_tools/src/reflect/entity_hashset.rs +++ b/module/core/reflect_tools/src/reflect/entity_hashset.rs @@ -4,7 +4,7 @@ use super::*; -/// Internal namespace. +/// Define a private namespace for all its items. pub mod private { use super::*; diff --git a/module/core/reflect_tools/src/reflect/entity_slice.rs b/module/core/reflect_tools/src/reflect/entity_slice.rs index e396f8bcf9..1584c874f2 100644 --- a/module/core/reflect_tools/src/reflect/entity_slice.rs +++ b/module/core/reflect_tools/src/reflect/entity_slice.rs @@ -4,7 +4,7 @@ use super::*; -/// Internal namespace. +/// Define a private namespace for all its items. pub mod private { use super::*; diff --git a/module/core/reflect_tools/src/reflect/entity_vec.rs b/module/core/reflect_tools/src/reflect/entity_vec.rs index c559136729..ec74a41b00 100644 --- a/module/core/reflect_tools/src/reflect/entity_vec.rs +++ b/module/core/reflect_tools/src/reflect/entity_vec.rs @@ -4,7 +4,7 @@ use super::*; -/// Internal namespace. +/// Define a private namespace for all its items. pub mod private { use super::*; diff --git a/module/core/reflect_tools/src/reflect/fields.rs b/module/core/reflect_tools/src/reflect/fields.rs index 428c95237b..811b9835d2 100644 --- a/module/core/reflect_tools/src/reflect/fields.rs +++ b/module/core/reflect_tools/src/reflect/fields.rs @@ -2,7 +2,7 @@ //! Iterator over fields. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { @@ -112,6 +112,10 @@ mod private mod vec; mod hmap; mod bmap; +mod hset; +mod bset; +mod deque; +mod llist; #[ doc( inline ) ] #[ allow( unused_imports ) ] diff --git a/module/core/reflect_tools/src/reflect/fields/bset.rs b/module/core/reflect_tools/src/reflect/fields/bset.rs new file mode 100644 index 0000000000..e68d4d7e4b --- /dev/null +++ b/module/core/reflect_tools/src/reflect/fields/bset.rs @@ -0,0 +1,65 @@ +//! +//! Implement fields for BTreeSet. +//! + +use crate::*; +use std::borrow::Cow; +use collection_tools::BTreeSet; + +impl< V, Borrowed > Fields< usize, &'_ Borrowed > for BTreeSet< V > +where + Borrowed : std::borrow::ToOwned + 'static + ?Sized, + V : std::borrow::Borrow< Borrowed >, +{ + + type Key< 'k > = usize + where Self : 'k, usize : 'k; + + type Val< 'v > = &'v Borrowed + where Self : 'v, V : 'v; + + fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > + { + self.iter().enumerate().map( move | ( key, val ) | ( key, val.borrow() ) ) + } + +} + +impl< V, Borrowed > Fields< usize, Option< Cow< '_, Borrowed > > > for BTreeSet< V > +where + Borrowed : std::borrow::ToOwned + 'static + ?Sized, + V : std::borrow::Borrow< Borrowed >, +{ + + type Key< 'k > = usize + where Self : 'k, usize : 'k; + + type Val< 'v > = Option< Cow< 'v, Borrowed > > + where Self : 'v; + + fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > + { + self.iter().enumerate().map( move | ( key, val ) | ( key, Some( Cow::Borrowed( val.borrow() ) ) ) ) + } + +} + +impl< V, Borrowed, Marker > Fields< usize, OptionalCow< '_, Borrowed, Marker > > for BTreeSet< V > +where + Borrowed : std::borrow::ToOwned + 'static + ?Sized, + V : std::borrow::Borrow< Borrowed >, + Marker : Clone + Copy + 'static, +{ + + type Key< 'k > = usize + where Self : 'k, usize : 'k; + + type Val< 'v > = OptionalCow< 'v, Borrowed, Marker > + where Self : 'v; + + fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > + { + self.iter().enumerate().map( move | ( key, val ) | ( key, OptionalCow::from( val.borrow() ) ) ) + } + +} diff --git a/module/core/reflect_tools/src/reflect/fields/deque.rs b/module/core/reflect_tools/src/reflect/fields/deque.rs new file mode 100644 index 0000000000..734255ad1a --- /dev/null +++ b/module/core/reflect_tools/src/reflect/fields/deque.rs @@ -0,0 +1,65 @@ +//! +//! Implement fields for Deque. +//! + +use crate::*; +use std::borrow::Cow; +use collection_tools::VecDeque; + +impl< V, Borrowed > Fields< usize, &'_ Borrowed > for VecDeque< V > +where + Borrowed : std::borrow::ToOwned + 'static + ?Sized, + V : std::borrow::Borrow< Borrowed >, +{ + + type Key< 'k > = usize + where Self : 'k, usize : 'k; + + type Val< 'v > = &'v Borrowed + where Self : 'v, V : 'v; + + fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > + { + self.iter().enumerate().map( move | ( key, val ) | ( key, val.borrow() ) ) + } + +} + +impl< V, Borrowed > Fields< usize, Option< Cow< '_, Borrowed > > > for VecDeque< V > +where + Borrowed : std::borrow::ToOwned + 'static + ?Sized, + V : std::borrow::Borrow< Borrowed >, +{ + + type Key< 'k > = usize + where Self : 'k, usize : 'k; + + type Val< 'v > = Option< Cow< 'v, Borrowed > > + where Self : 'v; + + fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > + { + self.iter().enumerate().map( move | ( key, val ) | ( key, Some( Cow::Borrowed( val.borrow() ) ) ) ) + } + +} + +impl< V, Borrowed, Marker > Fields< usize, OptionalCow< '_, Borrowed, Marker > > for VecDeque< V > +where + Borrowed : std::borrow::ToOwned + 'static + ?Sized, + V : std::borrow::Borrow< Borrowed >, + Marker : Clone + Copy + 'static, +{ + + type Key< 'k > = usize + where Self : 'k, usize : 'k; + + type Val< 'v > = OptionalCow< 'v, Borrowed, Marker > + where Self : 'v; + + fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > + { + self.iter().enumerate().map( move | ( key, val ) | ( key, OptionalCow::from( val.borrow() ) ) ) + } + +} diff --git a/module/core/reflect_tools/src/reflect/fields/hset.rs b/module/core/reflect_tools/src/reflect/fields/hset.rs new file mode 100644 index 0000000000..cfc01be06e --- /dev/null +++ b/module/core/reflect_tools/src/reflect/fields/hset.rs @@ -0,0 +1,65 @@ +//! +//! Implement fields for HashSet. +//! + +use crate::*; +use std::borrow::Cow; +use std::collections::HashSet; + +impl< V, Borrowed > Fields< usize, &'_ Borrowed > for HashSet< V > +where + Borrowed : std::borrow::ToOwned + 'static + ?Sized, + V : std::borrow::Borrow< Borrowed >, +{ + + type Key< 'k > = usize + where Self : 'k, usize : 'k; + + type Val< 'v > = &'v Borrowed + where Self : 'v, V : 'v; + + fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > + { + self.iter().enumerate().map( move | ( key, val ) | ( key, val.borrow() ) ) + } + +} + +impl< V, Borrowed > Fields< usize, Option< Cow< '_, Borrowed > > > for HashSet< V > +where + Borrowed : std::borrow::ToOwned + 'static + ?Sized, + V : std::borrow::Borrow< Borrowed >, +{ + + type Key< 'k > = usize + where Self : 'k, usize : 'k; + + type Val< 'v > = Option< Cow< 'v, Borrowed > > + where Self : 'v; + + fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > + { + self.iter().enumerate().map( move | ( key, val ) | ( key, Some( Cow::Borrowed( val.borrow() ) ) ) ) + } + +} + +impl< V, Borrowed, Marker > Fields< usize, OptionalCow< '_, Borrowed, Marker > > for HashSet< V > +where + Borrowed : std::borrow::ToOwned + 'static + ?Sized, + V : std::borrow::Borrow< Borrowed >, + Marker : Clone + Copy + 'static, +{ + + type Key< 'k > = usize + where Self : 'k, usize : 'k; + + type Val< 'v > = OptionalCow< 'v, Borrowed, Marker > + where Self : 'v; + + fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > + { + self.iter().enumerate().map( move | ( key, val ) | ( key, OptionalCow::from( val.borrow() ) ) ) + } + +} diff --git a/module/core/reflect_tools/src/reflect/fields/llist.rs b/module/core/reflect_tools/src/reflect/fields/llist.rs new file mode 100644 index 0000000000..40ca1ced98 --- /dev/null +++ b/module/core/reflect_tools/src/reflect/fields/llist.rs @@ -0,0 +1,65 @@ +//! +//! Implement fields for LinkedList. +//! + +use crate::*; +use std::borrow::Cow; +use collection_tools::LinkedList; + +impl< V, Borrowed > Fields< usize, &'_ Borrowed > for LinkedList< V > +where + Borrowed : std::borrow::ToOwned + 'static + ?Sized, + V : std::borrow::Borrow< Borrowed >, +{ + + type Key< 'k > = usize + where Self : 'k, usize : 'k; + + type Val< 'v > = &'v Borrowed + where Self : 'v, V : 'v; + + fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > + { + self.iter().enumerate().map( move | ( key, val ) | ( key, val.borrow() ) ) + } + +} + +impl< V, Borrowed > Fields< usize, Option< Cow< '_, Borrowed > > > for LinkedList< V > +where + Borrowed : std::borrow::ToOwned + 'static + ?Sized, + V : std::borrow::Borrow< Borrowed >, +{ + + type Key< 'k > = usize + where Self : 'k, usize : 'k; + + type Val< 'v > = Option< Cow< 'v, Borrowed > > + where Self : 'v; + + fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > + { + self.iter().enumerate().map( move | ( key, val ) | ( key, Some( Cow::Borrowed( val.borrow() ) ) ) ) + } + +} + +impl< V, Borrowed, Marker > Fields< usize, OptionalCow< '_, Borrowed, Marker > > for LinkedList< V > +where + Borrowed : std::borrow::ToOwned + 'static + ?Sized, + V : std::borrow::Borrow< Borrowed >, + Marker : Clone + Copy + 'static, +{ + + type Key< 'k > = usize + where Self : 'k, usize : 'k; + + type Val< 'v > = OptionalCow< 'v, Borrowed, Marker > + where Self : 'v; + + fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > + { + self.iter().enumerate().map( move | ( key, val ) | ( key, OptionalCow::from( val.borrow() ) ) ) + } + +} diff --git a/module/core/reflect_tools/src/reflect/fields/vec.rs b/module/core/reflect_tools/src/reflect/fields/vec.rs index bdf3977601..0a18259738 100644 --- a/module/core/reflect_tools/src/reflect/fields/vec.rs +++ b/module/core/reflect_tools/src/reflect/fields/vec.rs @@ -9,6 +9,7 @@ use collection_tools::Vec; impl< V, Borrowed > Fields< usize, &'_ Borrowed > for Vec< V > where Borrowed : std::borrow::ToOwned + 'static + ?Sized, + // Borrowed : ?Sized + 'static, V : std::borrow::Borrow< Borrowed >, { @@ -28,6 +29,7 @@ where impl< V, Borrowed > Fields< usize, Option< Cow< '_, Borrowed > > > for Vec< V > where Borrowed : std::borrow::ToOwned + 'static + ?Sized, + // Borrowed : ?Sized + 'static, V : std::borrow::Borrow< Borrowed >, { @@ -39,6 +41,7 @@ where fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) > { + // self.iter().enumerate().map( move | ( key, val ) | ( key, Some( Cow::Borrowed( &val ) ) ) ) self.iter().enumerate().map( move | ( key, val ) | ( key, Some( Cow::Borrowed( val.borrow() ) ) ) ) } @@ -47,6 +50,7 @@ where impl< V, Borrowed, Marker > Fields< usize, OptionalCow< '_, Borrowed, Marker > > for Vec< V > where Borrowed : std::borrow::ToOwned + 'static + ?Sized, + // Borrowed : ?Sized + 'static, V : std::borrow::Borrow< Borrowed >, Marker : Clone + Copy + 'static, { diff --git a/module/core/reflect_tools/src/reflect/primitive.rs b/module/core/reflect_tools/src/reflect/primitive.rs index 986291afb8..23ce9a125e 100644 --- a/module/core/reflect_tools/src/reflect/primitive.rs +++ b/module/core/reflect_tools/src/reflect/primitive.rs @@ -2,7 +2,7 @@ //! Define primitive and data types. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/core/reflect_tools/src/reflect/wrapper.rs b/module/core/reflect_tools/src/reflect/wrapper.rs index defbe192f1..8481bce1c7 100644 --- a/module/core/reflect_tools/src/reflect/wrapper.rs +++ b/module/core/reflect_tools/src/reflect/wrapper.rs @@ -2,12 +2,12 @@ //! Collection of wrappers. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { } -mod maybe_as; +mod optional_cow; #[ doc( inline ) ] #[ allow( unused_imports ) ] @@ -40,7 +40,7 @@ pub mod exposed #[ allow( unused_imports ) ] pub use super:: { - maybe_as::OptionalCow, + optional_cow::OptionalCow, }; } diff --git a/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs b/module/core/reflect_tools/src/reflect/wrapper/optional_cow.rs similarity index 88% rename from module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs rename to module/core/reflect_tools/src/reflect/wrapper/optional_cow.rs index f1351f8c92..5f329cc459 100644 --- a/module/core/reflect_tools/src/reflect/wrapper/maybe_as.rs +++ b/module/core/reflect_tools/src/reflect/wrapper/optional_cow.rs @@ -20,6 +20,19 @@ where Marker : Clone + Copy + 'static, { + /// Creates owned data from borrowed data, usually by cloning. + #[ inline( always ) ] + pub fn into_owned( &self ) -> < T as std::borrow::ToOwned >::Owned + where + < T as std::borrow::ToOwned >::Owned : Default, + { + match self.0.as_ref() + { + Some( c ) => c.clone().into_owned(), + None => < T as std::borrow::ToOwned >::Owned::default(), + } + } + /// Check is it borrowed. #[ inline( always ) ] pub fn is_borrowed( &self ) -> bool @@ -212,3 +225,15 @@ where T : Eq, { } + +impl< 'a, T, Marker > From< OptionalCow< 'a, T, Marker > > for Option< Cow< 'a, T > > +where + T : std::borrow::ToOwned + ?Sized, + Marker : Clone + Copy + 'static, +{ + #[ inline( always ) ] + fn from( src : OptionalCow< 'a, T, Marker > ) -> Self + { + src.0 + } +} diff --git a/module/core/reflect_tools/tests/inc/fundamental/fields_bset.rs b/module/core/reflect_tools/tests/inc/fundamental/fields_bset.rs new file mode 100644 index 0000000000..abaee19fd5 --- /dev/null +++ b/module/core/reflect_tools/tests/inc/fundamental/fields_bset.rs @@ -0,0 +1,60 @@ +#[ allow( unused_imports ) ] +use super::*; + +use the_module:: +{ + Fields, +}; + +// xxx : implement for other collections + +use std:: +{ + borrow::Cow, +}; + +#[ test ] +fn bset_string_fields() +{ + let collection : BTreeSet< String > = bset! + [ + "a".to_string(), + "b".to_string(), + ]; + + // k, v + let got : BTreeSet< _ > = Fields::< usize, &str >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = bset![ ( 0, "a" ), ( 1, "b" ) ]; + assert_eq!( got, exp ); + + // k, Option< Cow< '_, str > > + let got : BTreeSet< _ > = Fields::< usize, Option< Cow< '_, str > > >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = bset![ ( 0, Some( Cow::Borrowed( "a" ) ) ), ( 1, Some( Cow::Borrowed( "b" ) ) ) ]; + assert_eq!( got, exp ); + +} + +#[ test ] +fn bset_str_fields() +{ + let collection : BTreeSet< &str > = bset! + [ + "a", + "b", + ]; + + // k, v + let got : BTreeSet< _ > = Fields::< usize, &str >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = bset![ ( 0, "a" ), ( 1, "b" ) ]; + assert_eq!( got, exp ); + + // k, Option< Cow< '_, str > > + let got : BTreeSet< _ > = Fields::< usize, Option< Cow< '_, str > > >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = bset![ ( 0, Some( Cow::Borrowed( "a" ) ) ), ( 1, Some( Cow::Borrowed( "b" ) ) ) ]; + assert_eq!( got, exp ); + +} diff --git a/module/core/reflect_tools/tests/inc/fundamental/fields_deque.rs b/module/core/reflect_tools/tests/inc/fundamental/fields_deque.rs new file mode 100644 index 0000000000..190d8fc57b --- /dev/null +++ b/module/core/reflect_tools/tests/inc/fundamental/fields_deque.rs @@ -0,0 +1,73 @@ +#[ allow( unused_imports ) ] +use super::*; + +use the_module:: +{ + Fields, + OptionalCow, +}; + +// xxx : implement for other collections + +use std:: +{ + borrow::Cow, +}; + +#[ test ] +fn deque_string_fields() +{ + let collection = deque! + [ + "a".to_string(), + "b".to_string(), + ]; + + // k, v + let got : VecDeque< _ > = Fields::< usize, &str >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = deque![ ( 0, "a" ), ( 1, "b" ) ]; + assert_eq!( got, exp ); + + // k, Option< Cow< '_, str > > + let got : VecDeque< _ > = Fields::< usize, Option< Cow< '_, str > > >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = deque![ ( 0, Some( Cow::Borrowed( "a" ) ) ), ( 1, Some( Cow::Borrowed( "b" ) ) ) ]; + assert_eq!( got, exp ); + + // k, OptionalCow< '_, str, () > + let got : VecDeque< _ > = Fields::< usize, OptionalCow< '_, str, () > >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = deque![ ( 0, OptionalCow::from( "a" ) ), ( 1, OptionalCow::from( "b" ) ) ]; + assert_eq!( got, exp ); + +} + +#[ test ] +fn deque_str_fields() +{ + let collection = deque! + [ + "a", + "b", + ]; + + // k, v + let got : VecDeque< _ > = Fields::< usize, &str >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = deque![ ( 0, "a" ), ( 1, "b" ) ]; + assert_eq!( got, exp ); + + // k, Option< Cow< '_, str > > + let got : VecDeque< _ > = Fields::< usize, Option< Cow< '_, str > > >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = deque![ ( 0, Some( Cow::Borrowed( "a" ) ) ), ( 1, Some( Cow::Borrowed( "b" ) ) ) ]; + assert_eq!( got, exp ); + + // k, OptionalCow< '_, str, () > + let got : VecDeque< _ > = Fields::< usize, OptionalCow< '_, str, () > >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = deque![ ( 0, OptionalCow::from( "a" ) ), ( 1, OptionalCow::from( "b" ) ) ]; + assert_eq!( got, exp ); + +} diff --git a/module/core/reflect_tools/tests/inc/fundamental/fields_hset.rs b/module/core/reflect_tools/tests/inc/fundamental/fields_hset.rs new file mode 100644 index 0000000000..fddc44dc94 --- /dev/null +++ b/module/core/reflect_tools/tests/inc/fundamental/fields_hset.rs @@ -0,0 +1,60 @@ +#[ allow( unused_imports ) ] +use super::*; + +use the_module:: +{ + Fields, +}; + +// xxx : implement for other collections + +use std:: +{ + borrow::Cow, +}; + +#[ test ] +fn hset_string_fields() +{ + let collection : HashSet< String > = hset! + [ + "a".to_string(), + "b".to_string(), + ]; + + // k, v + let got : HashSet< _ > = Fields::< usize, &str >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + assert!( got.contains(&( 0, "a" ) ) || got.contains(&( 1, "a" ) ) ); + assert!( got.contains(&( 0, "b" ) ) || got.contains(&( 1, "b" ) ) ); + + // k, Option< Cow< '_, str > > + let got : HashSet< _ > = Fields::< usize, Option< Cow< '_, str > > >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + assert!( got.contains(&( 0, Some( Cow::Borrowed( "a" ) ) ) ) || got.contains(&( 1, Some( Cow::Borrowed( "a" ) ) ) ) ); + assert!( got.contains(&( 0, Some( Cow::Borrowed( "b" ) ) ) ) || got.contains(&( 1, Some( Cow::Borrowed( "b" ) ) ) ) ); + +} + +#[ test ] +fn hset_str_fields() +{ + let collection : HashSet< &str > = hset! + [ + "a", + "b", + ]; + + // k, v + let got : HashSet< _ > = Fields::< usize, &str >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + assert!( got.contains(&( 0, "a" ) ) || got.contains(&( 1, "a" ) ) ); + assert!( got.contains(&( 0, "b" ) ) || got.contains(&( 1, "b" ) ) ); + + // k, Option< Cow< '_, str > > + let got : HashSet< _ > = Fields::< usize, Option< Cow< '_, str > > >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + assert!( got.contains(&( 0, Some( Cow::Borrowed( "a" ) ) ) ) || got.contains(&( 1, Some( Cow::Borrowed( "a" ) ) ) ) ); + assert!( got.contains(&( 0, Some( Cow::Borrowed( "b" ) ) ) ) || got.contains(&( 1, Some( Cow::Borrowed( "b" ) ) ) ) ); + +} diff --git a/module/core/reflect_tools/tests/inc/fundamental/fields_llist.rs b/module/core/reflect_tools/tests/inc/fundamental/fields_llist.rs new file mode 100644 index 0000000000..dc93d87c0a --- /dev/null +++ b/module/core/reflect_tools/tests/inc/fundamental/fields_llist.rs @@ -0,0 +1,73 @@ +#[ allow( unused_imports ) ] +use super::*; + +use the_module:: +{ + Fields, + OptionalCow, +}; + +// xxx : implement for other collections + +use std:: +{ + borrow::Cow, +}; + +#[ test ] +fn llist_string_fields() +{ + let collection = llist! + [ + "a".to_string(), + "b".to_string(), + ]; + + // k, v + let got : LinkedList< _ > = Fields::< usize, &str >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = llist![ ( 0, "a" ), ( 1, "b" ) ]; + assert_eq!( got, exp ); + + // k, Option< Cow< '_, str > > + let got : LinkedList< _ > = Fields::< usize, Option< Cow< '_, str > > >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = llist![ ( 0, Some( Cow::Borrowed( "a" ) ) ), ( 1, Some( Cow::Borrowed( "b" ) ) ) ]; + assert_eq!( got, exp ); + + // k, OptionalCow< '_, str, () > + let got : LinkedList< _ > = Fields::< usize, OptionalCow< '_, str, () > >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = llist![ ( 0, OptionalCow::from( "a" ) ), ( 1, OptionalCow::from( "b" ) ) ]; + assert_eq!( got, exp ); + +} + +#[ test ] +fn llist_str_fields() +{ + let collection = llist! + [ + "a", + "b", + ]; + + // k, v + let got : LinkedList< _ > = Fields::< usize, &str >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = llist![ ( 0, "a" ), ( 1, "b" ) ]; + assert_eq!( got, exp ); + + // k, Option< Cow< '_, str > > + let got : LinkedList< _ > = Fields::< usize, Option< Cow< '_, str > > >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = llist![ ( 0, Some( Cow::Borrowed( "a" ) ) ), ( 1, Some( Cow::Borrowed( "b" ) ) ) ]; + assert_eq!( got, exp ); + + // k, OptionalCow< '_, str, () > + let got : LinkedList< _ > = Fields::< usize, OptionalCow< '_, str, () > >::fields( &collection ).collect(); + assert_eq!( got.len(), 2 ); + let exp = llist![ ( 0, OptionalCow::from( "a" ) ), ( 1, OptionalCow::from( "b" ) ) ]; + assert_eq!( got, exp ); + +} diff --git a/module/core/reflect_tools/tests/inc/mod.rs b/module/core/reflect_tools/tests/inc/mod.rs index de4b0b494e..d0ec8fff41 100644 --- a/module/core/reflect_tools/tests/inc/mod.rs +++ b/module/core/reflect_tools/tests/inc/mod.rs @@ -12,6 +12,10 @@ mod fundamental mod fields_vec; mod fields_hmap; mod fields_bmap; + mod fields_bset; + mod fields_deque; + mod fields_hset; + mod fields_llist; } diff --git a/module/core/reflect_tools_meta/License b/module/core/reflect_tools_meta/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/reflect_tools_meta/License +++ b/module/core/reflect_tools_meta/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/reflect_tools_meta/src/implementation/reflect.rs b/module/core/reflect_tools_meta/src/implementation/reflect.rs index 34d239b8d9..04799d0a5a 100644 --- a/module/core/reflect_tools_meta/src/implementation/reflect.rs +++ b/module/core/reflect_tools_meta/src/implementation/reflect.rs @@ -1,7 +1,7 @@ // use macro_tools::proc_macro2::TokenStream; use crate::*; -use macro_tools::{ Result, attr, diag }; +use macro_tools::{ Result, attr, diag, qt, proc_macro2, syn }; // diff --git a/module/core/strs_tools/Cargo.toml b/module/core/strs_tools/Cargo.toml index 507791fffb..37b6231be0 100644 --- a/module/core/strs_tools/Cargo.toml +++ b/module/core/strs_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strs_tools" -version = "0.16.0" +version = "0.18.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/strs_tools/License b/module/core/strs_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/strs_tools/License +++ b/module/core/strs_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/strs_tools/src/string/indentation.rs b/module/core/strs_tools/src/string/indentation.rs index b4574f3fbc..59c29951eb 100644 --- a/module/core/strs_tools/src/string/indentation.rs +++ b/module/core/strs_tools/src/string/indentation.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/core/strs_tools/src/string/number.rs b/module/core/strs_tools/src/string/number.rs index 69f8b2c0d1..1a0df1c3ad 100644 --- a/module/core/strs_tools/src/string/number.rs +++ b/module/core/strs_tools/src/string/number.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { } diff --git a/module/core/strs_tools/src/string/parse_request.rs b/module/core/strs_tools/src/string/parse_request.rs index 432b2098b6..44e215d15d 100644 --- a/module/core/strs_tools/src/string/parse_request.rs +++ b/module/core/strs_tools/src/string/parse_request.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/core/strs_tools/tests/inc/number_test.rs b/module/core/strs_tools/tests/inc/number_test.rs index cc8bf03006..2c03f223d1 100644 --- a/module/core/strs_tools/tests/inc/number_test.rs +++ b/module/core/strs_tools/tests/inc/number_test.rs @@ -1,5 +1,4 @@ use super::*; - // tests_impls! @@ -10,43 +9,43 @@ tests_impls! /* test.case( "parse" ); */ { - a_id!( the_module::number::parse::< f32, _ >( "1.0" ), Ok( 1.0 ) ); + a_id!( crate::the_module::string::number::parse::< f32, _ >( "1.0" ), Ok( 1.0 ) ); } /* test.case( "parse_partial" ); */ { - a_id!( the_module::number::parse_partial::< i32, _ >( "1a" ), Ok( ( 1, 1 ) ) ); + a_id!( crate::the_module::string::number::parse_partial::< i32, _ >( "1a" ), Ok( ( 1, 1 ) ) ); } /* test.case( "parse_partial_with_options" ); */ { - const FORMAT : u128 = the_module::number::format::STANDARD; - let options = the_module::number::ParseFloatOptions::builder() + const FORMAT : u128 = crate::the_module::string::number::format::STANDARD; + let options = crate::the_module::string::number::ParseFloatOptions::builder() .exponent( b'^' ) .decimal_point( b',' ) .build() .unwrap(); - let got = the_module::number::parse_partial_with_options::< f32, _, FORMAT >( "0", &options ); + let got = crate::the_module::string::number::parse_partial_with_options::< f32, _, FORMAT >( "0", &options ); let exp = Ok( ( 0.0, 1 ) ); a_id!( got, exp ); } /* test.case( "parse_with_options" ); */ { - const FORMAT: u128 = the_module::number::format::STANDARD; - let options = the_module::number::ParseFloatOptions::builder() + const FORMAT: u128 = crate::the_module::string::number::format::STANDARD; + let options = crate::the_module::string::number::ParseFloatOptions::builder() .exponent( b'^' ) .decimal_point( b',' ) .build() .unwrap(); - let got = the_module::number::parse_with_options::< f32, _, FORMAT >( "1,2345", &options ); + let got = crate::the_module::string::number::parse_with_options::< f32, _, FORMAT >( "1,2345", &options ); let exp = Ok( 1.2345 ); a_id!( got, exp ); } /* test.case( "to_string" ); */ { - a_id!( the_module::number::to_string( 5 ), "5" ); + a_id!( crate::the_module::string::number::to_string( 5 ), "5" ); } } diff --git a/module/core/test_tools/Cargo.toml b/module/core/test_tools/Cargo.toml index 2093e6b0b2..4f17161640 100644 --- a/module/core/test_tools/Cargo.toml +++ b/module/core/test_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test_tools" -version = "0.9.0" +version = "0.11.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -24,13 +24,15 @@ workspace = true features = [ "full" ] all-features = false - - # = features [features] -default = [ "enabled" ] -full = [ "enabled" ] +default = [ + "enabled", + # "standalone", + "normal", +] +full = [ "default" ] no_std = [ # "error_tools/no_std", # "meta_tools/no_std", @@ -53,39 +55,80 @@ use_alloc = [ # "former_stable/use_alloc", ] enabled = [ - "error_tools/enabled", - "meta_tools/enabled", - "mem_tools/enabled", - "typing_tools/enabled", - "data_type/enabled", - "diagnostics_tools/enabled", - "process_tools_published/enabled", - "collection_tools/enabled", + # "error_tools/enabled", + # "meta_tools/enabled", + # "mem_tools/enabled", + # "typing_tools/enabled", + # "data_type/enabled", + # "diagnostics_tools/enabled", + # "process_tools/enabled", + # "collection_tools/enabled", ] # nightly = [ "typing_tools/nightly" ] +normal = [ + "dep:error_tools", + "dep:collection_tools", + "dep:impls_index", + "dep:mem_tools", + "dep:typing_tools", + "dep:diagnostics_tools", + "dep:process_tools", +] +standalone = [ + "standalone_error_tools", + "standalone_collection_tools", + "standalone_impls_index", + "standalone_mem_tools", + # "dep:mem_tools", + "dep:typing_tools", + "dep:diagnostics_tools", + "dep:process_tools", +] +standalone_error_tools = [ "dep:anyhow", "dep:thiserror", "error_typed", "error_untyped" ] +standalone_collection_tools = [ "dep:hashbrown", "collection_constructors", "collection_into_constructors" ] +standalone_impls_index = [ "dep:impls_index_meta" ] +standalone_mem_tools = [] + +# error_tools +error_typed = [] +error_untyped = [] +# collection_tools +collection_constructors = [] +collection_into_constructors = [] + [dependencies] ## external -paste = "~1.0" # zzz : remove laster -rustversion = "~1.0" -# anyhow = "~1.0" -num-traits = "~0.2" trybuild = { version = "1.0.85", features = [ "diff" ] } -rand = "0.8.5" +rustversion = { workspace = true } +num-traits = { workspace = true } +rand = { workspace = true } +# tempdir = { workspace = true } ## internal -error_tools = { workspace = true, features = [ "full" ] } -meta_tools = { workspace = true, features = [ "full" ] } -mem_tools = { workspace = true, features = [ "full" ] } -typing_tools = { workspace = true, features = [ "full" ] } -data_type = { workspace = true, features = [ "full" ] } -diagnostics_tools = { workspace = true, features = [ "full" ] } -process_tools_published = { workspace = true, features = [ "full" ] } -collection_tools = { workspace = true, features = [ "full" ] } +error_tools = { workspace = true, features = [ "full" ], optional = true } +collection_tools = { workspace = true, features = [ "full" ], optional = true } +impls_index = { workspace = true, features = [ "full" ], optional = true } +mem_tools = { workspace = true, features = [ "full" ], optional = true } + +typing_tools = { workspace = true, features = [ "full" ], optional = true } +diagnostics_tools = { workspace = true, features = [ "full" ], optional = true } +process_tools = { workspace = true, features = [ "full" ], optional = true } + # former_stable = { workspace = true, features = [ "full" ] } +## transient + +# error_tools +anyhow = { workspace = true, optional = true } +thiserror = { workspace = true, optional = true } +# collection_tools +hashbrown = { workspace = true, optional = true } +# impls_index +impls_index_meta = { workspace = true, optional = true } + [build-dependencies] rustc_version = "0.4" diff --git a/module/core/test_tools/License b/module/core/test_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/test_tools/License +++ b/module/core/test_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/test_tools/src/lib.rs b/module/core/test_tools/src/lib.rs index 8baa4d9530..4d1b25124e 100644 --- a/module/core/test_tools/src/lib.rs +++ b/module/core/test_tools/src/lib.rs @@ -6,96 +6,235 @@ /// Namespace with dependencies. +#[ allow( unused_imports ) ] #[ cfg( feature = "enabled" ) ] pub mod dependency { - // zzz : exclude later + // // zzz : exclude later + // #[ doc( inline ) ] + // pub use ::paste; #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use ::paste; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use ::trybuild; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use ::rustversion; - - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use ::error_tools; #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use ::meta_tools; + pub use ::num_traits; + #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use ::mem_tools; + pub use super:: + { + error_tools, + collection_tools, + impls_index, + mem_tools, + typing_tools, + diagnostics_tools, + process_tools, + }; + +} + +mod private {} + +// + +// #[ cfg( feature = "enabled" ) ] +// // #[ cfg( not( feature = "no_std" ) ) ] +// ::meta_tools::mod_interface! +// { +// // #![ debug ] +// +// own use super::dependency::*; +// +// layer test; +// +// // xxx : comment out +// use super::exposed::meta; +// use super::exposed::mem; +// use super::exposed::typing; +// use super::exposed::dt; +// use super::exposed::diagnostics; +// use super::exposed::collection; +// // use super::exposed::process; +// +// // prelude use ::rustversion::{ nightly, stable }; +// +// // // xxx : eliminate need to do such things, putting itself to proper category +// // exposed use super::test::compiletime; +// // exposed use super::test::helper; +// // exposed use super::test::smoke_test; +// +// prelude use ::meta_tools as meta; +// prelude use ::mem_tools as mem; +// prelude use ::typing_tools as typing; +// prelude use ::data_type as dt; +// prelude use ::diagnostics_tools as diagnostics; +// prelude use ::collection_tools as collection; +// // prelude use ::process_tools as process; +// +// use ::collection_tools; // xxx : do that for all dependencies +// +// prelude use ::meta_tools:: +// { +// impls, +// index, +// tests_impls, +// tests_impls_optional, +// tests_index, +// }; +// +// prelude use ::typing_tools::{ implements }; +// +// } + +// xxx : use module namespaces +// #[ cfg( feature = "enabled" ) ] +// #[ cfg( not( feature = "no_std" ) ) ] +// pub use test::{ compiletime, helper, smoke_test }; + +#[ cfg( feature = "enabled" ) ] +pub mod test; + +/// Error tools. +#[ cfg( feature = "enabled" ) ] +#[ cfg( feature = "standalone" ) ] +mod standalone +{ + + /// Error tools. + #[ path = "../../../../core/error_tools/src/error/mod.rs" ] + pub mod error; + pub use error as error_tools; + + /// Collection tools. + #[ path = "../../../../core/collection_tools/src/collection/mod.rs" ] + pub mod collection; + pub use collection as collection_tools; + + /// impl and index macros. + #[ path = "../../../../core/impls_index/src/impls_index/mod.rs" ] + pub mod impls_index; + + /// Memory tools. + #[ path = "../../../../core/mem_tools/src/mem.rs" ] + pub mod mem_tools; + +} + +#[ cfg( feature = "enabled" ) ] +#[ cfg( feature = "standalone" ) ] +pub use standalone::*; + +#[ cfg( feature = "enabled" ) ] +#[ cfg( not( feature = "standalone" ) ) ] +pub use :: +{ + error_tools, + collection_tools, + impls_index, + mem_tools, +}; + +#[ cfg( feature = "enabled" ) ] +pub use :: +{ + typing_tools, + diagnostics_tools, + process_tools, +}; + +#[ cfg( feature = "enabled" ) ] +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; + #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use ::typing_tools; + pub use orphan::*; + #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use ::num_traits; + pub use test::own::*; + #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use ::diagnostics_tools; + pub use + { + error_tools::orphan::*, + collection_tools::orphan::*, + impls_index::orphan::*, + mem_tools::orphan::*, + typing_tools::orphan::*, + diagnostics_tools::orphan::*, + }; + +} + +/// Shared with parent namespace of the module +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use ::process_tools_published; + pub use exposed::*; + #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use ::process_tools_published as process_tools; + pub use test::orphan::*; } +/// Exposed namespace of the module. #[ cfg( feature = "enabled" ) ] -// #[ cfg( not( feature = "no_std" ) ) ] -::meta_tools::mod_interface! +#[ allow( unused_imports ) ] +pub mod exposed { - // #![ debug ] + use super::*; - own use super::dependency::*; + #[ doc( inline ) ] + pub use prelude::*; - layer test; + #[ doc( inline ) ] + pub use test::exposed::*; - // xxx : comment out - use super::exposed::meta; - use super::exposed::mem; - use super::exposed::typing; - use super::exposed::dt; - use super::exposed::diagnostics; - use super::exposed::collection; - // use super::exposed::process; + #[ doc( inline ) ] + pub use + { + error_tools::exposed::*, + collection_tools::exposed::*, + impls_index::exposed::*, + mem_tools::exposed::*, + typing_tools::exposed::*, + diagnostics_tools::exposed::*, + }; - // prelude use ::rustversion::{ nightly, stable }; +} - // // xxx : eliminate need to do such things, putting itself to proper category - // exposed use super::test::compiletime; - // exposed use super::test::helper; - // exposed use super::test::smoke_test; +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; - prelude use ::meta_tools as meta; - prelude use ::mem_tools as mem; - prelude use ::typing_tools as typing; - prelude use ::data_type as dt; - prelude use ::diagnostics_tools as diagnostics; - prelude use ::collection_tools as collection; - // prelude use ::process_tools as process; + #[ doc( inline ) ] + pub use test::prelude::*; - prelude use ::meta_tools:: + #[ doc( inline ) ] + pub use { - impls, - index, - tests_impls, - tests_impls_optional, - tests_index, + error_tools::prelude::*, + collection_tools::prelude::*, + impls_index::prelude::*, + mem_tools::prelude::*, + typing_tools::prelude::*, + diagnostics_tools::prelude::*, }; - prelude use ::typing_tools::{ implements }; } - -// xxx : use module namespaces -// #[ cfg( feature = "enabled" ) ] -// #[ cfg( not( feature = "no_std" ) ) ] -// pub use test::{ compiletime, helper, smoke_test }; diff --git a/module/core/test_tools/src/test/asset.rs b/module/core/test_tools/src/test/asset.rs index 410707ed36..c32cf9cb91 100644 --- a/module/core/test_tools/src/test/asset.rs +++ b/module/core/test_tools/src/test/asset.rs @@ -3,7 +3,7 @@ //! Test asset helper. //! -/// Internal namespace. +/// Define a private namespace for all its items. // #[ cfg( not( feature = "no_std" ) ) ] mod private { @@ -34,14 +34,73 @@ mod private } +// // +// // #[ cfg( not( feature = "no_std" ) ) ] +// crate::mod_interface! +// { // -// #[ cfg( not( feature = "no_std" ) ) ] -crate::mod_interface! +// // exposed use super; +// exposed use super::super::asset; +// +// // own use path_to_exe; +// +// } + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ allow( unused_imports ) ] +pub mod own { + use super::*; + + #[ doc( inline ) ] + pub use + { + }; + +} + +/// Shared with parent namespace of the module +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; + + #[ doc( inline ) ] + pub use exposed::*; - // exposed use super; - exposed use super::super::asset; + pub use super::super::asset; + +} + +/// Exposed namespace of the module. +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + + #[ doc( inline ) ] + pub use prelude::*; + + #[ doc( inline ) ] + pub use + { + }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; - // own use path_to_exe; + #[ doc( inline ) ] + pub use + { + }; } diff --git a/module/core/test_tools/src/test/compiletime.rs b/module/core/test_tools/src/test/compiletime.rs index 77f9d362ac..9792d17e3d 100644 --- a/module/core/test_tools/src/test/compiletime.rs +++ b/module/core/test_tools/src/test/compiletime.rs @@ -3,22 +3,144 @@ //! Try building a program for negative testing. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { #[ doc( inline ) ] pub use ::trybuild::*; } +// // // +// #[ doc( inline ) ] +// #[ allow( unused_imports ) ] +// pub use own::*; +// +// #[ doc = r" Own namespace of the module." ] +// #[ allow( unused_imports ) ] +// pub mod own +// { +// use super::private; +// mod __all__ +// { +// pub use super::super::*; +// pub use super::super::private::*; +// } +// #[ doc( inline ) ] +// pub use super::orphan::*; +// #[ doc( inline ) ] +// #[ allow( unused_imports ) ] +// pub use private::{*}; +// } +// +// #[ doc = r" Orphan namespace of the module." ] +// #[ allow( unused_imports ) ] +// pub mod orphan +// { +// mod __all__ +// { +// pub use super::super::*; +// pub use super::super::private::*; +// } +// #[ doc( inline ) ] +// pub use super::exposed::*; +// } +// +// #[ doc = r" Exposed namespace of the module." ] +// #[ allow( unused_imports ) ] +// pub mod exposed +// { +// mod __all__ +// { +// pub use super::super::*; +// pub use super::super::private::*; +// } +// #[ doc( inline ) ] +// pub use super::prelude::*; +// #[ doc( inline ) ] +// #[ allow( unused_imports ) ] +// pub use super::super::compiletime; +// } +// +// #[ doc = r" Prelude to use essentials: `use my_module::prelude::*`." ] +// #[ allow( unused_imports ) ] +// pub mod prelude +// { +// mod __all__ +// { +// pub use super::super::*; +// pub use super::super::private::*; +// } +// } + +// crate::mod_interface! +// { +// // #![ debug ] +// // xxx : make it working +// // exposed use super; +// exposed use super::super::compiletime; +// own use +// { +// * +// }; +// } + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; + + #[ doc( inline ) ] + pub use + { + private::*, + }; + +} + +/// Shared with parent namespace of the module +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; + + #[ doc( inline ) ] + pub use exposed::*; + + pub use super::super::compiletime; -crate::mod_interface! +} + +/// Exposed namespace of the module. +#[ allow( unused_imports ) ] +pub mod exposed { - // xxx : make it working - // exposed use super; - exposed use super::super::compiletime; - own use + use super::*; + + #[ doc( inline ) ] + pub use prelude::*; + + #[ doc( inline ) ] + pub use { - * }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; + + #[ doc( inline ) ] + pub use + { + }; + } diff --git a/module/core/test_tools/src/test/helper.rs b/module/core/test_tools/src/test/helper.rs index fe79e69784..16100d426a 100644 --- a/module/core/test_tools/src/test/helper.rs +++ b/module/core/test_tools/src/test/helper.rs @@ -5,7 +5,7 @@ // use super::*; -/// Internal namespace. +/// Define a private namespace for all its items. mod private { @@ -75,16 +75,78 @@ mod private pub use doc_file_test; } +// crate::mod_interface! +// { +// // xxx +// // #![ debug ] +// // exposed use super; +// exposed use super::super::helper; // +// prelude use +// { +// num, +// doc_file_test, +// }; +// } + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; + + #[ doc( inline ) ] + pub use + { + private::*, + }; + +} -crate::mod_interface! +/// Shared with parent namespace of the module +#[ allow( unused_imports ) ] +pub mod orphan { - // exposed use super; - exposed use super::super::helper; + use super::*; - prelude use + #[ doc( inline ) ] + pub use exposed::*; + + pub use super::super::helper; + +} + +/// Exposed namespace of the module. +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + + #[ doc( inline ) ] + pub use prelude::*; + + #[ doc( inline ) ] + pub use + { + private::num, + private::doc_file_test, + }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; + + #[ doc( inline ) ] + pub use { - num, - doc_file_test, }; + } diff --git a/module/core/test_tools/src/test/mod.rs b/module/core/test_tools/src/test/mod.rs index 60ec182ac4..c13f70ef67 100644 --- a/module/core/test_tools/src/test/mod.rs +++ b/module/core/test_tools/src/test/mod.rs @@ -3,12 +3,110 @@ //! Tools for testing. //! -// #[ cfg( not( feature = "no_std" ) ) ] -crate::mod_interface! -{ - layer asset; - layer compiletime; - layer helper; - layer smoke_test; - layer version; +mod private {} + +// // #[ cfg( not( feature = "no_std" ) ) ] +// crate::mod_interface! +// { +// layer asset; +// layer compiletime; +// layer helper; +// layer smoke_test; +// layer version; +// } + +pub mod asset; +pub mod compiletime; +pub mod helper; +pub mod smoke_test; +pub mod version; + +#[ cfg( feature = "enabled" ) ] +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; + + #[ doc( inline ) ] + pub use orphan::*; + + #[ doc( inline ) ] + pub use + { + asset::orphan::*, + compiletime::orphan::*, + helper::orphan::*, + smoke_test::orphan::*, + version::orphan::*, + }; + +} + +/// Shared with parent namespace of the module +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; + + #[ doc( inline ) ] + pub use exposed::*; + +} + +/// Exposed namespace of the module. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + + #[ doc( inline ) ] + pub use prelude::*; + + #[ doc( inline ) ] + pub use + { + asset::exposed::*, + compiletime::exposed::*, + helper::exposed::*, + smoke_test::exposed::*, + version::exposed::*, + }; + + #[ doc( inline ) ] + pub use crate::impls_index:: + { + impls, + index, + tests_impls, + tests_impls_optional, + tests_index, + }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ cfg( feature = "enabled" ) ] +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; + + #[ doc( inline ) ] + pub use + { + asset::prelude::*, + compiletime::prelude::*, + helper::prelude::*, + smoke_test::prelude::*, + version::prelude::*, + }; + } diff --git a/module/core/test_tools/src/test/smoke_test.rs b/module/core/test_tools/src/test/smoke_test.rs index 34ebd2f55f..a99b4ee1a0 100644 --- a/module/core/test_tools/src/test/smoke_test.rs +++ b/module/core/test_tools/src/test/smoke_test.rs @@ -8,11 +8,12 @@ // xxx2 : use process_tools to build and run rust programs, introduce program_ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { + #[ allow( unused_imports ) ] use crate::*; - use dependency::process_tools::environment; + use process_tools::environment; // zzz : comment out // pub mod environment // { @@ -316,17 +317,83 @@ mod private } +// // +// crate::mod_interface! +// { // -crate::mod_interface! +// // exposed use super; +// exposed use super::super::smoke_test; +// +// exposed use SmokeModuleTest; +// exposed use smoke_test_run; +// exposed use smoke_tests_run; +// exposed use smoke_test_for_local_run; +// exposed use smoke_test_for_published_run; +// +// } + + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; + + #[ doc( inline ) ] + pub use + { + private::*, + }; + +} + +/// Shared with parent namespace of the module +#[ allow( unused_imports ) ] +pub mod orphan +{ + use super::*; + + #[ doc( inline ) ] + pub use exposed::*; + + pub use super::super::smoke_test; + +} + +/// Exposed namespace of the module. +#[ allow( unused_imports ) ] +pub mod exposed { + use super::*; + + #[ doc( inline ) ] + pub use prelude::*; - // exposed use super; - exposed use super::super::smoke_test; + #[ doc( inline ) ] + pub use private:: + { + SmokeModuleTest, + smoke_test_run, + smoke_tests_run, + smoke_test_for_local_run, + smoke_test_for_published_run, + }; + +} - exposed use SmokeModuleTest; - exposed use smoke_test_run; - exposed use smoke_tests_run; - exposed use smoke_test_for_local_run; - exposed use smoke_test_for_published_run; +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; + + #[ doc( inline ) ] + pub use + { + }; } diff --git a/module/core/test_tools/src/test/version.rs b/module/core/test_tools/src/test/version.rs index 7737b5b456..f20821e54e 100644 --- a/module/core/test_tools/src/test/version.rs +++ b/module/core/test_tools/src/test/version.rs @@ -3,21 +3,80 @@ //! Version of Rust compiler //! -/// Internal namespace. +/// Define a private namespace for all its items. // #[ cfg( not( feature = "no_std" ) ) ] mod private { } +// // +// // #[ cfg( not( feature = "no_std" ) ) ] +// crate::mod_interface! +// { // -// #[ cfg( not( feature = "no_std" ) ) ] -crate::mod_interface! +// // exposed use super; +// exposed use super::super::version; +// +// prelude use ::rustversion::{ nightly, stable }; +// +// } + + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + +/// Own namespace of the module. +#[ allow( unused_imports ) ] +pub mod own +{ + use super::*; + + #[ doc( inline ) ] + pub use + { + private::*, + }; + +} + +/// Shared with parent namespace of the module +#[ allow( unused_imports ) ] +pub mod orphan { + use super::*; - // exposed use super; - exposed use super::super::version; + #[ doc( inline ) ] + pub use exposed::*; + + pub use super::super::version; + +} + +/// Exposed namespace of the module. +#[ allow( unused_imports ) ] +pub mod exposed +{ + use super::*; + + #[ doc( inline ) ] + pub use prelude::*; + + #[ doc( inline ) ] + pub use rustversion::{ nightly, stable }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ allow( unused_imports ) ] +pub mod prelude +{ + use super::*; - prelude use ::rustversion::{ nightly, stable }; + #[ doc( inline ) ] + pub use + { + }; } diff --git a/module/core/test_tools/tests/inc/basic_test.rs b/module/core/test_tools/tests/inc/impls_index_test.rs similarity index 99% rename from module/core/test_tools/tests/inc/basic_test.rs rename to module/core/test_tools/tests/inc/impls_index_test.rs index 8e631611f4..9b1133fb91 100644 --- a/module/core/test_tools/tests/inc/basic_test.rs +++ b/module/core/test_tools/tests/inc/impls_index_test.rs @@ -15,7 +15,6 @@ use super::*; use ::test_tools as the_module; - #[ cfg( feature = "enabled" ) ] #[ cfg( not( feature = "no_std" ) ) ] the_module::tests_impls! diff --git a/module/core/test_tools/tests/inc/mem_test.rs b/module/core/test_tools/tests/inc/mem_test.rs new file mode 100644 index 0000000000..1cf4a2b724 --- /dev/null +++ b/module/core/test_tools/tests/inc/mem_test.rs @@ -0,0 +1,26 @@ +use super::*; + +// + +#[ allow( dead_code ) ] +#[ test ] +fn same_data() +{ + let buf = [ 0u8; 128 ]; + assert!( the_module::mem::same_data( &buf, &buf ) ); + + let x = [ 0u8; 1 ]; + let y = 0u8; + + assert!( the_module::mem::same_data( &x, &y ) ); + + assert!( !the_module::mem::same_data( &buf, &x ) ); + assert!( !the_module::mem::same_data( &buf, &y ) ); + + struct H1( &'static str ); + struct H2( &'static str ); + + assert!( the_module::mem::same_data( &H1( "hello" ), &H2( "hello" ) ) ); + assert!( !the_module::mem::same_data( &H1( "qwerty" ), &H2( "hello" ) ) ); + +} diff --git a/module/core/test_tools/tests/inc/mod.rs b/module/core/test_tools/tests/inc/mod.rs index bf3d2e3d78..a6d6581d75 100644 --- a/module/core/test_tools/tests/inc/mod.rs +++ b/module/core/test_tools/tests/inc/mod.rs @@ -1,8 +1,26 @@ -#[ allow( unused_imports ) ] use super::*; -mod basic_test; +mod impls_index_test; +mod mem_test; mod try_build_test; // mod wtest_utility; // qqq : include tests of all internal dependencies + +// /// Error tools. +// #[ path = "../../../../core/error_tools/tests/inc/mod.rs" ] +// pub mod error; +// pub use error as error_tools; +// +// /// Collection tools. +// #[ path = "../../../../core/collection_tools/tests/inc/mod.rs" ] +// pub mod collection; +// pub use collection as collection_tools; + +// /// impl and index macros. +// #[ path = "../../../../core/impls_index/tests/inc/mod.rs" ] +// pub mod impls_index; + +// /// Memory tools. +// #[ path = "../../../../core/mem_tools/tests/inc/mod.rs" ] +// pub mod mem_tools; diff --git a/module/core/test_tools/tests/tests.rs b/module/core/test_tools/tests/tests.rs index 3cdbd75627..c9b1261fb2 100644 --- a/module/core/test_tools/tests/tests.rs +++ b/module/core/test_tools/tests/tests.rs @@ -1,12 +1,13 @@ +#![ allow( unused_imports ) ] + // #![ deny( rust_2018_idioms ) ] // #![ deny( missing_debug_implementations ) ] // #![ deny( missing_docs ) ] -#[ allow( unused_imports ) ] use test_tools as the_module; -#[ allow( unused_imports ) ] -#[ cfg( feature = "enabled" ) ] -#[ cfg( not( feature = "no_std" ) ) ] -use test_tools::exposed::*; + +// #[ cfg( feature = "enabled" ) ] +// #[ cfg( not( feature = "no_std" ) ) ] +// use test_tools::exposed::*; mod inc; diff --git a/module/core/time_tools/License b/module/core/time_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/time_tools/License +++ b/module/core/time_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/typing_tools/Cargo.toml b/module/core/typing_tools/Cargo.toml index 5b128ba0e5..2d75db2449 100644 --- a/module/core/typing_tools/Cargo.toml +++ b/module/core/typing_tools/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "typing_tools" -version = "0.8.0" +version = "0.10.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/typing_tools/License b/module/core/typing_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/typing_tools/License +++ b/module/core/typing_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/variadic_from/Cargo.toml b/module/core/variadic_from/Cargo.toml index 616b747a6c..073a4f994a 100644 --- a/module/core/variadic_from/Cargo.toml +++ b/module/core/variadic_from/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "variadic_from" -version = "0.22.0" +version = "0.27.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/variadic_from/License b/module/core/variadic_from/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/core/variadic_from/License +++ b/module/core/variadic_from/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/core/variadic_from/src/variadic.rs b/module/core/variadic_from/src/variadic.rs index 715a135960..1297cb443c 100644 --- a/module/core/variadic_from/src/variadic.rs +++ b/module/core/variadic_from/src/variadic.rs @@ -2,7 +2,7 @@ //! Variadic constructor. Constructor with n arguments. Like Default, but with arguments. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/core/wtools/Cargo.toml b/module/core/wtools/Cargo.toml index 8488ccd02b..c8d108f307 100644 --- a/module/core/wtools/Cargo.toml +++ b/module/core/wtools/Cargo.toml @@ -58,7 +58,7 @@ meta_default = [ "meta_mod_interface", # "meta_former", # "meta_options", - "meta_constructors", + # "meta_constructors", "meta_idents_concat", ] meta_full = [ @@ -68,7 +68,7 @@ meta_full = [ "meta_mod_interface", # "meta_former", # "meta_options", - "meta_constructors", + # "meta_constructors", "meta_idents_concat", ] # meta_use_std = [ "meta", "meta_tools/use_std" ] @@ -79,7 +79,7 @@ meta_for_each = [ "meta", "meta_tools/meta_for_each" ] meta_impls_index = [ "meta", "meta_tools/meta_impls_index" ] meta_mod_interface = [ "meta" ] # meta_mod_interface = [ "meta", "meta_tools/mod_interface" ] -meta_constructors = [ "meta", "meta_tools/meta_constructors" ] +# meta_constructors = [ "meta", "meta_tools/meta_constructors" ] meta_idents_concat = [ "meta", "meta_tools/meta_idents_concat" ] # meta_former = [ "meta", "meta_tools/former" ] # meta_options = [ "meta", "meta_tools/options" ] @@ -318,7 +318,6 @@ dt_default = [ # "dt_use_std", "data_type/default", "dt_either", - "dt_prelude", # "dt_type_constructor", # "dt_make", # "dt_vectorized_from", @@ -329,7 +328,6 @@ dt_full = [ # "dt_use_std", "data_type/full", "dt_either", - "dt_prelude", # "dt_type_constructor", # "dt_make", # "dt_vectorized_from", @@ -341,7 +339,6 @@ dt_full = [ dt_use_alloc = [ "dt", "data_type/use_alloc" ] dt_either = [ "dt", "data_type/dt_either" ] -dt_prelude = [ "dt", "data_type/dt_prelude" ] # dt_type_constructor = [ "dt", "data_type/dt_type_constructor" ] # dt_make = [ "dt", "data_type/dt_make" ] # dt_vectorized_from = [ "dt", "data_type/dt_vectorized_from" ] diff --git a/module/core/wtools/License b/module/core/wtools/License index e3e9e057cf..c32986cee3 100644 --- a/module/core/wtools/License +++ b/module/core/wtools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/move/assistant/.key/readme.md b/module/move/assistant/.key/readme.md new file mode 100644 index 0000000000..4209c24678 --- /dev/null +++ b/module/move/assistant/.key/readme.md @@ -0,0 +1,20 @@ +# Keys + +This document provides a concise example of an environment configuration script, used to set up environment variables for a project. These variables configure application behavior without altering the code. + +## Example of `.key/-env.sh` + +```bash +# OpenAI API key. +OPENAI_API_KEY=sk-proj-ABCDEFG +``` + +## How to Use in Shell + +To apply these variables to your current shell session, use: + +```bash +. ./key/-env.sh +``` + +This command sources the script, making the variables available in your current session. Ensure `-env.sh` is in the `key` directory relative to your current location. \ No newline at end of file diff --git a/module/move/assistant/Cargo.toml b/module/move/assistant/Cargo.toml index 6e2af1a870..50700f8c3c 100644 --- a/module/move/assistant/Cargo.toml +++ b/module/move/assistant/Cargo.toml @@ -15,6 +15,7 @@ Assist AI in writing code. """ categories = [ "algorithms", "development-tools" ] keywords = [ "fundamental", "general-purpose" ] +default-run = "main" [lints] workspace = true @@ -32,14 +33,31 @@ enabled = [ "reflect_tools/enabled", ] +[[bin]] +name = "main" +path = "src/bin/main.rs" + +[[bin]] +name = "list_resources" +path = "src/bin/list_resources.rs" + [dependencies] # xxx : qqq : optimze features +mod_interface = { workspace = true, features = [ "full" ] } former = { workspace = true, features = [ "full" ] } format_tools = { workspace = true, features = [ "full" ] } reflect_tools = { workspace = true, features = [ "full" ] } -openai-api-rs = { version = "4.0.9" } +openai-api-rs = { version = "=5.0.14" } tokio = { version = "1", features = ["full"] } dotenv = "0.15" +clap = { version = "4.5.20", features = ["derive"] } +pth = "0.21.0" +serde = { version = "1.0.213", features = ["derive"] } +serde_with = "3.11.0" +error_tools = "0.17.0" +derive_tools = { version = "0.32.0", features = ["full"] } +regex = { version = "1.10.3" } +serde_yaml = "0.9" [dev-dependencies] test_tools = { workspace = true } diff --git a/module/move/assistant/License b/module/move/assistant/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/move/assistant/License +++ b/module/move/assistant/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/move/assistant/Readme.md b/module/move/assistant/Readme.md index 0e9402c634..9296447b86 100644 --- a/module/move/assistant/Readme.md +++ b/module/move/assistant/Readme.md @@ -3,7 +3,9 @@ # Module :: assistant [![experimental](https://raster.shields.io/static/v1?label=stability&message=experimental&color=orange&logoColor=eee)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/ModuleassistantPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/ModuleassistantPush.yml) [![docs.rs](https://img.shields.io/docsrs/assistant?color=e3e8f0&logo=docs.rs)](https://docs.rs/assistant) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) -Assist AI in writing code. +**NOT ready for production** + + " )?; + writer.write( node.next.as_bytes() )?; + writer.write( b" : next\n" )?; + } + + writer.write( b"@enduml" )?; + Ok( () ) + } +} + +crate::mod_interface! +{ + own use plantuml_formatter; +} \ No newline at end of file diff --git a/module/move/assistant/src/agents/scenario_raw_processors/yaml_formatter.rs b/module/move/assistant/src/agents/scenario_raw_processors/yaml_formatter.rs new file mode 100644 index 0000000000..05d1bb5668 --- /dev/null +++ b/module/move/assistant/src/agents/scenario_raw_processors/yaml_formatter.rs @@ -0,0 +1,26 @@ +//! +//! Format scenario in YAML format (pretty-printing). +//! + +mod private +{ + use std::io; + + use crate::*; + use agents::scenario_raw::ScenarioRaw; + + /// Pretty-print `ScenarioRaw` in YAML format. + pub fn yaml_formatter + ( + scenario : &ScenarioRaw, + writer : &mut impl io::Write, + ) -> Result< (), serde_yaml::Error > + { + serde_yaml::to_writer( writer, scenario ) + } +} + +crate::mod_interface! +{ + own use yaml_formatter; +} \ No newline at end of file diff --git a/module/move/assistant/src/bin/list_resources.rs b/module/move/assistant/src/bin/list_resources.rs new file mode 100644 index 0000000000..d85d524ceb --- /dev/null +++ b/module/move/assistant/src/bin/list_resources.rs @@ -0,0 +1,55 @@ +#![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] +#![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] +#![ doc( html_root_url = "https://docs.rs/assistant/latest/assistant/" ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +use std:: +{ + env, + error::Error, +}; + +use format_tools:: +{ + AsTable, + TableFormatter, + output_format, +}; +use dotenv::dotenv; + +use assistant:: +{ + client::client, + Secret +}; + +#[ tokio::main ] +async fn main() -> Result< (), Box< dyn Error > > +{ + dotenv().ok(); + + let secret = Secret::load()?; + + let client = client( &secret )?; + + let response = client.file_list().await?; + // println!( "Files: {:?}", response.data ); + let files : Vec< _ > = response.data.into_iter().map( | e | assistant::FileDataWrap( e ) ).collect(); + println! + ( + "Files:\n{}", + AsTable::new( &files ).table_to_string_with_format( &output_format::Table::default() ), + ); + + let response = client.list_assistant( None, None, None, None ).await?; + + // println!( "Assistants: {:?}", assistants.data ); + let assistants : Vec< _ > = response.data.into_iter().map( | e | assistant::AssistantObjectWrap( e ) ).collect(); + println! + ( + "Assistants:\n{}", + AsTable::new( &assistants ).table_to_string_with_format( &output_format::Records::default() ), + ); + + Ok( () ) +} \ No newline at end of file diff --git a/module/move/assistant/src/main.rs b/module/move/assistant/src/bin/main.rs similarity index 64% rename from module/move/assistant/src/main.rs rename to module/move/assistant/src/bin/main.rs index ad03e3549a..419030d03b 100644 --- a/module/move/assistant/src/main.rs +++ b/module/move/assistant/src/bin/main.rs @@ -1,4 +1,3 @@ -#![ 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/" ) ] @@ -11,18 +10,33 @@ use std:: }; use dotenv::dotenv; +use clap::Parser; use assistant:: { - client, + client::client, + commands::{ Cli, CliCommand, self }, + Secret }; #[ 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 ); + + let secret = Secret::load()?; + + let client = client( &secret )?; + + let cli = Cli::parse(); + + match cli.command + { + CliCommand::OpenAi( openai_command ) => + { + commands::openai::command( &client, openai_command ).await; + } + } + Ok( () ) } diff --git a/module/move/assistant/src/client.rs b/module/move/assistant/src/client.rs index 946be0cf2a..1c9fd0bbee 100644 --- a/module/move/assistant/src/client.rs +++ b/module/move/assistant/src/client.rs @@ -2,95 +2,38 @@ //! Client of API. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { pub use openai_api_rs::v1:: { - api::Client, + api::OpenAIClient as Client, assistant::AssistantObject, }; use std:: { - env, error::Error, }; - use former::Former; + use crate::*; + use secret::Secret; - /// Options for configuring the OpenAI API client. - #[ derive( Former, Debug ) ] - pub struct ClientOptions + /// Creates a new OpenAI API client using the secrets. + pub fn client( secrets : &Secret ) -> Result< Client, Box< dyn Error > > { - /// The API key for authenticating with the OpenAI API. - pub api_key : Option< String >, + Ok( Client::new( secrets.OPENAI_API_KEY.clone() ) ) } - /// 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 own::*; - -/// Own namespace of the module. -#[ allow( unused_imports ) ] -pub mod own -{ - use super::*; - - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use orphan::*; - } -/// Orphan namespace of the module. -#[ allow( unused_imports ) ] -pub mod orphan +crate::mod_interface! { - use super::*; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use exposed::*; -} - -/// Exposed namespace of the module. -#[ allow( unused_imports ) ] -pub mod exposed -{ - use super::*; - - #[ doc( inline ) ] - pub use private:: + exposed use { - ClientOptions, - client, + Client, AssistantObject, + client }; - - // #[ doc( inline ) ] - // #[ allow( unused_imports ) ] - // pub use reflect_tools:: - // { - // Fields, - // _IteratorTrait, - // IteratorTrait, - // }; - -} - -/// Prelude to use essentials: `use my_module::prelude::*`. -#[ allow( unused_imports ) ] -pub mod prelude -{ - use super::*; } diff --git a/module/move/assistant/src/commands.rs b/module/move/assistant/src/commands.rs new file mode 100644 index 0000000000..480b13d8d5 --- /dev/null +++ b/module/move/assistant/src/commands.rs @@ -0,0 +1,77 @@ +//! +//! CLI commands of the tool. +//! + +/// Internal namespace. +mod private +{ + + use clap::{ Parser, Subcommand }; + + use crate::*; + use commands::openai; + + /// CLI commands of the tool. + #[ derive ( Debug, Parser ) ] + pub struct Cli + { + /// Root of the CLI commands. + #[ command ( subcommand ) ] + pub command : CliCommand, + } + + /// Root of the CLI commands. + #[ derive ( Debug, Subcommand ) ] + pub enum CliCommand + { + /// OpenAI API commands. + #[ command ( subcommand, name = "openai" ) ] + OpenAi( openai::Command ), + } + + const DEFAULT_MAX_TABLE_WIDTH : usize = 130; + + /// Common collection of arguments for formatting tabular data. + #[ derive( Debug, Parser ) ] + pub struct TableConfig + { + /// Limit table widht. + #[ arg( long, default_value_t = DEFAULT_MAX_TABLE_WIDTH ) ] + pub max_table_width : usize, + + /// Show tabular data as an ordinary table. + #[ arg( long ) ] + pub as_table : bool, + + /// Show each record of a tabular data as a separate table. + #[ arg( long ) ] + pub as_records : bool, + + /// Show only keys (columns) of tabular data. + #[ arg( long ) ] + pub columns : bool, + + /// Filter columns of tabular data. + #[ arg( long, value_delimiter( ',' ) ) ] + pub filter_columns : Vec< String >, + } + +} + +crate::mod_interface! +{ + layer openai; + layer openai_assistants; + layer openai_assistants_list; + layer openai_runs; + layer openai_runs_list; + layer openai_files; + layer openai_files_list; + + own use + { + Cli, + CliCommand, + TableConfig, + }; +} diff --git a/module/move/assistant/src/commands/openai.rs b/module/move/assistant/src/commands/openai.rs new file mode 100644 index 0000000000..42c7ea5595 --- /dev/null +++ b/module/move/assistant/src/commands/openai.rs @@ -0,0 +1,75 @@ +//! +//! Collection of OpenAI API commands. +//! + +mod private +{ + + use clap::Subcommand; + + use crate::*; + use client::Client; + use commands::{ openai_assistants, openai_files, openai_runs }; + + /// OpenAI API commands. + #[ derive ( Debug, Subcommand ) ] + pub enum Command + { + /// OpenAI assistants. + #[ command ( subcommand ) ] + Assistants + ( + openai_assistants::Command + ), + + /// OpenAI files. + #[ command ( subcommand ) ] + Files + ( + openai_files::Command + ), + + /// OpenAI runs. + #[ command ( subcommand ) ] + Runs + ( + openai_runs::Command + ), + } + + /// Execute OpenAI command. + pub async fn command + ( + client : &Client, + command : Command, + ) + { + match command + { + Command::Assistants( assistants_command ) => + { + openai_assistants::command( client, assistants_command ).await; + } + + Command::Files( files_command ) => + { + openai_files::command( client, files_command ).await; + } + + Command::Runs( runs_command ) => + { + openai_runs::command( client, runs_command ).await; + } + } + } + +} + +crate::mod_interface! +{ + own use + { + Command, + command, + }; +} \ No newline at end of file diff --git a/module/move/assistant/src/commands/openai_assistants.rs b/module/move/assistant/src/commands/openai_assistants.rs new file mode 100644 index 0000000000..0d941c94ba --- /dev/null +++ b/module/move/assistant/src/commands/openai_assistants.rs @@ -0,0 +1,52 @@ +//! +//! Collection of assistants commands for OpenAI API. +//! + +mod private +{ + + use clap::Subcommand; + + use crate::*; + use client::Client; + use commands::{ openai_assistants_list, TableConfig }; + + /// OpenAI assistants. + #[ derive ( Debug, Subcommand ) ] + pub enum Command + { + /// List OpenAI assistants. + List + { + /// Configure table formatting. + #[ clap( flatten ) ] + table_config : TableConfig, + }, + } + + /// Execute OpenAI command related to assistants. + pub async fn command + ( + client : &Client, + command : Command, + ) + { + match command + { + Command::List{ table_config } => + { + openai_assistants_list::command( client, table_config ).await; + } + } + } + +} + +crate::mod_interface! +{ + own use + { + Command, + command, + }; +} \ No newline at end of file diff --git a/module/move/assistant/src/commands/openai_assistants_list.rs b/module/move/assistant/src/commands/openai_assistants_list.rs new file mode 100644 index 0000000000..6ce7a80ac4 --- /dev/null +++ b/module/move/assistant/src/commands/openai_assistants_list.rs @@ -0,0 +1,34 @@ +//! +//! List assistants in OpenAI API (command part). +//! + +mod private +{ + + use crate::*; + use client::Client; + use actions; + use commands::TableConfig; + + /// List OpenAI assistants command. + pub async fn command + ( + client : &Client, + table_config : TableConfig, + ) + { + let result = actions::openai_assistants_list::action( client, table_config ).await; + + match result + { + Ok ( report ) => println!( "{}", report ), + Err ( error ) => println!( "{}", error ) + } + } + +} + +crate::mod_interface! +{ + own use command; +} \ No newline at end of file diff --git a/module/move/assistant/src/commands/openai_files.rs b/module/move/assistant/src/commands/openai_files.rs new file mode 100644 index 0000000000..ea72a42ad1 --- /dev/null +++ b/module/move/assistant/src/commands/openai_files.rs @@ -0,0 +1,52 @@ +//! +//! Collection of files commands for OpenAI API. +//! + +mod private +{ + + use clap::Subcommand; + + use crate::*; + use client::Client; + use commands::{ openai_files_list, TableConfig }; + + /// OpenAI files. + #[ derive ( Debug, Subcommand ) ] + pub enum Command + { + /// List OpenAI files. + List + { + /// Configure table formatting. + #[ clap( flatten ) ] + table_config : TableConfig, + }, + } + + /// Execute OpenAI commands related to files. + pub async fn command + ( + client : &Client, + command : Command, + ) + { + match command + { + Command::List{ table_config } => + { + openai_files_list::command( client, table_config ).await; + } + } + } + +} + +crate::mod_interface! +{ + own use + { + Command, + command, + }; +} \ No newline at end of file diff --git a/module/move/assistant/src/commands/openai_files_list.rs b/module/move/assistant/src/commands/openai_files_list.rs new file mode 100644 index 0000000000..6225b9faf2 --- /dev/null +++ b/module/move/assistant/src/commands/openai_files_list.rs @@ -0,0 +1,34 @@ +//! +//! List files in OpenAI API (command part). +//! + +mod private +{ + + use crate::*; + use client::Client; + use actions; + use commands::TableConfig; + + /// List files in your OpenAI API. + pub async fn command + ( + client : &Client, + table_config : TableConfig, + ) + { + let result = actions::openai_files_list::action( client, table_config ).await; + + match result + { + Ok ( report ) => println!( "{}", report ), + Err ( error ) => println!( "{}", error ) + } + } + +} + +crate::mod_interface! +{ + own use command; +} \ No newline at end of file diff --git a/module/move/assistant/src/commands/openai_runs.rs b/module/move/assistant/src/commands/openai_runs.rs new file mode 100644 index 0000000000..2cf7812000 --- /dev/null +++ b/module/move/assistant/src/commands/openai_runs.rs @@ -0,0 +1,55 @@ +//! +//! Collection of runs commands for OpenAI API. +//! + +mod private +{ + + use clap::Subcommand; + + use crate::*; + use client::Client; + use commands::{ openai_runs_list, TableConfig }; + + /// OpenAI runs. + #[ derive ( Debug, Subcommand ) ] + pub enum Command + { + /// List OpenAI runs in a thread. + List + { + /// Thread ID. + thread_id : String, + + /// Configure table formatting. + #[ clap( flatten ) ] + table_config : TableConfig, + } + } + + /// Execute OpenAI commands related to runs. + pub async fn command + ( + client : &Client, + command : Command, + ) + { + match command + { + Command::List { thread_id, table_config } => + { + openai_runs_list::command( client, thread_id, table_config ).await; + } + } + } + +} + +crate::mod_interface! +{ + own use + { + Command, + command, + }; +} \ No newline at end of file diff --git a/module/move/assistant/src/commands/openai_runs_list.rs b/module/move/assistant/src/commands/openai_runs_list.rs new file mode 100644 index 0000000000..6d08d64ed3 --- /dev/null +++ b/module/move/assistant/src/commands/openai_runs_list.rs @@ -0,0 +1,35 @@ +//! +//! List runs in OpenAI API (command part). +//! + +mod private +{ + + use crate::*; + use client::Client; + use actions; + use commands::TableConfig; + + /// List runs in the thread in OpenAI API. + pub async fn command + ( + client : &Client, + thread_id : String, + table_config : TableConfig, + ) + { + let result = actions::openai_runs_list::action( client, thread_id, table_config ).await; + + match result + { + Ok ( report ) => println!( "{}", report ), + Err ( error ) => println!( "{}", error ) + } + } + +} + +crate::mod_interface! +{ + own use command; +} \ No newline at end of file diff --git a/module/move/assistant/src/debug.rs b/module/move/assistant/src/debug.rs new file mode 100644 index 0000000000..294333abf0 --- /dev/null +++ b/module/move/assistant/src/debug.rs @@ -0,0 +1,30 @@ +//! +//! Client of API. +//! + +/// Define a private namespace for all its items. +mod private +{ + +} + +use format_tools:: +{ + Fields, + TableWithFields, +}; +use std::borrow::Cow; + +mod assistant_object; +mod file_data; +mod run_object; + +crate::mod_interface! +{ + exposed use + { + assistant_object::AssistantObjectWrap, + file_data::FileDataWrap, + run_object::RunObjectWrap, + }; +} diff --git a/module/move/assistant/src/debug/assistant_object.rs b/module/move/assistant/src/debug/assistant_object.rs new file mode 100644 index 0000000000..9ebcead56e --- /dev/null +++ b/module/move/assistant/src/debug/assistant_object.rs @@ -0,0 +1,84 @@ +use super::*; +use openai_api_rs::v1::assistant; + +/// A wrapper for `AssistantObject` to make pretty print. +#[ derive( Debug ) ] +pub struct AssistantObjectWrap( pub assistant::AssistantObject ); + +/// Manually implemented `Clone`, as `FileData` does not implement it. +impl Clone for AssistantObjectWrap +{ + fn clone( &self ) -> Self + { + // Manually clone each field of the wrapped AssistantObject + AssistantObjectWrap( assistant::AssistantObject + { + id : self.0.id.clone(), + object : self.0.object.clone(), + created_at : self.0.created_at, + name : self.0.name.clone(), + description : self.0.description.clone(), + model : self.0.model.clone(), + instructions : self.0.instructions.clone(), + tools : self.0.tools.clone(), + tool_resources : self.0.tool_resources.clone(), + metadata : self.0.metadata.clone(), + headers : self.0.headers.clone(), + } ) + } +} + +impl TableWithFields for AssistantObjectWrap {} +impl Fields< &'_ str, Option< Cow< '_, str > > > +for AssistantObjectWrap +{ + type Key< 'k > = &'k str; + type Val< 'v > = Option< Cow< 'v, str > >; + + fn fields( &self ) -> impl format_tools::IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > + { + use format_tools::ref_or_display_or_debug_multiline::field; + let mut dst = Vec::new(); + + // Use the field! macro for direct field references + dst.push( field!( &self.0.id ) ); + dst.push( field!( &self.0.object ) ); + dst.push( field!( &self.0.model ) ); + + // Manually handle fields that require function calls + dst.push( ( "created_at", Some( Cow::Owned( self.0.created_at.to_string() ) ) ) ); + dst.push( ( "name", self.0.name.as_deref().map( Cow::Borrowed ) ) ); + dst.push( ( "description", self.0.description.as_deref().map( Cow::Borrowed ) ) ); + dst.push( ( "instructions", self.0.instructions.as_deref().map( Cow::Borrowed ) ) ); + + // Handle complex fields like `tools`, `tool_resources`, `metadata`, and `headers` + if !self.0.tools.is_empty() + { + dst.push( ( "tools", Some( Cow::Borrowed( "tools present" ) ) ) ); + } + else + { + dst.push( ( "tools", Option::None ) ); + } + + if let Some( _metadata ) = &self.0.metadata + { + dst.push( ( "metadata", Some( Cow::Borrowed( "metadata present" ) ) ) ); + } + else + { + dst.push( ( "metadata", Option::None ) ); + } + + if let Some( _headers ) = &self.0.headers + { + dst.push( ( "headers", Some( Cow::Borrowed( "headers present" ) ) ) ); + } + else + { + dst.push( ( "headers", Option::None ) ); + } + + dst.into_iter() + } +} diff --git a/module/move/assistant/src/debug/file_data.rs b/module/move/assistant/src/debug/file_data.rs new file mode 100644 index 0000000000..b8029949c7 --- /dev/null +++ b/module/move/assistant/src/debug/file_data.rs @@ -0,0 +1,50 @@ + +use super::*; +use openai_api_rs::v1::file::FileData; + +// Assuming the `format_tools` module and `field!` macro are defined elsewhere + +/// A wrapper for `FileData` to make pretty print. +#[ derive( Debug ) ] +pub struct FileDataWrap( pub FileData ); + +/// Manually implemented `Clone`, as `FileData` does not implement it. +impl Clone for FileDataWrap +{ + fn clone( &self ) -> Self + { + FileDataWrap( FileData + { + id : self.0.id.clone(), + object : self.0.object.clone(), + bytes : self.0.bytes, + created_at : self.0.created_at, + filename : self.0.filename.clone(), + purpose : self.0.purpose.clone(), + } ) + } +} + +impl TableWithFields for FileDataWrap {} +impl Fields< &'_ str, Option< Cow< '_, str > > > +for FileDataWrap +{ + type Key<'k> = &'k str; + type Val< 'v > = Option< Cow< 'v, str > >; + + fn fields( &self ) -> impl format_tools::IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > + { + use format_tools::ref_or_display_or_debug_multiline::field; + let mut dst = Vec::new(); + + // Use the field! macro for direct field references + dst.push( field!( &self.0.id ) ); + dst.push( field!( &self.0.object ) ); + dst.push( ( "bytes", Some( Cow::Owned( self.0.bytes.to_string() ) ) ) ); + dst.push( ( "created_at", Some( Cow::Owned( self.0.created_at.to_string() ) ) ) ); + dst.push( field!( &self.0.filename ) ); + dst.push( field!( &self.0.purpose ) ); + + dst.into_iter() + } +} diff --git a/module/move/assistant/src/debug/run_object.rs b/module/move/assistant/src/debug/run_object.rs new file mode 100644 index 0000000000..efe2ce1e02 --- /dev/null +++ b/module/move/assistant/src/debug/run_object.rs @@ -0,0 +1,73 @@ + +use super::*; +use openai_api_rs::v1::run::RunObject; + +// Assuming the `format_tools` module and `field!` macro are defined elsewhere + +/// A wrapper for `RunObject` to make pretty print. +#[ derive( Debug ) ] +pub struct RunObjectWrap( pub RunObject ); + +/// Manually implemented `Clone`, as `RunObject` does not implement it. +impl Clone for RunObjectWrap { + fn clone(&self) -> Self { + RunObjectWrap(RunObject { + id : self.0.id.clone(), + object : self.0.object.clone(), + created_at : self.0.created_at, + thread_id : self.0.thread_id.clone(), + assistant_id : self.0.assistant_id.clone(), + status : self.0.status.clone(), + required_action : self.0.required_action.clone(), + last_error : self.0.last_error.clone(), + expires_at : self.0.expires_at, + started_at : self.0.started_at, + cancelled_at : self.0.cancelled_at, + failed_at : self.0.failed_at, + completed_at : self.0.completed_at, + model : self.0.model.clone(), + instructions : self.0.instructions.clone(), + tools : self.0.tools.clone(), + metadata : self.0.metadata.clone(), + headers : self.0.headers.clone(), + }) + } +} + +impl TableWithFields for RunObjectWrap {} +impl Fields< &'_ str, Option< Cow< '_, str > > > +for RunObjectWrap +{ + type Key< 'k > = &'k str; + type Val< 'v > = Option< Cow< 'v, str > >; + + fn fields( &self ) -> impl format_tools::IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) > + { + use format_tools::ref_or_display_or_debug_multiline::field; + let mut dst = Vec::new(); + + dst.push( field!( &self.0.id ) ); + dst.push( field!( &self.0.object ) ); + dst.push( ( "created_at", Some( Cow::Owned( self.0.created_at.to_string() ) ) ) ); + dst.push( field!( &self.0.thread_id ) ); + dst.push( field!( &self.0.assistant_id ) ); + dst.push( field!( &self.0.status ) ); + + dst.push( ( "required_action", self.0.required_action.as_ref().map( |ra| Cow::Owned( format!( "{:?}", ra ) ) ) ) ); + dst.push( ( "last_error", self.0.last_error.as_ref().map( |le| Cow::Owned( format!( "{:?}", le ) ) ) ) ); + dst.push( ( "expires_at", self.0.expires_at.map( |ea| Cow::Owned( ea.to_string() ) ) ) ); + dst.push( ( "started_at", self.0.started_at.map( |sa| Cow::Owned( sa.to_string() ) ) ) ); + dst.push( ( "cancelled_at", self.0.cancelled_at.map( |ca| Cow::Owned( ca.to_string() ) ) ) ); + dst.push( ( "failed_at", self.0.failed_at.map( |fa| Cow::Owned( fa.to_string() ) ) ) ); + dst.push( ( "completed_at", self.0.completed_at.map( |ca| Cow::Owned( ca.to_string() ) ) ) ); + + dst.push( field!( &self.0.model ) ); + dst.push( ( "instructions", self.0.instructions.as_ref().map( |i| Cow::Owned( i.clone() ) ) ) ); + + dst.push( ( "tools", Some( Cow::Owned( format!( "{:?}", self.0.tools ) ) ) ) ); + dst.push( ( "metadata", Some( Cow::Owned( format!( "{:?}", self.0.metadata ) ) ) ) ); + dst.push( ( "headers", self.0.headers.as_ref().map( |h| Cow::Owned( format!( "{:?}", h ) ) ) ) ); + + dst.into_iter() + } +} diff --git a/module/move/assistant/src/lib.rs b/module/move/assistant/src/lib.rs index 92684e4e90..4d21799cc5 100644 --- a/module/move/assistant/src/lib.rs +++ b/module/move/assistant/src/lib.rs @@ -1,65 +1,41 @@ -#![ 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 mod_interface::mod_interface; +use error_tools::thiserror; -/// Internal namespace. +/// Define a private namespace for all its items. mod private { } -pub mod client; - -#[ allow( unused_imports ) ] -pub use own::*; - -/// Own namespace of the module. -#[ allow( unused_imports ) ] -pub mod own +/// Serde-related exports. +pub mod ser { - use super::*; - - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super:: + pub use serde:: { - client::orphan::*, + Serialize, + Deserialize, }; - - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use orphan::*; - + pub use serde_with::*; } -/// Orphan namespace of the module. -#[ allow( unused_imports ) ] -pub mod orphan -{ - use super::*; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use exposed::*; -} +// pub mod client; -/// Exposed namespace of the module. -#[ allow( unused_imports ) ] -pub mod exposed +crate::mod_interface! { - use super::*; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super:: - { - client::exposed::*, - }; + layer client; + layer debug; + layer commands; + layer actions; + layer secret; + layer util; + layer agents; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use reflect_tools:: + exposed use ::reflect_tools:: { Fields, _IteratorTrait, @@ -67,18 +43,3 @@ pub mod exposed }; } - -/// Prelude to use essentials: `use my_module::prelude::*`. -#[ allow( unused_imports ) ] -pub mod prelude -{ - use super::*; - - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super:: - { - client::prelude::*, - }; - -} diff --git a/module/move/assistant/src/secret.rs b/module/move/assistant/src/secret.rs new file mode 100644 index 0000000000..aa90da77bc --- /dev/null +++ b/module/move/assistant/src/secret.rs @@ -0,0 +1,219 @@ +//! +//! Tool's secrets. +//! + +/// Internal namespace. +mod private +{ + use crate::*; + use std:: + { + env, + sync::OnceLock, + }; + + use error_tools::typed::Error; + use ser::DisplayFromStr; + + /// Typed secret error. + #[ ser::serde_as ] + #[ derive( Debug, Error, ser::Serialize ) ] + #[ serde( tag = "type", content = "data" ) ] + pub enum Error + { + + /// Secret file is illformed. + #[ error( "Secret file is illformed\n{0}" ) ] + SecretFileIllformed + ( + #[ from ] + #[ serde_as( as = "DisplayFromStr" ) ] + dotenv::Error + ), + + /// Some variable in the secrets is missing. + #[ error( "Secret misssing the variable {0}" ) ] + VariableMissing( &'static str ), + + /// Some variable in the secrets is illformed. + #[ error( "Secret error processing the variable {0}\n{1}" ) ] + VariableIllformed( &'static str, String ), + + } + + /// Result type for `Secret` methods. + pub type Result< R > = core::result::Result< R, Error >; + + /// Represents the application secrets loaded from environment variables. + #[ derive( Debug ) ] + #[ allow( non_snake_case ) ] + pub struct Secret + { + /// OpenAI API key. + pub OPENAI_API_KEY : String, + } + + impl Secret + { + + /// Loads secrets from environment variables. + /// + /// # Returns + /// + /// * `Result< Self >` - On success, returns a `Secret` instance with values from environment variables. + /// * On failure, returns an error indicating which environment variable is missing or invalid. + #[ allow( non_snake_case ) ] + pub fn load() -> Result< Self > + { + let path = "./.key/-env.sh"; + + // Attempt to load environment variables from the specified file + let r = dotenv::from_filename( path ); + if let Err( ref err ) = r + { + // Only return an error if it's not an Io error, and include the file path in the error message + if !matches!( err, dotenv::Error::Io( _ ) ) + { + return Err( r.expect_err( &format!( "Failed to load {path}" ) ).into() ); + } + } + + let config = Self + { + OPENAI_API_KEY : var( "OPENAI_API_KEY", None )?, + }; + Ok( config ) + } + + /// Reads the secrets, panicking with an explanation if loading fails. + /// + /// # Returns + /// + /// * `Secret` - The loaded secrets. + /// + /// # Panics + /// + /// * Panics with a detailed explanation if the secrets cannot be loaded. + + pub fn read() -> Secret + { + Self::load().unwrap_or_else( | err | + { + let example = include_str!( "../.key/readme.md" ); + let explanation = format! + ( +r#" = Lack of secrets + +Failed to load secret or some its parameters. +{err} + + = Fix + +Either define missing environment variable or make sure `./.key/-env.toml` file has it defined. + + = More information + +{example} +"# + ); + panic!( "{}", explanation ); + }) + } + + /// Retrieves a static reference to the secrets, initializing it if necessary. + /// + /// # Returns + /// + /// * `&'static Secret` - A static reference to the secrets. + /// + /// # Warning + /// + /// * Do not use this function unless absolutely necessary. + /// * Avoid using it in `lib.rs`. + pub fn get() -> &'static Secret + { + static INSTANCE : OnceLock< Secret > = OnceLock::new(); + INSTANCE.get_or_init( || Self::read() ) + } + + } + + /// Retrieves the value of an environment variable as a `String`. + /// + /// This function attempts to fetch the value of the specified environment variable. + /// If the variable is not set, it returns a provided default value if available, or an error if not. + /// + /// # Arguments + /// + /// * `name` - The name of the environment variable to retrieve. + /// * `default` - An optional default value to return if the environment variable is not set. + /// + /// # Returns + /// + /// * `Result` - On success, returns the value of the environment variable or the default value. + /// * On failure, returns an error indicating the missing environment variable. + fn var + ( + name : &'static str, + default : Option< &'static str >, + ) -> Result< String > + { + match env::var( name ) + { + Ok( value ) => Ok( value ), + Err( _ ) => + { + if let Some( default_value ) = default + { + Ok( default_value.to_string() ) + } + else + { + Err( Error::VariableMissing( name ) ) + } + } + } + } + + /// Retrieves the value of an environment variable as an `AbsolutePath`. + /// + /// This function attempts to fetch the value of the specified environment variable and convert it into an `AbsolutePath`. + /// If the variable is not set, it returns a provided default value if available, or an error if not. + /// + /// # Arguments + /// + /// * `name` - The name of the environment variable to retrieve. + /// * `default` - An optional default value to return if the environment variable is not set. + /// + /// # Returns + /// + /// * `Result` - On success, returns the parsed `AbsolutePath`. + /// * On failure, returns an error indicating the missing or ill-formed environment variable. + fn _var_path + ( + name : &'static str, + default : Option< &'static str >, + ) -> Result< pth::AbsolutePath > + { + let p = var( name, default )?; + pth::AbsolutePath::from_paths( ( pth::CurrentPath, p ) ) + .map_err( |e| Error::VariableIllformed( name, e.to_string() ) ) + } + +} + +crate::mod_interface! +{ + + own use + { + Error, + Result, + }; + + orphan use + { + Secret, + }; + +} \ No newline at end of file diff --git a/module/move/assistant/src/util.rs b/module/move/assistant/src/util.rs new file mode 100644 index 0000000000..7e34c0fd16 --- /dev/null +++ b/module/move/assistant/src/util.rs @@ -0,0 +1,10 @@ +//! +//! Collection of utility functions for this crate. +//! + +mod private {} + +crate::mod_interface! +{ + layer display_table; +} \ No newline at end of file diff --git a/module/move/assistant/src/util/display_table.rs b/module/move/assistant/src/util/display_table.rs new file mode 100644 index 0000000000..c4e7ddcd28 --- /dev/null +++ b/module/move/assistant/src/util/display_table.rs @@ -0,0 +1,128 @@ +//! +//! Function for displaying tabular data according to `TableConfig`. +//! + +mod private +{ + + use std::fmt; + + use format_tools:: + { + TableFormatter, + output_format, + print, + TableOutputFormat, + }; + + use crate::*; + use commands::{ TableConfig }; + + /// Function for displaying tabular data according to `TableConfig`. + pub fn display_tabular_data<'a> + ( + data : &'a impl TableFormatter< 'a >, + f : &mut fmt::Formatter< '_ >, + table_config : &'a TableConfig, + ) -> fmt::Result + { + if table_config.as_table + { + display_table( data, f, table_config ) + } + else if table_config.as_records + { + display_records( data, f, table_config ) + } + else if table_config.columns + { + display_columns( data, f, table_config ) + } + else + { + display_table( data, f, table_config ) + } + } + + fn display_table<'a> + ( + data : &'a impl TableFormatter< 'a >, + f : &mut fmt::Formatter< '_ >, + table_config : &'a TableConfig, + ) -> fmt::Result + { + let mut format = output_format::Table::default(); + format.max_width = table_config.max_table_width; + + display_data + ( + data, + f, + format, + &table_config.filter_columns, + ) + } + + fn display_records<'a> + ( + data : &'a impl TableFormatter< 'a >, + f : &mut fmt::Formatter< '_ >, + table_config : &'a TableConfig, + ) -> fmt::Result + { + let mut format = output_format::Records::default(); + format.max_width = table_config.max_table_width; + + display_data + ( + data, + f, + format, + &table_config.filter_columns, + ) + } + + fn display_columns<'a> + ( + data : &'a impl TableFormatter< 'a >, + f : &mut fmt::Formatter< '_ >, + table_config : &'a TableConfig, + ) -> fmt::Result + { + let mut format = output_format::Records::default(); + format.max_width = table_config.max_table_width; + + display_data + ( + data, + f, + format, + &table_config.filter_columns, + ) + } + + fn display_data<'a> + ( + data : &'a impl TableFormatter< 'a >, + f : &mut fmt::Formatter< '_ >, + format : impl TableOutputFormat, + filter_columns : &'a Vec< String >, + ) -> fmt::Result + { + let mut printer = print::Printer::with_format( &format ); + let binding = | title : &str | + { + filter_columns.is_empty() || filter_columns.iter().any( |c| c.as_str() == title ) + }; + printer.filter_col = &binding; + + let mut context = print::Context::new( f, printer ); + TableFormatter::fmt( data, &mut context ) + } + +} + +crate::mod_interface! +{ + own use display_tabular_data; +} \ No newline at end of file diff --git a/module/move/assistant/tests/inc/agents_tests/context_test.rs b/module/move/assistant/tests/inc/agents_tests/context_test.rs new file mode 100644 index 0000000000..e28fc8c264 --- /dev/null +++ b/module/move/assistant/tests/inc/agents_tests/context_test.rs @@ -0,0 +1,128 @@ +use super::*; + +use the_module::agents:: +{ + path::Path, + context:: + { + ContextDir, + ContextEntry, + }, +}; + +#[ test ] +fn context_dir_add_terminal() +{ + let mut ctx : ContextDir< () > = ContextDir::new(); + let entry = ContextEntry::Terminal( () ); + let name = "test"; + + let res = ctx.add( name, entry.clone() ); + + assert!( res ); + assert_eq!( ctx.get( name ), Some( &entry ) ); +} + +#[ test ] +fn context_dir_add_dir() +{ + let mut ctx : ContextDir< () > = ContextDir::new(); + let entry : ContextEntry< () > = ContextDir::new().into(); + let name = "test"; + + let res = ctx.add( name, entry.clone() ); + + assert!( res ); + assert_eq!( ctx.get( name ), Some( &entry ) ); +} + +#[ test ] +fn context_dir_add_duplicate() +{ + let name = "test"; + let orig_entry = ContextEntry::Terminal( 1 ); + + let mut ctx : ContextDir< usize > = ContextDir::new(); + ctx.add( name, orig_entry.clone() ); + + let res = ctx.add( name, ContextEntry::Terminal( 2 ) ); + + assert!( !res ); + assert_eq!( ctx.get( name ), Some( &orig_entry ) ); +} + +#[ test ] +fn context_dir_get() +{ + let mut ctx : ContextDir< usize > = ContextDir::new(); + ctx.add( "test_1", ContextEntry::Terminal( 1 ) ); + ctx.add( "test_2", ContextEntry::Terminal( 2 ) ); + ctx.add( "test_3", ContextEntry::Terminal( 3 ) ); + + assert_eq!( ctx.get( "test_1" ), Some( &ContextEntry::Terminal( 1 ) ) ); + assert_eq!( ctx.get( "test_2" ), Some( &ContextEntry::Terminal( 2 ) ) ); + assert_eq!( ctx.get( "test_3" ), Some( &ContextEntry::Terminal( 3 ) ) ); +} + +#[ test ] +fn context_dir_get_non_existing() +{ + let ctx : ContextDir< () > = ContextDir::new(); + + let res = ctx.get( "test" ); + + assert!( res.is_none() ); +} + +#[ test ] +fn context_dir_get_by_path_relative() +{ + let value_1 = ContextEntry::Terminal( 1 ); + let value_2 = ContextEntry::Terminal( 2 ); + let value_3 = ContextEntry::Terminal( 3 ); + + let mut dir_1 : ContextDir< usize > = ContextDir::new(); + dir_1.add( "value_1", value_1.clone() ); + dir_1.add( "value_2", value_2.clone() ); + + let mut dir_3 : ContextDir< usize > = ContextDir::new(); + dir_3.add( "value_3", value_3.clone() ); + + let mut dir_2 : ContextDir< usize > = ContextDir::new(); + dir_2.add( "dir_3", dir_3.into() ); + + let mut ctx : ContextDir< usize > = ContextDir::new(); + ctx.add( "dir_1", dir_1.into() ); + ctx.add( "dir_2", dir_2.into() ); + + let got_value_1 = ctx.get_by_path( &Path::try_from( "dir_1::value_1" ).unwrap() ); + let got_value_2 = ctx.get_by_path( &Path::try_from( "dir_1::value_2" ).unwrap() ); + let got_value_3 = ctx.get_by_path( &Path::try_from( "dir_2::dir_3::value_3" ).unwrap() ); + + assert_eq!( got_value_1, Some( &value_1 ) ); + assert_eq!( got_value_2, Some( &value_2 ) ); + assert_eq!( got_value_3, Some( &value_3 ) ); +} + +#[ test ] +fn context_dir_get_by_path_absolute() +{ + let entry = ContextEntry::Terminal( () ); + let mut ctx : ContextDir< () > = ContextDir::new(); + ctx.add( "test", entry.clone() ); + + let res = ctx.get_by_path( &&Path::try_from( "::test" ).unwrap() ); + + assert!( res.is_some() ); + assert_eq!( res.unwrap(), &entry ); +} + +#[ test ] +fn context_dir_get_by_path_non_existing() +{ + let ctx : ContextDir< () > = ContextDir::new(); + + let res = ctx.get_by_path( &Path::try_from( "test" ).unwrap() ); + + assert!( res.is_none() ); +} \ No newline at end of file diff --git a/module/move/assistant/tests/inc/agents_tests/mod.rs b/module/move/assistant/tests/inc/agents_tests/mod.rs new file mode 100644 index 0000000000..f4260d9ed5 --- /dev/null +++ b/module/move/assistant/tests/inc/agents_tests/mod.rs @@ -0,0 +1,9 @@ +use super::*; + +mod test_scenarios; + +mod path_test; +mod context_test; +mod scenario_raw_test; +mod scenario_raw_processors; +mod scenario_processed_test; \ No newline at end of file diff --git a/module/move/assistant/tests/inc/agents_tests/path_test.rs b/module/move/assistant/tests/inc/agents_tests/path_test.rs new file mode 100644 index 0000000000..277f4965ff --- /dev/null +++ b/module/move/assistant/tests/inc/agents_tests/path_test.rs @@ -0,0 +1,259 @@ +use super::*; + +use the_module::agents::path::Path; + +#[ test ] +fn path_create_right() +{ + let path_str = "agent::completion"; + + let path = Path::try_from( path_str ); + + assert!( path.is_ok() ); + assert_eq! ( path.unwrap().inner(), path_str ); +} + +#[ test ] +fn path_create_wrong() +{ + let path = Path::try_from( "agent:completion" ); + assert!( path.is_err() ); +} + +#[ test ] +fn path_create_absolute() +{ + let path_str = "::agent::completion"; + + let path = Path::try_from( path_str ); + + assert!( path.is_ok() ); + assert_eq! ( path.unwrap().inner(), path_str ); +} + +#[ test ] +fn path_create_trailing() +{ + let path_str = "agent::completion::"; + + let path = Path::try_from( path_str ); + + assert!( path.is_ok() ); + assert_eq! ( path.unwrap().inner(), path_str ); +} + +#[ test ] +fn path_some_parent_relative() +{ + let path_str = "agent::completion"; + let path = Path::try_from( path_str ).unwrap(); + + let path_parent = path.parent(); + + assert!( path_parent.is_some() ); + assert_eq!( path_parent.unwrap().inner(), "agent" ); +} + +#[ test ] +fn path_some_parent_relative_trailing() +{ + let path_str = "agent::completion::"; + let path = Path::try_from( path_str ).unwrap(); + + let path_parent = path.parent(); + + assert!( path_parent.is_some() ); + assert_eq!( path_parent.unwrap().inner(), "agent" ); +} + +#[ test ] +fn path_some_parent_absolute() +{ + let path_str = "::agent"; + let path = Path::try_from( path_str ).unwrap(); + + let path_parent = path.parent(); + + assert!( path_parent.is_some() ); + assert_eq!( path_parent.unwrap().inner(), "::" ); +} + +#[ test ] +fn path_some_parent_absolute_trailing() +{ + let path_str = "::agent::"; + let path = Path::try_from( path_str ).unwrap(); + + let path_parent = path.parent(); + + assert!( path_parent.is_some() ); + assert_eq!( path_parent.unwrap().inner(), "::" ); +} + +#[ test ] +fn path_none_parent() +{ + let path_str = "agent"; + let path = Path::try_from( path_str ).unwrap(); + + let path_parent = path.parent(); + + assert!( path_parent.is_none() ); +} + +#[ test ] +fn path_is_relative() +{ + let path_str = "agent"; + let path = Path::try_from( path_str ).unwrap(); + + let is_relative = path.is_relative(); + let is_absolute = path.is_absolute(); + + assert!( is_relative ); + assert!( !is_absolute ); +} + +#[ test ] +fn path_is_absolute() +{ + let path_str = "::agent"; + let path = Path::try_from( path_str ).unwrap(); + + let is_relative = path.is_relative(); + let is_absolute = path.is_absolute(); + + assert!( !is_relative ); + assert!( is_absolute ); +} + +#[ test ] +fn path_join_relative() +{ + let orig_path = Path::try_from( "agent" ).unwrap(); + let append = Path::try_from( "completion" ).unwrap(); + + let combined = orig_path.join( &append ); + + assert_eq!( combined.inner(), "agent::completion" ); +} + +#[ test ] +fn path_join_absolute() +{ + let orig_path = Path::try_from( "agent" ).unwrap(); + let append = Path::try_from( "::completion" ).unwrap(); + + let combined = orig_path.join( &append ); + + assert_eq!( combined.inner(), "::completion" ); +} + +#[ test ] +fn path_join_root() +{ + let orig_path = Path::try_from( "::" ).unwrap(); + let append = Path::try_from( "agent" ).unwrap(); + + let combined = orig_path.join( &append ); + + assert_eq!( combined.inner(), "::agent" ); +} + +#[ test ] +fn path_join_trailing() +{ + let orig_path = Path::try_from( "agents::" ).unwrap(); + let append = Path::try_from( "completion" ).unwrap(); + + let combined = orig_path.join( &append ); + + assert_eq!( combined.inner(), "agents::completion" ); +} + +#[ test ] +fn path_starts_with_abs_abs() +{ + let a = Path::try_from( "::agent::completion" ).unwrap(); + let b = Path::try_from( "::agent" ).unwrap(); + + let starts_with = a.starts_with( &b ); + + assert!( starts_with ); +} + +#[ test ] +fn path_starts_with_abs_rel() +{ + let a = Path::try_from( "::agent::completion" ).unwrap(); + let b = Path::try_from( "agent" ).unwrap(); + + let starts_with = a.starts_with( &b ); + + assert!( !starts_with ); +} + +#[ test ] +fn path_starts_with_rel_abs() +{ + let a = Path::try_from( "agent" ).unwrap(); + let b = Path::try_from( "::agent::completion" ).unwrap(); + + let starts_with = a.starts_with( &b ); + + assert!( !starts_with ); +} + +#[ test ] +fn path_starts_with_rel_rel() +{ + let a = Path::try_from( "agent::completion" ).unwrap(); + let b = Path::try_from( "agent" ).unwrap(); + + let starts_with = a.starts_with( &b ); + + assert!( starts_with ); +} + +#[ test ] +fn path_not_starts_with_abs_abs() +{ + let a = Path::try_from( "::agent::completion" ).unwrap(); + let b = Path::try_from( "::output" ).unwrap(); + + let starts_with = a.starts_with( &b ); + + assert!( !starts_with ); +} + +#[ test ] +fn path_not_starts_with_rel_rel() +{ + let a = Path::try_from( "agent::completion" ).unwrap(); + let b = Path::try_from( "output" ).unwrap(); + + let starts_with = a.starts_with( &b ); + + assert!( !starts_with ); +} + +#[ test ] +fn path_inner() +{ + let path_str = "::agent::completion"; + let path = Path::try_from( path_str ).unwrap(); + + let inner = path.inner(); + + assert_eq!( inner, path_str ); +} + +#[ test ] +fn path_components() +{ + let path = Path::try_from( "::agents::completion" ).unwrap(); + + let components : Vec< &str > = path.components().collect(); + + assert_eq!( components, vec![ "::", "agents", "completion" ] ); +} \ No newline at end of file diff --git a/module/move/assistant/tests/inc/agents_tests/scenario_processed_test.rs b/module/move/assistant/tests/inc/agents_tests/scenario_processed_test.rs new file mode 100644 index 0000000000..5fc734ae41 --- /dev/null +++ b/module/move/assistant/tests/inc/agents_tests/scenario_processed_test.rs @@ -0,0 +1,25 @@ +use super::*; + +use the_module::agents::scenario_processed::ScenarioProcessed; + +use test_scenarios:: +{ + gen_test_scenario_raw, + gen_test_scenario_raw_wrong, +}; + +#[ test ] +fn scenario_processed_right() +{ + let scenario_processed = ScenarioProcessed::try_from( gen_test_scenario_raw() ); + + assert!( scenario_processed.is_ok() ); +} + +#[ test ] +fn scenario_processed_wrong() +{ + let scenario_processed = ScenarioProcessed::try_from( gen_test_scenario_raw_wrong() ); + + assert!( scenario_processed.is_err() ); +} \ No newline at end of file diff --git a/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/mod.rs b/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/mod.rs new file mode 100644 index 0000000000..bbaccfe254 --- /dev/null +++ b/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/mod.rs @@ -0,0 +1,4 @@ +use super::*; + +mod plantuml_formatter_test; +mod yaml_formatter_test; \ No newline at end of file diff --git a/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/plantuml_formatter_test.rs b/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/plantuml_formatter_test.rs new file mode 100644 index 0000000000..44d5cf86b7 --- /dev/null +++ b/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/plantuml_formatter_test.rs @@ -0,0 +1,33 @@ +use super::*; + +use the_module::agents::scenario_raw_processors::plantuml_formatter::plantuml_formatter; + +use test_scenarios::gen_test_scenario_raw; + + +#[ test ] +fn plantuml_formatter_test() +{ + let expected_plantuml = r#"@startuml +json node_1 { + "type": "agents::completion", + "model": "gpt-4o-mini" +} +json node_2 { + "type": "agents::classify", + "model": "gpt-4o" +} +json ::scenario::termination { +} +node_1 --> node_2 : next +node_2 --> ::scenario::termination : next +@enduml"#; + + let scenario_raw = gen_test_scenario_raw(); + + let mut buffer = Vec::new(); + let result = plantuml_formatter( &scenario_raw, &mut buffer ); + + assert!( result.is_ok() ); + assert_eq!( String::from_utf8( buffer ).unwrap(), expected_plantuml ); +} diff --git a/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/yaml_formatter_test.rs b/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/yaml_formatter_test.rs new file mode 100644 index 0000000000..fd64cbacec --- /dev/null +++ b/module/move/assistant/tests/inc/agents_tests/scenario_raw_processors/yaml_formatter_test.rs @@ -0,0 +1,33 @@ +use super::*; + +use the_module::agents::scenario_raw_processors::yaml_formatter::yaml_formatter; + +use test_scenarios::gen_test_scenario_raw; + +#[ test ] +fn yaml_formatter_test() +{ + let expected_yaml = r#"nodes: +- id: node_1 + type: agents::completion + model: gpt-4o-mini + next: node_2 +- id: node_2 + type: agents::classify + model: gpt-4o + next: ::scenario::termination"#; + + let scenario_raw = gen_test_scenario_raw(); + + let mut buffer = Vec::new(); + let result = yaml_formatter( &scenario_raw, &mut buffer ); + assert!( result.is_ok() ); + + let result = String::from_utf8( buffer ); + assert!( result.is_ok() ); + + let result = result.unwrap(); + println!( "{}", result ); + + assert_eq!( result.trim(), expected_yaml.trim() ); +} diff --git a/module/move/assistant/tests/inc/agents_tests/scenario_raw_test.rs b/module/move/assistant/tests/inc/agents_tests/scenario_raw_test.rs new file mode 100644 index 0000000000..2f8acc60fe --- /dev/null +++ b/module/move/assistant/tests/inc/agents_tests/scenario_raw_test.rs @@ -0,0 +1,49 @@ +use super::*; + +use the_module::agents::scenario_raw::ScenarioRaw; + +use test_scenarios::gen_test_scenario_raw; + +#[ test ] +fn scenario_read() +{ + let scenario_text = r#" + nodes: + - id: node_1 + type: agents::completion + model: gpt-4o-mini + next: node_2 + + - id: node_2 + type: agents::classify + model: gpt-4o + next: ::scenario::termination + "#; + + let expected_scenario_raw = gen_test_scenario_raw(); + + let scenario_raw = ScenarioRaw::read( scenario_text.as_bytes() ); + + assert!( scenario_raw.is_ok() ); + + let scenario_raw = scenario_raw.unwrap(); + assert_eq!( scenario_raw, expected_scenario_raw ); +} + +#[ test ] +fn scenario_wrong() +{ + let scenario_text = r#" + nodes: + - completion: + model: + company: openai + name: gpt-4o + depends_on: + node_2 + "#; + + let scenario_raw = ScenarioRaw::read( scenario_text.as_bytes() ); + + assert!( scenario_raw.is_err() ); +} \ No newline at end of file diff --git a/module/move/assistant/tests/inc/agents_tests/test_scenarios.rs b/module/move/assistant/tests/inc/agents_tests/test_scenarios.rs new file mode 100644 index 0000000000..02433a68ea --- /dev/null +++ b/module/move/assistant/tests/inc/agents_tests/test_scenarios.rs @@ -0,0 +1,64 @@ +use super::*; + +use the_module::agents::scenario_raw:: +{ + ScenarioRaw, + NodeRaw, +}; + +/// Generates an example `ScenarioRaw`. +pub fn gen_test_scenario_raw() -> ScenarioRaw +{ + ScenarioRaw::former() + .nodes( vec! + [ + NodeRaw::former() + .id( "node_1".to_string() ) + .r#type( "agents::completion".to_string() ) + .params( + { + let mut map : HashMap< String, String > = HashMap::new(); + map.insert( "model".into(), "gpt-4o-mini".into() ); + map + } + ) + .next( "node_2".to_string() ) + .form(), + + NodeRaw::former() + .id( "node_2".to_string() ) + .r#type( "agents::classify".to_string() ) + .params( + { + let mut map : HashMap< String, String > = HashMap::new(); + map.insert( "model".into(), "gpt-4o".into() ); + map + } + ) + .next( "::scenario::termination".to_string() ) + .form(), + ] ) + .form() +} + +/// Generates a `ScenarioRaw` with wrong syntax for `Path`. +pub fn gen_test_scenario_raw_wrong() -> ScenarioRaw +{ + ScenarioRaw::former() + .nodes( vec! + [ + NodeRaw::former() + .id( "node_1".to_string() ) + .r#type( ":agents:".to_string() ) // This part is incorrect. Path written in wrong syntax. + .params( + { + let mut map : HashMap< String, String > = HashMap::new(); + map.insert( "model".into(), "gpt-4o-mini".into() ); + map + } + ) + .next( "node_2".to_string() ) + .form(), + ] ) + .form() +} \ No newline at end of file diff --git a/module/move/assistant/tests/inc/mod.rs b/module/move/assistant/tests/inc/mod.rs index 0706620c6e..abf35e2f97 100644 --- a/module/move/assistant/tests/inc/mod.rs +++ b/module/move/assistant/tests/inc/mod.rs @@ -1,6 +1,7 @@ #[ allow( unused_imports ) ] use super::*; -mod basic_test; +mod agents_tests; +mod basic_test; mod experiment; diff --git a/module/move/crates_tools/Cargo.toml b/module/move/crates_tools/Cargo.toml index 3bc5d48dab..3f14f8e209 100644 --- a/module/move/crates_tools/Cargo.toml +++ b/module/move/crates_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "crates_tools" -version = "0.12.0" +version = "0.14.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/move/crates_tools/License b/module/move/crates_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/move/crates_tools/License +++ b/module/move/crates_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/move/crates_tools/src/lib.rs b/module/move/crates_tools/src/lib.rs index 92dc8c0048..f43c975b7f 100644 --- a/module/move/crates_tools/src/lib.rs +++ b/module/move/crates_tools/src/lib.rs @@ -3,7 +3,7 @@ #![ doc( html_root_url = "https://docs.rs/crates_tools/latest/crates_tools/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -/// Internal namespace. +/// Define a private namespace for all its items. #[ cfg( feature = "enabled" ) ] mod private { diff --git a/module/move/deterministic_rand/Cargo.toml b/module/move/deterministic_rand/Cargo.toml index 1a469f1249..ae667e3e41 100644 --- a/module/move/deterministic_rand/Cargo.toml +++ b/module/move/deterministic_rand/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "deterministic_rand" -version = "0.5.0" +version = "0.6.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/move/deterministic_rand/License b/module/move/deterministic_rand/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/move/deterministic_rand/License +++ b/module/move/deterministic_rand/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/move/deterministic_rand/src/hrng_deterministic.rs b/module/move/deterministic_rand/src/hrng_deterministic.rs index ceb64b06c0..e489d8522e 100644 --- a/module/move/deterministic_rand/src/hrng_deterministic.rs +++ b/module/move/deterministic_rand/src/hrng_deterministic.rs @@ -6,7 +6,7 @@ //! Both have the same interface and are interchengable by switching on/off a feature `determinsim`. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/move/deterministic_rand/src/hrng_non_deterministic.rs b/module/move/deterministic_rand/src/hrng_non_deterministic.rs index 1ab19d55d2..57db16656b 100644 --- a/module/move/deterministic_rand/src/hrng_non_deterministic.rs +++ b/module/move/deterministic_rand/src/hrng_non_deterministic.rs @@ -6,7 +6,7 @@ //! Both have the same interface and are interchengable by switching on/off a feature `determinsim`. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/move/deterministic_rand/src/iter.rs b/module/move/deterministic_rand/src/iter.rs index caab96a148..cdfb83e100 100644 --- a/module/move/deterministic_rand/src/iter.rs +++ b/module/move/deterministic_rand/src/iter.rs @@ -3,7 +3,7 @@ //! Extensions of iterator for determinism. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/move/deterministic_rand/src/lib.rs b/module/move/deterministic_rand/src/lib.rs index b41e465453..dccd3d6c55 100644 --- a/module/move/deterministic_rand/src/lib.rs +++ b/module/move/deterministic_rand/src/lib.rs @@ -18,6 +18,8 @@ pub use hrng_deterministic as hrng; #[ cfg( any( not( feature = "determinism" ), feature = "no_std" ) ) ] pub use hrng_non_deterministic as hrng; +mod private {} + mod_interface! { diff --git a/module/move/deterministic_rand/src/seed.rs b/module/move/deterministic_rand/src/seed.rs index c7f1e078a9..fc68cc4cdf 100644 --- a/module/move/deterministic_rand/src/seed.rs +++ b/module/move/deterministic_rand/src/seed.rs @@ -3,7 +3,7 @@ //! Master seed. //! -/// Internal namespace. +/// Define a private namespace for all its items. mod private { #[ cfg( feature = "no_std" ) ] diff --git a/module/move/graphs_tools/Cargo.toml b/module/move/graphs_tools/Cargo.toml index f0eeb97831..b5d158bc21 100644 --- a/module/move/graphs_tools/Cargo.toml +++ b/module/move/graphs_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "graphs_tools" -version = "0.2.0" +version = "0.3.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/move/graphs_tools/License b/module/move/graphs_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/move/graphs_tools/License +++ b/module/move/graphs_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/move/graphs_tools/Readme.md b/module/move/graphs_tools/Readme.md index d65e2f6913..07a0274fe4 100644 --- a/module/move/graphs_tools/Readme.md +++ b/module/move/graphs_tools/Readme.md @@ -5,12 +5,11 @@ [![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_graphs_tools_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_graphs_tools_push.yml) [![docs.rs](https://img.shields.io/docsrs/graphs_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/graphs_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%2Fmove%2Fgraphs_tools%2Fexamples%2Fgraphs_tools_trivial.rs,RUN_POSTFIX=--example%20graphs_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) -Graphs tools. +**NOT ready for production** + - ```rust #[ cfg( all( feature = "cell_factory", feature = "use_std" ) ) ] { @@ -37,3 +36,4 @@ cd wTools cd examples/graphs_tools_trivial cargo run ``` +--> diff --git a/module/move/graphs_tools/src/abs/edge.rs b/module/move/graphs_tools/src/abs/edge.rs index 550a350efb..214f8f10d9 100644 --- a/module/move/graphs_tools/src/abs/edge.rs +++ b/module/move/graphs_tools/src/abs/edge.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/move/graphs_tools/src/abs/factory.rs b/module/move/graphs_tools/src/abs/factory.rs index 0f6d19e324..ad6bc76c8b 100644 --- a/module/move/graphs_tools/src/abs/factory.rs +++ b/module/move/graphs_tools/src/abs/factory.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/move/graphs_tools/src/abs/id_generator.rs b/module/move/graphs_tools/src/abs/id_generator.rs index 943315c041..2090439804 100644 --- a/module/move/graphs_tools/src/abs/id_generator.rs +++ b/module/move/graphs_tools/src/abs/id_generator.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::prelude::*; diff --git a/module/move/graphs_tools/src/abs/identity.rs b/module/move/graphs_tools/src/abs/identity.rs index 412b759d73..287e69f4b1 100644 --- a/module/move/graphs_tools/src/abs/identity.rs +++ b/module/move/graphs_tools/src/abs/identity.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::prelude::*; diff --git a/module/move/graphs_tools/src/abs/node.rs b/module/move/graphs_tools/src/abs/node.rs index b227581718..703bd0893d 100644 --- a/module/move/graphs_tools/src/abs/node.rs +++ b/module/move/graphs_tools/src/abs/node.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/move/graphs_tools/src/algo/dfs.rs b/module/move/graphs_tools/src/algo/dfs.rs index 0a75884e2c..13e7c81e84 100644 --- a/module/move/graphs_tools/src/algo/dfs.rs +++ b/module/move/graphs_tools/src/algo/dfs.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/move/graphs_tools/src/canonical/edge.rs b/module/move/graphs_tools/src/canonical/edge.rs index 3bf782aaee..4d02b207d4 100644 --- a/module/move/graphs_tools/src/canonical/edge.rs +++ b/module/move/graphs_tools/src/canonical/edge.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/move/graphs_tools/src/canonical/factory_generative.rs b/module/move/graphs_tools/src/canonical/factory_generative.rs index ba735895c4..1e2e838081 100644 --- a/module/move/graphs_tools/src/canonical/factory_generative.rs +++ b/module/move/graphs_tools/src/canonical/factory_generative.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/move/graphs_tools/src/canonical/factory_readable.rs b/module/move/graphs_tools/src/canonical/factory_readable.rs index 9ec9bf6012..d545d38d89 100644 --- a/module/move/graphs_tools/src/canonical/factory_readable.rs +++ b/module/move/graphs_tools/src/canonical/factory_readable.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/move/graphs_tools/src/canonical/identity.rs b/module/move/graphs_tools/src/canonical/identity.rs index 90b53e8879..f4c1a38eba 100644 --- a/module/move/graphs_tools/src/canonical/identity.rs +++ b/module/move/graphs_tools/src/canonical/identity.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/move/graphs_tools/src/canonical/node.rs b/module/move/graphs_tools/src/canonical/node.rs index 94d7f7d313..ce0aa547bd 100644 --- a/module/move/graphs_tools/src/canonical/node.rs +++ b/module/move/graphs_tools/src/canonical/node.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/move/gspread/.secret/readme.md b/module/move/gspread/.secret/readme.md new file mode 100644 index 0000000000..e3e100f72d --- /dev/null +++ b/module/move/gspread/.secret/readme.md @@ -0,0 +1,42 @@ +# Getting API Keys for OAuth Authentication + +Follow these steps to create and configure your OAuth credentials for using Google APIs. + +## 1. Create API Credentials + +1. Go to the [Google API Console](https://console.developers.google.com/). +2. From the projects list, select an existing project or create a new one. +3. In the left side menu, select **APIs & Services**. +4. On the left menu, click **Credentials**. +5. Click **Create Credentials** and select **OAuth client ID**. +6. In the **Application type** section, select **Desktop app**. +7. Provide an appropriate name for your client ID (e.g., "Gspread OAuth Client"). +8. Click **Create**. + +Once the credential is created, you will receive a **Client ID** and **Client Secret**. These are required for accessing the API. + +## 2. Store Your Credentials + +Save the **Client ID** and **Client Secret** in a `.env` within a `.secret` directory. The file should look like this: + +```bash +CLIENT_ID=YOUR_CLIENT_ID +CLIENT_SECRET=YOUR_SECRET_KEY +``` + +## 3. Why do we need it? + +After executing each command, you need to grant the GSPREAD program access to the Google API. You will receive a link that begin with 'Please direct your browser to https://....' that will redirect you to your browser, where you must authorize the access. You will need to select the appropriate Google account that has the credentials for the application. The **CLIENT_ID** and **CLIENT_SECRET** are set up to do this process. + +## 4. Troubleshooting + +If you encounter a page displaying an error instead of the Google account selection screen, it is likely that you need to add **AUTH_URI** or **TOKEN_URI** to the .env file. In this case, all four secrets are required. To retrieve them, download the API key you created in JSON format. Open the file and copy the necessary keys into the .env file. After making these changes, your .env file should look like this: + +```bash +CLIENT_ID=YOUR_CLIENT_ID +CLIENT_SECRET=YOUR_SECRET_KEY +AUTH_URI=YOUR_AUTH_URI +TOKEN_URI=YOUR_TOKEN_URI +``` + +If you still get some issues, follow [Google OAuth Documentation](https://developers.google.com/identity/protocols/oauth2/). \ No newline at end of file diff --git a/module/move/gspread/Cargo.toml b/module/move/gspread/Cargo.toml new file mode 100644 index 0000000000..8d1d86b4a3 --- /dev/null +++ b/module/move/gspread/Cargo.toml @@ -0,0 +1,49 @@ +[package] +name = "gspread" +version = "0.1.0" +edition = "2021" +authors = [ + "Vsevolod Bakutov " +] +license = "MIT" +description = """ + Google Sheets Cli API +""" +categories = [ "algorithms", "development-tools" ] +keywords = [ "fundamental", "general-purpose" ] +default-run = "main" + +[[bin]] +name = "main" +path = "src/bin/main.rs" + +[features] +default = [ "enabled" ] +full = [ "enabled" ] +enabled = [ + "former/enabled", + "format_tools/enabled", + "reflect_tools/enabled", +] + +[dependencies] +mod_interface = { workspace = true, features = ["full"] } +former = { workspace = true, features = ["full"] } +format_tools = { workspace = true, features = ["full"] } +reflect_tools = { workspace = true, features = [ "full" ] } +clap = { version = "4.5.20", features = ["derive"] } +tokio = { version = "1", features = ["full"] } +google-sheets4 = "6.0.0" +hyper-util = "0.1.10" +yup-oauth2 = "11.0.0" +pth = "0.21.0" +dotenv = "0.15" +serde = { version = "1.0.213", features = ["derive"] } +serde_with = "3.11.0" +error_tools = "0.19.0" +derive_tools = { version = "0.32.0", features = ["full"] } +serde_json = "1.0.132" +regex = "1.11.1" + +[dev-dependencies] +test_tools = { workspace = true } diff --git a/module/move/gspread/readme.md b/module/move/gspread/readme.md new file mode 100644 index 0000000000..9b1cc3aaee --- /dev/null +++ b/module/move/gspread/readme.md @@ -0,0 +1,9 @@ +## Module :: gspread + +[![experimental](https://img.shields.io/badge/status-experimental-orange)](https://github.com/emersion/stability-badges#experimental) +[![ask](https://img.shields.io/badge/discord-join%20chat-7289DA)](https://discord.gg/RzQGqF5z) + + +**NOT ready for production** + +NOT ready for production \ No newline at end of file diff --git a/module/move/gspread/src/actions.rs b/module/move/gspread/src/actions.rs new file mode 100644 index 0000000000..1c96538040 --- /dev/null +++ b/module/move/gspread/src/actions.rs @@ -0,0 +1,16 @@ +//! +//! CLI actions of the tool. +//! + +mod private {} + +crate::mod_interface! +{ + layer gspread; + layer gspread_get_header; + layer gspread_get_rows; + layer gspread_cell_get; + layer gspread_cell_set; + layer gspread_cells_set; +} + diff --git a/module/move/gspread/src/actions/gspread.rs b/module/move/gspread/src/actions/gspread.rs new file mode 100644 index 0000000000..60b0fd980c --- /dev/null +++ b/module/move/gspread/src/actions/gspread.rs @@ -0,0 +1,66 @@ +//! +//! Google Sheets API actions. +//! +//! This module also contains the definition of Google Sheets Error. +//! + +mod private +{ + use regex::Regex; + use error_tools::typed::Error; + use derive_tools::AsRefStr; + use crate::*; + use ser::DisplayFromStr; + + #[ ser::serde_as ] + #[ derive( Debug, Error, AsRefStr, ser::Serialize ) ] + #[ serde( tag = "type", content = "data" ) ] + pub enum Error + { + #[ error( "Google Sheets returned error:\n{0}" ) ] + ApiError + ( + #[ from ] + #[ serde_as( as = "DisplayFromStr" ) ] + google_sheets4::Error + ), + + #[ error( "Invalid URL format: {0}" ) ] + InvalidUrl + ( + String + ), + } + + pub fn get_spreadsheet_id_from_url + ( + url : &str + ) -> Result< &str > + { + + let re = Regex::new( r"d/([^/]+)/edit" ).unwrap(); + if let Some( captures ) = re.captures( url ) + { + if let Some( id ) = captures.get( 1 ) + { + return Ok( id.as_str() ); + } + } + + Err + ( + Error::InvalidUrl( "Wrong url format.\nFix: copy sheet's the whole url from your browser. Usage: --url ''".to_string() ) + ) + } + + pub type Result< T > = core::result::Result< T, Error >; +} + +crate::mod_interface! +{ + own use + { + Result, + get_spreadsheet_id_from_url, + }; +} \ No newline at end of file diff --git a/module/move/gspread/src/actions/gspread_cell_get.rs b/module/move/gspread/src/actions/gspread_cell_get.rs new file mode 100644 index 0000000000..3a4d6b1be3 --- /dev/null +++ b/module/move/gspread/src/actions/gspread_cell_get.rs @@ -0,0 +1,42 @@ +//! +//! Action for command "cell get" +//! +//! It returns a selected cell +//! + +mod private +{ + use crate::*; + use actions::gspread::Result; + use client::SheetsType; + use ser::JsonValue; + + pub async fn action + ( + hub : &SheetsType, + spreadsheet_id : &str, + table_name : &str, + cell_id : &str, + ) -> Result< JsonValue > + { + let result = hub + .spreadsheets() + .values_get( spreadsheet_id, format!( "{}!{}", table_name, cell_id ).as_str() ) + .doit() + .await? + .1 + .values; + + match result + { + Some( values ) => Ok( values.get( 0 ).unwrap().get( 0 ).unwrap().clone() ), + None => Ok( JsonValue::Null.clone() ) + } + + } +} + +crate::mod_interface! +{ + own use action; +} \ No newline at end of file diff --git a/module/move/gspread/src/actions/gspread_cell_set.rs b/module/move/gspread/src/actions/gspread_cell_set.rs new file mode 100644 index 0000000000..818a667f1c --- /dev/null +++ b/module/move/gspread/src/actions/gspread_cell_set.rs @@ -0,0 +1,50 @@ +//! +//! Action for command "cell set" +//! +//! It updates a selected cell +//! + + +mod private +{ + use google_sheets4::api::ValueRange; + use crate::*; + use actions::gspread::Result; + use client::SheetsType; + use ser::JsonValue; + + pub async fn action + ( + hub : &SheetsType, + spreadsheet_id : &str, + table_name : &str, + cell_id : &str, + value : &str + ) -> Result< i32 > + { + + let value = JsonValue::String( value.to_string() ); + let value_range = ValueRange + { + values : Some( vec![ vec![ value ] ] ), + ..ValueRange::default() + }; + + let result = hub + .spreadsheets() + .values_update( value_range, spreadsheet_id, format!( "{}!{}", table_name, cell_id ).as_str() ) + .value_input_option( "USER_ENTERED" ) + .doit() + .await? + .1 + .updated_cells + .unwrap(); + + Ok( result ) + } +} + +crate::mod_interface! +{ + own use action; +} \ No newline at end of file diff --git a/module/move/gspread/src/actions/gspread_cells_set.rs b/module/move/gspread/src/actions/gspread_cells_set.rs new file mode 100644 index 0000000000..a6528b6c4b --- /dev/null +++ b/module/move/gspread/src/actions/gspread_cells_set.rs @@ -0,0 +1,132 @@ +//! +//! Set command -> set specified values in specified columns in specified row +//! + +mod private +{ + use crate::*; + use google_sheets4::api:: + { + BatchUpdateValuesRequest, + ValueRange + }; + use ser:: + { + Deserialize, + JsonValue + }; + use std::collections::HashMap; + + /// Structure for --json value + #[ derive( Deserialize, Debug ) ] + struct ParsedJson + { + #[ serde( flatten ) ] + columns : HashMap< String, String > + } + + /// Parse --json value + fn parse_json + ( + json_str : &str + ) -> Result< ParsedJson, String > + { + serde_json::from_str::< ParsedJson >( json_str ).map_err + ( + | err | format!( "Failed to parse JSON: {}", err ) + ) + } + + /// Check availables keys. + /// Available keys: "id" -> row's id + fn check_select_row_by_key + ( + key : &str + ) -> Result< (), String > + { + let keys = vec![ "id" ]; + if keys.contains( &key ) + { + Ok( () ) + } + else + { + Err( format!( "Invalid select_row_by_key: '{}'. Allowed keys: {:?}", key, keys ) ) + } + } + + fn is_all_uppercase_letters + ( + s : &str + ) -> Result< (), String > + { + if s.chars().all( | c | c.is_ascii_uppercase() ) + { + Ok( () ) + } + else + { + Err( format!( "The string '{}' contains invalid characters. Only uppercase letters (A-Z) are allowed.", s ) ) + } + } + + pub async fn action + ( + hub : &SheetsType, + select_row_by_key : &str, + json_str : &str, + spreadsheet_id : &str, + table_name : &str + ) -> Result< String, String > + { + check_select_row_by_key( select_row_by_key )?; + + let mut pairs = parse_json( json_str )?; + + let row_id = pairs + .columns + .remove( select_row_by_key ) + .ok_or_else( || format!( "Key '{}' not found in JSON", select_row_by_key ) )?; + + let mut value_ranges= Vec::new(); + + for ( key, value ) in pairs.columns.into_iter() + { + is_all_uppercase_letters( key.as_str() )?; + value_ranges.push + ( + ValueRange + { + range: Some( format!( "{}!{}{}", table_name, key, row_id ) ), + values: Some( vec![ vec![ JsonValue::String( value.to_string() ) ] ] ), + ..Default::default() + } + ); + }; + + let req = BatchUpdateValuesRequest + { + value_input_option: Some( "USER_ENTERED".to_string() ), + data: Some( value_ranges ), + include_values_in_response: Some( true ), + ..Default::default() + }; + + let result = hub + .spreadsheets() + .values_batch_update( req, spreadsheet_id ) + .doit() + .await; + + match result + { + Ok( _ ) => Ok( format!( "Cells were sucsessfully updated!" ) ), + Err( error ) => Err( format!( "{}", error ) ) + } + } +} + +crate::mod_interface! +{ + own use action; +} \ No newline at end of file diff --git a/module/move/gspread/src/actions/gspread_get_header.rs b/module/move/gspread/src/actions/gspread_get_header.rs new file mode 100644 index 0000000000..8f7b83c477 --- /dev/null +++ b/module/move/gspread/src/actions/gspread_get_header.rs @@ -0,0 +1,58 @@ +//! +//! Action for command "header" +//! +//! It returns header (first row) +//! + + +mod private +{ + use std::fmt; + use crate::*; + use client::SheetsType; + use actions::gspread::Result; + use format_tools::AsTable; + use util::display_table::display_header; + use ser::JsonValue; + + #[ derive( Debug ) ] + pub struct Report + { + pub rows : Vec< RowWrapper > + } + + impl fmt::Display for Report + { + fn fmt + ( + &self, + f : &mut fmt::Formatter + ) -> fmt::Result + { + display_header( &AsTable::new( &self.rows ), f ) + } + } + + pub async fn action + ( + hub : &SheetsType, + spreadsheet_id : &str, + table_name: &str) -> Result< Vec< Vec< JsonValue > > > + { + let result = hub + .spreadsheets() + .values_get( spreadsheet_id, format!( "{}!A1:Z1", table_name ).as_str() ) + .doit() + .await? + .1 + .values + .unwrap_or_else( | | Vec::new() ); + + Ok( result ) + } +} + +crate::mod_interface! +{ + own use action; +} \ No newline at end of file diff --git a/module/move/gspread/src/actions/gspread_get_rows.rs b/module/move/gspread/src/actions/gspread_get_rows.rs new file mode 100644 index 0000000000..3a083217ed --- /dev/null +++ b/module/move/gspread/src/actions/gspread_get_rows.rs @@ -0,0 +1,38 @@ +//! +//! Action for command "rows" +//! +//! It returns all rows but not header +//! + + +mod private +{ + use crate::*; + use client::SheetsType; + use actions::gspread::Result; + use ser::JsonValue; + + pub async fn action + ( + hub : &SheetsType, + spreadsheet_id : &str, + table_name : &str + ) -> Result< Vec< Vec < JsonValue > > > + { + let result = hub + .spreadsheets() + .values_get( spreadsheet_id, format!( "{}!A2:Z", table_name ).as_str() ) + .doit() + .await? + .1 + .values + .unwrap_or_else( | | Vec::new() ); + + Ok( result ) + } +} + +crate::mod_interface! +{ + own use action; +} diff --git a/module/move/gspread/src/bin/main.rs b/module/move/gspread/src/bin/main.rs new file mode 100644 index 0000000000..8f55f07f1c --- /dev/null +++ b/module/move/gspread/src/bin/main.rs @@ -0,0 +1,32 @@ +use std::error::Error; +use clap::Parser; +use dotenv::dotenv; + +use gspread:: +{ + client::hub, + commands::{ Cli, CliCommand, self }, + secret::Secret, +}; + +#[ tokio::main ] +async fn main() -> Result< (), Box< dyn Error > > +{ + dotenv().ok(); + + let secret = Secret::read(); + + let hub = hub( &secret ).await?; + + let cli = Cli::parse(); + + match cli.command + { + CliCommand::GSpread( cmd ) => + { + commands::gspread::command( &hub, cmd ).await; + } + } + + Ok( () ) +} diff --git a/module/move/gspread/src/client.rs b/module/move/gspread/src/client.rs new file mode 100644 index 0000000000..c836ccf4d3 --- /dev/null +++ b/module/move/gspread/src/client.rs @@ -0,0 +1,79 @@ +//! +//! Client of API. +//! + +mod private +{ + + use google_sheets4 as sheets4; + use sheets4::Sheets; + use sheets4::hyper_rustls; + use sheets4::hyper_util; + use sheets4::yup_oauth2:: + { + self, + ApplicationSecret + }; + use hyper_util::client::legacy::connect::HttpConnector; + + pub use hyper_util::client::legacy::Client; + + use std:: + { + error::Error, + }; + + use crate::*; + use secret::Secret; + + pub type SheetsType = Sheets< hyper_rustls::HttpsConnector< HttpConnector > >; + + pub async fn hub( secrets: &Secret ) -> Result< SheetsType, Box< dyn Error > > + { + let secret: ApplicationSecret = ApplicationSecret + { + client_id : secrets.CLIENT_ID.clone(), + auth_uri : secrets.AUTH_URI.clone(), + token_uri : secrets.TOKEN_URI.clone(), + client_secret : secrets.CLIENT_SECRET.clone(), + .. Default::default() + }; + + let auth = yup_oauth2::InstalledFlowAuthenticator::builder + ( + secret, + yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect, + ) + .build() + .await + .unwrap(); + + let client = Client::builder + ( + hyper_util::rt::TokioExecutor::new() + ) + .build + ( + hyper_rustls::HttpsConnectorBuilder::new() + .with_native_roots() + .unwrap() + .https_or_http() + .enable_http1() + .build() + ); + + Ok( Sheets::new( client, auth ) ) + } + + +} + +crate::mod_interface! +{ + exposed use + { + hub, + Client, + SheetsType + }; +} \ No newline at end of file diff --git a/module/move/gspread/src/commands.rs b/module/move/gspread/src/commands.rs new file mode 100644 index 0000000000..5ce88f9eb2 --- /dev/null +++ b/module/move/gspread/src/commands.rs @@ -0,0 +1,52 @@ +//! +//! Commands +//! + + +mod private +{ + + use clap:: + { + Parser, + Subcommand + }; + + use crate::*; + use commands::gspread; + + /// CLI commands of the tool. + #[ derive ( Debug, Parser ) ] + pub struct Cli + { + /// Root of the CLI commands. + #[ command ( subcommand ) ] + pub command : CliCommand, + } + + /// Root of the CLI commands. + #[ derive ( Debug, Subcommand ) ] + pub enum CliCommand + { + /// Google Sheets commands. + #[ command ( subcommand, name = "gspread" ) ] + GSpread( gspread::Command ), + } + +} + +crate::mod_interface! +{ + layer gspread; + layer gspread_header; + layer gspread_rows; + layer gspread_cell; + layer gspread_cells; + + own use + { + Cli, + CliCommand, + }; +} + diff --git a/module/move/gspread/src/commands/gspread.rs b/module/move/gspread/src/commands/gspread.rs new file mode 100644 index 0000000000..8398aa3ec6 --- /dev/null +++ b/module/move/gspread/src/commands/gspread.rs @@ -0,0 +1,104 @@ +//! +//! Collection of Google Sheets API commands. +//! + + +mod private +{ + + use clap::{ Subcommand, Parser }; + + use crate::*; + use client::SheetsType; + + use commands:: + { + gspread_header, + gspread_rows, + gspread_cell, + gspread_cells + }; + + #[ derive( Debug, Parser ) ] + pub struct CommonArgs + { + #[ arg( long ) ] + pub url : String, + + #[ arg( long ) ] + pub tab : String + } + + #[ derive( Debug, Subcommand ) ] + pub enum Command + { + + #[ command ( name = "header" ) ] + Header + ( + CommonArgs + ), + + #[ command( name = "rows" ) ] + Rows + ( + CommonArgs + ), + + #[ command ( subcommand, name = "cell" ) ] + Cell + ( + gspread_cell::Commands + ), + + #[ command ( subcommand, name = "cells" ) ] + Cells + ( + gspread_cells::Commands + ) + + } + + pub async fn command + ( + hub : &SheetsType, + command : Command, + ) + { + match command + { + + Command::Header( header_command ) => + { + gspread_header::command( hub, header_command ).await; + }, + + Command::Rows( rows_command ) => + { + gspread_rows::command( hub, rows_command ).await; + }, + + Command::Cell( cell_command ) => + { + gspread_cell::command( hub, cell_command ).await; + }, + + Command::Cells( cells_command) => + { + gspread_cells::command( hub, cells_command ).await; + }, + + } + } + +} + +crate::mod_interface! +{ + own use + { + CommonArgs, + Command, + command, + }; +} \ No newline at end of file diff --git a/module/move/gspread/src/commands/gspread_cell.rs b/module/move/gspread/src/commands/gspread_cell.rs new file mode 100644 index 0000000000..057da2dd09 --- /dev/null +++ b/module/move/gspread/src/commands/gspread_cell.rs @@ -0,0 +1,122 @@ +//! +//! Collection of subcommands fo command "cell" +//! + +mod private +{ + + use clap::Subcommand; + + use crate::*; + use actions; + use actions::gspread::get_spreadsheet_id_from_url; + use client::SheetsType; + + #[ derive( Debug, Subcommand ) ] + pub enum Commands + { + #[ command( name = "get" ) ] + Get + { + #[ arg( long ) ] + url : String, + + #[ arg( long ) ] + tab : String, + + #[ arg( long ) ] + cel : String, + }, + + #[ command( name = "set" ) ] + Set + { + #[ arg( long ) ] + url : String, + + #[ arg( long ) ] + tab : String, + + #[ arg( long ) ] + cel : String, + + #[ arg( long ) ] + val : String + } + } + + pub async fn command + ( + hub : &SheetsType, + commands : Commands + ) + { + match commands + { + Commands::Get { url, tab, cel } => + { + let spreadsheet_id = match get_spreadsheet_id_from_url( url.as_str() ) + { + Ok( id ) => id, + Err( error ) => + { + eprintln!( "Error extracting spreadsheet ID: {}", error ); + return; + } + }; + + let result = actions::gspread_cell_get::action + ( + hub, + spreadsheet_id, + tab.as_str(), + cel.as_str() + ).await; + + match result + { + Ok( value ) => println!( "Value: {}", value ), + Err( error ) => println!( "Error: {}", error ), + } + }, + + Commands::Set { url, tab, cel, val } => + { + let spreadsheet_id = match get_spreadsheet_id_from_url( url.as_str() ) + { + Ok( id ) => id, + Err( error ) => + { + eprintln!( "Error extracting spreadsheet ID: {}", error ); + return; + } + }; + + let result = actions::gspread_cell_set::action + ( + hub, + spreadsheet_id, + tab.as_str(), + cel.as_str(), + val.as_str() + ).await; + + match result + { + Ok( value ) => println!( "Success: {:?}", value ), + Err( error ) => println!( "Error: {}", error ), + } + } + + } + } +} + +crate::mod_interface! +{ + own use + { + command, + Commands, + }; +} \ No newline at end of file diff --git a/module/move/gspread/src/commands/gspread_cells.rs b/module/move/gspread/src/commands/gspread_cells.rs new file mode 100644 index 0000000000..13ecf1e378 --- /dev/null +++ b/module/move/gspread/src/commands/gspread_cells.rs @@ -0,0 +1,80 @@ +//! +//! Cells commands. +//! set command -> set specified values in specified columns in specified row. +//! + +mod private +{ + use clap::Subcommand; + + use crate::*; + use actions::gspread::get_spreadsheet_id_from_url; + + #[ derive( Debug, Subcommand ) ] + pub enum Commands + { + #[ command( name = "set" ) ] + Set + { + #[ arg( long ) ] + select_row_by_key : String, + + #[ arg( long ) ] + json : String, + + #[ arg( long ) ] + url : String, + + #[ arg( long ) ] + tab : String + } + + } + + pub async fn command + ( + hub : &SheetsType, + commands : Commands + ) + { + match commands + { + Commands::Set { select_row_by_key, json, url, tab } => + { + let spreadsheet_id = match get_spreadsheet_id_from_url( url.as_str() ) + { + Ok( id ) => id, + Err( error ) => + { + eprintln!( "Error extracting spreadsheet ID: {}", error ); + return; + } + }; + + let result = actions::gspread_cells_set::action + ( + &hub, + select_row_by_key.as_str(), + json.as_str(), + spreadsheet_id, + tab.as_str() + ).await; + + match result + { + Ok( msg ) => println!( "{}", msg ), + Err( error ) => println!( "{}", error ) + } + } + } + } +} + +crate::mod_interface! +{ + own use + { + command, + Commands + }; +} \ No newline at end of file diff --git a/module/move/gspread/src/commands/gspread_header.rs b/module/move/gspread/src/commands/gspread_header.rs new file mode 100644 index 0000000000..5048d3e4ed --- /dev/null +++ b/module/move/gspread/src/commands/gspread_header.rs @@ -0,0 +1,86 @@ +//! +//! Command "header" +//! + +mod private +{ + use std::fmt; + use crate::*; + use commands::gspread::CommonArgs; + use client::SheetsType; + use actions; + use actions::gspread::get_spreadsheet_id_from_url; + use format_tools::AsTable; + use util::display_table::display_header; + + #[ derive( Debug ) ] + pub struct Report + { + pub rows : Vec< RowWrapper > + } + + impl fmt::Display for Report + { + fn fmt + ( + &self, + f : &mut fmt::Formatter + ) -> fmt::Result + { + display_header( &AsTable::new( &self.rows ), f ) + } + } + + pub async fn command + ( + hub : &SheetsType, + args : CommonArgs, + ) + { + match args + { + CommonArgs { url, tab } => + { + let spreadsheet_id = match get_spreadsheet_id_from_url( url.as_str() ) + { + Ok( id ) => id, + Err( error ) => + { + eprintln!( "Error extracting spreadsheet ID: {}", error ); + return; + } + }; + + let result = actions::gspread_get_header::action + ( + hub, + spreadsheet_id, + tab.as_str() + ).await; + + match result + { + Ok( header ) => + { + let header_wrapped = header + .into_iter() + .map( | row | RowWrapper{ max_len: row.len(), row } ) + .collect(); + + println!( "Header: \n {}", Report{ rows: header_wrapped } ); + } + Err( error ) => println!( "Error: {}", error ), + } + } + } + } +} + +crate::mod_interface! +{ + own use + { + command + }; +} + diff --git a/module/move/gspread/src/commands/gspread_rows.rs b/module/move/gspread/src/commands/gspread_rows.rs new file mode 100644 index 0000000000..426d7f2dde --- /dev/null +++ b/module/move/gspread/src/commands/gspread_rows.rs @@ -0,0 +1,85 @@ +//! +//! Command "rows" +//! + +mod private +{ + use std::fmt; + use crate::*; + use commands::gspread::CommonArgs; + use client::SheetsType; + use actions; + use actions::gspread::get_spreadsheet_id_from_url; + use format_tools::AsTable; + use util::display_table::display_rows; + + pub struct Report + { + pub rows : Vec< RowWrapper > + } + + impl fmt::Display for Report + { + fn fmt + ( + &self, + f : &mut fmt::Formatter + ) -> fmt::Result + { + display_rows( &AsTable::new( &self.rows ), f ) + } + } + + pub async fn command + ( + hub : &SheetsType, + args : CommonArgs + ) + { + match args + { + CommonArgs { url, tab } => + { + let spreadsheet_id = match get_spreadsheet_id_from_url( url.as_str() ) + { + Ok( id ) => id, + Err( error ) => + { + eprintln!( "Error extracting spreadsheet ID: {}", error ); + return; + } + }; + + let result = actions::gspread_get_rows::action + ( + hub, + spreadsheet_id, + tab.as_str() + ).await; + + match result + { + Ok( rows ) => + { + let max_len = rows.iter().map(|row| row.len()).max().unwrap_or(0); + let rows_wrapped: Vec = rows + .into_iter() + .map(|row| RowWrapper { row, max_len }) + .collect(); + + println!( "Rows: \n {}", Report{ rows: rows_wrapped } ); + } + Err( error ) => println!( "Error: {}", error ), + } + } + } + } +} + +crate::mod_interface! +{ + own use + { + command + }; +} diff --git a/module/move/gspread/src/debug.rs b/module/move/gspread/src/debug.rs new file mode 100644 index 0000000000..11f63d821e --- /dev/null +++ b/module/move/gspread/src/debug.rs @@ -0,0 +1,20 @@ +mod private +{ +} + +use format_tools:: +{ + Fields, + TableWithFields, +}; +use std::borrow::Cow; + +pub mod row_wrapper; + +crate::mod_interface! +{ + exposed use + { + row_wrapper::RowWrapper, + }; +} diff --git a/module/move/gspread/src/debug/row_wrapper.rs b/module/move/gspread/src/debug/row_wrapper.rs new file mode 100644 index 0000000000..b8e1635ac7 --- /dev/null +++ b/module/move/gspread/src/debug/row_wrapper.rs @@ -0,0 +1,59 @@ +//! +//! Gspread wrapper for outputting data to console +//! +//! It is used for "header" and "rows" commands +//! + +use super::*; +use crate::*; +use ser::JsonValue; + + +#[ derive( Debug ) ] +pub struct RowWrapper +{ + pub row: Vec< JsonValue >, + pub max_len: usize +} + +impl Clone for RowWrapper +{ + fn clone( &self ) -> Self + { + Self + { + row: self.row.clone(), + max_len: self.max_len.clone() + } + } +} + +impl TableWithFields for RowWrapper {} +impl Fields< &'_ str, Option< Cow< '_, str > > > +for RowWrapper +{ + type Key< 'k > = &'k str; + type Val< 'v > = Option< Cow< 'v, str > >; + + fn fields( &self ) -> impl IteratorTrait< Item= ( &'_ str, Option > ) > + { + let mut dst = Vec::new(); + + for ( index, value ) in self.row.iter().enumerate() + { + let column_name = format!( "Column{}", index ); + let title = Box::leak( column_name.into_boxed_str() ) as &str; + dst.push( ( title, Some( Cow::Owned( value.to_string() ) ) ) ) + } + + //adding empty values for missing cells + for index in self.row.len()..self.max_len + { + let column_name = format!( "Column{}", index ); + let title = Box::leak( column_name.into_boxed_str() ) as &str; + dst.push( ( title, Some( Cow::Owned( "".to_string() ) ) ) ); + } + + dst.into_iter() + } +} \ No newline at end of file diff --git a/module/move/gspread/src/lib.rs b/module/move/gspread/src/lib.rs new file mode 100644 index 0000000000..c0d2432985 --- /dev/null +++ b/module/move/gspread/src/lib.rs @@ -0,0 +1,41 @@ +use mod_interface::mod_interface; +use error_tools::thiserror; + +mod private +{ +} + +pub mod ser +{ + pub use serde:: + { + Serialize, + Deserialize, + }; + pub use serde_json:: + { + value::{ Value as JsonValue, Number as JsonNumber }, + error::Error, + self + }; + pub use serde_with::*; +} + +crate::mod_interface! +{ + + layer client; + layer debug; + layer commands; + layer actions; + layer secret; + layer util; + + exposed use ::reflect_tools:: + { + Fields, + _IteratorTrait, + IteratorTrait, + }; + +} \ No newline at end of file diff --git a/module/move/gspread/src/secret.rs b/module/move/gspread/src/secret.rs new file mode 100644 index 0000000000..48567b77f4 --- /dev/null +++ b/module/move/gspread/src/secret.rs @@ -0,0 +1,159 @@ +//! +//! Tool's secret +//! + +mod private +{ + use crate::*; + use std:: + { + env, + sync::OnceLock, + }; + + use error_tools::typed::Error; + use ser::DisplayFromStr; + + #[ ser::serde_as ] + #[ derive( Debug, Error, ser::Serialize ) ] + #[ serde( tag = "type", content = "data" ) ] + pub enum Error + { + #[ error( "Secret file is illformed\n{0}" ) ] + SecretFileIllformed + ( + #[ from ] + #[ serde_as( as = "DisplayFromStr" ) ] + dotenv::Error + ), + + #[ error( "Secret missing the variable {0}" ) ] + VariableMissing( &'static str ), + + #[ error( "Secret error processing in the variable {0}\n{1}" ) ] + VariableIllformed( &'static str, String ), + + } + + pub type Result< R > = std::result::Result< R, Error >; + + #[ derive( Debug ) ] + #[ allow( non_snake_case ) ] + pub struct Secret + { + pub CLIENT_SECRET : String, + pub CLIENT_ID: String, + pub AUTH_URI : String, + pub TOKEN_URI : String, + } + + impl Secret + { + #[ allow( non_snake_case ) ] + pub fn load() -> Result< Self > + { + let path = "./.secret/.env"; + + let r = dotenv::from_path( path ); + if let Err( ref err ) = r + { + if !matches!( err, dotenv::Error::Io(_) ) + { + return Err( r.expect_err( &format!( "Failed to load {path}" ) ).into() ); + } + } + + let config = Self + { + CLIENT_SECRET : var( "CLIENT_SECRET", None )?, + CLIENT_ID : var( "CLIENT_ID", None )?, + AUTH_URI : var ( "AUTH_URI", Some( "https://accounts.google.com/o/oauth2/auth" ) )?, + TOKEN_URI : var ( "TOKEN_URI", Some( "https://oauth2.googleapis.com/token" ) )? + }; + Ok( config ) + } + + pub fn read() -> Secret + { + Self::load().unwrap_or_else( | err | + { + let example = include_str!("../.secret/readme.md"); + let explanation = format! + ( + r#" = Lack of secrets + +Failed to load secret or some its parameters. +{err} + + = Fix + +Add missing secret to .env file in .secret directory. Example: MISSING_SECRET=YOUR_MISSING_SECRET + + = More information + +{example} +"# + ); + panic!( "{}", explanation ); + }) + } + + pub fn get() -> &'static Secret + { + static INSTANCE : OnceLock< Secret > = OnceLock::new(); + INSTANCE.get_or_init( || Self::read() ) + } + + } + + fn var + ( + name : &'static str, + default : Option< &'static str >, + ) -> Result < String > + { + match env::var( name ) + { + Ok( val ) => Ok ( val ), + Err( _ ) => + { + if let Some( default_value ) = default + { + Ok( default_value.to_string() ) + } + else + { + Err ( Error::VariableMissing( name ) ) + } + } + } + } + + fn _var_path + ( + name : &'static str, + default : Option<&'static str>, + ) -> Result < pth::AbsolutePath > + { + let p = var( name, default )?; + pth::AbsolutePath::from_paths( ( pth::CurrentPath, p ) ) + .map_err( |e| Error::VariableIllformed( name, e.to_string() ) ) + } + +} + +crate::mod_interface! +{ + + own use + { + Error, + Result, + }; + + orphan use + { + Secret, + }; + +} \ No newline at end of file diff --git a/module/move/gspread/src/util.rs b/module/move/gspread/src/util.rs new file mode 100644 index 0000000000..ac76ad86b2 --- /dev/null +++ b/module/move/gspread/src/util.rs @@ -0,0 +1,6 @@ +mod private {} + +crate::mod_interface! +{ + layer display_table; +} \ No newline at end of file diff --git a/module/move/gspread/src/util/display_table.rs b/module/move/gspread/src/util/display_table.rs new file mode 100644 index 0000000000..3d96964d9b --- /dev/null +++ b/module/move/gspread/src/util/display_table.rs @@ -0,0 +1,55 @@ + + +mod private +{ + + use std::fmt; + + use format_tools:: + { + TableFormatter, + print, + output_format, + TableOutputFormat + }; + + pub fn display_rows< 'a > + ( + data : &'a impl TableFormatter< 'a >, + f : &mut fmt::Formatter< '_ > + ) -> fmt::Result + { + display_data( data, f, output_format::Table::default() ) + } + + pub fn display_header < 'a > + ( + data : &'a impl TableFormatter< 'a >, + f : &mut fmt::Formatter< '_ > + ) -> fmt::Result + { + display_data( data, f, output_format::Table::default() ) + } + + pub fn display_data < 'a > + ( + data : &'a impl TableFormatter< 'a >, + f : &mut fmt::Formatter< '_ >, + format : impl TableOutputFormat, + ) -> fmt::Result + { + let printer = print::Printer::with_format( &format ); + let mut context = print::Context::new( f, printer ); + TableFormatter::fmt( data, &mut context ) + } + +} + +crate::mod_interface! +{ + own use + { + display_rows, + display_header + }; +} \ No newline at end of file diff --git a/module/move/gspread/tests/inc/cell_tests.rs b/module/move/gspread/tests/inc/cell_tests.rs new file mode 100644 index 0000000000..f93ec7b1a4 --- /dev/null +++ b/module/move/gspread/tests/inc/cell_tests.rs @@ -0,0 +1,99 @@ +#[ allow( unused_imports ) ] +use super::*; + +use the_module:: +{ + hub, + Secret, + actions, + SheetsType, + ser::JsonValue +}; + +async fn setup() -> ( SheetsType, &'static str, &'static str ) +{ + let secret = Secret::load().expect( "Failed to load secret" ); + let hub = hub( &secret ).await.expect( "Failed to create a hub" ); + let spreadsheet_id = "1EAEdegMpitv-sTuxt8mV8xQxzJE7h_J0MxQoyLH7xxU"; + let table_name = "tab5"; + + ( hub, spreadsheet_id, table_name ) +} + +#[ tokio::test ] +async fn test_get_cell() +{ + let ( hub, spreadsheet_id, table_name ) = setup().await; + let cell_id = "R2C1"; + + let result = actions::gspread_cell_get::action + ( + &hub, + spreadsheet_id, + table_name, + cell_id + ) + .await + .expect( "Error getting cell" ); + + assert_eq!( result, "Vsevolod" ) +} + +#[ tokio::test ] +async fn test_get_cell_empty() +{ + let ( hub, spreadsheet_id, table_name ) = setup().await; + let cell_id = "R4C1"; + + let result = actions::gspread_cell_get::action + ( + &hub, + spreadsheet_id, + table_name, + cell_id + ) + .await + .expect( "Error getting cell" ); + + assert_eq!( result, JsonValue::Null ) +} + +#[ tokio::test ] +async fn test_set_cell() +{ + let ( hub, spreadsheet_id, table_name ) = setup().await; + let cell_id = "R2C1"; + let value = "Seva"; + + let result = actions::gspread_cell_set::action + ( + &hub, + spreadsheet_id, + table_name, + cell_id, + value + ) + .await; + + assert!( result.is_ok() ); +} + +#[ tokio::test ] +async fn test_set_empty_cell() +{ + let ( hub, spreadsheet_id, table_name ) = setup().await; + let cell_id = "R4C1"; + let value = "Stanislav"; + + let result = actions::gspread_cell_set::action + ( + &hub, + spreadsheet_id, + table_name, + cell_id, + value + ) + .await; + + assert!( result.is_ok() ); +} \ No newline at end of file diff --git a/module/move/gspread/tests/inc/cells_tests.rs b/module/move/gspread/tests/inc/cells_tests.rs new file mode 100644 index 0000000000..4c91a9a19c --- /dev/null +++ b/module/move/gspread/tests/inc/cells_tests.rs @@ -0,0 +1,79 @@ +#[ allow( unused_imports ) ] +use super::*; + +use the_module:: +{ + hub, + Secret, + actions, + SheetsType, +}; + +async fn setup() -> ( SheetsType, &'static str, &'static str, &'static str ) +{ + let secret = Secret::load().expect( "Failed to load secret" ); + let hub = hub( &secret ).await.expect( "Failed to create a hub" ); + let select_row_by_key = "id"; + let spreadsheet_id = "1EAEdegMpitv-sTuxt8mV8xQxzJE7h_J0MxQoyLH7xxU"; + let table_name = "tab7"; + + ( hub, select_row_by_key, spreadsheet_id, table_name ) +} + +#[ tokio::test ] +async fn test_set_cells() +{ + let + ( + hub, + select_row_by_key, + spreadsheet_id, + table_name + ) = setup().await; + + let json = r#"{ "id": "2", "A": "new_val1", "B": "new_val2"}"#; + + let result = actions::gspread_cells_set::action + ( + &hub, + select_row_by_key, + json, + spreadsheet_id, + table_name, + ) + .await + .expect( "Error while updating" ); + + assert_eq!( result, "Cells were sucsessfully updated!" ) +} + +#[ tokio::test ] +async fn test_set_cells_wrong_row() +{ + let + ( + hub, + select_row_by_key, + spreadsheet_id, + table_name + ) = setup().await; + + let json = r#"{ "id": "a", "A": "new_val1", "B": "new_val2"}"#; + + let result = actions::gspread_cells_set::action + ( + &hub, + select_row_by_key, + json, + spreadsheet_id, + table_name, + ) + .await + .expect( "Error while updating" ); + + assert_eq! + ( + result, + r#"Bad Request: {"error":{"code":400,"message":"Invalid data[0]: Unable to parse range: tab7!Aa","status":"INVALID_ARGUMENT"}}"# + ) +} \ No newline at end of file diff --git a/module/move/gspread/tests/inc/header_tests.rs b/module/move/gspread/tests/inc/header_tests.rs new file mode 100644 index 0000000000..3009a63bb1 --- /dev/null +++ b/module/move/gspread/tests/inc/header_tests.rs @@ -0,0 +1,90 @@ +#[ allow( unused_imports ) ] +use super::*; + +use the_module:: +{ + hub, + Secret, + actions, + SheetsType +}; + +async fn setup() -> ( SheetsType, &'static str ) +{ + let secret = Secret::load().expect( "Failed to load secret" ); + let hub = hub( &secret ).await.expect( "Failed to create a hub" ); + let spreadsheet_id = "1EAEdegMpitv-sTuxt8mV8xQxzJE7h_J0MxQoyLH7xxU"; + + ( hub, spreadsheet_id ) +} +#[ tokio::test ] +async fn test_get_header() +{ + let ( hub, spreadsheet_id ) = setup().await; + let table_name = "tab1"; + + let result = actions::gspread_get_header::action + ( + &hub, + spreadsheet_id, + table_name + ) + .await + .expect( "Error getting header" ); + + assert_eq!( result, vec![ vec![ "Name", "Surname", "Age" ] ] ); +} + +#[ tokio::test ] +async fn test_get_header_with_spaces() +{ + let ( hub, spreadsheet_id ) = setup().await; + let table_name = "tab2"; + + let result = actions::gspread_get_header::action + ( + &hub, + spreadsheet_id, + table_name + ) + .await + .expect( "Error getting header" ); + + assert_eq!( result, vec![ vec![ "Name", "", "Age" ] ] ); +} + +#[ tokio::test ] +async fn test_get_header_empty() +{ + let ( hub, spreadsheet_id ) = setup().await; + let table_name = "tab3"; + + let result = actions::gspread_get_header::action + ( + &hub, + spreadsheet_id, + table_name + ) + .await + .expect( "Error getting header" ); + + assert_eq!( result, Vec::< Vec< String > >::new() ); +} + +#[ tokio::test ] +async fn test_get_header_with_empty_end() +{ + let ( hub, spreadsheet_id ) = setup().await; + let table_name = "tab4"; + + let result = actions::gspread_get_header::action + ( + &hub, + spreadsheet_id, + table_name + ) + .await + .expect( "Error getting header" ); + + assert_eq!( result, vec![ vec![ "Name", "Surname" ] ] ); +} \ No newline at end of file diff --git a/module/move/gspread/tests/inc/mod.rs b/module/move/gspread/tests/inc/mod.rs new file mode 100644 index 0000000000..a357c3fe4a --- /dev/null +++ b/module/move/gspread/tests/inc/mod.rs @@ -0,0 +1,14 @@ +//! +//! Here is used the +//! https://docs.google.com/spreadsheets/d/1EAEdegMpitv-sTuxt8mV8xQxzJE7h_J0MxQoyLH7xxU/edit?gid=0#gid=0 +//! test spreadsheet +//! + + +#[ allow( unused_imports ) ] +use super::*; + +mod header_tests; +mod rows_tests; +mod cell_tests; +mod cells_tests; \ No newline at end of file diff --git a/module/move/gspread/tests/inc/rows_tests.rs b/module/move/gspread/tests/inc/rows_tests.rs new file mode 100644 index 0000000000..d9032f8544 --- /dev/null +++ b/module/move/gspread/tests/inc/rows_tests.rs @@ -0,0 +1,93 @@ +#[ allow( unused_imports ) ] +use super::*; + +use the_module:: +{ + hub, + Secret, + actions, + SheetsType +}; + +async fn setup() -> ( SheetsType, &'static str ) +{ + let secret = Secret::load().expect( "Failed to load secret" ); + let hub = hub( &secret ).await.expect( "Failed to create a hub" ); + let spreadsheet_id = "1EAEdegMpitv-sTuxt8mV8xQxzJE7h_J0MxQoyLH7xxU"; + + ( hub, spreadsheet_id ) +} + +#[ tokio::test ] +async fn test_get_rows() +{ + let ( hub, spreadsheet_id ) = setup().await; + let table_name = "tab1"; + + let result = actions::gspread_get_rows::action + ( + &hub, + spreadsheet_id, + table_name + ) + .await + .expect( "Error getting rows" ); + + assert_eq! + ( + result, + vec![ + vec![ "Vsevolod", "Bakutov", "20" ], + vec![ "Victor", "Ovsyanik", "85" ], + vec![ "Olexandr", "Optimus", "28" ], + vec![ "Ivan", "Optimus", "34" ], + vec![ "Bogdan", "Optimus", "28" ], + ] + ) +} + +#[ tokio::test ] +async fn test_get_rows_with_spaces() +{ + let ( hub, spreadsheet_id ) = setup().await; + let table_name = "tab2"; + + let result = actions::gspread_get_rows::action + ( + &hub, + spreadsheet_id, + table_name + ) + .await + .expect( "Error getting rows" ); + + assert_eq! + ( + result, + vec![ + vec![ "Vsevolod", "Bakutov" ], + vec![ "Victor", "", "85" ], + vec![ "", "Optimus", "28" ], + vec![ ], + vec![ "Bogdan", "Optimus", "28" ], + ] + ) +} + +#[ tokio::test ] +async fn test_get_rows_empty() +{ + let ( hub, spreadsheet_id ) = setup().await; + let table_name = "tab3"; + + let result = actions::gspread_get_rows::action + ( + &hub, + spreadsheet_id, + table_name + ) + .await + .expect( "Error getting rows" ); + + assert_eq!( result, Vec::< Vec< String > >::new() ) +} \ No newline at end of file diff --git a/module/move/gspread/tests/smoke_test.rs b/module/move/gspread/tests/smoke_test.rs new file mode 100644 index 0000000000..c3163b32ed --- /dev/null +++ b/module/move/gspread/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(); +} \ No newline at end of file diff --git a/module/move/gspread/tests/tests.rs b/module/move/gspread/tests/tests.rs new file mode 100644 index 0000000000..201ae26926 --- /dev/null +++ b/module/move/gspread/tests/tests.rs @@ -0,0 +1,9 @@ + + +#[ allow( unused_imports ) ] +use gspread as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; \ No newline at end of file diff --git a/module/move/optimization_tools/Cargo.toml b/module/move/optimization_tools/Cargo.toml index de8500b846..af2f73c222 100644 --- a/module/move/optimization_tools/Cargo.toml +++ b/module/move/optimization_tools/Cargo.toml @@ -40,7 +40,9 @@ lp_parse = [ "dep:exmex" ] derive_tools = { workspace = true, features = [ "derive_more", "full", "strum" ] } deterministic_rand = { workspace = true, features = [ "default" ] } iter_tools = { workspace = true, features = [ "default" ] } -meta_tools = { workspace = true, features = [ "meta_constructors" ] } +# meta_tools = { workspace = true, features = [ "meta_constructors" ] } +meta_tools = { workspace = true, features = [] } +collection_tools = { workspace = true } # qqq : use intead of meta_tools error_tools = { workspace = true, features = ["default"] } env_logger = "0.10.1" log = "0.4.20" diff --git a/module/move/optimization_tools/License b/module/move/optimization_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/move/optimization_tools/License +++ b/module/move/optimization_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/move/plot_interface/License b/module/move/plot_interface/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/move/plot_interface/License +++ b/module/move/plot_interface/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/move/plot_interface/Readme.md b/module/move/plot_interface/Readme.md index 0e604acfb8..6102a14813 100644 --- a/module/move/plot_interface/Readme.md +++ b/module/move/plot_interface/Readme.md @@ -5,11 +5,12 @@ [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_plot_interface_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_plot_interface_push.yml) [![docs.rs](https://img.shields.io/docsrs/plot_interface?color=e3e8f0&logo=docs.rs)](https://docs.rs/plot_interface) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) -Plot interface. +**NOT ready for production** + + ```rust ``` @@ -27,4 +28,4 @@ git clone https://github.com/Wandalen/wTools cd wTools cd examples/plot_interface_trivial cargo run -``` +``` --> diff --git a/module/move/plot_interface/src/plot/abs/change.rs b/module/move/plot_interface/src/plot/abs/change.rs index b6ba9fc235..fc14b77ec9 100644 --- a/module/move/plot_interface/src/plot/abs/change.rs +++ b/module/move/plot_interface/src/plot/abs/change.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/abs/changer.rs b/module/move/plot_interface/src/plot/abs/changer.rs index 99e39449e0..9e09820670 100644 --- a/module/move/plot_interface/src/plot/abs/changer.rs +++ b/module/move/plot_interface/src/plot/abs/changer.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/abs/context.rs b/module/move/plot_interface/src/plot/abs/context.rs index 526b5bf488..c9f844e802 100644 --- a/module/move/plot_interface/src/plot/abs/context.rs +++ b/module/move/plot_interface/src/plot/abs/context.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/abs/identity.rs b/module/move/plot_interface/src/plot/abs/identity.rs index d8be2ccff7..1fe2b0e613 100644 --- a/module/move/plot_interface/src/plot/abs/identity.rs +++ b/module/move/plot_interface/src/plot/abs/identity.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/abs/registry.rs b/module/move/plot_interface/src/plot/abs/registry.rs index b6d662b429..21a2cd6be7 100644 --- a/module/move/plot_interface/src/plot/abs/registry.rs +++ b/module/move/plot_interface/src/plot/abs/registry.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/color.rs b/module/move/plot_interface/src/plot/color.rs index b14a3e268e..fc2b94c17f 100644 --- a/module/move/plot_interface/src/plot/color.rs +++ b/module/move/plot_interface/src/plot/color.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/context.rs b/module/move/plot_interface/src/plot/sys/context.rs index e5c23e71f6..ee2f95fbf3 100644 --- a/module/move/plot_interface/src/plot/sys/context.rs +++ b/module/move/plot_interface/src/plot/sys/context.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/context_changer.rs b/module/move/plot_interface/src/plot/sys/context_changer.rs index 2f87310469..fa33094931 100644 --- a/module/move/plot_interface/src/plot/sys/context_changer.rs +++ b/module/move/plot_interface/src/plot/sys/context_changer.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/drawing.rs b/module/move/plot_interface/src/plot/sys/drawing.rs index 7fdca77c2d..1ec732286b 100644 --- a/module/move/plot_interface/src/plot/sys/drawing.rs +++ b/module/move/plot_interface/src/plot/sys/drawing.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/drawing/change_new.rs b/module/move/plot_interface/src/plot/sys/drawing/change_new.rs index 914678a907..4661f9587b 100644 --- a/module/move/plot_interface/src/plot/sys/drawing/change_new.rs +++ b/module/move/plot_interface/src/plot/sys/drawing/change_new.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/drawing/changer.rs b/module/move/plot_interface/src/plot/sys/drawing/changer.rs index bfe7cf170f..7fd62e8e44 100644 --- a/module/move/plot_interface/src/plot/sys/drawing/changer.rs +++ b/module/move/plot_interface/src/plot/sys/drawing/changer.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/drawing/command.rs b/module/move/plot_interface/src/plot/sys/drawing/command.rs index f98cedfd22..998272ee16 100644 --- a/module/move/plot_interface/src/plot/sys/drawing/command.rs +++ b/module/move/plot_interface/src/plot/sys/drawing/command.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/drawing/queue.rs b/module/move/plot_interface/src/plot/sys/drawing/queue.rs index c68de594ba..c3148011bb 100644 --- a/module/move/plot_interface/src/plot/sys/drawing/queue.rs +++ b/module/move/plot_interface/src/plot/sys/drawing/queue.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/drawing/rect_change_new.rs b/module/move/plot_interface/src/plot/sys/drawing/rect_change_new.rs index 7b1a3acfc7..57fe8b5898 100644 --- a/module/move/plot_interface/src/plot/sys/drawing/rect_change_new.rs +++ b/module/move/plot_interface/src/plot/sys/drawing/rect_change_new.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/drawing/rect_change_region.rs b/module/move/plot_interface/src/plot/sys/drawing/rect_change_region.rs index bdbb18321d..84c1634301 100644 --- a/module/move/plot_interface/src/plot/sys/drawing/rect_change_region.rs +++ b/module/move/plot_interface/src/plot/sys/drawing/rect_change_region.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/drawing/rect_changer.rs b/module/move/plot_interface/src/plot/sys/drawing/rect_changer.rs index 85d56d9b48..cb5ddf757f 100644 --- a/module/move/plot_interface/src/plot/sys/drawing/rect_changer.rs +++ b/module/move/plot_interface/src/plot/sys/drawing/rect_changer.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/stroke_brush.rs b/module/move/plot_interface/src/plot/sys/stroke_brush.rs index 08c73b350b..edfbfc4878 100644 --- a/module/move/plot_interface/src/plot/sys/stroke_brush.rs +++ b/module/move/plot_interface/src/plot/sys/stroke_brush.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/stroke_brush/change_color.rs b/module/move/plot_interface/src/plot/sys/stroke_brush/change_color.rs index ae615f89a4..76bd951613 100644 --- a/module/move/plot_interface/src/plot/sys/stroke_brush/change_color.rs +++ b/module/move/plot_interface/src/plot/sys/stroke_brush/change_color.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/stroke_brush/change_new.rs b/module/move/plot_interface/src/plot/sys/stroke_brush/change_new.rs index d147f3241b..caa1c2f75c 100644 --- a/module/move/plot_interface/src/plot/sys/stroke_brush/change_new.rs +++ b/module/move/plot_interface/src/plot/sys/stroke_brush/change_new.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/stroke_brush/change_width.rs b/module/move/plot_interface/src/plot/sys/stroke_brush/change_width.rs index 192b42e8ad..758fbe75a7 100644 --- a/module/move/plot_interface/src/plot/sys/stroke_brush/change_width.rs +++ b/module/move/plot_interface/src/plot/sys/stroke_brush/change_width.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/stroke_brush/changer.rs b/module/move/plot_interface/src/plot/sys/stroke_brush/changer.rs index c6f8ab0f5f..d6208455a0 100644 --- a/module/move/plot_interface/src/plot/sys/stroke_brush/changer.rs +++ b/module/move/plot_interface/src/plot/sys/stroke_brush/changer.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/plot_interface/src/plot/sys/target.rs b/module/move/plot_interface/src/plot/sys/target.rs index 96f38bfe51..820f3a3b97 100644 --- a/module/move/plot_interface/src/plot/sys/target.rs +++ b/module/move/plot_interface/src/plot/sys/target.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::prelude::*; diff --git a/module/move/refiner/License b/module/move/refiner/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/move/refiner/License +++ b/module/move/refiner/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/move/sqlx_query/License b/module/move/sqlx_query/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/move/sqlx_query/License +++ b/module/move/sqlx_query/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/move/sqlx_query/src/lib.rs b/module/move/sqlx_query/src/lib.rs index b0855a6219..53d4a4043e 100644 --- a/module/move/sqlx_query/src/lib.rs +++ b/module/move/sqlx_query/src/lib.rs @@ -17,7 +17,7 @@ #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/../../../", "Readme.md" ) ) ] -/// Internal namespace. +/// Define a private namespace for all its items. #[ cfg( feature = "enabled" ) ] mod private { diff --git a/module/move/unitore/Cargo.toml b/module/move/unitore/Cargo.toml index 8f98fba818..fa560e6cae 100644 --- a/module/move/unitore/Cargo.toml +++ b/module/move/unitore/Cargo.toml @@ -32,7 +32,7 @@ enabled = [] [dependencies] error_tools = { workspace = true, features = [ "default" ] } -proper_path_tools = { workspace = true, features = [ "default" ] } +pth = { workspace = true, features = [ "default" ] } tokio = { version = "1.36.0", features = [ "rt", "rt-multi-thread", "io-std", "macros" ] } hyper = { version = "1.1.0", features = [ "client" ] } hyper-tls = "0.6.0" diff --git a/module/move/unitore/src/action/config.rs b/module/move/unitore/src/action/config.rs index 9dfc356fe0..a2da010f41 100644 --- a/module/move/unitore/src/action/config.rs +++ b/module/move/unitore/src/action/config.rs @@ -16,7 +16,7 @@ use gluesql::{ prelude::Payload, sled_storage::SledStorage }; /// Add configuration file with subscriptions to storage. pub async fn config_add( mut storage : FeedStorage< SledStorage >, path : &PathBuf ) -> Result< impl Report > { - let path = proper_path_tools::path::normalize( path ); + let path = pth::path::normalize( path ); let mut err_str = format!( "Invalid path for config file {:?}", path ); @@ -63,7 +63,7 @@ pub async fn config_add( mut storage : FeedStorage< SledStorage >, path : &PathB /// Remove configuration file from storage. pub async fn config_delete( mut storage : FeedStorage< SledStorage >, path : &PathBuf ) -> Result< impl Report > { - let path = proper_path_tools::path::normalize( path ); + let path = pth::path::normalize( path ); let path = path.canonicalize().context( format!( "Invalid path for config file {:?}", path ) )?; let config = Config::new( path.to_string_lossy().to_string() ); diff --git a/module/move/unitore/src/command/config.rs b/module/move/unitore/src/command/config.rs index bbd436ccb9..b1e678a732 100644 --- a/module/move/unitore/src/command/config.rs +++ b/module/move/unitore/src/command/config.rs @@ -18,7 +18,28 @@ impl ConfigCommand /// Create command for adding config. pub fn add() -> Result< Command > { - let rt = tokio::runtime::Runtime::new()?; + #[ tokio::main ] + async fn add_command( o : VerifiedCommand ) + { + // qqq: could we print something on None value? + let Some( path ) = o.args.get_owned::< PathBuf >( 0 ) else { return; }; + + let path_to_storage = std::env::var( "UNITORE_STORAGE_PATH" ).ok() + .unwrap_or_else( || String::from( "./_data" ) ); + let config = Config::default().path( path_to_storage ); + + let res = ( || async + { + let feed_storage = FeedStorage::init_storage( &config ).await?; + config_add( feed_storage, &path ).await + } )().await; + + match res + { + Ok( report ) => report.report(), + Err( err ) => println!( "{:?}", err ), + } + } Ok ( @@ -37,38 +58,7 @@ impl ConfigCommand " link = \"https://feeds.bbci.co.uk/news/world/rss.xml\"\n", )) .subject().hint( "Path" ).kind( Type::Path ).optional( false ).end() - .routine( move | o : VerifiedCommand | - { - let path_arg = o.args - .get_owned::< wca::Value >( 0 ); - - if let Some( path ) = path_arg - { - let path : PathBuf = path.into(); - - let res = rt.block_on - ( async move - { - let path_to_storage = std::env::var( "UNITORE_STORAGE_PATH" ) - .unwrap_or( String::from( "./_data" ) ) - ; - - let config = Config::default() - .path( path_to_storage ) - ; - - let feed_storage = FeedStorage::init_storage( &config ).await?; - config_add( feed_storage, &path ).await - } - ); - - match res - { - Ok( report ) => report.report(), - Err( err ) => println!( "{:?}", err ), - } - } - }) + .routine( add_command ) .end() ) } @@ -76,8 +66,29 @@ impl ConfigCommand /// Create command for deleting config. pub fn delete() -> Result< Command > { - let rt = tokio::runtime::Runtime::new()?; - + #[ tokio::main ] + async fn delete_command( o : VerifiedCommand ) + { + // qqq: could we print something on None value? + let Some( path ) = o.args.get_owned::< PathBuf >( 0 ) else { return; }; + + let path_to_storage = std::env::var( "UNITORE_STORAGE_PATH" ).ok() + .unwrap_or_else( || String::from( "./_data" ) ); + let config = Config::default().path( path_to_storage ); + + let res = ( || async + { + let feed_storage = FeedStorage::init_storage( &config ).await?; + config_delete( feed_storage, &path ).await + } )().await; + + match res + { + Ok( report ) => report.report(), + Err( err ) => println!( "{:?}", err ), + } + } + Ok( Command::former() .phrase( "config.delete" ) @@ -87,38 +98,7 @@ impl ConfigCommand " Example: .config.delete ./config/feeds.toml", )) .subject().hint( "Path" ).kind( Type::Path ).optional( false ).end() - .routine( move | o : VerifiedCommand | - { - let path_arg = o.args - .get_owned::< wca::Value >( 0 ); - - if let Some( path ) = path_arg - { - let path : PathBuf = path.into(); - - let res = rt.block_on - ( async move - { - let path_to_storage = std::env::var( "UNITORE_STORAGE_PATH" ) - .unwrap_or( String::from( "./_data" ) ) - ; - - let config = Config::default() - .path( path_to_storage ) - ; - - let feed_storage = FeedStorage::init_storage( &config ).await?; - config_delete( feed_storage, &path ).await - } - ); - - match res - { - Ok( report ) => report.report(), - Err( err ) => println!( "{:?}", err ), - } - } - }) + .routine( delete_command ) .end() ) } diff --git a/module/move/unitore/src/entity/config.rs b/module/move/unitore/src/entity/config.rs index 92f9f550d6..536c1c5142 100644 --- a/module/move/unitore/src/entity/config.rs +++ b/module/move/unitore/src/entity/config.rs @@ -44,7 +44,7 @@ pub trait ConfigStore // qqq : use AbsolutePath newtype from `path_tools` // qqq : normalize all paths with `path_tools::path::normalize` -// https://docs.rs/proper_path_tools/latest/proper_path_tools/path/fn.normalize.html +// https://docs.rs/pth/latest/pth/path/fn.normalize.html // added path normalization // unitore .query.execute \'SELECT \* FROM feed\' diff --git a/module/move/unitore/tests/config_add.rs b/module/move/unitore/tests/config_add.rs index 7f080622b8..6673b0f608 100644 --- a/module/move/unitore/tests/config_add.rs +++ b/module/move/unitore/tests/config_add.rs @@ -12,7 +12,7 @@ use error_tools::untyped::Result; async fn config_add() -> Result< () > { let path = PathBuf::from( "./tests/fixtures/test_config.toml" ); - let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); + let temp_path = pth::path::unique_folder_name().unwrap(); let config = Config::default() .path( format!( "./{}", temp_path ) ) diff --git a/module/move/unitore/tests/config_delete.rs b/module/move/unitore/tests/config_delete.rs index 9a7ffdf10a..c3393702cc 100644 --- a/module/move/unitore/tests/config_delete.rs +++ b/module/move/unitore/tests/config_delete.rs @@ -16,7 +16,7 @@ async fn config_delete() -> Result< () > { let path = std::path::PathBuf::from( "./tests/fixtures/test_config.toml" ); - let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); + let temp_path = pth::path::unique_folder_name().unwrap(); let config = Config::default() .path( format!( "./{}", temp_path ) ) diff --git a/module/move/unitore/tests/frames_download.rs b/module/move/unitore/tests/frames_download.rs index 11494838f9..0b78b077d0 100644 --- a/module/move/unitore/tests/frames_download.rs +++ b/module/move/unitore/tests/frames_download.rs @@ -2,7 +2,7 @@ use feed_rs::parser as feed_parser; use gluesql:: { core:: - { + { chrono::{ DateTime, Utc }, data::Value }, @@ -20,7 +20,7 @@ use error_tools::untyped::Result; #[ tokio::test ] async fn test_save() -> Result< () > { - let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); + let temp_path = pth::path::unique_folder_name().unwrap(); let config = Config::default() .path( format!( "./{}", temp_path ) ) @@ -52,7 +52,7 @@ async fn test_save() -> Result< () > #[ tokio::test ] async fn test_update() -> Result< () > { - let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); + let temp_path = pth::path::unique_folder_name().unwrap(); let config = Config::default() .path( format!( "./{}", temp_path ) ) diff --git a/module/move/unitore/tests/query_execute.rs b/module/move/unitore/tests/query_execute.rs index 4215971781..0e47c9e576 100644 --- a/module/move/unitore/tests/query_execute.rs +++ b/module/move/unitore/tests/query_execute.rs @@ -41,14 +41,14 @@ fn query_execute() -> Result< () > assert!( res.is_ok() ); // test action - let rt = tokio::runtime::Runtime::new()?; + let rt = tokio::runtime::Runtime::new()?; let ca = CommandsAggregator::former() .command( "query.execute" ) .hint( "hint" ) .long_hint( "long_hint" ) .subject().hint( "SQL query" ).kind( Type::String ).optional( false ).end() .routine( move | o : VerifiedCommand | - { + { let mut f_store = MockStore::new(); f_store .expect_query_execute() @@ -62,19 +62,19 @@ fn query_execute() -> Result< () > ] ) ) ) - ; + ; _ = rt.block_on( async move { let query_arg = o.args .get_owned::< String >( 0 ) ; - + let query_str = query_arg.unwrap(); query::query_execute( f_store, query_str ).await - } ); + } ); } ) .end() - .perform(); + .perform(); let entries = ca.perform( vec![ ".query.execute".to_string(), "SELECT title FROM frame".into() ] ); assert!( entries.is_ok() ); Ok( () ) @@ -84,7 +84,7 @@ fn query_execute() -> Result< () > async fn query_feeds() -> Result< () > { let path = PathBuf::from( "./tests/fixtures/test_config.toml" ); - let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); + let temp_path = pth::path::unique_folder_name().unwrap(); let config = sled::Config::default() .path( format!( "./{}", temp_path ) ) @@ -114,7 +114,7 @@ async fn query_feeds() -> Result< () > #[ tokio::test ] async fn query_frames() -> Result< () > { - let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); + let temp_path = pth::path::unique_folder_name().unwrap(); let config = sled::Config::default() .path( format!( "./{}", temp_path ) ) @@ -160,7 +160,7 @@ async fn query_frames() -> Result< () > async fn query_configs() -> Result< () > { let path = PathBuf::from( "./tests/fixtures/test_config.toml" ); - let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); + let temp_path = pth::path::unique_folder_name().unwrap(); let config = sled::Config::default() .path( format!( "./{}", temp_path ) ) @@ -182,6 +182,6 @@ async fn query_configs() -> Result< () > { assert!( false ); } - + Ok( () ) } diff --git a/module/move/unitore/tests/table_list.rs b/module/move/unitore/tests/table_list.rs index ff06deae00..88b16d519e 100644 --- a/module/move/unitore/tests/table_list.rs +++ b/module/move/unitore/tests/table_list.rs @@ -13,7 +13,7 @@ use error_tools::untyped::Result; #[ tokio::test ] async fn table_list() -> Result< () > { - let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); + let temp_path = pth::path::unique_folder_name().unwrap(); let config = Config::default() .path( format!( "./{}", temp_path ) ) @@ -30,7 +30,7 @@ async fn table_list() -> Result< () > .map( | row | row[ 1 ].clone() ) .collect::< Vec< _ > >() ; - + assert_eq!( column_names.len(), 9 ); assert!( column_names.contains( &Str( String::from( "published") ) ) ); assert!( column_names.contains( &Str( String::from( "authors") ) ) ); diff --git a/module/move/unitore/tests/tables_list.rs b/module/move/unitore/tests/tables_list.rs index f740e94b08..7f5fbb57f7 100644 --- a/module/move/unitore/tests/tables_list.rs +++ b/module/move/unitore/tests/tables_list.rs @@ -9,7 +9,7 @@ use error_tools::untyped::Result; #[ tokio::test ] async fn tables_list() -> Result< () > { - let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); + let temp_path = pth::path::unique_folder_name().unwrap(); let config = Config::default() .path( format!( "./{}", temp_path ) ) diff --git a/module/move/wca/Cargo.toml b/module/move/wca/Cargo.toml index 2d69a8aaff..06791cf645 100644 --- a/module/move/wca/Cargo.toml +++ b/module/move/wca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wca" -version = "0.20.0" +version = "0.23.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -40,12 +40,12 @@ harness = false [dependencies] ## internal -error_tools = { workspace = true, features = [ "default" ] } -strs_tools = { workspace = true, features = [ "default" ] } -mod_interface = { workspace = true, features = [ "default" ] } -iter_tools = { workspace = true, features = [ "default" ] } -former = { workspace = true, features = [ "default" ] } -# xxx : qqq : optimize set of features +error_tools = { workspace = true, features = [ "enabled", "error_typed", "error_untyped" ] } +mod_interface = { workspace = true, features = [ "enabled" ] } +iter_tools = { workspace = true, features = [ "enabled" ] } +former = { workspace = true, features = [ "enabled", "derive_former" ] } +# xxx : aaa : optimize set of features +# aaa : done. ## external log = "0.4" diff --git a/module/move/wca/License b/module/move/wca/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/move/wca/License +++ b/module/move/wca/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/move/wca/Readme.md b/module/move/wca/Readme.md index b808fce2bc..ecda885b57 100644 --- a/module/move/wca/Readme.md +++ b/module/move/wca/Readme.md @@ -14,7 +14,7 @@ The tool to make CLI ( commands user interface ). It is able to aggregate extern ```rust #[ cfg( not( feature = "no_std" ) ) ] { - use wca::{ VerifiedCommand, Context, Type }; + use wca::{ VerifiedCommand, Type }; fn main() { @@ -37,7 +37,7 @@ The tool to make CLI ( commands user interface ). It is able to aggregate extern .end() .perform(); - let args = std::env::args().skip( 1 ).collect::< Vec< String > >(); + let args: Vec< String > = std::env::args().skip( 1 ).collect(); ca.perform( args ).unwrap(); } diff --git a/module/move/wca/examples/wca_custom_error.rs b/module/move/wca/examples/wca_custom_error.rs new file mode 100644 index 0000000000..47fef16985 --- /dev/null +++ b/module/move/wca/examples/wca_custom_error.rs @@ -0,0 +1,43 @@ +//! +//! # Handling Errors with CommandsAggregator +//! +//! This module provides an example of how to use `wca::CommandsAggregator` to manage error handling in a command-line interface. The `CommandsAggregator` offers a fluent interface for defining commands and associating them with various error types, making it straightforward to handle and present errors in a structured way. +//! +//! ## Purpose +//! +//! The primary goal of this example is to showcase how `CommandsAggregator` facilitates error handling, whether errors are simple strings, custom typed errors, untyped errors, or errors with additional context. This approach ensures that error management is both consistent and extensible. +//! + +#[ derive( Debug, error_tools::typed::Error )] +enum CustomError +{ + #[ error( "this is typed error" ) ] + TheError, +} + +fn main() -> error_tools::error::untyped::Result< () > +{ + let ca = wca::CommandsAggregator::former() + .command( "error.string" ) + .hint( "Returns error as a string" ) + .routine( || { Err( "this is string error" ) } ) + .end() + .command( "error.typed" ) + .hint( "Returns error as a custom error" ) + .routine( || { Err( CustomError::TheError ) } ) + .end() + .command( "error.untyped" ) + .hint( "Returns error as untyped error" ) + .routine( || { Err( error_tools::error::untyped::format_err!( "this is untyped error" ) ) } ) + .end() + .command( "error.with_context" ) + .hint( "Returns error as untyped error with context" ) + .routine( || { Err( error_tools::error::untyped::format_err!( "this is untyped error" ).context( "with context" ) ) } ) + .end() + .perform(); + + let args: Vec< String > = std::env::args().skip( 1 ).collect(); + () = ca.perform( args )?; + + Ok( () ) +} \ No newline at end of file diff --git a/module/move/wca/examples/wca_fluent.rs b/module/move/wca/examples/wca_fluent.rs index 487d6ee97d..3d5475a481 100644 --- a/module/move/wca/examples/wca_fluent.rs +++ b/module/move/wca/examples/wca_fluent.rs @@ -7,10 +7,10 @@ //! -use wca::{ Context, Handler, Type, VerifiedCommand }; +use wca::{ executor::{ Context, Handler }, Type, VerifiedCommand }; use std::sync::{ Arc, Mutex }; -fn main() +fn main() -> error_tools::error::untyped::Result< () > { let ca = wca::CommandsAggregator::former() @@ -45,7 +45,8 @@ fn main() .end() .perform(); - let args = std::env::args().skip( 1 ).collect::< Vec< String > >(); - ca.perform( args ).unwrap(); + let args: Vec< String > = std::env::args().skip( 1 ).collect(); + ca.perform( args )?; + Ok( () ) } diff --git a/module/move/wca/examples/wca_suggest.rs b/module/move/wca/examples/wca_suggest.rs index 2bb73fa111..b9b54989a8 100644 --- a/module/move/wca/examples/wca_suggest.rs +++ b/module/move/wca/examples/wca_suggest.rs @@ -22,7 +22,7 @@ use wca::{ CommandsAggregator, Type, VerifiedCommand }; -fn main() +fn main() -> error_tools::error::untyped::Result< () > { let ca = CommandsAggregator::former() @@ -34,14 +34,11 @@ fn main() { println!( "= Args\n{:?}\n\n= Properties\n{:?}\n", o.args, o.props ); }) - .end() + .end() .perform(); - let args = std::env::args().skip( 1 ).collect::< Vec< String > >(); - match ca.perform( args.join( " " ) ) - { - Ok( _ ) => {} - Err( err ) => println!( "{err}" ), - }; + let args: Vec< String > = std::env::args().skip( 1 ).collect(); + ca.perform( args.join( " " ) )?; + Ok( () ) } diff --git a/module/move/wca/examples/wca_trivial.rs b/module/move/wca/examples/wca_trivial.rs index c228e6e20a..1df6dec815 100644 --- a/module/move/wca/examples/wca_trivial.rs +++ b/module/move/wca/examples/wca_trivial.rs @@ -16,7 +16,7 @@ fn exit() std::process::exit( 0 ) } -fn main() +fn main() -> error_tools::error::untyped::Result< () > { let ca = CommandsAggregator::former() .command( "exit" ) @@ -33,7 +33,7 @@ fn main() .perform() ; - // aaa : qqq2 : for Bohdan : that should work + // aaa : aaa2 : for Bohdan : that should work // let ca = wca::CommandsAggregator::former() // .command( "echo" ) // .hint( "prints all subjects and properties" ) @@ -50,6 +50,8 @@ fn main() // ca.execute( input ).unwrap(); //aaa: works - let input = std::env::args().skip( 1 ).collect::< Vec< String > >(); - ca.perform( input ).unwrap(); + let input: Vec< String > = std::env::args().skip( 1 ).collect(); + ca.perform( input )?; + + Ok( () ) } diff --git a/module/move/wca/src/ca/aggregator.rs b/module/move/wca/src/ca/aggregator.rs index 05575b9136..c8cd532342 100644 --- a/module/move/wca/src/ca/aggregator.rs +++ b/module/move/wca/src/ca/aggregator.rs @@ -3,9 +3,8 @@ mod private use crate::*; use ca:: { - Verifier, Executor, - grammar::command::private:: + grammar::command:: { CommandFormer, CommandAsSubformer, @@ -14,15 +13,17 @@ mod private }, help::{ HelpGeneratorFn, HelpGeneratorOptions, HelpVariants }, }; + use verifier::{ Verifier, VerificationError, VerifiedCommand }; + use parser::{ Program, Parser, ParserError }; + use grammar::Dictionary; + use executor::Context; - // qqq : group uses - use std::collections::HashSet; - use std::fmt; + use std:: + { + fmt, + collections::HashSet + }; use former::StoragePreform; - // use wtools:: - // { - // }; - // use wtools::thiserror; use error:: { // Result, @@ -54,11 +55,11 @@ mod private /// source of the program input : String, /// original error - error : wError, + error : ParserError, }, /// This variant represents errors that occur during grammar conversion. #[ error( "Can not identify a command.\nDetails: {0}" ) ] - Verifier( wError ), + Verifier( VerificationError ), /// This variant is used to represent errors that occur during executor conversion. #[ error( "Can not find a routine for a command.\nDetails: {0}" ) ] ExecutorConverter( wError ), @@ -70,14 +71,14 @@ mod private { /// This variant is used to represent validation errors. /// It carries a `ValidationError` payload that provides additional information about the error. - #[ error( "Validation error. {0}" ) ] + #[ error( "Validation error\n{0}" ) ] Validation( ValidationError ), /// This variant represents execution errors. - #[ error( "Execution failed. {0:?}" ) ] + #[ error( "Execution failed\n{0:?}" ) ] Execution( wError ), } - // xxx : qqq : qqq2 : for Bohdan : one level is obviously redundant + // xxx : aaa : aaa2 : for Bohdan : one level is obviously redundant // Program< Namespace< ExecutableCommand_ > > -> Program< ExecutableCommand_ > // aaa : done. The concept of `Namespace` has been removed struct CommandsAggregatorCallback( Box< dyn Fn( &str, &Program< VerifiedCommand > ) > ); @@ -283,7 +284,7 @@ mod private callback.0( &program.join( " " ), &grammar_program ) } - self.executor.program( &self.dictionary, grammar_program ).map_err( | e | Error::Execution( e ) ) + self.executor.program( &self.dictionary, grammar_program ).map_err( | e | Error::Execution( e.into() ) ) } } } @@ -293,8 +294,8 @@ mod private crate::mod_interface! { exposed use CommandsAggregator; - exposed use CommandsAggregatorFormer; - exposed use Error; - exposed use ValidationError; + orphan use CommandsAggregatorFormer; + orphan use Error; + orphan use ValidationError; exposed use Order; } diff --git a/module/move/wca/src/ca/executor/context.rs b/module/move/wca/src/ca/executor/context.rs index df60994a23..716bbafda6 100644 --- a/module/move/wca/src/ca/executor/context.rs +++ b/module/move/wca/src/ca/executor/context.rs @@ -7,7 +7,7 @@ mod private /// # Examples: /// /// ``` - /// # use wca::{ Routine, Handler, Context, Value, Args, Props, VerifiedCommand }; + /// # use wca::{ executor::{ Routine, Handler, Args, Props, Context }, Value, VerifiedCommand }; /// # use std::sync::{ Arc, Mutex }; /// let routine = Routine::from( Handler::from /// ( @@ -33,7 +33,7 @@ mod private /// } /// assert_eq!( 1, *ctx.get::< Mutex< i32 > >().unwrap().lock().unwrap() ); /// ``` - // qqq : ? + // xxx clarification is needed qqq : поточнити #[ derive( Debug, Clone ) ] pub struct Context { @@ -91,5 +91,5 @@ mod private crate::mod_interface! { - exposed use Context; + orphan use Context; } diff --git a/module/move/wca/src/ca/executor/executor.rs b/module/move/wca/src/ca/executor/executor.rs index fe1cbff998..9d662801a8 100644 --- a/module/move/wca/src/ca/executor/executor.rs +++ b/module/move/wca/src/ca/executor/executor.rs @@ -2,13 +2,23 @@ mod private { use crate::*; - // use wtools::error::Result; - use error::return_err; - use ca::help::private::{ HelpGeneratorOptions, LevelOfDetail, generate_help_content }; + use ca::help::{ HelpGeneratorOptions, generate_help_content, LevelOfDetail }; + use verifier::VerifiedCommand; + use parser::Program; + use grammar::Dictionary; + use executor::{ Routine, Context }; // aaa : for Bohdan : how is it useful? where is it used? // aaa : `ExecutorType` has been removed + #[ derive( Debug, error::typed::Error ) ] + pub enum CommandError + { + #[ error( "Internal command: `.{}` failed with: {}", command.phrase, error ) ] + Internal { command: VerifiedCommand, error: InternalCommandError }, + #[ error( "Command: `.{}` failed with: {}", command.phrase, error ) ] + User { command: VerifiedCommand, error: error::untyped::Error }, + } /// Executor that is responsible for executing the program's commands. /// It uses the given `Context` to store and retrieve values during runtime. @@ -36,9 +46,10 @@ mod private /// /// A `Result` with `Ok( () )` if the execution was successful, or an `Err` containing an error message if an error occurred. /// - // qqq : use typed error + // aaa : use typed error + // aaa : done pub fn program( &self, dictionary : &Dictionary, program : Program< VerifiedCommand > ) - -> error::untyped::Result< () > + -> Result< (), CommandError > { for command in program.commands { @@ -60,18 +71,21 @@ mod private /// # Returns /// /// Returns a Result indicating success or failure. If successful, returns `Ok(())`, otherwise returns an error. - // qqq : use typed error + // aaa : use typed error + // aaa : done pub fn command( &self, dictionary : &Dictionary, command : VerifiedCommand ) - -> error::untyped::Result< () > + -> Result< (), CommandError > { if command.internal_command { - _exec_internal_command( dictionary, command ) + _exec_internal_command( dictionary, command.clone() ) + .map_err( | error | CommandError::Internal { command, error } ) } else { let routine = dictionary.command( &command.phrase ).unwrap().routine.clone(); - _exec_command( command, routine, self.context.clone() ) + _exec_command( command.clone(), routine, self.context.clone() ) + .map_err( | error | CommandError::User { command, error } ) } } @@ -80,6 +94,7 @@ mod private } // qqq : use typed error + // aaa : should it be typed? it is user command with unknown error type fn _exec_command( command : VerifiedCommand, routine : Routine, ctx : Context ) -> error::untyped::Result< () > { @@ -90,9 +105,19 @@ mod private } } - // qqq : use typed error + #[ derive( Debug, error::typed::Error ) ] + pub enum InternalCommandError + { + #[ error( "Encountered an unrecognized internal command: `.{user_input}`." ) ] + UnknownInternalCommand { user_input: String }, + #[ error( "Not found command that starts with `.{user_input}`." ) ] + CommandNotFound { user_input: String }, + } + + // aaa : use typed error + // aaa : done fn _exec_internal_command( dictionary : &Dictionary, command : VerifiedCommand ) - -> error::untyped::Result< () > + -> Result< (), InternalCommandError > { match command.phrase.as_str() { @@ -122,7 +147,7 @@ mod private let commands = dictionary.search( name.strip_prefix( '.' ).unwrap_or( name ) ); if commands.is_empty() { - return_err!( "Not found command that starts with `.{}`.", name ); + return Err( InternalCommandError::CommandNotFound { user_input : name.into() } ); } let generator_args = HelpGeneratorOptions::former() .command_prefix( "." ) @@ -151,10 +176,10 @@ mod private } else { - return_err!( "Not found command that starts with `.{}`.", name ); + return Err( InternalCommandError::CommandNotFound { user_input : name.into() } ); } } - unexpected => return_err!( "Encountered an unrecognized internal command: `.{}`.", unexpected ), + unexpected => return Err( InternalCommandError::UnknownInternalCommand { user_input: unexpected.into() }), } Ok( () ) diff --git a/module/move/wca/src/ca/executor/mod.rs b/module/move/wca/src/ca/executor/mod.rs index 77789544d0..1793a9d23f 100644 --- a/module/move/wca/src/ca/executor/mod.rs +++ b/module/move/wca/src/ca/executor/mod.rs @@ -1,3 +1,5 @@ +mod private {} + crate::mod_interface! { diff --git a/module/move/wca/src/ca/executor/routine.rs b/module/move/wca/src/ca/executor/routine.rs index 45fc96bed1..ad9a455052 100644 --- a/module/move/wca/src/ca/executor/routine.rs +++ b/module/move/wca/src/ca/executor/routine.rs @@ -2,13 +2,17 @@ mod private { use crate::*; - // qqq : group + // aaa : group + // aaa : done - use std::collections::HashMap; - // use wtools::error::Result; - - use std::{ fmt::Formatter, rc::Rc }; - // use wtools::anyhow::anyhow; + use std:: + { + collections::HashMap, + fmt::Formatter, + rc::Rc, + }; + use verifier::VerifiedCommand; + use executor::Context; /// Command Args /// @@ -17,7 +21,7 @@ mod private /// # Example: /// /// ``` - /// use wca::{ Args, Value }; + /// use wca::{ executor::Args, Value }; /// /// let args = Args( vec![ Value::String( "Hello, World!".to_string() ) ] ); /// @@ -30,7 +34,7 @@ mod private /// /// ## Use case /// ``` - /// # use wca::{ Routine, Handler, VerifiedCommand }; + /// # use wca::{ executor::{ Routine, Handler }, VerifiedCommand }; /// let routine = Routine::from( Handler::from /// ( /// | o : VerifiedCommand | @@ -47,7 +51,7 @@ mod private /// Returns owned casted value by its index /// /// ``` - /// # use wca::{ Args, Value }; + /// # use wca::{ executor::Args, Value }; /// /// let args = Args( vec![ Value::String( "Hello, World!".to_string() ) ] ); /// @@ -79,7 +83,7 @@ mod private /// # Example: /// /// ``` - /// use wca::{ Props, Value }; + /// use wca::{ executor::Props, Value }; /// /// let props = Props( [ ( "hello".to_string(), Value::String( "World!".to_string() ) ) ].into() ); /// let hello_prop : &str = props.get_owned( "hello" ).unwrap(); @@ -89,7 +93,7 @@ mod private /// /// ## Use case /// ``` - /// # use wca::{ Routine, Handler, Props, VerifiedCommand }; + /// # use wca::{ executor::{ Routine, Handler, Props }, VerifiedCommand }; /// let routine = Routine::from( Handler::from /// ( /// | o : VerifiedCommand | @@ -106,7 +110,7 @@ mod private /// Returns owned casted value by its key /// /// ``` - /// # use wca::{ Props, Value }; + /// # use wca::{ executor::Props, Value }; /// /// let props = Props( [ ( "hello".to_string(), Value::String( "World!".to_string() ) ) ].into() ); /// let hello_prop : &str = props.get_owned( "hello" ).unwrap(); @@ -132,7 +136,10 @@ mod private // aaa : done. now it works with the following variants: // fn(), fn(args), fn(props), fn(args, props), fn(context), fn(context, args), fn(context, props), fn(context, args, props) - // qqq : why not public? + // aaa : why not public? // aaa : described + + // These type aliases are kept private to hide implementation details and prevent misuse. + // Exposing them would risk complicating the API and limit future refactoring flexibility. type RoutineWithoutContextFn = dyn Fn( VerifiedCommand ) -> error::untyped::Result< () >; type RoutineWithContextFn = dyn Fn( Context, VerifiedCommand ) -> error::untyped::Result< () >; @@ -140,7 +147,7 @@ mod private /// Routine handle. /// /// ``` - /// # use wca::{ Handler, Routine }; + /// # use wca::executor::{ Handler, Routine }; /// let routine = Routine::from( Handler::from /// ( /// || @@ -151,7 +158,7 @@ mod private /// ``` /// /// ``` - /// # use wca::{ Handler, Routine, VerifiedCommand }; + /// # use wca::{ executor::{ Handler, Routine }, VerifiedCommand }; /// let routine = Routine::from( Handler::from /// ( /// | o : VerifiedCommand | @@ -162,7 +169,7 @@ mod private /// ``` /// /// ``` - /// # use wca::{ Handler, Routine }; + /// # use wca::executor::{ Handler, Routine }; /// let routine = Routine::from( Handler::from /// ( /// | ctx, o | @@ -243,7 +250,7 @@ mod private /// /// - `WithoutContext`: A routine that does not require any context. /// - `WithContext`: A routine that requires a context. -// qqq : for Bohdan : instead of array of Enums, lets better have 5 different arrays of different Routine and no enum +// xxx clarification is needed : for Bohdan : instead of array of Enums, lets better have 5 different arrays of different Routine and no enum // to use statical dispatch #[ derive( Clone ) ] pub enum Routine @@ -327,15 +334,25 @@ mod private } // xxx + // aaa : This is an untyped error because we want to provide a common interface for all commands, while also allowing users to propagate their own specific custom errors. impl IntoResult for std::convert::Infallible { fn into_result( self ) -> error::untyped::Result< () > { Ok( () ) } } impl IntoResult for () { fn into_result( self ) -> error::untyped::Result< () > { Ok( () ) } } - impl< E : std::fmt::Debug > IntoResult + impl< E : std::fmt::Debug + std::fmt::Display + 'static > IntoResult for error::untyped::Result< (), E > { fn into_result( self ) -> error::untyped::Result< () > { - self.map_err( | e | error::untyped::format_err!( "{e:?}" )) - // xxx : qqq : ? + use std::any::TypeId; + // if it's anyhow error we want to have full context(debug), and if it's not(this error) we want to display + if TypeId::of::< error::untyped::Error >() == TypeId::of::< E >() + { + self.map_err( | e | error::untyped::format_err!( "{e:?}" )) + } + else + { + self.map_err( | e | error::untyped::format_err!( "{e}" )) + } + // xxx : aaa : ? } } } @@ -344,8 +361,8 @@ mod private crate::mod_interface! { - exposed use Routine; - exposed use Handler; - exposed use Args; - exposed use Props; + orphan use Routine; + orphan use Handler; + orphan use Args; + orphan use Props; } diff --git a/module/move/wca/src/ca/facade.rs b/module/move/wca/src/ca/facade.rs deleted file mode 100644 index 80fca20afc..0000000000 --- a/module/move/wca/src/ca/facade.rs +++ /dev/null @@ -1,345 +0,0 @@ -// mod private -// { -// use crate::*; -// use core::fmt; -// use ca::grammar; -// -// /// Macro for parsing WCA arguments. -// /// -// /// # Examples -// /// ```rust -// /// use wca::Value; -// /// -// /// let mut args = vec![ Value::Number( 42. ), Value::String( "Rust".into() ) ].into_iter(); -// /// wca::parse_args!( args, n : f64, name : String ); -// /// -// /// assert_eq!( n, 42. ); -// /// assert_eq!( name, "Rust" ); -// /// ``` -// #[macro_export] -// macro_rules! parse_args -// { -// ( $args : ident, mut $b : ident : $ty : ident $( $rest : tt )* ) => -// { -// let mut $b : $ty = std::convert::TryFrom::try_from( $args.next().unwrap() ).unwrap(); -// $crate::parse_args!( $args $( $rest )* ) -// }; -// ( $args : ident, $b : ident : $ty : ident $( $rest : tt )* ) => -// { -// let $b : $ty = std::convert::TryFrom::try_from( $args.next().unwrap() ).unwrap(); -// $crate::parse_args!( $args $( $rest )* ) -// }; -// ( $args : ident, $b : ident $( $rest : tt )* ) => -// { -// let $b = $args.next().unwrap(); -// $crate::parse_args!( $args $( $rest )* ) -// }; -// ( $args : ident, mut $b : ident $( $rest : tt )* ) => -// { -// let mut $b = $args.next().unwrap(); -// $crate::parse_args!( $args $( $rest )* ) -// }; -// ( $args : ident ) => -// { -// assert!( $args.next().is_none() ); -// }; -// ( $args : ident, ) => -// { -// $crate::parse_args!( $args ) -// }; -// } -// -// /// Creates a command-line interface (CLI) builder with the given initial state. -// /// -// /// This function initializes a `CommandBuilder` with the provided `state` and -// /// returns it for further configuration of the CLI. -// pub fn cui< T >( state : T ) -> CommandBuilder< T > -// { -// CommandBuilder::with_state( state ) -// } -// -// /// A struct representing a property. -// #[ derive( Debug, Clone ) ] -// pub struct Property< 'a > -// { -// /// The name of the property. -// pub name : &'a str, -// /// The hint for the property. -// pub debug : &'a str, -// /// The tag representing the property's type. -// pub tag : Type, -// } -// -// impl< 'a > Property< 'a > -// { -// /// Constructor of a property. -// pub fn new( name : &'a str, hint : &'a str, tag : Type ) -> Self { Self { name, hint, tag } } -// } -// -// /// A builder struct for constructing commands. -// #[ derive( Debug ) ] -// pub struct CommandBuilder< T > -// { -// state : T, -// commands : Vec< Command >, -// handlers : std::collections::HashMap< String, Routine >, -// } -// -// impl< T > CommandBuilder< T > -// { -// /// Constructs a `CommandBuilder` with the given state. -// pub fn with_state( state : T ) -> Self -// { -// Self { state, handlers : < _ >::default(), commands : vec![] } -// } -// } -// -// #[ derive( Debug ) ] -// pub struct Builder< F > -// { -// handler : F, -// command : Command, -// } -// -// impl< F > Builder< F > -// { -// /// Creates a new instance of the command with the provided handler function. -// /// -// /// This method takes in a handler function `handler` and creates a new instance of the command. -// /// The `handler` function is used to handle the execution logic associated with the command. -// /// -// /// # Arguments -// /// -// /// * `handler` - The handler function that will be invoked when the command is executed. -// /// -// /// # Returns -// /// -// /// A new instance of the command with the specified `handler`. -// /// -// #[ inline ] -// pub fn new( handler: F ) -> Self -// { -// let name = -// { -// use iter_tools::Itertools as _; -// -// let name = std::any::type_name::< F >(); -// let name = name.split("::").last().unwrap(); -// name.split( '_' ).join( "." ) -// }; -// -// Self { handler, command : Command::former().phrase( name ).form() } -// } -// -// /// Adds an argument to the command. -// /// -// /// This method takes in the `hint` and `tag` parameters to create a `ValueDescription` object -// /// representing an argument. The `ValueDescription` object is then appended to the command's -// /// `subjects` collection. -// /// -// /// # Arguments -// /// -// /// * `hint` - The hint for the argument, represented as a string slice (`&str`). -// /// * `tag` - The type of the argument, represented by a `Type` object from the `Type` module. -// /// -// /// # Returns -// /// -// /// The modified command instance with the argument added. -// /// -// #[ inline ] -// pub fn arg( mut self, hint : &str, tag : Type ) -> Self -// { -// self.command.subjects.push( grammar::command::ValueDescription -// { -// hint : hint.into(), -// kind : tag, -// optional : false, -// }); -// -// self -// } -// -// /// Adds a property to the command. -// /// -// /// This method takes in the `name`, `hint`, and `kind` parameters to create a `ValueDescription` -// /// object representing a property. The `ValueDescription` object is then inserted into the -// /// command's properties collection using the `name` as the key. -// /// -// /// # Example -// /// ```no_rust -// /// let ca = cui(()) -// /// .command(user.property("name", "Name property", Type::String)) -// /// .build(); -// /// ``` -// /// -// /// # Arguments -// /// -// /// * `name` - The name of the property. It should implement the `ToString` trait. -// /// * `hint` - The hint for the property. It should implement the `ToString` trait. -// /// * `kind` - The type of the property, represented by a `Type` object from the `Type` module. -// /// -// /// # Returns -// /// -// /// The modified command instance with the property added. -// /// -// #[ inline ] -// pub fn property( mut self, name : impl ToString , hint : impl ToString, kind : Type ) -> Self -// { -// self.command.properties.insert -// ( -// name.to_string(), -// grammar::command::ValueDescription -// { -// hint : hint.to_string(), -// kind, -// optional : false, -// } -// ); -// -// self -// } -// -// /// Adds multiple properties to the command. -// /// -// /// This method takes in an array of `Property` objects and adds them to the command's properties. -// /// The properties are provided in the `properties` parameter as an array of length `N`. -// /// -// /// ```without_std -// /// let ca = cui(()) -// /// .properties([ -// /// Property::new("name", "Name property", Type::String), -// /// Property::new("age", "Age property", Type::Integer), -// /// ]).build(); -// /// ``` -// /// -// /// # Arguments -// /// -// /// * `properties` - An array of `Property` objects representing the properties to be added. -// /// -// /// # Returns -// /// -// /// The modified command instance with the properties added. -// /// -// #[ inline ] -// pub fn properties< const N: usize >( mut self, properties : [ Property< '_ >; N ] ) -> Self -// { -// self.command.properties.reserve( properties.len() ); -// -// for Property { name, hint, tag } in properties -// { -// self = self.property(name, hint, tag); -// } -// -// self -// } -// } -// -// impl< T: Clone + 'static > CommandBuilder< T > -// { -// /// Adds a command to the `CommandBuilder`. -// /// ```no_rust -// /// let ca = cui( () ) // Add commands using the builder pattern -// /// .command( command ) -// /// .command( command2 ) -// /// .command( echo.arg("string", Type::String ) ) // Customize your commands by chaining methods such as properties -// /// // property, and arg to add properties and arguments. -// /// .build(); -// /// -// /// ``` -// pub fn command< F, E > -// ( -// mut self, -// command : impl IntoBuilder< F, T >, -// ) -> Self -// where -// F : Fn( T, Args, Props ) -> Result< (), E > + 'static + Copy, -// E : fmt::Debug, -// { -// let Builder { handler, command } = command.into_builder(); -// let state = self.state.clone(); -// -// let closure = closure::closure!( | ( args, props ) | -// { -// handler( state.clone(), args, props ) -// .map_err( | report | BasicError::new( format!( "{report:?}" ) ).into() ) -// }); -// -// let handler = Routine::new( closure ); -// -// self.handlers.insert( command.phrase.clone(), handler ); -// self.commands.push( command ); -// -// self -// } -// -// /// Builds and returns a `wca::CommandsAggregator` instance. -// /// -// /// This method finalizes the construction of the `CommandBuilder` by -// /// creating a `wca::CommandsAggregator` instance with the accumulated -// /// commands and handlers. -// pub fn build( self ) -> CommandsAggregator -// { -// CommandsAggregator::former().grammar( self.commands ).executor( self.handlers ).perform() -// } -// } -// -// /// An extension trait for commands. -// /// -// /// This trait provides additional methods for enhancing commands, such as -// /// adding arguments and properties. -// pub trait CommandExt< T > : Sized -// { -// /// Adds an argument to the command. -// fn arg( self, hint : &str, tag : Type ) -> Builder< Self > -// { -// Builder::new( self ).arg( hint, tag ) -// } -// -// /// Adds property to the command. -// fn property< const N: usize >( self, name : impl ToString , hint : impl ToString, kind : Type ) -> Builder< Self > -// { -// Builder::new( self ).property( name, hint, kind ) -// } -// -// /// Adds properties to the command. -// fn properties< const N: usize >( self, properties: [ Property< '_ >; N ] ) -> Builder< Self > -// { -// Builder::new( self ).properties( properties ) -// } -// } -// -// impl< F: Fn( T, Args, Props ) -> Result< (), E>, T, E > CommandExt< T > for F {} -// -// /// A trait for converting a type into a `Builder`. -// pub trait IntoBuilder< F, T > : Sized -// { -// /// Converts the type into a `Builder` instance. -// fn into_builder( self ) -> Builder< F >; -// } -// -// impl< F, T > IntoBuilder< F, T > for Builder< F > -// { -// fn into_builder( self ) -> Self -// { -// self -// } -// } -// -// impl< F: Fn( T, Args, Props ) -> Result< (), E >, T, E > IntoBuilder< F, T > for F -// { -// fn into_builder( self ) -> Builder< F > -// { -// Builder::new( self ) -// } -// } -// -// } -// -// crate::mod_interface! -// { -// exposed use cui; -// exposed use CommandBuilder; -// exposed use Property; -// prelude use IntoBuilder; -// prelude use CommandExt; -// } diff --git a/module/move/wca/src/ca/formatter.rs b/module/move/wca/src/ca/formatter.rs index 59fb4b31ff..30e6787d6d 100644 --- a/module/move/wca/src/ca/formatter.rs +++ b/module/move/wca/src/ca/formatter.rs @@ -3,16 +3,29 @@ mod private use crate::*; use iter_tools::Itertools; - use ca::aggregator::private::Order; + use ca::aggregator::Order; + use grammar::Dictionary; - /// - + /// Enum representing the format options for generating help content. + /// + /// `HelpFormat` defines the output format of help content, enabling the choice + /// between different styles, such as `Markdown` for structured text, or other + /// custom formats. #[ derive( Debug, Clone, PartialEq ) ] pub enum HelpFormat { + /// Generates help content in Markdown format, suitable for environments + /// that support Markdown rendering (e.g., documentation platforms, text editors). Markdown, + /// Represents an alternative format, customizable for different needs. Another, } + /// Generates Markdown-formatted help content based on a dictionary of terms and a specified order. + /// + /// The `md_generator` function takes a reference to a `Dictionary` and an `Order` to produce + /// a help document in Markdown format. This function is useful for generating structured, + /// readable help documentation suitable for Markdown-compatible platforms. pub fn md_generator( grammar : &Dictionary, order: Order ) -> String { let text = grammar.commands() @@ -91,5 +104,6 @@ mod private crate::mod_interface! { - + own use HelpFormat; + own use md_generator; } \ No newline at end of file diff --git a/module/move/wca/src/ca/grammar/command.rs b/module/move/wca/src/ca/grammar/command.rs index 3bfbd7a695..0c17e726b1 100644 --- a/module/move/wca/src/ca/grammar/command.rs +++ b/module/move/wca/src/ca/grammar/command.rs @@ -2,10 +2,11 @@ mod private { use crate::*; - use std::collections::{ HashMap }; + use std::collections::HashMap; use indexmap::IndexMap; use former::{ Former, StoragePreform }; use iter_tools::Itertools; + use executor::{ Routine, Handler }; /// A description of a Value in a command. Used to specify the expected type and provide a hint for the Value. /// @@ -35,7 +36,7 @@ mod private pub struct PropertyDescription { name : String, - // qqq : how to re-use ValueDescriptionFormer without additional end? + // xxx : how to re-use ValueDescriptionFormer without additional end? // #[subform_scalar] // value : ValueDescription, /// providing guidance to the user for entering a valid value @@ -74,7 +75,7 @@ mod private /// # Example: /// /// ``` - /// # use wca::{ Command, Type }; + /// # use wca::{ grammar::Command, Type }; /// let command = Command::former() /// .hint( "hint" ) /// .long_hint( "long_hint" ) @@ -103,7 +104,8 @@ mod private /// Map of aliases. // Aliased key -> Original key pub properties_aliases : HashMap< String, String >, - // qqq : make it usable and remove default(?) + // aaa : make it usable and remove default(?) + // aaa : it is usable /// The type `Routine` represents the specific implementation of the routine. #[ scalar( setter = false ) ] #[ former( default = Routine::from( Handler::< _, std::convert::Infallible >::from( || { panic!( "No routine available: A handler function for the command is missing" ) } ) ) ) ] @@ -246,9 +248,15 @@ mod private crate::mod_interface! { - exposed use Command; - exposed use CommandFormer; + orphan use Command; + orphan use CommandFormer; own use ValueDescription; + + own use CommandAsSubformer; + own use CommandAsSubformerEnd; + own use CommandFormerStorage; + } -// qqq : use orphan instead of exposed for ALL files in the folder, dont use prelude for structs \ No newline at end of file +// aaa : use orphan instead of exposed for ALL files in the folder, dont use prelude for structs +// aaa : done. \ No newline at end of file diff --git a/module/move/wca/src/ca/grammar/dictionary.rs b/module/move/wca/src/ca/grammar/dictionary.rs index e6887aef26..8dc784f3db 100644 --- a/module/move/wca/src/ca/grammar/dictionary.rs +++ b/module/move/wca/src/ca/grammar/dictionary.rs @@ -4,8 +4,9 @@ mod private use former::Former; use indexmap::IndexMap; use iter_tools::Itertools; + use grammar::Command; - // qqq : `Former` does not handle this situation well + // xxx : `Former` does not handle this situation well // /// A collection of commands. // /// @@ -25,8 +26,6 @@ mod private pub( crate ) order : Order, } - // qqq : IDK how to integrate it into the `CommandsAggregatorFormer` - // impl DictionaryFormer { pub fn command( mut self, command : Command ) -> Self @@ -109,5 +108,5 @@ mod private crate::mod_interface! { - exposed use Dictionary; + orphan use Dictionary; } diff --git a/module/move/wca/src/ca/grammar/mod.rs b/module/move/wca/src/ca/grammar/mod.rs index f31e992b38..28a87f9e2b 100644 --- a/module/move/wca/src/ca/grammar/mod.rs +++ b/module/move/wca/src/ca/grammar/mod.rs @@ -1,3 +1,5 @@ +mod private {} + crate::mod_interface! { /// User grammar settings. diff --git a/module/move/wca/src/ca/grammar/types.rs b/module/move/wca/src/ca/grammar/types.rs index d5c6e971df..99526b35dd 100644 --- a/module/move/wca/src/ca/grammar/types.rs +++ b/module/move/wca/src/ca/grammar/types.rs @@ -6,9 +6,6 @@ mod private Display, Formatter }; - // use wtools; - // use wtools::{ error::Result, err }; - use error::err; use iter_tools::Itertools; /// Available types that can be converted to a `Value` @@ -59,7 +56,7 @@ mod private /// # Example: /// /// ``` - /// # use wca::{ VerifiedCommand, Value, Args, Props }; + /// # use wca::{ VerifiedCommand, Value, executor::{ Args, Props } }; /// # use std::collections::HashMap; /// let command = VerifiedCommand /// { @@ -119,7 +116,7 @@ mod private } Value::List( list ) => { - let list = list.iter().map( | element | element.to_string() ).join( "," ); // qqq : don't hardcode ", " find way to get original separator + let list = list.iter().map( | element | element.to_string() ).join( "," ); write!( f, "{list}" )?; } } @@ -186,16 +183,18 @@ mod private match self { Self::String => Ok( Value::String( value ) ), - Self::Number => value.parse().map_err( | _ | err!( "Can not parse number from `{}`", value ) ).map( Value::Number ), + Self::Number => value.parse().map_err( | _ | error::untyped::format_err!( "Can not parse number from `{}`", value ) ).map( Value::Number ), Self::Path => Ok( Value::Path( value.into() ) ), - Self::Bool => Ok( Value::Bool( match value.as_str() { "1" | "true" => true, "0" | "false" => false, _ => return Err( err!( "Can not parse bool from `{}`", value ) ) } ) ), + Self::Bool => Ok( Value::Bool( match value.as_str() { "1" | "true" => true, "0" | "false" => false, _ => return Err( error::untyped::format_err!( "Can not parse bool from `{}`", value ) ) } ) ), Self::List( kind, delimeter ) => { - let values = value + let values: error::untyped::Result< Vec< Value > > = value .split( *delimeter ) .map( | val | kind.try_cast( val.into() ) ) - .collect::< error::untyped::Result< Vec< Value > > >()?; - // qqq : avoid using fish notation whenever possible. review whole crate + .collect(); + let values = values?; + // aaa : avoid using fish notation whenever possible. review whole crate + // aaa : done Ok( Value::List( values ) ) }, } diff --git a/module/move/wca/src/ca/help.rs b/module/move/wca/src/ca/help.rs index b7d0593634..6a40e28e1c 100644 --- a/module/move/wca/src/ca/help.rs +++ b/module/move/wca/src/ca/help.rs @@ -3,30 +3,36 @@ mod private use crate::*; use ca:: { - Command, - Routine, Type, - formatter::private:: + formatter:: { HelpFormat, md_generator }, tool::table::format_table, }; + use verifier::VerifiedCommand; + use grammar::{ Command, Dictionary }; + use executor::Routine; use iter_tools::Itertools; use std::rc::Rc; use error::untyped::format_err; use former::Former; - // qqq : for Bohdan : it should transparent mechanist which patch list of commands, not a stand-alone mechanism + // aaa : for Bohdan : it should transparent mechanist which patch list of commands, not a stand-alone mechanism + // aaa : it is + /// Enum `LevelOfDetail` specifies the granularity of detail for rendering or processing: #[ derive( Debug, Default, Copy, Clone, PartialEq, Eq ) ] pub enum LevelOfDetail { + /// No detail (default). #[ default ] None, + /// Basic level of detail. Simple, + /// High level of detail. Detailed, } @@ -63,8 +69,15 @@ mod private pub order : Order, } - // qqq : for Barsik : make possible to change properties order - pub( crate ) fn generate_help_content( dictionary : &Dictionary, o : HelpGeneratorOptions< '_ > ) -> String + // aaa : for Barsik : make possible to change properties order + // aaa : order option + + /// Generates help content as a formatted string based on a given dictionary and options. + /// + /// This function takes a `Dictionary` of terms or commands and a `HelpGeneratorOptions` + /// struct to customize the help output, generating a user-friendly help message + /// or guide in `String` format. + pub fn generate_help_content( dictionary : &Dictionary, o : HelpGeneratorOptions< '_ > ) -> String { struct Row { @@ -357,7 +370,7 @@ mod private /// /// ``` /// # use wca::ca::help::{ HelpGeneratorOptions, HelpGeneratorFn }; - /// use wca::{ Command, Dictionary }; + /// use wca::grammar::{ Command, Dictionary }; /// /// fn my_help_generator( dictionary : &Dictionary, args : HelpGeneratorOptions< '_ > ) -> String /// { @@ -418,5 +431,9 @@ crate::mod_interface! { own use HelpGeneratorFn; own use HelpGeneratorOptions; + own use LevelOfDetail; + own use generate_help_content; + prelude use HelpVariants; + } diff --git a/module/move/wca/src/ca/input.rs b/module/move/wca/src/ca/input.rs index c2826f99ef..46f70221b8 100644 --- a/module/move/wca/src/ca/input.rs +++ b/module/move/wca/src/ca/input.rs @@ -1,7 +1,6 @@ mod private { - use std::io; - use std::io::Write; + use std::io::{ self, Write }; /// Ask use input from standard input. pub fn ask( request : &str ) -> String @@ -78,6 +77,6 @@ mod private crate::mod_interface! { exposed use ask; - exposed use Input; - exposed use IntoInput; + orphan use Input; + orphan use IntoInput; } diff --git a/module/move/wca/src/ca/mod.rs b/module/move/wca/src/ca/mod.rs index 3526d2c8fa..66c6832f28 100644 --- a/module/move/wca/src/ca/mod.rs +++ b/module/move/wca/src/ca/mod.rs @@ -2,6 +2,8 @@ //! Commands aggregator library. //! +mod private {} + crate::mod_interface! { diff --git a/module/move/wca/src/ca/parser/command.rs b/module/move/wca/src/ca/parser/command.rs index 332c9e71f6..84cfbefc2b 100644 --- a/module/move/wca/src/ca/parser/command.rs +++ b/module/move/wca/src/ca/parser/command.rs @@ -25,7 +25,7 @@ mod private /// # Example: /// /// ``` - /// # use wca::ParsedCommand; + /// # use wca::parser::ParsedCommand; /// # use std::collections::HashMap; /// ParsedCommand /// { @@ -57,6 +57,6 @@ mod private crate::mod_interface! { - exposed use Program; - exposed use ParsedCommand; + orphan use Program; + orphan use ParsedCommand; } diff --git a/module/move/wca/src/ca/parser/mod.rs b/module/move/wca/src/ca/parser/mod.rs index 6d21385d36..50322eee12 100644 --- a/module/move/wca/src/ca/parser/mod.rs +++ b/module/move/wca/src/ca/parser/mod.rs @@ -1,3 +1,5 @@ +mod private {} + crate::mod_interface! { /// This module defines a raw representation of parsed commands, providing a foundation for further processing and @@ -5,7 +7,7 @@ crate::mod_interface! /// a straightforward and easy-to-work-with format, allowing for efficient manipulation and subsequent conversion to /// other representations. layer command; - + /// This module is responsible for processing command-line arguments and parsing them into a raw representation of a /// program containing multiple parsed commands. The input list of arguments is transformed into a structured format, /// allowing the program to efficiently handle and manipulate the parsed commands. diff --git a/module/move/wca/src/ca/parser/parser.rs b/module/move/wca/src/ca/parser/parser.rs index 1efe959495..0fec9fb6f4 100644 --- a/module/move/wca/src/ca/parser/parser.rs +++ b/module/move/wca/src/ca/parser/parser.rs @@ -3,8 +3,19 @@ mod private use crate::*; use std::collections::HashMap; + use parser::{ Program, ParsedCommand }; - use error::{ return_err }; + // use error::{ return_err }; + + #[ allow( missing_docs ) ] + #[ derive( Debug, error::typed::Error ) ] + pub enum ParserError + { + #[ error( "Internal Error: {details}" ) ] + InternalError { details: String }, + #[ error( "Unexpected input. Expected: {expected}, found {input}" ) ] + UnexpectedInput { expected: String, input: String }, + } /// `Parser` is a struct used for parsing data. #[ derive( Debug ) ] @@ -21,13 +32,14 @@ mod private /// # Returns /// /// Returns a `Result` with a `Program` containing the parsed commands if successful, or an error if parsing fails. - // qqq : use typed error - pub fn parse< As, A >( &self, args : As ) -> error::untyped::Result< Program< ParsedCommand > > + // aaa : use typed error + // aaa : done. + pub fn parse< As, A >( &self, args : As ) -> Result< Program< ParsedCommand >, ParserError > where As : IntoIterator< Item = A >, A : Into< String >, { - let args = args.into_iter().map( Into::into ).collect::< Vec< _ > >(); + let args: Vec< _ > = args.into_iter().map( Into::into ).collect(); let mut commands = vec![]; let mut i = 0; while i < args.len() @@ -54,18 +66,18 @@ mod private } // returns ParsedCommand and relative position of the last parsed item - // qqq : use typed error - fn parse_command( args : &[ String ] ) -> error::untyped::Result< ( ParsedCommand, usize ) > + // aaa : use typed error + fn parse_command( args : &[ String ] ) -> Result< ( ParsedCommand, usize ), ParserError > { if args.is_empty() { - return_err!( "Unexpected behaviour: Try to parse command without input" ); + return Err( ParserError::InternalError { details: "Try to parse command without input".into() } ); } let mut i = 0; if !Self::valid_command_name( &args[ i ] ) { - return_err!( "Unexpected input: Expected a command, found: `{}`", args[ i ] ); + return Err( ParserError::UnexpectedInput { expected: "command".into(), input: args[ i ].clone() } ); } let name = match args[ i ].strip_prefix( '.' ).unwrap() { @@ -91,8 +103,9 @@ mod private } // returns ( subjects, properties, relative_end_pos ) - // qqq : use typed error - fn parse_command_args( args : &[ String ] ) -> error::untyped::Result< ( Vec< String >, HashMap< String, String >, usize ) > + // aaa : use typed error + // aaa : done + fn parse_command_args( args : &[ String ] ) -> Result< ( Vec< String >, HashMap< String, String >, usize ), ParserError > { let mut i = 0; @@ -125,7 +138,7 @@ mod private // prop: else { - return_err!( "Unexpected input '{}': Detected a possible property key preceding the ':' character. However, no corresponding value was found.", item ); + return Err( ParserError::UnexpectedInput { expected: "property value".into(), input: "end of input".into() } ); } } // prop : value | prop :value @@ -146,13 +159,18 @@ mod private // : else { - return_err!( "Unexpected input '{} :': Detected a possible property key preceding the ':' character. However, no corresponding value was found.", item ); + return Err( ParserError::UnexpectedInput { expected: "property value".into(), input: "end of input".into() } ); } } - else if !properties_turn { subjects.push( item.to_string() ); } - - else { return_err!( "Unexpected input: Expected `command` or `property`, found: `{}`", item ); } + else if !properties_turn + { + subjects.push( item.to_string() ); + } + else + { + return Err( ParserError::UnexpectedInput { expected: "`command` or `property`".into(), input: item.into() } ); + } i += 1; } @@ -165,5 +183,6 @@ mod private crate::mod_interface! { - exposed use Parser; + orphan use Parser; + orphan use ParserError; } diff --git a/module/move/wca/src/ca/tool/mod.rs b/module/move/wca/src/ca/tool/mod.rs index 116804b97d..3f400c96a9 100644 --- a/module/move/wca/src/ca/tool/mod.rs +++ b/module/move/wca/src/ca/tool/mod.rs @@ -1,3 +1,5 @@ +mod private {} + crate::mod_interface! { @@ -5,7 +7,10 @@ crate::mod_interface! layer table; orphan use super::super::tool; - orphan use ::error_tools as error; + + // orphan use ::error_tools as error; + use ::error_tools; + orphan use ::iter_tools; // use ::strs_tools as string; // xxx : check diff --git a/module/move/wca/src/ca/tool/table.rs b/module/move/wca/src/ca/tool/table.rs index 192caa0396..4315ee5c8e 100644 --- a/module/move/wca/src/ca/tool/table.rs +++ b/module/move/wca/src/ca/tool/table.rs @@ -3,7 +3,7 @@ mod private use crate::*; // use wtools::error::{ Result, err }; - use error::err; + // use error::err; /// Represents a table composed of multiple rows. /// @@ -81,6 +81,10 @@ mod private .collect() } + #[ derive( Debug, error::typed::Error ) ] + #[ error( "Invalid table" ) ] + pub struct FormatTableError; + /// Formats a table into a readable string representation. /// /// # Arguments @@ -90,15 +94,16 @@ mod private /// # Returns /// /// * `error::untyped::Result` - A `error::untyped::Result` containing the formatted table as a `String`, or an `Error` if the table is invalid. - // qqq : use typed error - pub fn format_table< IntoTable >( table : IntoTable ) -> error::untyped::Result< String > + // aaa : use typed error + // aaa : done + pub fn format_table< IntoTable >( table : IntoTable ) -> Result< String, FormatTableError > where IntoTable : Into< Table >, { let table = table.into(); if !table.validate() { - return Err( err!( "Invalid table" ) ); + return Err( FormatTableError ); } let max_lengths = max_column_lengths( &table ); diff --git a/module/move/wca/src/ca/verifier/command.rs b/module/move/wca/src/ca/verifier/command.rs index ef8c2824b9..c945bbb997 100644 --- a/module/move/wca/src/ca/verifier/command.rs +++ b/module/move/wca/src/ca/verifier/command.rs @@ -1,13 +1,14 @@ mod private { use crate::*; + use executor::{ Args, Props }; /// Represents a grammatically correct command with a phrase descriptor, a list of command subjects, and a set of command options. /// /// # Example: /// /// ``` - /// # use wca::{ VerifiedCommand, Value, Args, Props }; + /// # use wca::{ VerifiedCommand, Value, executor::{ Args, Props } }; /// # use std::collections::HashMap; /// VerifiedCommand /// { @@ -46,4 +47,5 @@ crate::mod_interface! exposed use VerifiedCommand; } -// qqq : use orphan instead of exposed for ALL files in the folder, dont use prelude for structs \ No newline at end of file +// aaa : use orphan instead of exposed for ALL files in the folder, dont use prelude for structs +// aaa : done. \ No newline at end of file diff --git a/module/move/wca/src/ca/verifier/mod.rs b/module/move/wca/src/ca/verifier/mod.rs index 7ed35ae7b9..4723d0bdcc 100644 --- a/module/move/wca/src/ca/verifier/mod.rs +++ b/module/move/wca/src/ca/verifier/mod.rs @@ -1,3 +1,5 @@ +mod private {} + crate::mod_interface! { /// Represents a grammatically correct command with a phrase descriptor, a list of command subjects, and a set of command options.. diff --git a/module/move/wca/src/ca/verifier/verifier.rs b/module/move/wca/src/ca/verifier/verifier.rs index 6fc13fc28e..c0636a594b 100644 --- a/module/move/wca/src/ca/verifier/verifier.rs +++ b/module/move/wca/src/ca/verifier/verifier.rs @@ -2,19 +2,55 @@ mod private { use crate::*; - use ca::grammar::command::ValueDescription; - // use former::Former; + use help::{ HelpGeneratorOptions, LevelOfDetail, generate_help_content }; + use grammar::{ Dictionary, Command, command::ValueDescription }; + use executor::{ Args, Props }; use std::collections::HashMap; use indexmap::IndexMap; - // use wtools::{ error, error::Result, err }; - use error::err; - use ca::help::private::{ HelpGeneratorOptions, LevelOfDetail, generate_help_content }; + use verifier::VerifiedCommand; + use parser::{ Program, ParsedCommand }; + + #[ allow( missing_docs ) ] + #[ derive( Debug, error::typed::Error ) ] + pub enum VerificationError + { + #[ error + ( + "Command not found. {} {}", + if let Some( phrase ) = name_suggestion { format!( "Maybe you mean `.{phrase}`?" ) } else { "Please use `.` command to see the list of available commands.".into() }, + if let Some( info ) = command_info { format!( "Command info: `{info}`" ) } else { "".into() } + )] + CommandNotFound { name_suggestion: Option< String >, command_info: Option< String > }, + #[ error( "Fail in command `.{command_name}` while processing subjects. {error}" ) ] + Subject { command_name: String, error: SubjectError }, + #[ error( "Fail in command `.{command_name}` while processing properties. {error}" ) ] + Property { command_name: String, error: PropertyError }, + } + + #[ allow( missing_docs ) ] + #[ derive( Debug, error::typed::Error ) ] + pub enum SubjectError + { + #[ error( "Missing not optional subject" ) ] + MissingNotOptional, + #[ error( "Can not identify a subject: `{value}`" ) ] + CanNotIdentify { value: String }, + } + + #[ allow( missing_docs ) ] + #[ derive( Debug, error::typed::Error ) ] + pub enum PropertyError + { + #[ error( "Expected: {description:?}. Found: {input}" ) ] + Cast { description: ValueDescription, input: String }, + } + // xxx /// Converts a `ParsedCommand` to a `VerifiedCommand` by performing validation and type casting on values. /// /// ``` - /// # use wca::{ Command, Type, Verifier, Dictionary, ParsedCommand }; + /// # use wca::{ Type, verifier::Verifier, grammar::{ Dictionary, Command }, parser::ParsedCommand }; /// # use std::collections::HashMap; /// # fn main() -> Result< (), Box< dyn std::error::Error > > /// # { @@ -48,13 +84,15 @@ mod private dictionary : &Dictionary, raw_program : Program< ParsedCommand > ) - -> error::untyped::Result< Program< VerifiedCommand > > - // qqq : use typed error + -> Result< Program< VerifiedCommand >, VerificationError > + // aaa : use typed error + // aaa : done { - let commands = raw_program.commands + let commands: Result< Vec< VerifiedCommand >, VerificationError > = raw_program.commands .into_iter() .map( | n | self.to_command( dictionary, n ) ) - .collect::< error::untyped::Result< Vec< VerifiedCommand > > >()?; + .collect(); + let commands = commands?; Ok( Program { commands } ) } @@ -109,14 +147,15 @@ mod private if Self::is_valid_command_variant( expected_subjects_count, raw_subjects_count, possible_subjects_count ) { Some( variant ) } else { None } } - // qqq : use typed error + // aaa : use typed error + // aaa : done. fn extract_subjects( command : &Command, raw_command : &ParsedCommand, used_properties : &[ &String ] ) -> - error::untyped::Result< Vec< Value > > + Result< Vec< Value >, SubjectError > { let mut subjects = vec![]; - let all_subjects = raw_command + let all_subjects: Vec< _ > = raw_command .subjects.clone().into_iter() .chain ( @@ -124,7 +163,7 @@ mod private .filter( |( key, _ )| !used_properties.contains( key ) ) .map( |( key, value )| format!( "{key}:{value}" ) ) ) - .collect::< Vec< _ > >(); + .collect(); let mut rc_subjects_iter = all_subjects.iter(); let mut current = rc_subjects_iter.next(); @@ -134,20 +173,21 @@ mod private { Some( v ) => v, None if *optional => continue, - _ => return Err( err!( "Missing not optional subject" ) ), + _ => return Err( SubjectError::MissingNotOptional ), }; subjects.push( value ); current = rc_subjects_iter.next(); } - if let Some( value ) = current { return Err( err!( "Can not identify a subject: `{}`", value ) ) } + if let Some( value ) = current { return Err( SubjectError::CanNotIdentify { value: value.clone() } ) } Ok( subjects ) } - // qqq : use typed error + // aaa : use typed error + // aaa : done. fn extract_properties( command: &Command, raw_command : HashMap< String, String > ) -> - error::untyped::Result< HashMap< String, Value > > + Result< HashMap< String, Value >, PropertyError > { raw_command.into_iter() .filter_map @@ -163,9 +203,9 @@ mod private .map ( |( value_description, key, value )| - value_description.kind.try_cast( value ).map( | v | ( key.clone(), v ) ) + value_description.kind.try_cast( value.clone() ).map( | v | ( key.clone(), v ) ).map_err( | _ | PropertyError::Cast { description: value_description.clone(), input: format!( "{key}: {value}" ) } ) ) - .collect::< error::untyped::Result< HashMap< _, _ > > >() + .collect() } fn group_properties_and_their_aliases< 'a, Ks >( aliases : &'a HashMap< String, String >, used_keys : Ks ) -> Vec< &String > @@ -186,16 +226,17 @@ mod private { reverse_aliases.get( key ).into_iter().flatten().map( | k | *k ).chain( Some( key ) ) }) - .collect::< Vec< _ > >() + .collect() } /// Converts raw command to grammatically correct /// /// Make sure that this command is described in the grammar and matches it(command itself and all it options too). - // qqq : use typed error + // aaa : use typed error + // aaa : done. pub fn to_command( &self, dictionary : &Dictionary, raw_command : ParsedCommand ) -> - error::untyped::Result< VerifiedCommand > + Result< VerifiedCommand, VerificationError > { if raw_command.name.ends_with( '.' ) | raw_command.name.ends_with( ".?" ) { @@ -208,30 +249,31 @@ mod private }); } let command = dictionary.command( &raw_command.name ) - .ok_or_else::< error::untyped::Error, _ > + .ok_or_else::< VerificationError, _ > ( || { #[ cfg( feature = "on_unknown_suggest" ) ] if let Some( phrase ) = Self::suggest_command( dictionary, &raw_command.name ) - { return err!( "Command not found. Maybe you mean `.{}`?", phrase ) } - err!( "Command not found. Please use `.` command to see the list of available commands." ) + { + return VerificationError::CommandNotFound { name_suggestion: Some( phrase ), command_info: None }; + } + VerificationError::CommandNotFound { name_suggestion: None, command_info: None } } )?; let Some( cmd ) = Self::check_command( command, &raw_command ) else { - error::untyped::bail! - ( - "`{}` command with specified subjects not found. Command info: `{}`", - &raw_command.name, - generate_help_content( dictionary, HelpGeneratorOptions::former().for_commands([ dictionary.command( &raw_command.name ).unwrap() ]).command_prefix( "." ).subject_detailing( LevelOfDetail::Detailed ).form() ).strip_suffix( " " ).unwrap() - ); + return Err( VerificationError::CommandNotFound + { + name_suggestion: Some( command.phrase.clone() ), + command_info: Some( generate_help_content( dictionary, HelpGeneratorOptions::former().for_commands([ dictionary.command( &raw_command.name ).unwrap() ]).command_prefix( "." ).subject_detailing( LevelOfDetail::Detailed ).form() ).strip_suffix( " " ).unwrap().into() ), + } ); }; - let properties = Self::extract_properties( cmd, raw_command.properties.clone() )?; + let properties = Self::extract_properties( cmd, raw_command.properties.clone() ).map_err( | e | VerificationError::Property { command_name: cmd.phrase.clone(), error: e } )?; let used_properties_with_their_aliases = Self::group_properties_and_their_aliases( &cmd.properties_aliases, properties.keys() ); - let subjects = Self::extract_subjects( cmd, &raw_command, &used_properties_with_their_aliases )?; + let subjects = Self::extract_subjects( cmd, &raw_command, &used_properties_with_their_aliases ).map_err( | e | VerificationError::Subject { command_name: cmd.phrase.clone(), error: e } )?; Ok( VerifiedCommand { @@ -248,5 +290,10 @@ mod private crate::mod_interface! { - exposed use Verifier; + orphan use Verifier; + orphan use VerificationError; + + // own use LevelOfDetail; + // own use generate_help_content; + } diff --git a/module/move/wca/src/lib.rs b/module/move/wca/src/lib.rs index c318aa58fd..2fcb2a8409 100644 --- a/module/move/wca/src/lib.rs +++ b/module/move/wca/src/lib.rs @@ -4,13 +4,12 @@ #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "doc/", "wca.md" ) ) ] -#![ allow( where_clauses_object_safety ) ] // https://github.com/chris-morgan/anymap/issues/31 -// qqq : xxx : is it neccessary? - use mod_interface::mod_interface; pub mod ca; +mod private {} + crate::mod_interface! { use super::ca; diff --git a/module/move/wca/tests/inc/adapter.rs b/module/move/wca/tests/inc/adapter.rs deleted file mode 100644 index 33d5cd7e61..0000000000 --- a/module/move/wca/tests/inc/adapter.rs +++ /dev/null @@ -1,44 +0,0 @@ -use super::*; -use the_module::exposed::*; - -tests_impls! -{ - fn simple() - { - fn command( () : (), args : Args, props : Props) -> Result< (), () > - { - Ok( () ) - } - - fn command2( () : (), args : Args, props : Props ) -> Result< (), () > - { - Ok( () ) - } - - fn echo( () : (), args : Args, props : Props ) -> Result< (), () > - { - Ok( () ) - } - - let ca = the_module::cui( () ).command( command ).command( command2 ).command( echo.arg( "string", Type::String ) ).build(); - - a_id!( (), ca.perform( ".command2 .help" ).unwrap() ); - - a_id!( (), ca.perform( ".help command" ).unwrap() ); - a_id!( (), ca.perform( ".help command2" ).unwrap() ); - a_id!( (), ca.perform( ".help help" ).unwrap() ); - - a_id!( (), ca.perform( ".help.command" ).unwrap() ); - a_id!( (), ca.perform( ".help.command2" ).unwrap() ); - a_id!( (), ca.perform( ".help.help" ).unwrap() ); - - a_true!( ca.perform( ".help.help.help" ).is_err() ); - a_true!( ca.perform( ".echo 34" ).is_ok() ); - a_true!( ca.perform( ".echo" ).is_err() ); - } -} - -tests_index! -{ - simple -} diff --git a/module/move/wca/tests/inc/commands_aggregator/basic.rs b/module/move/wca/tests/inc/commands_aggregator/basic.rs index f7019bebf6..6c9ba72c09 100644 --- a/module/move/wca/tests/inc/commands_aggregator/basic.rs +++ b/module/move/wca/tests/inc/commands_aggregator/basic.rs @@ -1,5 +1,14 @@ use super::*; -use the_module::VerifiedCommand; +use the_module:: +{ + parser::Parser, + VerifiedCommand, + CommandsAggregator, + HelpVariants, + Type, + Error, + ValidationError, +}; // @@ -52,8 +61,7 @@ tests_impls! .perform(); a_id!( (), ca.perform( "." ).unwrap() ); - // qqq : this use case is disabled - // a_id!( (), ca.perform( ".cmd." ).unwrap() ); + a_id!( (), ca.perform( ".cmd." ).unwrap() ); } fn error_types() @@ -136,10 +144,10 @@ tests_impls! fn string_subject_with_colon() { - let dictionary = &the_module::Dictionary::former() + let dictionary = &the_module::grammar::Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -150,7 +158,7 @@ tests_impls! ) .perform(); let parser = Parser; - let grammar = the_module::Verifier; + let grammar = the_module::verifier::Verifier; let executor = the_module::Executor::former().form(); let raw_command = parser.parse( [ ".command", "qwe:rty", "nightly:true" ] ).unwrap().commands.remove( 0 ); @@ -163,10 +171,10 @@ tests_impls! fn no_prop_subject_with_colon() { - let dictionary = &the_module::Dictionary::former() + let dictionary = &the_module::grammar::Dictionary::former() .command ( - the_module::Command::former() + the_module::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -177,7 +185,7 @@ tests_impls! .form(); let parser = Parser; - let grammar = the_module::Verifier; + let grammar = the_module::verifier::Verifier; let executor = the_module::Executor::former().form(); let raw_command = parser.parse( [ ".command", "qwe:rty" ] ).unwrap().commands.remove( 0 ); @@ -190,10 +198,10 @@ tests_impls! fn optional_prop_subject_with_colon() { - let dictionary = &the_module::Dictionary::former() + let dictionary = &the_module::grammar::Dictionary::former() .command ( - the_module::Command::former() + the_module::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -205,7 +213,7 @@ tests_impls! .form(); let parser = Parser; - let grammar = the_module::Verifier; + let grammar = the_module::verifier::Verifier; let executor = the_module::Executor::former().form(); let raw_command = parser.parse( [ ".command", "qwe:rty" ] ).unwrap().commands.remove( 0 ); @@ -216,7 +224,8 @@ tests_impls! a_id!( (), executor.command( dictionary, grammar_command ).unwrap() ); } - // qqq : make the following test work + // aaa : make the following test work + // aaa : works fn subject_with_spaces() { let query = "SELECT title, links, MIN( published ) FROM Frames"; diff --git a/module/move/wca/tests/inc/commands_aggregator/callback.rs b/module/move/wca/tests/inc/commands_aggregator/callback.rs index 834426c32d..21910a6560 100644 --- a/module/move/wca/tests/inc/commands_aggregator/callback.rs +++ b/module/move/wca/tests/inc/commands_aggregator/callback.rs @@ -1,5 +1,6 @@ use super::*; use std::sync::{ Arc, Mutex }; +use the_module::CommandsAggregator; #[ test ] fn changes_state_of_local_variable_on_perform() diff --git a/module/move/wca/tests/inc/commands_aggregator/help.rs b/module/move/wca/tests/inc/commands_aggregator/help.rs index 1df2be062e..2ce5a0bca5 100644 --- a/module/move/wca/tests/inc/commands_aggregator/help.rs +++ b/module/move/wca/tests/inc/commands_aggregator/help.rs @@ -1,7 +1,10 @@ -use std::fs::{DirBuilder, File}; -use std::io::Write; -use std::path::Path; -use std::process::{Command, Stdio}; +use std:: +{ + io::Write, + path::Path, + fs::{ DirBuilder, File }, + process::{ Command, Stdio }, +}; pub fn start_sync< AP, Args, Arg, P > ( @@ -11,9 +14,14 @@ pub fn start_sync< AP, Args, Arg, P > ) -> String where AP : AsRef< Path >, Args : IntoIterator< Item = Arg >, Arg : AsRef< std::ffi::OsStr >, P : AsRef< Path >, { let ( application, path ) = ( application.as_ref(), path.as_ref() ); - let args = args.into_iter().map( | a | a.as_ref().into() ).collect::< Vec< std::ffi::OsString > >(); + let args: Vec< std::ffi::OsString > = args.into_iter().map( | a | a.as_ref().into() ).collect(); let child = Command::new( application ).args( &args ).stdout( Stdio::piped() ).stderr( Stdio::piped() ).current_dir( path ).spawn().unwrap(); let output = child.wait_with_output().unwrap(); + + if !output.status.success() + { + println!( "{}", String::from_utf8( output.stderr ).unwrap() ); + } String::from_utf8( output.stdout ).unwrap() } diff --git a/module/move/wca/tests/inc/commands_aggregator/mod.rs b/module/move/wca/tests/inc/commands_aggregator/mod.rs index ca0cdc4b5a..fedda3d681 100644 --- a/module/move/wca/tests/inc/commands_aggregator/mod.rs +++ b/module/move/wca/tests/inc/commands_aggregator/mod.rs @@ -1,16 +1,5 @@ use super::*; -use the_module:: -{ - Parser, - - CommandsAggregator, - HelpVariants, - Type, - Error, - ValidationError, -}; - mod basic; mod callback; mod help; diff --git a/module/move/wca/tests/inc/executor/command.rs b/module/move/wca/tests/inc/executor/command.rs index b1dcf7ac12..e489b90764 100644 --- a/module/move/wca/tests/inc/executor/command.rs +++ b/module/move/wca/tests/inc/executor/command.rs @@ -1,5 +1,15 @@ use super::*; -use the_module::VerifiedCommand; +use the_module:: +{ + parser::Parser, + VerifiedCommand, + executor::Context, Type, + grammar::Dictionary, + verifier::Verifier, + + Executor, + // wtools +}; // @@ -14,7 +24,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -42,7 +52,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -78,7 +88,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -121,7 +131,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "check" ) @@ -137,7 +147,7 @@ tests_impls! ) .form(); let verifier = Verifier; - let mut ctx = wca::Context::new( Mutex::new( 1 ) ); + let mut ctx = wca::executor::Context::new( Mutex::new( 1 ) ); // init executor let executor = Executor::former() .context( ctx ) @@ -160,7 +170,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) diff --git a/module/move/wca/tests/inc/executor/mod.rs b/module/move/wca/tests/inc/executor/mod.rs index 7c84cbf8a3..617cf69b75 100644 --- a/module/move/wca/tests/inc/executor/mod.rs +++ b/module/move/wca/tests/inc/executor/mod.rs @@ -1,17 +1,4 @@ use super::*; -// qqq : rid of global uses in tests -use the_module:: -{ - Parser, - - Context, Type, - Dictionary, - Verifier, - - Executor, - // wtools -}; - mod command; mod program; diff --git a/module/move/wca/tests/inc/executor/program.rs b/module/move/wca/tests/inc/executor/program.rs index de33330259..ef0f63940a 100644 --- a/module/move/wca/tests/inc/executor/program.rs +++ b/module/move/wca/tests/inc/executor/program.rs @@ -1,5 +1,15 @@ use super::*; -use the_module::VerifiedCommand; +use the_module:: +{ + parser::Parser, + VerifiedCommand, + executor::Context, Type, + grammar::Dictionary, + verifier::Verifier, + + Executor, + // wtools +}; // @@ -14,7 +24,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -47,7 +57,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "inc" ) @@ -63,7 +73,7 @@ tests_impls! ) .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "eq" ) @@ -91,7 +101,7 @@ tests_impls! let verifier = Verifier; // starts with 0 - let ctx = wca::Context::new( Mutex::new( 0 ) ); + let ctx = wca::executor::Context::new( Mutex::new( 0 ) ); // init simple executor let executor = Executor::former() .context( ctx ) diff --git a/module/move/wca/tests/inc/grammar/from_command.rs b/module/move/wca/tests/inc/grammar/from_command.rs index 9823236c0c..343cde7ffb 100644 --- a/module/move/wca/tests/inc/grammar/from_command.rs +++ b/module/move/wca/tests/inc/grammar/from_command.rs @@ -1,5 +1,14 @@ use super::*; +use the_module:: +{ + parser::Parser, + + Type, Value, + grammar::Dictionary, + verifier::Verifier, +}; + // tests_impls! @@ -13,7 +22,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -45,7 +54,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -92,7 +101,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -121,7 +130,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -156,7 +165,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -184,7 +193,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -223,7 +232,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -268,7 +277,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -297,7 +306,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -328,7 +337,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) @@ -369,7 +378,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command" ) diff --git a/module/move/wca/tests/inc/grammar/from_program.rs b/module/move/wca/tests/inc/grammar/from_program.rs index 670eaf178c..256fd6dcd9 100644 --- a/module/move/wca/tests/inc/grammar/from_program.rs +++ b/module/move/wca/tests/inc/grammar/from_program.rs @@ -1,5 +1,14 @@ use super::*; +use the_module:: +{ + parser::Parser, + + Type, Value, + grammar::Dictionary, + verifier::Verifier, +}; + // tests_impls! @@ -12,7 +21,7 @@ tests_impls! let dictionary = &Dictionary::former() .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command1" ) @@ -21,7 +30,7 @@ tests_impls! ) .command ( - wca::Command::former() + wca::grammar::Command::former() .hint( "hint" ) .long_hint( "long_hint" ) .phrase( "command2" ) diff --git a/module/move/wca/tests/inc/grammar/mod.rs b/module/move/wca/tests/inc/grammar/mod.rs index 38c94dc114..454495c496 100644 --- a/module/move/wca/tests/inc/grammar/mod.rs +++ b/module/move/wca/tests/inc/grammar/mod.rs @@ -1,12 +1,4 @@ use super::*; -use the_module:: -{ - Parser, - - Type, Value, - Dictionary, - Verifier, -}; mod from_command; mod from_program; diff --git a/module/move/wca/tests/inc/grammar/types.rs b/module/move/wca/tests/inc/grammar/types.rs index 7421fce48f..b04ab6c346 100644 --- a/module/move/wca/tests/inc/grammar/types.rs +++ b/module/move/wca/tests/inc/grammar/types.rs @@ -1,5 +1,5 @@ use super::*; -use wca::TryCast; +use the_module::{ TryCast, Type, Value }; // @@ -134,7 +134,7 @@ tests_impls! let string = Type::List( Type::String.into(), ',' ).try_cast( origin_string.into() ).unwrap(); a_id!( origin_string, string.to_string() ); - // xxx : qqq : that fails now. suggest solution + // xxx clarification is needed : qqq : that fails now. suggest solution // let origin_string = "100;3.14"; // let string = Type::List( Type::Number.into(), ';' ).try_cast( origin_string.into() ).unwrap(); // a_id!( origin_string, string.to_string() ); diff --git a/module/move/wca/tests/inc/mod.rs b/module/move/wca/tests/inc/mod.rs index c2617e9035..b51887947e 100644 --- a/module/move/wca/tests/inc/mod.rs +++ b/module/move/wca/tests/inc/mod.rs @@ -1,10 +1,6 @@ #[ allow( unused_imports ) ] use super::*; -#[ allow( unused_imports ) ] -use the_module::tool::*; -#[ allow( unused_imports ) ] -use std::collections::HashMap; #[ cfg( not( feature = "no_std" ) ) ] mod parser; @@ -15,6 +11,5 @@ mod executor; #[ cfg( not( feature = "no_std" ) ) ] mod commands_aggregator; -// qqq : for Bohdan : why commented out? resolve -// #[ cfg( not( feature = "no_std" ) ) ] -// mod adapter; +// aaa : for Bohdan : why commented out? resolve +// aaa : no longer relevant, so removed diff --git a/module/move/wca/tests/inc/parser/command.rs b/module/move/wca/tests/inc/parser/command.rs index 986ab1d0c0..7f5c1aecf4 100644 --- a/module/move/wca/tests/inc/parser/command.rs +++ b/module/move/wca/tests/inc/parser/command.rs @@ -1,4 +1,5 @@ use super::*; +use the_module::parser::{ ParsedCommand, Parser }; // diff --git a/module/move/wca/tests/inc/parser/mod.rs b/module/move/wca/tests/inc/parser/mod.rs index 456679d11a..617cf69b75 100644 --- a/module/move/wca/tests/inc/parser/mod.rs +++ b/module/move/wca/tests/inc/parser/mod.rs @@ -1,10 +1,4 @@ use super::*; -use wca:: -{ - Program, ParsedCommand, - - Parser, -}; mod command; mod program; diff --git a/module/move/wca/tests/inc/parser/program.rs b/module/move/wca/tests/inc/parser/program.rs index 081f8cc3e8..04b07c322f 100644 --- a/module/move/wca/tests/inc/parser/program.rs +++ b/module/move/wca/tests/inc/parser/program.rs @@ -1,4 +1,5 @@ use super::*; +use the_module::parser::{ Program, ParsedCommand, Parser }; // diff --git a/module/move/willbe/Cargo.toml b/module/move/willbe/Cargo.toml index d87621762c..4f16918129 100644 --- a/module/move/willbe/Cargo.toml +++ b/module/move/willbe/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "willbe" -version = "0.14.0" +version = "0.20.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", @@ -41,7 +41,7 @@ enabled = [ "iter_tools/enabled", "mod_interface/enabled", "wca/enabled", - "proper_path_tools/enabled", + "pth/enabled", "process_tools/enabled", "derive_tools/enabled", "data_type/enabled", @@ -88,7 +88,7 @@ former = { workspace = true, features = [ "default" ] } iter_tools = { workspace = true, features = [ "default" ] } mod_interface = { workspace = true, features = [ "default" ] } wca = { workspace = true, features = [ "default" ] } -proper_path_tools = { workspace = true, features = [ "default", "path_utf8" ] } +pth = { workspace = true, features = [ "default", "path_utf8" ] } process_tools = { workspace = true, features = [ "default" ] } derive_tools = { workspace = true, features = [ "derive_display", "derive_from_str", "derive_deref", "derive_from", "derive_as_ref" ] } data_type = { workspace = true, features = [ "either" ] } diff --git a/module/move/willbe/License b/module/move/willbe/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/move/willbe/License +++ b/module/move/willbe/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/move/willbe/src/action/cicd_renew.rs b/module/move/willbe/src/action/cicd_renew.rs index fdf14a1216..5814e2802c 100644 --- a/module/move/willbe/src/action/cicd_renew.rs +++ b/module/move/willbe/src/action/cicd_renew.rs @@ -19,7 +19,7 @@ mod private use error:: { typed::Error, - err, + // err, }; #[ derive( Debug, Error ) ] @@ -42,7 +42,7 @@ mod private // qqq : for Petro : should return Report and typed error in Result /// Generate workflows for modules in .github/workflows directory. - pub fn cicd_renew( base_path : &Path ) -> Result< (), CiCdGenerateError > + pub fn action( base_path : &Path ) -> Result< (), CiCdGenerateError > { let workspace_cache = Workspace::try_from( CrateDir::try_from( base_path )? )?; let packages = workspace_cache.packages(); @@ -375,7 +375,7 @@ mod private return url::repo_url_extract( &url ) .and_then( | url | url::git_info_extract( &url ).ok() ) .map( UsernameAndRepository ) - .ok_or_else( || err!( "Fail to parse repository url from workspace Cargo.toml")) + .ok_or_else( || error::untyped::format_err!( "Fail to parse repository url from workspace Cargo.toml")) } else { @@ -393,7 +393,7 @@ mod private .and_then( | url | url::repo_url_extract( &url ) ) .and_then( | url | url::git_info_extract( &url ).ok() ) .map( UsernameAndRepository ) - .ok_or_else( || err!( "Fail to extract repository url") ) + .ok_or_else( || error::untyped::format_err!( "Fail to extract repository url") ) } } @@ -401,5 +401,5 @@ mod private crate::mod_interface! { - exposed use cicd_renew; + own use action; } diff --git a/module/move/willbe/src/action/deploy_renew.rs b/module/move/willbe/src/action/deploy_renew.rs index 2a6d3b52fd..0f1c965332 100644 --- a/module/move/willbe/src/action/deploy_renew.rs +++ b/module/move/willbe/src/action/deploy_renew.rs @@ -5,146 +5,76 @@ mod private use error::{ untyped::Context }; use tool::template::*; - // /// Template for creating deploy files. - // /// - // /// Includes terraform deploy options to GCP, and Hetzner, - // /// a Makefile for useful commands, and a key directory. - // #[ derive( Debug ) ] - // pub struct DeployTemplate - // { - // files : DeployTemplateFiles, - // parameters : TemplateParameters, - // values : TemplateValues, - // } - - // // qqq : for Viktor : why DeployTemplate can't be part of template.rs? - - // impl Template< DeployTemplateFiles > for DeployTemplate - // { - // fn create_all( self, path : &Path ) -> error::untyped::Result< () > - // { - // self.files.create_all( path, &self.values ) - // } - - // fn parameters( &self ) -> &TemplateParameters - // { - // &self.parameters - // } - - // fn set_values( &mut self, values : TemplateValues ) - // { - // self.values = values - // } - - // fn get_values( &self ) -> &TemplateValues - // { - // &self.values - // } - - // fn get_values_mut( &mut self ) -> &mut TemplateValues - // { - // &mut self.values - // } - - // fn parameter_storage( &self ) -> &Path { - // "./.deploy_template.toml".as_ref() - // } - - // fn template_name( &self ) -> &'static str { - // "deploy" - // } - // } - - // impl Default for DeployTemplate - // { - // fn default() -> Self - // { - // let parameters = TemplateParameters::former() - // .parameter( "gcp_project_id" ).is_mandatory( true ).end() - // .parameter( "gcp_region" ).end() - // .parameter( "gcp_artifact_repo_name" ).end() - // .parameter( "docker_image_name" ).end() - // .form(); - - // Self - // { - // files : Default::default(), - // parameters, - // values : Default::default(), - // } - // } - // } - - // // qqq : for Viktor : is that structure required? - // /// Files for the deploy template. - // /// - // /// Default implementation contains all required files. - // #[ derive( Debug ) ] - // pub struct DeployTemplateFiles( Vec< TemplateFileDescriptor > ); - - // impl Default for DeployTemplateFiles - // { - // fn default() -> Self - // { - // let formed = TemplateFilesBuilder::former() - // // root - // .file().data( include_str!( "../../template/deploy/.deploy_template.toml.hbs" ) ).path( "./.deploy_template.toml" ).mode( WriteMode::TomlExtend ).is_template( true ).end() - // .file().data( include_str!( "../../template/deploy/Makefile.hbs" ) ).path( "./Makefile" ).is_template( true ).end() - // // /key - // .file().data( include_str!( "../../template/deploy/key/pack.sh" ) ).path( "./key/pack.sh" ).end() - // .file().data( include_str!( "../../template/deploy/key/Readme.md" ) ).path( "./key/Readme.md" ).end() - // // /deploy/ - // .file().data( include_str!( "../../template/deploy/deploy/Dockerfile" ) ).path( "./deploy/Dockerfile" ).end() - // .file().data( include_str!( "../../template/deploy/deploy/Readme.md" ) ).path( "./deploy/Readme.md" ).end() - // // /deploy/gar - // .file().data( include_str!( "../../template/deploy/deploy/gar/Readme.md" ) ).path( "./deploy/gar/Readme.md" ).end() - // .file().data( include_str!( "../../template/deploy/deploy/gar/main.tf" ) ).path( "./deploy/gar/main.tf" ).end() - // .file().data( include_str!( "../../template/deploy/deploy/gar/outputs.tf" ) ).path( "./deploy/gar/outputs.tf" ).end() - // .file().data( include_str!( "../../template/deploy/deploy/gar/variables.tf" ) ).path( "./deploy/gar/variables.tf" ).end() - // // /deploy/gce - // .file().data( include_str!( "../../template/deploy/deploy/gce/Readme.md" ) ).path( "./deploy/gce/Readme.md" ).end() - // .file().data( include_str!( "../../template/deploy/deploy/gce/main.tf" ) ).path( "./deploy/gce/main.tf" ).end() - // .file().data( include_str!( "../../template/deploy/deploy/gce/outputs.tf" ) ).path( "./deploy/gce/outputs.tf" ).end() - // .file().data( include_str!( "../../template/deploy/deploy/gce/variables.tf" ) ).path( "./deploy/gce/variables.tf" ).end() - // // /deploy/gce/templates - // .file().data( include_str!( "../../template/deploy/deploy/gce/templates/cloud-init.tpl" ) ).path( "./deploy/gce/templates/cloud-init.tpl" ).end() - // // /deploy/gcs - // .file().data( include_str!( "../../template/deploy/deploy/gcs/main.tf" ) ).path( "./deploy/gcs/main.tf" ).end() - // // /deploy/hetzner - // .file().data( include_str!( "../../template/deploy/deploy/hetzner/main.tf" ) ).path( "./deploy/hetzner/main.tf" ).end() - // .file().data( include_str!( "../../template/deploy/deploy/hetzner/outputs.tf" ) ).path( "./deploy/hetzner/outputs.tf" ).end() - // .file().data( include_str!( "../../template/deploy/deploy/hetzner/variables.tf" ) ).path( "./deploy/hetzner/variables.tf" ).end() - // // /deploy/hetzner/templates - // .file().data( include_str!( "../../template/deploy/deploy/hetzner/templates/cloud-init.tpl" ) ).path( "./deploy/hetzner/templates/cloud-init.tpl" ).end() - // // /deploy/aws - // .file().data( include_str!( "../../template/deploy/deploy/aws/main.tf" ) ).path( "./deploy/aws/main.tf" ).end() - // .file().data( include_str!( "../../template/deploy/deploy/aws/outputs.tf" ) ).path( "./deploy/aws/outputs.tf" ).end() - // .file().data( include_str!( "../../template/deploy/deploy/aws/variables.tf" ) ).path( "./deploy/aws/variables.tf" ).end() - // // /deploy/aws/templates - // .file().data( include_str!( "../../template/deploy/deploy/aws/templates/cloud-init.tpl" ) ).path( "./deploy/aws/templates/cloud-init.tpl" ).end() - // .form(); - - // Self( formed.files ) - // } - // } - - // // qqq : for Viktor : should not be required - // impl TemplateFiles for DeployTemplateFiles {} - // // qqq : for Viktor : should not be required - // impl IntoIterator for DeployTemplateFiles - // { - // type Item = TemplateFileDescriptor; - - // type IntoIter = std::vec::IntoIter< Self::Item >; - - // fn into_iter( self ) -> Self::IntoIter - // { - // self.0.into_iter() - // } - // } + /// Template for creating deploy files. + /// + /// Includes terraform deploy options to GCP, and Hetzner, + /// a Makefile for useful commands, and a key directory. + #[ derive( Debug ) ] + pub struct DeployTemplate; + + impl DeployTemplate + { + /// Creates am instance of `[TemplateHolder]` for deployment template. + /// + /// Used for properly initializing a template + pub fn default() -> TemplateHolder + { + let parameters = TemplateParameters::former() + .parameter( "gcp_project_id" ).is_mandatory( true ).end() + .parameter( "gcp_region" ).end() + .parameter( "gcp_artifact_repo_name" ).end() + .parameter( "docker_image_name" ).end() + .form(); + + TemplateHolder + { + files : get_deploy_template_files(), + parameters, + values : Default::default(), + parameter_storage : "./.deploy_template.toml".as_ref(), + template_name : "deploy", + } + } + } - // aaa : for Petro : redundant function - // aaa : this function not my, but ok I'll remove it. + fn get_deploy_template_files() -> Vec< TemplateFileDescriptor > + { + let formed = TemplateFilesBuilder::former() + // root + .file().data( include_str!( "../../template/deploy/.deploy_template.toml.hbs" ) ).path( "./.deploy_template.toml" ).mode( WriteMode::TomlExtend ).is_template( true ).end() + .file().data( include_str!( "../../template/deploy/Makefile.hbs" ) ).path( "./Makefile" ).is_template( true ).end() + // /key + .file().data( include_str!( "../../template/deploy/key/pack.sh" ) ).path( "./key/pack.sh" ).end() + .file().data( include_str!( "../../template/deploy/key/Readme.md" ) ).path( "./key/Readme.md" ).end() + // /deploy/ + .file().data( include_str!( "../../template/deploy/deploy/redeploy.sh" ) ).path( "./deploy/redeploy.sh" ).end() + .file().data( include_str!( "../../template/deploy/deploy/cloud-init.tpl.hbs" ) ).path( "./deploy/cloud-init.tpl" ).is_template( true ).end() + .file().data( include_str!( "../../template/deploy/deploy/Dockerfile" ) ).path( "./deploy/Dockerfile" ).end() + .file().data( include_str!( "../../template/deploy/deploy/Readme.md" ) ).path( "./deploy/Readme.md" ).end() + // /deploy/gar + .file().data( include_str!( "../../template/deploy/deploy/gar/Readme.md" ) ).path( "./deploy/gar/Readme.md" ).end() + .file().data( include_str!( "../../template/deploy/deploy/gar/main.tf.hbs" ) ).path( "./deploy/gar/main.tf" ).is_template( true ).end() + .file().data( include_str!( "../../template/deploy/deploy/gar/outputs.tf" ) ).path( "./deploy/gar/outputs.tf" ).end() + .file().data( include_str!( "../../template/deploy/deploy/gar/variables.tf" ) ).path( "./deploy/gar/variables.tf" ).end() + // /deploy/gce + .file().data( include_str!( "../../template/deploy/deploy/gce/Readme.md" ) ).path( "./deploy/gce/Readme.md" ).end() + .file().data( include_str!( "../../template/deploy/deploy/gce/main.tf.hbs" ) ).path( "./deploy/gce/main.tf" ).is_template( true ).end() + .file().data( include_str!( "../../template/deploy/deploy/gce/outputs.tf.hbs" ) ).path( "./deploy/gce/outputs.tf" ).is_template( true ).end() + .file().data( include_str!( "../../template/deploy/deploy/gce/variables.tf" ) ).path( "./deploy/gce/variables.tf" ).end() + // /deploy/gcs + .file().data( include_str!( "../../template/deploy/deploy/gcs/main.tf" ) ).path( "./deploy/gcs/main.tf" ).end() + // /deploy/hetzner + .file().data( include_str!( "../../template/deploy/deploy/hetzner/main.tf.hbs" ) ).path( "./deploy/hetzner/main.tf" ).is_template( true ).end() + .file().data( include_str!( "../../template/deploy/deploy/hetzner/outputs.tf.hbs" ) ).path( "./deploy/hetzner/outputs.tf" ).is_template( true ).end() + .file().data( include_str!( "../../template/deploy/deploy/hetzner/variables.tf" ) ).path( "./deploy/hetzner/variables.tf" ).end() + // /deploy/aws + .file().data( include_str!( "../../template/deploy/deploy/aws/main.tf" ) ).path( "./deploy/aws/main.tf" ).end() + .file().data( include_str!( "../../template/deploy/deploy/aws/outputs.tf" ) ).path( "./deploy/aws/outputs.tf" ).end() + .file().data( include_str!( "../../template/deploy/deploy/aws/variables.tf" ) ).path( "./deploy/aws/variables.tf" ).end() + .form(); + + formed.files + } fn dir_name_to_formatted( dir_name : &str, separator : &str ) -> String { @@ -179,7 +109,6 @@ mod private template .values .insert_if_empty( "gcp_artifact_repo_name", wca::Value::String( artifact_repo_name ) ); - template .values .insert_if_empty( "docker_image_name", wca::Value::String( docker_image_name ) ); @@ -187,7 +116,7 @@ mod private .values .insert_if_empty( "gcp_region", wca::Value::String( "europe-central2".into() ) ); } - template.create_all( path )?; + template.files.create_all( path, &template.values )?; Ok( () ) } @@ -196,5 +125,5 @@ mod private crate::mod_interface! { orphan use deploy_renew; - //orphan use DeployTemplate; + orphan use DeployTemplate; } diff --git a/module/move/willbe/src/action/features.rs b/module/move/willbe/src/action/features.rs index 26b8701cc2..ca7312d289 100644 --- a/module/move/willbe/src/action/features.rs +++ b/module/move/willbe/src/action/features.rs @@ -112,3 +112,4 @@ crate::mod_interface! orphan use FeaturesOptions; orphan use FeaturesReport; } +// qqq : don't use orphan here \ No newline at end of file diff --git a/module/move/willbe/src/action/list.rs b/module/move/willbe/src/action/list.rs index 6f2708217b..c747532f6d 100644 --- a/module/move/willbe/src/action/list.rs +++ b/module/move/willbe/src/action/list.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; @@ -13,7 +13,7 @@ mod private }; use error:: { - ErrWith, err, + ErrWith, untyped::{ Context, format_err }, }; use tool::{ TreePrinter, ListNodeReport }; @@ -39,7 +39,7 @@ mod private { "tree" => ListFormat::Tree, "toposort" => ListFormat::Topological, - e => return Err( err!( "Unknown format '{}'. Available values : [tree, toposort]", e )) + e => return Err( error::untyped::format_err!( "Unknown format '{}'. Available values : [tree, toposort]", e )) }; Ok( value ) @@ -105,7 +105,7 @@ mod private { "nothing" => ListFilter::Nothing, "local" => ListFilter::Local, - e => return Err( err!( "Unknown filter '{}'. Available values : [nothing, local]", e ) ) + e => return Err( error::untyped::format_err!( "Unknown filter '{}'. Available values : [nothing, local]", e ) ) }; Ok( value ) @@ -436,7 +436,7 @@ mod private /// - `Result` - A result containing the list report if successful, /// or a tuple containing the list report and error if not successful. #[ cfg_attr( feature = "tracing", tracing::instrument ) ] - pub fn list( args : ListOptions ) + pub fn list_all( args : ListOptions ) -> ResultWithReport< ListReport, error::untyped::Error > // qqq : should be specific error // qqq : use typed error @@ -462,17 +462,32 @@ mod private .package_find_by_manifest( manifest_file ) .ok_or_else( || format_err!( "Package not found in the workspace" ) ) .err_with_report( report )?; + let version = if args.info.contains( &PackageAdditionalInfo::Version ) + { + Some( package.version().to_string() ) + } + else + { + None + }; + let crate_dir = if args.info.contains( &PackageAdditionalInfo::Path ) + { + Some( package.crate_dir() ).transpose() + } + else + { + Ok( None ) + } + .err_with_report( report )?; let mut package_report = tool::ListNodeReport { name : package.name().to_string(), - // qqq : for Bohdan : too long lines - version : if args.info.contains( &PackageAdditionalInfo::Version ) { Some( package.version().to_string() ) } else { None }, - // qqq : for Bohdan : don't put multiline if into struct constructor - crate_dir : if args.info.contains( &PackageAdditionalInfo::Path ) - { Some( package.crate_dir() ).transpose() } - else - { Ok( None ) } - .err_with_report( report )?, + // aaa : for Bohdan : too long lines + // aaa : moved out + version, + // aaa : for Bohdan : don't put multiline if into struct constructor + // aaa : moved out + crate_dir, duplicate : false, normal_dependencies : vec![], dev_dependencies : vec![], @@ -849,5 +864,5 @@ crate::mod_interface! /// Contains output of a single node of the action. // own use ListNodeReport; /// List packages in workspace. - orphan use list; + orphan use list_all; } diff --git a/module/move/willbe/src/action/main_header.rs b/module/move/willbe/src/action/main_header.rs index 7c1b5af526..05ca9ec085 100644 --- a/module/move/willbe/src/action/main_header.rs +++ b/module/move/willbe/src/action/main_header.rs @@ -18,8 +18,8 @@ mod private use entity::{ PathError, WorkspaceInitError }; use error:: { - err, - untyped::Error, + // err, + // untyped::Error, }; use workspace_md_extension::WorkspaceMdExtension; @@ -86,7 +86,7 @@ mod private { /// Represents a common error. #[ error( "Common error: {0}" ) ] - Common(#[ from ] Error ), + Common( #[ from ] error::untyped::Error ), // qqq : rid of /// Represents an I/O error. #[ error( "I/O error: {0}" ) ] IO( #[ from ] std::io::Error ), @@ -116,14 +116,14 @@ mod private // aaa : done let repository_url = workspace .repository_url() - .ok_or_else::< Error, _ > - ( || err!( "repo_url not found in workspace Cargo.toml" ) )?; + .ok_or_else::< error::untyped::Error, _ > + ( || error::untyped::format_err!( "repo_url not found in workspace Cargo.toml" ) )?; let master_branch = workspace.master_branch().unwrap_or( "master".into() ); let workspace_name = workspace .workspace_name() - .ok_or_else::< Error, _ > - ( || err!( "workspace_name not found in workspace Cargo.toml" ) )?; + .ok_or_else::< error::untyped::Error, _ > + ( || error::untyped::format_err!( "workspace_name not found in workspace Cargo.toml" ) )?; let discord_url = workspace.discord_url(); @@ -193,7 +193,7 @@ mod private /// [![docs.rs](https://raster.shields.io/static/v1?label=docs&message=online&color=eee&logo=docsdotrs&logoColor=eee)](https://docs.rs/wtools) /// /// ``` - pub fn readme_header_renew( crate_dir : CrateDir ) + pub fn action( crate_dir : CrateDir ) // -> Result< MainHeaderRenewReport, ( MainHeaderRenewReport, MainHeaderRenewError ) > -> ResultWithReport< MainHeaderRenewReport, MainHeaderRenewError > { @@ -265,7 +265,7 @@ mod private crate::mod_interface! { /// Generate header. - orphan use readme_header_renew; + own use action; /// Report. orphan use MainHeaderRenewReport; /// Error. diff --git a/module/move/willbe/src/action/mod.rs b/module/move/willbe/src/action/mod.rs index 728271c2a5..c824bfd6f7 100644 --- a/module/move/willbe/src/action/mod.rs +++ b/module/move/willbe/src/action/mod.rs @@ -1,3 +1,5 @@ +mod private {} + crate::mod_interface! { /// Deploy new. diff --git a/module/move/willbe/src/action/publish.rs b/module/move/willbe/src/action/publish.rs index 58412a2d7a..6b8f4dc657 100644 --- a/module/move/willbe/src/action/publish.rs +++ b/module/move/willbe/src/action/publish.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; @@ -109,6 +109,7 @@ mod private /// /// # Arguments /// * `patterns` - A vector of patterns specifying the folders to search for packages. + /// * `exclude_dev_dependencies` - A boolean value indicating whether to exclude dev dependencies from manifest before publish. /// * `dry` - A boolean value indicating whether to perform a dry run. /// * `temp` - A boolean value indicating whether to use a temporary directory. /// @@ -119,6 +120,8 @@ mod private ( patterns : Vec< String >, channel : channel::Channel, + exclude_dev_dependencies : bool, + commit_changes : bool, dry : bool, temp : bool ) @@ -233,6 +236,8 @@ mod private .channel( channel ) .workspace_dir( CrateDir::try_from( workspace_root_dir ).unwrap() ) .option_base_temp_dir( dir.clone() ) + .exclude_dev_dependencies( exclude_dev_dependencies ) + .commit_changes( commit_changes ) .dry( dry ) .roots( roots ) .packages( queue ) diff --git a/module/move/willbe/src/action/publish_diff.rs b/module/move/willbe/src/action/publish_diff.rs index d27920c7bc..a6b76e6528 100644 --- a/module/move/willbe/src/action/publish_diff.rs +++ b/module/move/willbe/src/action/publish_diff.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; @@ -22,6 +22,7 @@ mod private pub struct PublishDiffOptions { path : PathBuf, + exclude_dev_dependencies : bool, keep_archive : Option< PathBuf >, } @@ -105,7 +106,7 @@ mod private let path = AbsolutePath::try_from( o.path )?; let dir = CrateDir::try_from( path.clone() )?; - let list = action::list + let list = action::list_all ( action::list::ListOptions::former() .path_to_manifest( dir ) @@ -141,16 +142,17 @@ mod private let name = &package.name()?; let version = &package.version()?; - _ = cargo::pack - ( - cargo::PackOptions::former() - .path( dir.as_ref() ) - .allow_dirty( true ) - .checking_consistency( false ) - .dry( false ).form() - )?; - let l = CrateArchive::read( packed_crate::local_path( name, version, dir )? )?; - let r = CrateArchive::download_crates_io( name, version ).unwrap(); + _ = cargo::pack + ( + cargo::PackOptions::former() + .path( dir.as_ref() ) + .allow_dirty( true ) + .checking_consistency( false ) + .exclude_dev_dependencies( o.exclude_dev_dependencies) + .dry( false ).form() + )?; + let l = CrateArchive::read( packed_crate::local_path( name, version, dir )? )?; + let r = CrateArchive::download_crates_io( name, version ).unwrap(); if let Some( out_path ) = &o.keep_archive diff --git a/module/move/willbe/src/action/readme_modules_headers_renew.rs b/module/move/willbe/src/action/readme_modules_headers_renew.rs index 5370a9d0fa..aeba473c74 100644 --- a/module/move/willbe/src/action/readme_modules_headers_renew.rs +++ b/module/move/willbe/src/action/readme_modules_headers_renew.rs @@ -20,11 +20,11 @@ mod private use package::Package; use error:: { - err, + // err, untyped:: { // Result, - Error as wError, + // Error as wError, Context, }, }; @@ -101,7 +101,7 @@ mod private { /// Represents a common error. #[ error( "Common error: {0}" ) ] - Common(#[ from ] wError ), + Common(#[ from ] error::untyped::Error ), // qqq : rid of /// Represents an I/O error. #[ error( "I/O error: {0}" ) ] IO( #[ from ] std::io::Error ), @@ -140,7 +140,7 @@ mod private let stability = package.stability()?; let module_name = package.name()?; let repository_url = package.repository()? - .ok_or_else::< wError, _ >( || err!( "Fail to find repository_url in module`s Cargo.toml" ) )?; + .ok_or_else::< error::untyped::Error, _ >( || error::untyped::format_err!( "Fail to find repository_url in module`s Cargo.toml" ) )?; let discord_url = package .discord_url()? @@ -172,14 +172,14 @@ mod private let repo_url = url::repo_url_extract( &self.repository_url ) .and_then( | r | url::git_info_extract( &r ).ok() ) - .ok_or_else::< wError, _ >( || err!( "Fail to parse repository url" ) )?; + .ok_or_else::< error::untyped::Error, _ >( || error::untyped::format_err!( "Fail to parse repository url" ) )?; let example= if let Some( name ) = find_example_file ( self.module_path.as_path(), &self.module_name ) { - let relative_path = proper_path_tools::path::path_relative + let relative_path = pth::path::path_relative ( workspace_path.try_into().unwrap(), name @@ -269,7 +269,7 @@ mod private .join ( repository::readme_path( path.parent().unwrap().as_ref() ) - // .ok_or_else::< wError, _ >( || err!( "Fail to find README.md at {}", &path ) ) + // .ok_or_else::< error::untyped::Error, _ >( || error::untyped::format_err!( "Fail to find README.md at {}", &path ) ) .err_with_report( &report )? ); diff --git a/module/move/willbe/src/action/test.rs b/module/move/willbe/src/action/test.rs index be0b90405c..0d22053121 100644 --- a/module/move/willbe/src/action/test.rs +++ b/module/move/willbe/src/action/test.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; @@ -71,7 +71,7 @@ mod private // -> Result< TestsReport, ( TestsReport, Error ) > { - // qqq : incapsulate progress bar logic into some function of struct. don't keep it here + // aaa : incapsulate progress bar logic into some function of struct. don't keep it here // aaa : done let mut report = TestsReport::default(); @@ -164,7 +164,7 @@ Try to install it with `rustup install {}` command(-s)", ).err_with_report( &report )?; println!( "{plan}" ); - // aaa : split on two functions for create plan and for execute + // aaa : split on two functions for create plan and for execute // aaa : it's already separated, look line: 203 : let result = tests_run( &options ); let temp_path = if temp diff --git a/module/move/willbe/src/action/workspace_renew.rs b/module/move/willbe/src/action/workspace_renew.rs index 58e4ad61ea..05936758d9 100644 --- a/module/move/willbe/src/action/workspace_renew.rs +++ b/module/move/willbe/src/action/workspace_renew.rs @@ -134,7 +134,7 @@ mod private // qqq : for Petro : should return report // qqq : for Petro : should have typed error /// Creates workspace template - pub fn workspace_renew + pub fn action ( path : &Path, mut template : WorkspaceTemplate, @@ -172,6 +172,6 @@ mod private crate::mod_interface! { - exposed use workspace_renew; + own use action; orphan use WorkspaceTemplate; } diff --git a/module/move/willbe/src/command/cicd_renew.rs b/module/move/willbe/src/command/cicd_renew.rs index 50b1a8de91..c82b45b8da 100644 --- a/module/move/willbe/src/command/cicd_renew.rs +++ b/module/move/willbe/src/command/cicd_renew.rs @@ -10,7 +10,7 @@ mod private // qqq : typed error pub fn cicd_renew() -> error::untyped::Result< () > { - action::cicd_renew + action::cicd_renew::action ( &std::env::current_dir()? ) diff --git a/module/move/willbe/src/command/deploy_renew.rs b/module/move/willbe/src/command/deploy_renew.rs index c66107fe8d..7e1e68e476 100644 --- a/module/move/willbe/src/command/deploy_renew.rs +++ b/module/move/willbe/src/command/deploy_renew.rs @@ -4,9 +4,7 @@ mod private use wca::VerifiedCommand; use error::{ untyped::Context }; - use tool::TemplateHolder; - //use tool::template::Template; - // use action::deploy_renew::*; + use action::deploy_renew::*; /// /// Create new deploy. @@ -17,7 +15,7 @@ mod private { let current_dir = std::env::current_dir()?; - let mut template = TemplateHolder::default(); + let mut template = DeployTemplate::default(); _ = template.load_existing_params( ¤t_dir ); let parameters = template.parameters(); let mut values = parameters.values_from_props( &o.props ); diff --git a/module/move/willbe/src/command/list.rs b/module/move/willbe/src/command/list.rs index c1bb086099..7687b6db1d 100644 --- a/module/move/willbe/src/command/list.rs +++ b/module/move/willbe/src/command/list.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; @@ -80,7 +80,7 @@ mod private .dependency_categories( categories ) .form(); - match action::list( o ) + match action::list_all( o ) { Ok( report ) => { @@ -97,10 +97,10 @@ mod private Ok( () ) } - impl TryFrom< wca::Props > for ListProperties + impl TryFrom< wca::executor::Props > for ListProperties { type Error = error::untyped::Error; - fn try_from( value : wca::Props ) -> Result< Self, Self::Error > + fn try_from( value : wca::executor::Props ) -> Result< Self, Self::Error > { let mut this = Self::former(); diff --git a/module/move/willbe/src/command/main_header.rs b/module/move/willbe/src/command/main_header.rs index efd23e67c4..b29229e9bd 100644 --- a/module/move/willbe/src/command/main_header.rs +++ b/module/move/willbe/src/command/main_header.rs @@ -1,14 +1,14 @@ mod private { use crate::*; - use action; + // use action; use error::untyped::{ Error }; /// Generates header to main Readme.md file. // qqq : typed error pub fn readme_header_renew() -> error::untyped::Result< () > { - match action::readme_header_renew + match crate::action::main_header::action ( CrateDir::transitive_try_from::< AbsolutePath >( CurrentPath )? ) diff --git a/module/move/willbe/src/command/mod.rs b/module/move/willbe/src/command/mod.rs index f6115c3f10..d54c8f2df5 100644 --- a/module/move/willbe/src/command/mod.rs +++ b/module/move/willbe/src/command/mod.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; @@ -25,6 +25,16 @@ mod private .kind( Type::String ) .optional( true ) .end() + .property( "exclude_dev_dependencies" ) + .hint( "Setting this option to true will temporarily remove development dependencies before executing the command, then restore them afterward. Default is `true`." ) + .kind( Type::Bool ) + .optional( true ) + .end() + .property( "commit_changes" ) + .hint( "Indicates whether changes should be committed. Default is `false`." ) + .kind( Type::Bool ) + .optional( true ) + .end() .property( "dry" ) .hint( "Enables 'dry run'. Does not publish, only simulates. Default is `true`." ) .kind( Type::Bool ) @@ -47,6 +57,11 @@ mod private .kind( Type::Path ) .optional( true ) .end() + .property( "exclude_dev_dependencies" ) + .hint( "Setting this option to true will temporarily remove development dependencies before executing the command, then restore them afterward. Default is `true`." ) + .kind( Type::Bool ) + .optional( true ) + .end() .property( "keep_archive" ) .hint( "Save remote package version to the specified path" ) .kind( Type::Path ) @@ -128,8 +143,8 @@ with_gitpod: If set to 1, a column with a link to Gitpod will be added. Clicking .end() .command( "test" ) - .hint( "execute tests in specific packages" ) - .long_hint( "this command runs tests in designated packages based on the provided path. It allows for inclusion and exclusion of features, testing on different Rust version channels, parallel execution, and feature combination settings." ) + .hint( "List crate features to run tests for each combination, aiming for full test coverage of the crate." ) + .long_hint( "List crate features, different optimization level (Release & Debug) and toolchain (stable & nightly) to run tests for each combination. Сan be used for packages as well as workspaces. Supports parallel execution." ) .subject().hint( "A path to directories with packages. If no path is provided, the current directory is used." ).kind( Type::Path ).optional( true ).end() .property( "dry" ).hint( "Enables 'dry run'. Does not run tests, only simulates. Default is `true`." ).kind( Type::Bool ).optional( true ).end() .property( "temp" ).hint( "If flag is `true` all test will be running in temporary directories. Default `true`." ).kind( Type::Bool ).optional( true ).end() @@ -225,7 +240,7 @@ with_gitpod: If set to 1, a column with a link to Gitpod will be added. Clicking .command( "deploy.renew" ) .hint( "Create deploy template" ) - .long_hint( "Creates static files and directories.\nDeployment to different hosts is done via Makefile." ) + .long_hint( "Creates static files and directories.\nDeployment to different hosts is done via Makefile.\n\nUsage example: deploy.renew gcp_project_id:wtools" ) .property( "gcp_project_id" ) .hint( "Google Cloud Platform Project id for image deployment, terraform state bucket, and, if specified, GCE instance deployment." ) .kind( Type::String ) @@ -239,12 +254,12 @@ with_gitpod: If set to 1, a column with a link to Gitpod will be added. Clicking .property( "gcp_artifact_repo_name" ) .hint( "Google Cloud Platform Artifact Repository to store docker image in. Will be generated from current directory name if unspecified." ) .kind( Type::String ) - .optional( false ) + .optional( true ) .end() .property( "docker_image_name" ) .hint( "Docker image name to build and deploy. Will be generated from current directory name if unspecified." ) .kind( Type::String ) - .optional( false ) + .optional( true ) .end() .routine( command::deploy_renew ) .end() diff --git a/module/move/willbe/src/command/publish.rs b/module/move/willbe/src/command/publish.rs index a70af4265d..d02fa67bb5 100644 --- a/module/move/willbe/src/command/publish.rs +++ b/module/move/willbe/src/command/publish.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; @@ -15,6 +15,10 @@ mod private { #[ former( default = Channel::Stable ) ] channel : Channel, + #[ former( default = false ) ] + exclude_dev_dependencies : bool, + #[ former( default = false ) ] + commit_changes : bool, #[ former( default = true ) ] dry : bool, #[ former( default = true ) ] @@ -52,10 +56,12 @@ mod private let PublishProperties { channel, + exclude_dev_dependencies, + commit_changes, dry, temp } = o.props.try_into()?; - let plan = action::publish_plan( patterns, channel, dry, temp ) + let plan = action::publish_plan( patterns, channel, exclude_dev_dependencies, commit_changes, dry, temp ) .context( "Failed to plan the publication process" )?; let mut formatted_plan = String::new(); @@ -95,10 +101,10 @@ mod private } } - impl TryFrom< wca::Props > for PublishProperties + impl TryFrom< wca::executor::Props > for PublishProperties { type Error = error::untyped::Error; - fn try_from( value : wca::Props ) -> Result< Self, Self::Error > + fn try_from( value : wca::executor::Props ) -> Result< Self, Self::Error > { let mut this = Self::former(); @@ -110,6 +116,10 @@ mod private else { this }; + this = if let Some( v ) = value + .get_owned( "exclude_dev_dependencies" ) { this.exclude_dev_dependencies::< bool >( v ) } else { this }; + this = if let Some( v ) = value + .get_owned( "commit_changes" ) { this.commit_changes::< bool >( v ) } else { this }; this = if let Some( v ) = value .get_owned( "dry" ) { this.dry::< bool >( v ) } else { this }; this = if let Some( v ) = value diff --git a/module/move/willbe/src/command/publish_diff.rs b/module/move/willbe/src/command/publish_diff.rs index 4691331866..6408de6de5 100644 --- a/module/move/willbe/src/command/publish_diff.rs +++ b/module/move/willbe/src/command/publish_diff.rs @@ -13,6 +13,8 @@ mod private #[ derive( former::Former ) ] struct PublishDiffProperties { + #[ former( default = false ) ] + exclude_dev_dependencies : bool, keep_archive : Option< PathBuf >, } @@ -33,10 +35,11 @@ mod private pub fn publish_diff( o : VerifiedCommand ) -> error::untyped::Result< () > // qqq : use typed error { let path : PathBuf = o.args.get_owned( 0 ).unwrap_or( std::env::current_dir()? ); - let PublishDiffProperties { keep_archive } = o.props.try_into()?; + let PublishDiffProperties { keep_archive, exclude_dev_dependencies } = o.props.try_into()?; let mut o = action::PublishDiffOptions::former() - .path( path ); + .path( path ) + .exclude_dev_dependencies( exclude_dev_dependencies ); if let Some( k ) = keep_archive.clone() { o = o.keep_archive( k ); } let o = o.form(); @@ -50,13 +53,19 @@ mod private Ok( () ) } - impl TryFrom< wca::Props > for PublishDiffProperties + impl TryFrom< wca::executor::Props > for PublishDiffProperties { type Error = error::untyped::Error; - fn try_from( value : wca::Props ) -> Result< Self, Self::Error > + fn try_from( value : wca::executor::Props ) -> Result< Self, Self::Error > { let mut this = Self::former(); + this = if let Some( v ) = value + .get_owned( "exclude_dev_dependencies" ) + { this.exclude_dev_dependencies::< bool >( v ) } + else + { this }; + this = if let Some( v ) = value .get_owned( "keep_archive" ) { this.keep_archive::< PathBuf >( v ) } diff --git a/module/move/willbe/src/command/readme_headers_renew.rs b/module/move/willbe/src/command/readme_headers_renew.rs index 9a79a2b144..3f7af310a7 100644 --- a/module/move/willbe/src/command/readme_headers_renew.rs +++ b/module/move/willbe/src/command/readme_headers_renew.rs @@ -1,8 +1,8 @@ mod private { use crate::*; - use action; - use error::{ err }; + // use action; + // use error::{ err }; use std::fmt::{ Display, Formatter }; #[ derive( Debug, Default ) ] @@ -64,7 +64,6 @@ mod private } } - /// Aggregates two commands: `generate_modules_headers` & `generate_main_header` pub fn readme_headers_renew() -> error::untyped::Result< () > // qqq : use typed error { @@ -73,7 +72,7 @@ mod private let crate_dir = CrateDir::transitive_try_from::< AbsolutePath >( CurrentPath )?; let mut fail = false; - match action::readme_header_renew( crate_dir.clone() ) + match crate::action::main_header::action( crate_dir.clone() ) { Ok( r ) => { @@ -103,7 +102,7 @@ mod private if fail { eprintln!( "{report}" ); - Err( err!( "Something went wrong" ) ) + Err( error::untyped::format_err!( "Something went wrong" ) ) } else { diff --git a/module/move/willbe/src/command/test.rs b/module/move/willbe/src/command/test.rs index 9a05c92c89..36fac78a27 100644 --- a/module/move/willbe/src/command/test.rs +++ b/module/move/willbe/src/command/test.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; @@ -147,10 +147,10 @@ Set at least one of them to true." ); } } - impl TryFrom< wca::Props > for TestsProperties + impl TryFrom< wca::executor::Props > for TestsProperties { type Error = error::untyped::Error; - fn try_from( value : wca::Props ) -> Result< Self, Self::Error > + fn try_from( value : wca::executor::Props ) -> Result< Self, Self::Error > { let mut this = Self::former(); @@ -192,4 +192,4 @@ crate::mod_interface! { /// run tests in specified crate exposed use test; -} \ No newline at end of file +} diff --git a/module/move/willbe/src/command/workspace_renew.rs b/module/move/willbe/src/command/workspace_renew.rs index 7baa1515f6..018046b146 100644 --- a/module/move/willbe/src/command/workspace_renew.rs +++ b/module/move/willbe/src/command/workspace_renew.rs @@ -23,7 +23,7 @@ mod private { let WorkspaceNewProperties { repository_url, branches } = o.props.try_into()?; let template = WorkspaceTemplate::default(); - action::workspace_renew + action::workspace_renew::action ( &std::env::current_dir()?, template, @@ -33,11 +33,11 @@ mod private .context( "Fail to create workspace" ) } - impl TryFrom< wca::Props > for WorkspaceNewProperties + impl TryFrom< wca::executor::Props > for WorkspaceNewProperties { type Error = error::untyped::Error; - fn try_from( value : wca::Props ) -> std::result::Result< Self, Self::Error > + fn try_from( value : wca::executor::Props ) -> std::result::Result< Self, Self::Error > { let mut this = Self::former(); diff --git a/module/move/willbe/src/entity/channel.rs b/module/move/willbe/src/entity/channel.rs index cb45418c06..65fe6b7716 100644 --- a/module/move/willbe/src/entity/channel.rs +++ b/module/move/willbe/src/entity/channel.rs @@ -61,7 +61,7 @@ mod private .bin_path( program ) .args( options.into_iter().map( OsString::from ).collect::< Vec< _ > >() ) .current_path( path.as_ref().to_path_buf() ) - .run().map_err::< Error, _ >( | report | err!( report.to_string() ) )?; + .run().map_err::< Error, _ >( | report | error::untyped::format_err!( report.to_string() ) )?; let list = report .out diff --git a/module/move/willbe/src/entity/dependency.rs b/module/move/willbe/src/entity/dependency.rs index 337ecb01a2..5d09c1cea0 100644 --- a/module/move/willbe/src/entity/dependency.rs +++ b/module/move/willbe/src/entity/dependency.rs @@ -260,8 +260,13 @@ mod private } DependenciesSort::Topological => { - // qqq : too long line - graph::toposort( graph::construct( &graph ) ).map_err( | err | format_err!( "{}", err ) )?.into_iter().filter( | x | x != &root ).collect() + // aaa : too long line + // aaa : splited + graph::toposort( graph::construct( &graph ) ) + .map_err( | err | format_err!( "{}", err ) )? + .into_iter() + .filter( | x | x != &root ) + .collect() }, }; diff --git a/module/move/willbe/src/entity/files.rs b/module/move/willbe/src/entity/files.rs index 8385e87167..d8941dfa27 100644 --- a/module/move/willbe/src/entity/files.rs +++ b/module/move/willbe/src/entity/files.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/move/willbe/src/entity/files/either.rs b/module/move/willbe/src/entity/files/either.rs index aa7fdb5863..ef151d616c 100644 --- a/module/move/willbe/src/entity/files/either.rs +++ b/module/move/willbe/src/entity/files/either.rs @@ -16,7 +16,7 @@ use std:: // Result, // }; -/// Wrapper over `data_type::Either< CrateDir, ManifestFile >` with utils methods. +/// Wrapper over `data_type::Either< CrateDir, ManifestFile >` with util methods. #[ derive( Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug ) ] pub struct EitherDirOrFile( data_type::Either< CrateDir, ManifestFile > ); diff --git a/module/move/willbe/src/entity/manifest.rs b/module/move/willbe/src/entity/manifest.rs index 4df6ead08d..5a0f7a58aa 100644 --- a/module/move/willbe/src/entity/manifest.rs +++ b/module/move/willbe/src/entity/manifest.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/move/willbe/src/entity/mod.rs b/module/move/willbe/src/entity/mod.rs index 6f26700128..100b331e89 100644 --- a/module/move/willbe/src/entity/mod.rs +++ b/module/move/willbe/src/entity/mod.rs @@ -1,3 +1,5 @@ +mod private {} + crate::mod_interface! { /// Rust toolchain channel: stable/nightly. diff --git a/module/move/willbe/src/entity/package_md_extension.rs b/module/move/willbe/src/entity/package_md_extension.rs index 76ffdbac88..29fe95b645 100644 --- a/module/move/willbe/src/entity/package_md_extension.rs +++ b/module/move/willbe/src/entity/package_md_extension.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/move/willbe/src/entity/publish.rs b/module/move/willbe/src/entity/publish.rs index ed1e336129..f7cc9965c8 100644 --- a/module/move/willbe/src/entity/publish.rs +++ b/module/move/willbe/src/entity/publish.rs @@ -26,7 +26,7 @@ mod private /// Options for bumping the package version. pub bump : version::BumpOptions, /// Git options related to the package. - pub git_options : entity::git::GitOptions, + pub git_options : Option< entity::git::GitOptions >, /// Options for publishing the package using Cargo. pub publish : cargo::PublishOptions, /// Indicates whether the process should be dry-run (no actual publishing). @@ -42,6 +42,9 @@ mod private package : package::Package< 'a >, channel : channel::Channel, base_temp_dir : Option< path::PathBuf >, + exclude_dev_dependencies : bool, + #[ former( default = true ) ] + commit_changes : bool, #[ former( default = true ) ] dry : bool, } @@ -58,6 +61,7 @@ mod private channel : self.channel, allow_dirty : self.dry, checking_consistency : !self.dry, + exclude_dev_dependencies : self.exclude_dev_dependencies, temp_path : self.base_temp_dir.clone(), dry : self.dry, }; @@ -73,17 +77,21 @@ mod private dependencies : dependencies.clone(), dry : self.dry, }; - let git_options = entity::git::GitOptions + let git_options = if self.commit_changes { - git_root : workspace_root, - items : dependencies.iter().chain([ &crate_dir ]).map( | d | d.clone().absolute_path().join( "Cargo.toml" ) ).collect(), - message : format!( "{}-v{}", self.package.name().unwrap(), new_version ), - dry : self.dry, - }; + Some( entity::git::GitOptions + { + git_root : workspace_root, + items : dependencies.iter().chain([ &crate_dir ]).map( | d | d.clone().absolute_path().join( "Cargo.toml" ) ).collect(), + message : format!( "{}-v{}", self.package.name().unwrap(), new_version ), + dry : self.dry, + }) + } else { None }; let publish = cargo::PublishOptions { path : crate_dir.clone().absolute_path().inner(), temp_path : self.base_temp_dir.clone(), + exclude_dev_dependencies : self.exclude_dev_dependencies, retry_count : 2, dry : self.dry, }; @@ -121,6 +129,14 @@ mod private /// Release channels for rust. pub channel : channel::Channel, + /// Setting this option to true will temporarily remove development dependencies before executing the command, then restore them afterward. + #[ allow( dead_code ) ] // former related + pub exclude_dev_dependencies : bool, + + /// Indicates whether changes should be committed. + #[ former( default = true ) ] + pub commit_changes : bool, + /// `dry` - A boolean value indicating whether to do a dry run. If set to `true`, the application performs /// a simulated run without making any actual changes. If set to `false`, the operations are actually executed. /// This property is optional and defaults to `true`. @@ -161,7 +177,7 @@ mod private .collect(); for wanted in &self.roots { - let list = action::list + let list = action::list_all ( action::list::ListOptions::former() .path_to_manifest( wanted.clone() ) @@ -246,6 +262,14 @@ mod private { plan = plan.dry( dry ); } + if let Some( exclude_dev_dependencies ) = &self.storage.exclude_dev_dependencies + { + plan = plan.exclude_dev_dependencies( *exclude_dev_dependencies ) + } + if let Some( commit_changes ) = &self.storage.commit_changes + { + plan = plan.commit_changes( *commit_changes ) + } let plan = plan .channel( channel ) .package( package ) @@ -362,45 +386,55 @@ mod private } = instruction; pack.dry = dry; bump.dry = dry; - git_options.dry = dry; + git_options.as_mut().map( | d | d.dry = dry ); publish.dry = dry; report.get_info = Some( cargo::pack( pack ).err_with_report( &report )? ); // aaa : redundant field? // aaa : removed let bump_report = version::bump( bump ).err_with_report( &report )?; report.bump = Some( bump_report.clone() ); - let git_root = git_options.git_root.clone(); - let git = match entity::git::perform_git_commit( git_options ) + + let git_root = git_options.as_ref().map( | g | g.git_root.clone() ); + if let Some( git_options ) = git_options { - Ok( git ) => git, - Err( e ) => + let git = match entity::git::perform_git_commit( git_options ) { - version::revert( &bump_report ) - .map_err( | le | format_err!( "Base error:\n{}\nRevert error:\n{}", e.to_string().replace( '\n', "\n\t" ), le.to_string().replace( '\n', "\n\t" ) ) ) - .err_with_report( &report )?; - return Err(( report, e )); - } - }; - report.add = git.add; - report.commit = git.commit; + Ok( git ) => git, + Err( e ) => + { + version::revert( &bump_report ) + .map_err( | le | format_err!( "Base error:\n{}\nRevert error:\n{}", e.to_string().replace( '\n', "\n\t" ), le.to_string().replace( '\n', "\n\t" ) ) ) + .err_with_report( &report )?; + return Err(( report, e )); + } + }; + report.add = git.add; + report.commit = git.commit; + } report.publish = match cargo::publish( publish ) { Ok( publish ) => Some( publish ), Err( e ) => { - tool::git::reset( git_root.as_ref(), true, 1, false ) - .map_err - ( - | le | - format_err!( "Base error:\n{}\nRevert error:\n{}", e.to_string().replace( '\n', "\n\t" ), le.to_string().replace( '\n', "\n\t" ) ) - ) - .err_with_report( &report )?; + if let Some( git_root ) = git_root.as_ref() + { + tool::git::reset( git_root.as_ref(), true, 1, false ) + .map_err + ( + | le | + format_err!( "Base error:\n{}\nRevert error:\n{}", e.to_string().replace( '\n', "\n\t" ), le.to_string().replace( '\n', "\n\t" ) ) + ) + .err_with_report( &report )?; + } return Err(( report, e )); } }; - let res = tool::git::push( &git_root, dry ).err_with_report( &report )?; - report.push = Some( res ); + if let Some( git_root ) = git_root.as_ref() + { + let res = tool::git::push( &git_root, dry ).err_with_report( &report )?; + report.push = Some( res ); + } Ok( report ) } diff --git a/module/move/willbe/src/entity/test.rs b/module/move/willbe/src/entity/test.rs index 938c5ca415..b8b7b67227 100644 --- a/module/move/willbe/src/entity/test.rs +++ b/module/move/willbe/src/entity/test.rs @@ -36,12 +36,12 @@ mod private /// Represents the optimization setting for the test variant. optimization : optimization::Optimization, /// Contains additional features or characteristics of the test variant. - features : collection::BTreeSet, + features : collection::BTreeSet< String >, } impl fmt::Display for TestVariant { - fn fmt( &self, f : &mut fmt::Formatter< '_ >) -> fmt::Result + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { let features = if self.features.is_empty() { " ".to_string() } else { self.features.iter().join( " " ) }; writeln!( f, "{} {} {}", self.optimization, self.channel, features )?; @@ -58,7 +58,7 @@ mod private impl fmt::Display for TestPlan { - fn fmt( &self, f : &mut fmt::Formatter< '_ >) -> std::fmt::Result + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> std::fmt::Result { writeln!( f, "Plan: " )?; for plan in &self.packages_plan diff --git a/module/move/willbe/src/entity/version.rs b/module/move/willbe/src/entity/version.rs index 0722b8a59c..7018f00481 100644 --- a/module/move/willbe/src/entity/version.rs +++ b/module/move/willbe/src/entity/version.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/move/willbe/src/entity/workspace_md_extension.rs b/module/move/willbe/src/entity/workspace_md_extension.rs index f463d4cf60..a6d10dd9cb 100644 --- a/module/move/willbe/src/entity/workspace_md_extension.rs +++ b/module/move/willbe/src/entity/workspace_md_extension.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/move/willbe/src/lib.rs b/module/move/willbe/src/lib.rs index 87149b74fa..27cf2d036a 100644 --- a/module/move/willbe/src/lib.rs +++ b/module/move/willbe/src/lib.rs @@ -5,7 +5,7 @@ pub use mod_interface::mod_interface; -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::*; diff --git a/module/move/willbe/src/tool/cargo.rs b/module/move/willbe/src/tool/cargo.rs index 71590ecd45..5a3974ddd9 100644 --- a/module/move/willbe/src/tool/cargo.rs +++ b/module/move/willbe/src/tool/cargo.rs @@ -1,13 +1,15 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { + use crate::*; + #[ allow( unused_imports ) ] use crate::tool::*; use std::ffi::OsString; use std::path::PathBuf; - use error::err; - use error::untyped::format_err; + // use error::err; + // use error::untyped::format_err; use former::Former; use process_tools::process; // use process_tools::process::*; @@ -47,6 +49,9 @@ mod private // aaa : don't abuse negative form, rename to checking_consistency // renamed and changed logic pub( crate ) checking_consistency : bool, + /// Setting this option to true will temporarily remove development dependencies before executing the command, then restore them afterward. + #[ former( default = true ) ] + pub( crate ) exclude_dev_dependencies : bool, /// An optional temporary path to be used during packaging. /// /// This field may contain a path to a temporary directory that will be used during the packaging process. @@ -79,6 +84,53 @@ mod private } } + #[ derive( Debug ) ] + struct TemporaryManifestFile + { + original : PathBuf, + temporary : PathBuf, + } + + impl TemporaryManifestFile + { + /// Creates a backup copy of the original file, allowing the original file location to serve as a temporary workspace. + /// When the object is dropped, the temporary file at the original location is replaced by the backup, restoring the original file. + fn new( path : impl Into< PathBuf > ) -> error::untyped::Result< Self > + { + let path = path.into(); + if !path.ends_with( "Cargo.toml" ) + { + error::untyped::bail!( "Wrong path to temporary manifest" ); + } + + let mut index = 0; + let original = loop + { + let temp_path = PathBuf::from( format!( "{}.temp_{index}", path.display() ) ); + if !temp_path.exists() + { + _ = std::fs::copy( &path, &temp_path )?; + break temp_path; + } + index += 1; + }; + + Ok( Self + { + original, + temporary : path, + }) + } + } + + impl Drop for TemporaryManifestFile + { + fn drop( &mut self ) + { + _ = std::fs::rename( &self.original, &self.temporary ).ok(); + } + } + /// /// Assemble the local package into a distributable tarball. /// @@ -96,6 +148,17 @@ mod private // qqq : use typed error pub fn pack( args : PackOptions ) -> error::untyped::Result< process::Report > { + let _temp = if args.exclude_dev_dependencies + { + let manifest = TemporaryManifestFile::new( args.path.join( "Cargo.toml" ) )?; + let mut file = Manifest::try_from( ManifestFile::try_from( &manifest.temporary )? )?; + let data = file.data(); + + _ = data.remove( "dev-dependencies" ); + file.store()?; + + Some( manifest ) + } else { None }; let ( program, options ) = ( "rustup", args.to_pack_args() ); if args.dry @@ -118,7 +181,7 @@ mod private .bin_path( program ) .args( options.into_iter().map( OsString::from ).collect::< Vec< _ > >() ) .current_path( args.path ) - .run().map_err( | report | err!( report.to_string() ) ) + .run().map_err( | report | error::untyped::format_err!( report.to_string() ) ) } } @@ -129,6 +192,7 @@ mod private { pub( crate ) path : PathBuf, pub( crate ) temp_path : Option< PathBuf >, + pub( crate ) exclude_dev_dependencies : bool, #[ former( default = 0usize ) ] pub( crate ) retry_count : usize, pub( crate ) dry : bool, @@ -162,6 +226,17 @@ mod private pub fn publish( args : PublishOptions ) -> error::untyped::Result< process::Report > // qqq : use typed error { + let _temp = if args.exclude_dev_dependencies + { + let manifest = TemporaryManifestFile::new( args.path.join( "Cargo.toml" ) )?; + let mut file = Manifest::try_from( ManifestFile::try_from( &manifest.temporary )? )?; + let data = file.data(); + + _ = data.remove( "dev-dependencies" ); + file.store()?; + + Some( manifest ) + } else { None }; let ( program, arguments) = ( "cargo", args.as_publish_args() ); if args.dry @@ -197,11 +272,11 @@ mod private } if args.retry_count > 0 { - Err( format_err!( "It took {} attempts, but still failed. Here are the errors:\n{}", args.retry_count + 1, results.into_iter().map( | r | format!( "- {r}" ) ).collect::< Vec< _ > >().join( "\n" ) ) ) + Err( error::untyped::format_err!( "It took {} attempts, but still failed. Here are the errors:\n{}", args.retry_count + 1, results.into_iter().map( | r | format!( "- {r}" ) ).collect::< Vec< _ > >().join( "\n" ) ) ) } else { - Err( results.remove( 0 ) ).map_err( | report | err!( report.to_string() ) ) + Err( results.remove( 0 ) ).map_err( | report | error::untyped::format_err!( report.to_string() ) ) } } } diff --git a/module/move/willbe/src/tool/collection.rs b/module/move/willbe/src/tool/collection.rs deleted file mode 100644 index edd7bec8c8..0000000000 --- a/module/move/willbe/src/tool/collection.rs +++ /dev/null @@ -1,12 +0,0 @@ -/// Internal namespace. -mod private -{ -} - -crate::mod_interface! -{ - - use ::collection_tools; - own use ::collection_tools::own::*; - -} diff --git a/module/move/willbe/src/tool/error.rs b/module/move/willbe/src/tool/error.rs deleted file mode 100644 index bc00b92ba9..0000000000 --- a/module/move/willbe/src/tool/error.rs +++ /dev/null @@ -1,21 +0,0 @@ -/// Internal namespace. -#[ allow( unused_imports ) ] -mod private -{ - use crate::tool::*; - use ::error_tools::own::*; - -} - -crate::mod_interface! -{ - // #![ debug ] - - use ::error_tools; - own use ::error_tools::own::*; - - // exposed use ErrWith; - // exposed use ResultWithReport; - // exposed use ::error_tools::Result; - -} diff --git a/module/move/willbe/src/tool/files.rs b/module/move/willbe/src/tool/files.rs index 38878c477d..95f19de887 100644 --- a/module/move/willbe/src/tool/files.rs +++ b/module/move/willbe/src/tool/files.rs @@ -1,5 +1,5 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { #[ allow( unused_imports ) ] diff --git a/module/move/willbe/src/tool/git.rs b/module/move/willbe/src/tool/git.rs index 828e4d3c64..9e240c804b 100644 --- a/module/move/willbe/src/tool/git.rs +++ b/module/move/willbe/src/tool/git.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { #[ allow( unused_imports ) ] @@ -7,7 +7,7 @@ mod private use std::ffi::OsString; use std::path::Path; use process_tools::process::*; - use error::err; + // use error::err; // qqq : group dependencies /// Adds changes to the Git staging area. @@ -56,7 +56,7 @@ mod private .bin_path( program ) .args( args.into_iter().map( OsString::from ).collect::< Vec< _ > >() ) .current_path( path.as_ref().to_path_buf() ) - .run().map_err( | report | err!( report.to_string() ) ) + .run().map_err( | report | error::untyped::format_err!( report.to_string() ) ) } } @@ -102,7 +102,7 @@ mod private .bin_path( program ) .args( args.into_iter().map( OsString::from ).collect::< Vec< _ > >() ) .current_path( path.as_ref().to_path_buf() ) - .run().map_err( | report | err!( report.to_string() ) ) + .run().map_err( | report | error::untyped::format_err!( report.to_string() ) ) } } @@ -148,7 +148,7 @@ mod private .bin_path( program ) .args( args.into_iter().map( OsString::from ).collect::< Vec< _ > >() ) .current_path( path.as_ref().to_path_buf() ) - .run().map_err( | report | err!( report.to_string() ) ) + .run().map_err( | report | error::untyped::format_err!( report.to_string() ) ) } } @@ -173,7 +173,7 @@ mod private where P : AsRef< Path >, { - if commits_count < 1 { return Err( err!( "Cannot reset, the count of commits must be greater than 0" ) ) } + if commits_count < 1 { return Err( error::untyped::format_err!( "Cannot reset, the count of commits must be greater than 0" ) ) } let ( program, args ) : ( _, Vec< _ > ) = ( "git", @@ -205,7 +205,7 @@ mod private .bin_path( program ) .args( args.into_iter().map( OsString::from ).collect::< Vec< _ > >() ) .current_path( path.as_ref().to_path_buf() ) - .run().map_err( | report | err!( report.to_string() ) ) + .run().map_err( | report | error::untyped::format_err!( report.to_string() ) ) } } @@ -232,7 +232,7 @@ mod private .bin_path( program ) .args( args.into_iter().map( OsString::from ).collect::< Vec< _ > >() ) .current_path( path.as_ref().to_path_buf() ) - .run().map_err( | report | err!( report.to_string() ) ) + .run().map_err( | report | error::untyped::format_err!( report.to_string() ) ) } } diff --git a/module/move/willbe/src/tool/graph.rs b/module/move/willbe/src/tool/graph.rs index 296547ac82..dec62fdc9e 100644 --- a/module/move/willbe/src/tool/graph.rs +++ b/module/move/willbe/src/tool/graph.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { #[ allow( unused_imports ) ] diff --git a/module/move/willbe/src/tool/http.rs b/module/move/willbe/src/tool/http.rs index d682a79d69..81e13a2d74 100644 --- a/module/move/willbe/src/tool/http.rs +++ b/module/move/willbe/src/tool/http.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { #[ allow( unused_imports ) ] diff --git a/module/move/willbe/src/tool/iter.rs b/module/move/willbe/src/tool/iter.rs index a7b82abd7a..855c492006 100644 --- a/module/move/willbe/src/tool/iter.rs +++ b/module/move/willbe/src/tool/iter.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { } diff --git a/module/move/willbe/src/tool/macros.rs b/module/move/willbe/src/tool/macros.rs index 81861cb3de..96f7a3b06d 100644 --- a/module/move/willbe/src/tool/macros.rs +++ b/module/move/willbe/src/tool/macros.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { } diff --git a/module/move/willbe/src/tool/mod.rs b/module/move/willbe/src/tool/mod.rs index 060a323c2f..7864cdc660 100644 --- a/module/move/willbe/src/tool/mod.rs +++ b/module/move/willbe/src/tool/mod.rs @@ -1,3 +1,5 @@ +mod private {} + crate::mod_interface! { @@ -6,12 +8,15 @@ crate::mod_interface! orphan use super::cargo; /// Function and structures to work with collections. - layer collection; - orphan use super::collection; + // layer collection; + // orphan use super::collection; + use ::collection_tools; + // own use ::collection_tools::own::*; /// Errors handling. - layer error; - orphan use super::error; + // layer error; + // orphan use super::error; + use ::error_tools; /// Operate over files. layer files; diff --git a/module/move/willbe/src/tool/path.rs b/module/move/willbe/src/tool/path.rs index c07f0b3d6e..611a9c21ed 100644 --- a/module/move/willbe/src/tool/path.rs +++ b/module/move/willbe/src/tool/path.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { } @@ -6,7 +6,7 @@ mod private crate::mod_interface! { - use ::proper_path_tools; - own use ::proper_path_tools::own::*; + use ::pth; + own use ::pth::own::*; } diff --git a/module/move/willbe/src/tool/query.rs b/module/move/willbe/src/tool/query.rs index 3528d887ae..4b8a14d10e 100644 --- a/module/move/willbe/src/tool/query.rs +++ b/module/move/willbe/src/tool/query.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { #[ allow( unused_imports ) ] diff --git a/module/move/willbe/src/tool/repository.rs b/module/move/willbe/src/tool/repository.rs index 66474d906d..c78d304661 100644 --- a/module/move/willbe/src/tool/repository.rs +++ b/module/move/willbe/src/tool/repository.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { #[ allow( unused_imports ) ] diff --git a/module/move/willbe/src/tool/template.rs b/module/move/willbe/src/tool/template.rs index affe4072be..91c804c8ce 100644 --- a/module/move/willbe/src/tool/template.rs +++ b/module/move/willbe/src/tool/template.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { #[ allow( unused_imports ) ] @@ -15,15 +15,10 @@ mod private }; use error::untyped::Context; - // qqq : for Nikita : is that trait really necessary? - // Template - remove - // DeployTemplate - move here - // DeployTemplateFiles - remove - - /// Template for creating deploy files. + /// Container for templates. /// - /// Includes terraform deploy options to GCP, and Hetzner, - /// a Makefile for useful commands, and a key directory. + /// Includes files to create, parameters that those templates accept, + /// and values for those parameters. #[ derive( Debug ) ] pub struct TemplateHolder { @@ -33,11 +28,15 @@ mod private pub parameters : TemplateParameters, /// The values associated with the template. pub values : TemplateValues, + /// Path to the parameter storage for recovering values + /// for already generated templated files. + pub parameter_storage : &'static Path, + /// Name of the template to generate + pub template_name : &'static str, } impl TemplateFiles for Vec< TemplateFileDescriptor > {} - // qqq : for Viktor : why DeployTemplate can't be part of template.rs? impl TemplateHolder { @@ -95,27 +94,6 @@ mod private &mut self.values } - /// Returns the path to the parameter storage file. - /// - /// # Returns - /// - /// A reference to a `Path` representing the parameter storage file. - pub fn parameter_storage( &self ) -> &Path - { - "./.deploy_template.toml".as_ref() - // qqq : for Mykyta : hardcode? - } - - /// Returns the name of the template. - /// - /// # Returns - /// - /// A static string slice representing the template name. - pub fn template_name( &self ) -> &'static str - { - "deploy" - } - /// Loads existing parameters from the specified path and updates the template values. /// /// # Parameters @@ -127,10 +105,10 @@ mod private /// An `Option` which is `Some(())` if the parameters are loaded successfully, or `None` otherwise. pub fn load_existing_params( &mut self, path : &Path ) -> Option< () > { - let data = fs::read_to_string( path.join( self.parameter_storage() ) ).ok()?; + let data = fs::read_to_string( path.join( self.parameter_storage ) ).ok()?; let document = data.parse::< toml_edit::Document >().ok()?; let parameters : Vec< _ > = self.parameters().descriptors.iter().map( | d | &d.parameter ).cloned().collect(); - let template_table = document.get( self.template_name() )?; + let template_table = document.get( self.template_name )?; for parameter in parameters { let value = template_table.get( ¶meter ) @@ -164,26 +142,6 @@ mod private } } - impl Default for TemplateHolder - { - fn default() -> Self - { - let parameters = TemplateParameters::former() - .parameter( "gcp_project_id" ).is_mandatory( true ).end() - .parameter( "gcp_region" ).end() - .parameter( "gcp_artifact_repo_name" ).end() - .parameter( "docker_image_name" ).end() - .form(); - - Self - { - files : Default::default(), - parameters, - values : Default::default(), - } - } - } - /// Files stored in a template. /// /// Can be iterated over, consuming the owner of the files. @@ -214,7 +172,7 @@ mod private impl TemplateParameters { /// Extracts template values from props for parameters required for this template. - pub fn values_from_props( &self, props : &wca::Props ) -> TemplateValues + pub fn values_from_props( &self, props : &wca::executor::Props ) -> TemplateValues { let values = self.descriptors .iter() diff --git a/module/move/willbe/src/tool/url.rs b/module/move/willbe/src/tool/url.rs index f1ab5b8f9c..58c2792e4c 100644 --- a/module/move/willbe/src/tool/url.rs +++ b/module/move/willbe/src/tool/url.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { #[ allow( unused_imports ) ] diff --git a/module/move/willbe/src/wtools.rs b/module/move/willbe/src/wtools.rs index 1735805c0b..4fe43d10e9 100644 --- a/module/move/willbe/src/wtools.rs +++ b/module/move/willbe/src/wtools.rs @@ -21,8 +21,8 @@ // /// Collection of function and structures to manipulate paths. // pub mod path_tools // { -// // pub use proper_path_tools::own::*; -// // pub use proper_path_tools::own::path; -// // zzz : make use proper_path_tools::own::path working +// // pub use pth::own::*; +// // pub use pth::own::path; +// // zzz : make use pth::own::path working // pub use proper_path::own as path; // } diff --git a/module/move/willbe/template/deploy/Makefile.hbs b/module/move/willbe/template/deploy/Makefile.hbs index 2f3461aea8..f978b887eb 100644 --- a/module/move/willbe/template/deploy/Makefile.hbs +++ b/module/move/willbe/template/deploy/Makefile.hbs @@ -1,16 +1,5 @@ .PHONY: deploy -# Secrets that can be provided via ENV vars or files in ./key/ directory. - -# Hetzner API token -export SECRET_CSP_HETZNER ?= $(shell cat key/SECRET_CSP_HETZNER 2> /dev/null) -# Cloud Storage file encryption key -export SECRET_STATE_ARCHIVE_KEY ?= $(shell cat key/SECRET_STATE_ARCHIVE_KEY 2> /dev/null) -# AWS Access Key id -export SECRET_AWS_ACCESS_KEY_ID ?= $(shell cat key/SECRET_AWS_ACCESS_KEY_ID 2> /dev/null) -# AWS Access Key -export SECRET_AWS_ACCESS_KEY ?= $(shell cat key/SECRET_AWS_ACCESS_KEY 2> /dev/null) - # Configuration variables for deployment. Can be edited for desired behavior. # Base terraform directory @@ -24,9 +13,9 @@ export TF_VAR_REPO_NAME ?= {{gcp_artifact_repo_name}} # Pushed image name export TF_VAR_IMAGE_NAME ?= {{docker_image_name}} # Path to the service account credentials -export google_sa_creds ?= key/service_account.json +export google_sa_creds ?= key/-service_account.json # Cloud Storage bucket name -export TF_VAR_BUCKET_NAME ?= uaconf_tfstate +export TF_VAR_BUCKET_NAME ?= {{docker_image_name}}_tfstate # Specifies where to deploy the project. Possible values: `hetzner`, `gce`, `aws` export CSP ?= hetzner @@ -43,129 +32,118 @@ export AWS_ACCESS_KEY_ID ?= $(SECRET_AWS_ACCESS_KEY_ID) # AWS Secret Access key for deploying to an EC2 instance export AWS_SECRET_ACCESS_KEY ?= $(SECRET_AWS_ACCESS_KEY) -# Check Hetzner and deployment related keys +# Check Hetzner and deployment related keys check-hetzner-keys: - @[ -f key/SECRET_CSP_HETZNER ] \ - || [ ! -z "${SECRET_CSP_HETZNER}" ] \ - || { echo "ERROR: File key/SECRET_CSP_HETZNER does not exist"; exit 1; } + @[ ! -z "${SECRET_CSP_HETZNER}" ] \ + || { echo "ERROR: Key SECRET_CSP_HETZNER does not exist"; exit 1; } -# Check AWS and deployment related keys +# Check AWS and deployment related keys check-aws-keys: - @[ -f key/SECRET_AWS_ACCESS_KEY_ID ] \ - || [ ! -z "${SECRET_AWS_ACCESS_KEY_ID}" ] \ - || echo "ERROR: File key/SECRET_AWS_ACCESS_KEY_ID does not exist" - @[ -f key/SECRET_AWS_ACCESS_KEY ] \ - || [ ! -z "${SECRET_AWS_ACCESS_KEY}" ] \ - || echo "ERROR: File key/SECRET_AWS_ACCESS_KEY does not exist" - @[ -f key/SECRET_AWS_ACCESS_KEY_ID ] \ - || [ ! -z "${SECRET_AWS_ACCESS_KEY_ID}" ] \ - || exit 1 - @[ -f key/SECRET_AWS_ACCESS_KEY ] \ - || [ ! -z "${SECRET_AWS_ACCESS_KEY}" ] \ - || exit 1 + @[ ! -z "${SECRET_AWS_ACCESS_KEY_ID}" ] \ + || echo "ERROR: Key SECRET_AWS_ACCESS_KEY_ID does not exist" + @[ ! -z "${SECRET_AWS_ACCESS_KEY}" ] \ + || echo "ERROR: Key SECRET_AWS_ACCESS_KEY does not exist" + @[ ! -z "${SECRET_AWS_ACCESS_KEY_ID}" ] || exit 1 + @[ ! -z "${SECRET_AWS_ACCESS_KEY}" ] || exit 1 check-gce-keys: - @echo "All required GCE keys are the same as GCP keys" + @echo "All required GCE keys are the same as GCP keys" # Check if required GCP keys are present check-gcp-keys: - @[ -f key/service_account.json ] \ - || echo "ERROR: File key/service_account.json does not exist" - @[ -f key/SECRET_STATE_ARCHIVE_KEY ] \ - || [ ! -z "${SECRET_STATE_ARCHIVE_KEY}" ] \ - || echo "ERROR: File key/SECRET_STATE_ARCHIVE_KEY does not exist" - @[ -f key/service_account.json ] \ - || exit 1 - @[ -f key/SECRET_STATE_ARCHIVE_KEY ] \ - || [ ! -z "${SECRET_STATE_ARCHIVE_KEY}" ] \ - || exit 1 + @[ -f key/-service_account.json ] \ + || echo "ERROR: Key file key/-service_account.json does not exist" + @[ ! -z "${SECRET_STATE_ARCHIVE_KEY}" ] \ + || echo "ERROR: Key SECRET_STATE_ARCHIVE_KEY does not exist" + @[ -f key/-service_account.json ] || exit 1 + @[ ! -z "${SECRET_STATE_ARCHIVE_KEY}" ] || exit 1 # Start local docker container start: - docker compose up -d + docker compose up -d # Stop local docker container stop: - docker compose down + docker compose down # Remove created docker image clean: stop - docker rmi $(TF_VAR_IMAGE_NAME) - docker buildx prune -af + docker rmi $(TF_VAR_IMAGE_NAME) + docker buildx prune -af # Install gcloud for Debian/Ubuntu install-gcloud: - # GCloud - sudo apt-get update - sudo apt-get install -y apt-transport-https ca-certificates gnupg curl sudo - curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg - echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list - sudo apt-get update && sudo apt-get install -y google-cloud-cli + # GCloud + sudo apt-get update + sudo apt-get install -y apt-transport-https ca-certificates gnupg curl sudo + curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg + echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list + sudo apt-get update && sudo apt-get install -y google-cloud-cli # Install terraform for Debian/Ubuntu install-terraform: - sudo apt-get update && sudo apt-get install -y gnupg software-properties-common - wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg - gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint - echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list - sudo apt update && sudo apt-get install terraform + sudo apt-get update && sudo apt-get install -y gnupg software-properties-common + wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg + gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint + echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list + sudo apt update && sudo apt-get install terraform # Install gcloud and terraform install: install-gcloud install-terraform - gcloud --version - terraform -version + gcloud --version + terraform -version # Login to GCP with user account gcp-auth: - gcloud auth application-default login + gcloud auth application-default login # Authorize to GCP with service account gcp-service: - gcloud auth activate-service-account --key-file=$(google_sa_creds) + gcloud auth activate-service-account --key-file=$(google_sa_creds) # Add docker repo auth helper gcp-docker: - gcloud auth configure-docker $(TF_VAR_REGION)-docker.pkg.dev --quiet + gcloud auth configure-docker $(TF_VAR_REGION)-docker.pkg.dev --quiet # Initializes all terraform projects # Downloads required modules and validates .tf files tf-init: - terraform -chdir=$(tf_dir)/gar init - terraform -chdir=$(tf_dir)/gce init - terraform -chdir=$(tf_dir)/hetzner init - terraform -chdir=$(tf_dir)/aws init + terraform -chdir=$(tf_dir)/gar init + terraform -chdir=$(tf_dir)/gce init + terraform -chdir=$(tf_dir)/hetzner init + terraform -chdir=$(tf_dir)/aws init # Creates Artifact Registry repository on GCP in specified location create-artifact-repo: tf-init - terraform -chdir=$(tf_dir)/gar apply -auto-approve + terraform -chdir=$(tf_dir)/gar apply -auto-approve # Builds uarust_conf_site image build-image: - docker build . -t name:$(TF_VAR_IMAGE_NAME) -t $(tag) + docker build . -t name:$(TF_VAR_IMAGE_NAME) -t $(tag) # Builds and pushes local docker image to the private repository push-image: gcp-docker create-artifact-repo - docker push $(tag) + docker push $(tag) # Creates GCE instance with the website configured on boot create-gce: check-gce-keys gcp-service state_storage_pull push-image - terraform -chdir=$(tf_dir)/gce apply -auto-approve + terraform -chdir=$(tf_dir)/gce apply -auto-approve # Creates AWS EC2 instance with the website configured on boot create-aws: check-aws-keys gcp-service state_storage_pull push-image - terraform -chdir=$(tf_dir)/aws apply -auto-approve + terraform -chdir=$(tf_dir)/aws apply -auto-approve # Creates Hetzner instance with the website configured on boot create-hetzner: check-hetzner-keys gcp-service state_storage_pull push-image - terraform -chdir=$(tf_dir)/hetzner apply -auto-approve + terraform -chdir=$(tf_dir)/hetzner apply -auto-approve # Deploys everything and updates terraform states deploy-in-container: create-$(CSP) state_storage_push # Deploys using tools from the container deploy: check-gcp-keys build-image - docker build . -t deploy-$(TF_VAR_IMAGE_NAME) -f ./$(tf_dir)/Dockerfile --build-arg google_sa_creds="$(google_sa_creds)" - @docker run -v //var/run/docker.sock:/var/run/docker.sock -v .:/app \ + docker build . -t deploy-$(TF_VAR_IMAGE_NAME) -f ./$(tf_dir)/Dockerfile --build-arg google_sa_creds="$(google_sa_creds)" + @docker run -v //var/run/docker.sock:/var/run/docker.sock -v .:/app \ -e SECRET_STATE_ARCHIVE_KEY=$(SECRET_STATE_ARCHIVE_KEY) \ -e SECRET_CSP_HETZNER=$(SECRET_CSP_HETZNER) \ -e SECRET_AWS_ACCESS_KEY_ID=$(SECRET_AWS_ACCESS_KEY_ID) \ @@ -175,35 +153,39 @@ deploy: check-gcp-keys build-image # Review changes that terraform will do on apply tf-plan: tf-init - terraform -chdir=$(tf_dir)/gar plan - terraform -chdir=$(tf_dir)/gce plan - terraform -chdir=$(tf_dir)/hetzner plan - terraform -chdir=$(tf_dir)/aws plan + terraform -chdir=$(tf_dir)/gar plan + terraform -chdir=$(tf_dir)/gce plan + terraform -chdir=$(tf_dir)/hetzner plan + terraform -chdir=$(tf_dir)/aws plan # Destroy created infrastracture on GCP tf-destroy: tf-init - terraform -chdir=$(tf_dir)/gar destroy - terraform -chdir=$(tf_dir)/gce destroy - terraform -chdir=$(tf_dir)/hetzner destroy - terraform -chdir=$(tf_dir)/aws destroy + terraform -chdir=$(tf_dir)/gar destroy + terraform -chdir=$(tf_dir)/gce destroy + terraform -chdir=$(tf_dir)/hetzner destroy + terraform -chdir=$(tf_dir)/aws destroy # Pushes encrypted terraform state files to the GCS Bucket state_storage_push: - @echo Pushing encrypted terraform state files to the GCS Bucket - @gcloud storage cp $(tf_dir)/gce/terraform.tfstate gs://$(TF_VAR_BUCKET_NAME)/gce.tfstate --encryption-key="$(SECRET_STATE_ARCHIVE_KEY)" - @gcloud storage cp $(tf_dir)/gar/terraform.tfstate gs://$(TF_VAR_BUCKET_NAME)/gar.tfstate --encryption-key="$(SECRET_STATE_ARCHIVE_KEY)" - @gcloud storage cp $(tf_dir)/hetzner/terraform.tfstate gs://$(TF_VAR_BUCKET_NAME)/hetzner.tfstate --encryption-key="$(SECRET_STATE_ARCHIVE_KEY)" - @gcloud storage cp $(tf_dir)/aws/terraform.tfstate gs://$(TF_VAR_BUCKET_NAME)/aws.tfstate --encryption-key="$(SECRET_STATE_ARCHIVE_KEY)" + @echo Pushing encrypted terraform state files to the GCS Bucket + -@gcloud storage cp $(tf_dir)/gce/terraform.tfstate gs://$(TF_VAR_BUCKET_NAME)/gce.tfstate --encryption-key="$(SECRET_STATE_ARCHIVE_KEY)" + -@gcloud storage cp $(tf_dir)/gar/terraform.tfstate gs://$(TF_VAR_BUCKET_NAME)/gar.tfstate --encryption-key="$(SECRET_STATE_ARCHIVE_KEY)" + -@gcloud storage cp $(tf_dir)/hetzner/terraform.tfstate gs://$(TF_VAR_BUCKET_NAME)/hetzner.tfstate --encryption-key="$(SECRET_STATE_ARCHIVE_KEY)" + -@gcloud storage cp $(tf_dir)/aws/terraform.tfstate gs://$(TF_VAR_BUCKET_NAME)/aws.tfstate --encryption-key="$(SECRET_STATE_ARCHIVE_KEY)" # Pulls and decrypts terraform state files to the GCS Bucket state_storage_pull: - @echo Pulling terraform state files to the GCS Bucket - -@gcloud storage cp gs://$(TF_VAR_BUCKET_NAME)/gce.tfstate $(tf_dir)/gce/terraform.tfstate --decryption-keys="$(SECRET_STATE_ARCHIVE_KEY)" - -@gcloud storage cp gs://$(TF_VAR_BUCKET_NAME)/gar.tfstate $(tf_dir)/gar/terraform.tfstate --decryption-keys="$(SECRET_STATE_ARCHIVE_KEY)" - -@gcloud storage cp gs://$(TF_VAR_BUCKET_NAME)/hetzner.tfstate $(tf_dir)/hetzner/terraform.tfstate --decryption-keys="$(SECRET_STATE_ARCHIVE_KEY)" - -@gcloud storage cp gs://$(TF_VAR_BUCKET_NAME)/aws.tfstate $(tf_dir)/aws/terraform.tfstate --decryption-keys="$(SECRET_STATE_ARCHIVE_KEY)" + @echo Pulling terraform state files to the GCS Bucket + -@gcloud storage cp gs://$(TF_VAR_BUCKET_NAME)/gce.tfstate $(tf_dir)/gce/terraform.tfstate --decryption-keys="$(SECRET_STATE_ARCHIVE_KEY)" + -@gcloud storage cp gs://$(TF_VAR_BUCKET_NAME)/gar.tfstate $(tf_dir)/gar/terraform.tfstate --decryption-keys="$(SECRET_STATE_ARCHIVE_KEY)" + -@gcloud storage cp gs://$(TF_VAR_BUCKET_NAME)/hetzner.tfstate $(tf_dir)/hetzner/terraform.tfstate --decryption-keys="$(SECRET_STATE_ARCHIVE_KEY)" + -@gcloud storage cp gs://$(TF_VAR_BUCKET_NAME)/aws.tfstate $(tf_dir)/aws/terraform.tfstate --decryption-keys="$(SECRET_STATE_ARCHIVE_KEY)" # Creates GCS Bucket for terraform states state_storage_init: - terraform -chdir=$(tf_dir)/gcs init - terraform -chdir=$(tf_dir)/gcs apply + terraform -chdir=$(tf_dir)/gcs init + terraform -chdir=$(tf_dir)/gcs apply + +# Destroys GCS Bucket for terraform states +state_storage_destroy: + terraform -chdir=$(tf_dir)/gcs destroy diff --git a/module/move/willbe/template/deploy/deploy/Dockerfile b/module/move/willbe/template/deploy/deploy/Dockerfile index c196de7aff..1fa8f2bf8b 100644 --- a/module/move/willbe/template/deploy/deploy/Dockerfile +++ b/module/move/willbe/template/deploy/deploy/Dockerfile @@ -3,7 +3,7 @@ ENV TF_VERSION=1.7.4 WORKDIR / -# Installation terraform +# Install terraform RUN apt update --allow-releaseinfo-change \ && apt install wget unzip \ && mkdir -p /usr/lib/terraform/${TF_VERSION} \ diff --git a/module/move/willbe/template/deploy/deploy/aws/main.tf b/module/move/willbe/template/deploy/deploy/aws/main.tf index 4e83260aaf..9572193a66 100644 --- a/module/move/willbe/template/deploy/deploy/aws/main.tf +++ b/module/move/willbe/template/deploy/deploy/aws/main.tf @@ -60,17 +60,16 @@ resource "aws_instance" "web" { associate_public_ip_address = true # Startup script for the instance - # Installs docker, gcloud CLI, downloads docker images and starts the container - user_data = templatefile("${path.module}/templates/cloud-init.tpl", { + # Installs docker and gcloud CLI + user_data = templatefile("${path.module}/../cloud-init.tpl", { location = "${var.REGION}" project_id = "${var.PROJECT_ID}" repo_name = "${var.REPO_NAME}" image_name = "${var.IMAGE_NAME}" service_account_creds = "${replace(data.local_sensitive_file.service_account_creds.content, "\n", "")}" - timestamp = "${timestamp()}" }) - user_data_replace_on_change = true + key_name = aws_key_pair.redeploy.key_name } # Static IP address for the instace that will persist on restarts and redeploys @@ -78,3 +77,33 @@ resource "aws_eip" "static" { instance = aws_instance.web.id domain = "vpc" } + +resource "aws_key_pair" "redeploy" { + public_key = data.local_sensitive_file.ssh_public_key.content +} + +resource "terraform_data" "redeploy" { + triggers_replace = timestamp() + + connection { + type = "ssh" + user = "ubuntu" + private_key = data.local_sensitive_file.ssh_private_key.content + host = aws_eip.static.public_ip + } + + provisioner "file" { + source = "${path.module}/../redeploy.sh" + destination = "/tmp/redeploy.sh" + } + + provisioner "remote-exec" { + inline = [ + "#!/bin/bash", + "( tail -f -n1 /var/log/deploy-init.log & ) | grep -q 'Docker configuration file updated.'", + "source /etc/environment", + "chmod +x /tmp/redeploy.sh", + "sudo /tmp/redeploy.sh" + ] + } +} diff --git a/module/move/willbe/template/deploy/deploy/aws/templates/cloud-init.tpl b/module/move/willbe/template/deploy/deploy/aws/templates/cloud-init.tpl deleted file mode 100644 index 7a19732c3a..0000000000 --- a/module/move/willbe/template/deploy/deploy/aws/templates/cloud-init.tpl +++ /dev/null @@ -1,46 +0,0 @@ -#cloud-config - -write_files: -- path: /etc/systemd/system/${image_name}.service - permissions: 0644 - owner: root - content: | - [Unit] - Description=Start ${image_name} docker container. Build: ${timestamp} - Wants=network-online.target - After=network-online.target - - [Service] - Environment="HOME=/root" - ExecStart=/usr/bin/docker run --restart unless-stopped -d -p 80:80 --name=${image_name} ${location}-docker.pkg.dev/${project_id}/${repo_name}/${image_name} -- path: /root/service_account.json - permissions: 0600 - owner: root - content: | - ${service_account_creds} -- path: /root/init.sh - permissions: 0700 - owner: root - content: | - # Install docker - apt update - apt install apt-transport-https ca-certificates curl software-properties-common -y - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" - apt update - apt install docker-ce -y - # Install gcloud CLI - curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg - echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list - apt-get update - apt-get install -y google-cloud-cli - # Configure docker with gcloud - gcloud auth activate-service-account --key-file=/root/service_account.json - gcloud auth configure-docker ${location}-docker.pkg.dev --quiet - # Start docker container - systemctl daemon-reload - systemctl start ${image_name}.service - - -runcmd: -- nohup /root/init.sh > /var/log/uaconf-instance-init.log 2>&1 & diff --git a/module/move/willbe/template/deploy/deploy/aws/variables.tf b/module/move/willbe/template/deploy/deploy/aws/variables.tf index ede2b296f3..c536019a13 100644 --- a/module/move/willbe/template/deploy/deploy/aws/variables.tf +++ b/module/move/willbe/template/deploy/deploy/aws/variables.tf @@ -20,5 +20,15 @@ variable "IMAGE_NAME" { # Google Cloud Platform credentials data "local_sensitive_file" "service_account_creds" { - filename = "${path.module}/../../key/service_account.json" + filename = "${path.module}/../../key/-service_account.json" +} + +# Private key for SSH connection +data "local_sensitive_file" "ssh_private_key" { + filename = "${path.module}/../../key/-rsa_ssh_key" +} + +# Public key for SSH connection +data "local_sensitive_file" "ssh_public_key" { + filename = "${path.module}/../../key/-rsa_ssh_key.pub" } diff --git a/module/move/willbe/template/deploy/deploy/hetzner/templates/cloud-init.tpl b/module/move/willbe/template/deploy/deploy/cloud-init.tpl.hbs similarity index 65% rename from module/move/willbe/template/deploy/deploy/hetzner/templates/cloud-init.tpl rename to module/move/willbe/template/deploy/deploy/cloud-init.tpl.hbs index 37cb18d6e9..ce5dcfc9e2 100644 --- a/module/move/willbe/template/deploy/deploy/hetzner/templates/cloud-init.tpl +++ b/module/move/willbe/template/deploy/deploy/cloud-init.tpl.hbs @@ -1,18 +1,6 @@ #cloud-config write_files: -- path: /etc/systemd/system/${image_name}.service - permissions: 0644 - owner: root - content: | - [Unit] - Description=Start ${image_name} docker container. Build: ${timestamp} - Wants=network-online.target - After=network-online.target - - [Service] - Environment="HOME=/root" - ExecStart=/usr/bin/docker run -d -p 80:80 --name=${image_name} ${location}-docker.pkg.dev/${project_id}/${repo_name}/${image_name} - path: /root/service_account.json permissions: 0600 owner: root @@ -22,6 +10,10 @@ write_files: permissions: 0700 owner: root content: | + # Configure env for redeploy script + echo "DOCKER_IMAGE=${location}-docker.pkg.dev/${project_id}/${repo_name}/${image_name}" >> /etc/environment + echo "DOCKER_IMAGE_NAME=${image_name}" >> /etc/environment + # Install docker apt update apt install apt-transport-https ca-certificates curl software-properties-common -y @@ -37,10 +29,7 @@ write_files: # Configure docker with gcloud gcloud auth activate-service-account --key-file=/root/service_account.json gcloud auth configure-docker ${location}-docker.pkg.dev --quiet - # Start docker container - systemctl daemon-reload - systemctl start ${image_name}.service runcmd: -- nohup /root/init.sh > /var/log/uaconf-instance-init.log 2>&1 & +- nohup /root/init.sh > /var/log/deploy-init.log 2>&1 & diff --git a/module/move/willbe/template/deploy/deploy/gar/main.tf b/module/move/willbe/template/deploy/deploy/gar/main.tf.hbs similarity index 82% rename from module/move/willbe/template/deploy/deploy/gar/main.tf rename to module/move/willbe/template/deploy/deploy/gar/main.tf.hbs index 77709d13e6..920cd1db1e 100644 --- a/module/move/willbe/template/deploy/deploy/gar/main.tf +++ b/module/move/willbe/template/deploy/deploy/gar/main.tf.hbs @@ -9,7 +9,7 @@ resource "google_artifact_registry_repository" "container-images-repo" { location = var.REGION project = var.PROJECT_ID repository_id = var.REPO_NAME - description = "Docker image registry for the Learn Together web-site" + description = "Docker image registry for the {{docker_image_name}} deployments" # Format of the repository. We are using Docker. format = "DOCKER" } diff --git a/module/move/willbe/template/deploy/deploy/gce/main.tf b/module/move/willbe/template/deploy/deploy/gce/main.tf.hbs similarity index 62% rename from module/move/willbe/template/deploy/deploy/gce/main.tf rename to module/move/willbe/template/deploy/deploy/gce/main.tf.hbs index 9e74a148e1..f2cb1598d0 100644 --- a/module/move/willbe/template/deploy/deploy/gce/main.tf +++ b/module/move/willbe/template/deploy/deploy/gce/main.tf.hbs @@ -1,9 +1,8 @@ locals { # Helper var for formatting docker image name - image_name = format("%s-docker.pkg.dev/%s/%s/%s", var.REGION, var.PROJECT_ID, var.REPO_NAME, var.IMAGE_NAME) + image_name = format("%s-docker.pkg.dev/%s/%s/%s", var.REGION, var.PROJECT_ID, var.REPO_NAME, var.IMAGE_NAME) # Helper var for formatting subnetwork for our instance - subnetwork = format("projects/%s/regions/%s/subnetworks/default", var.PROJECT_ID, var.REGION) - instance_name = format("ltsite-%s", formatdate("YYYYMMDDhhmmss", timestamp())) + subnetwork = format("projects/%s/regions/%s/subnetworks/default", var.PROJECT_ID, var.REGION) } # Provider for resource creation @@ -18,10 +17,10 @@ resource "google_compute_address" "default" { } # GCE instance block. -resource "google_compute_instance" "lts-container-vm" { - project = var.PROJECT_ID +resource "google_compute_instance" "{{docker_image_name}}" { + project = var.PROJECT_ID # Instance name - name = local.instance_name + name = "{{docker_image_name}}" # Instance size. e2-micro is 0.25-2 vCPU & 1GB RAM machine_type = "e2-micro" zone = var.ZONE @@ -29,12 +28,12 @@ resource "google_compute_instance" "lts-container-vm" { # Main disk options boot_disk { initialize_params { - # Disk image name. We're using Container-optimised OS (COS). - image = "projects/cos-cloud/global/images/cos-stable-109-17800-147-15" + # Disk image name. We're using Ubuntu 24.04 distro. + image = "projects/ubuntu-os-cloud/global/images/ubuntu-2404-noble-amd64-v20241004" # Disk size in GB. 10GB is allowed minimum. - size = 10 + size = 10 # Disk type. Possible values: pd-standard, pd-ssd, or pd-balanced. - type = "pd-balanced" + type = "pd-balanced" } } @@ -52,19 +51,20 @@ resource "google_compute_instance" "lts-container-vm" { metadata = { # Cloud-init startup script for configuring the instance with our docker container. user-data = "${data.cloudinit_config.conf.rendered}" + ssh-keys = "root:${data.local_sensitive_file.ssh_public_key.content}" } allow_stopping_for_update = true scheduling { # Restart on failure. - automatic_restart = true + automatic_restart = true # Describes maintenance behavior for the instance. Possible values: MIGRATE or TERMINATE. on_host_maintenance = "MIGRATE" # Configures whether to allow stopping instance at any moment for reduced cost. - preemptible = false + preemptible = false # Configures spot instance. Possible values: SPOT or STANDARD. - provisioning_model = "STANDARD" + provisioning_model = "STANDARD" } # Configues service account scopes. @@ -86,3 +86,29 @@ resource "google_compute_instance" "lts-container-vm" { # Use `https-server` for https traffic on port 443. tags = ["http-server"] } + +resource "terraform_data" "redeploy" { + triggers_replace = timestamp() + + connection { + type = "ssh" + user = "root" + private_key = data.local_sensitive_file.ssh_private_key.content + host = google_compute_instance.{{docker_image_name}}.network_interface[0].access_config[0].nat_ip + } + + provisioner "file" { + source = "${path.module}/../redeploy.sh" + destination = "/tmp/redeploy.sh" + } + + provisioner "remote-exec" { + inline = [ + "#!/bin/bash", + "( tail -f -n1 /var/log/deploy-init.log & ) | grep -q 'Docker configuration file updated.'", + "source /etc/environment", + "chmod +x /tmp/redeploy.sh", + "/tmp/redeploy.sh" + ] + } +} diff --git a/module/move/willbe/template/deploy/deploy/gce/outputs.tf b/module/move/willbe/template/deploy/deploy/gce/outputs.tf.hbs similarity index 79% rename from module/move/willbe/template/deploy/deploy/gce/outputs.tf rename to module/move/willbe/template/deploy/deploy/gce/outputs.tf.hbs index 9228e2fa83..58b076f05b 100644 --- a/module/move/willbe/template/deploy/deploy/gce/outputs.tf +++ b/module/move/willbe/template/deploy/deploy/gce/outputs.tf.hbs @@ -1,5 +1,5 @@ locals { - ip = google_compute_instance.lts-container-vm.network_interface[0].access_config[0].nat_ip + ip = google_compute_instance.{{docker_image_name}}.network_interface[0].access_config[0].nat_ip } # Output that we get after applying. diff --git a/module/move/willbe/template/deploy/deploy/gce/templates/cloud-init.tpl b/module/move/willbe/template/deploy/deploy/gce/templates/cloud-init.tpl deleted file mode 100644 index 5c465968d9..0000000000 --- a/module/move/willbe/template/deploy/deploy/gce/templates/cloud-init.tpl +++ /dev/null @@ -1,24 +0,0 @@ -#cloud-config - -users: -- name: ${image_name} - uid: 2000 - -write_files: -- path: /etc/systemd/system/${image_name}.service - permissions: 0644 - owner: root - content: | - [Unit] - Description=Start the Learn Together ${image_name} docker container - Wants=gcr-online.target - After=gcr-online.target - - [Service] - Environment="HOME=/home/${image_name}" - ExecStartPre=/usr/bin/docker-credential-gcr configure-docker --registries=${location}-docker.pkg.dev - ExecStart=/usr/bin/docker run -d -p 80:80 --name=${image_name} ${location}-docker.pkg.dev/${project_id}/${repo_name}/${image_name} - -runcmd: -- systemctl daemon-reload -- systemctl start ${image_name}.service \ No newline at end of file diff --git a/module/move/willbe/template/deploy/deploy/hetzner/main.tf b/module/move/willbe/template/deploy/deploy/hetzner/main.tf deleted file mode 100644 index da3118ecef..0000000000 --- a/module/move/willbe/template/deploy/deploy/hetzner/main.tf +++ /dev/null @@ -1,49 +0,0 @@ -terraform { - # Specifies terraform API provider to use for `hcloud` - required_providers { - hcloud = { - source = "hetznercloud/hcloud" - version = "1.45.0" - } - } -} - -# Configures hcloud provider for deploy -provider "hcloud" { - # Hetzner API token - token = var.HCLOUD_TOKEN -} - -# Static IP for the instance -resource "hcloud_primary_ip" "primary_ip" { - name = "uaconf-2024-ip" - datacenter = "hel1-dc2" - type = "ipv4" - assignee_type = "server" - auto_delete = false -} - -# Hetzner instance itself -resource "hcloud_server" "uaconf" { - name = "uaconf-2024" - image = "ubuntu-22.04" - server_type = "cx11" - datacenter = "hel1-dc2" - - public_net { - ipv4_enabled = true - ipv4 = hcloud_primary_ip.primary_ip.id - ipv6_enabled = false - } - - # Startup script for the instance - # Installs docker, gcloud CLI, downloads docker images and starts the container - user_data = templatefile("${path.module}/templates/cloud-init.tpl", { - location = "${var.REGION}" - project_id = "${var.PROJECT_ID}" - repo_name = "${var.REPO_NAME}" - image_name = "${var.IMAGE_NAME}" - service_account_creds = "${replace(data.local_sensitive_file.service_account_creds.content, "\n", "")}" - timestamp = "${timestamp()}" - }) -} diff --git a/module/move/willbe/template/deploy/deploy/hetzner/main.tf.hbs b/module/move/willbe/template/deploy/deploy/hetzner/main.tf.hbs new file mode 100644 index 0000000000..b75e946aab --- /dev/null +++ b/module/move/willbe/template/deploy/deploy/hetzner/main.tf.hbs @@ -0,0 +1,82 @@ +terraform { + # Specifies terraform API provider to use for `hcloud` + required_providers { + hcloud = { + source = "hetznercloud/hcloud" + version = "1.45.0" + } + } +} + +# Configures hcloud provider for deploy +provider "hcloud" { + # Hetzner API token + token = var.HCLOUD_TOKEN +} + +# Creates an SSH key used for redeploy +resource "hcloud_ssh_key" "redeploy" { + name = "{{docker_image_name}} redeploy key" + public_key = data.local_sensitive_file.ssh_public_key.content +} + +# Static IP for the instance +resource "hcloud_primary_ip" "primary_ip" { + name = "{{docker_image_name}}-ip" + datacenter = "hel1-dc2" + type = "ipv4" + assignee_type = "server" + auto_delete = false +} + +# Hetzner instance itself +resource "hcloud_server" "{{docker_image_name}}" { + name = "{{docker_image_name}}" + image = "ubuntu-22.04" + server_type = "cx22" + datacenter = "hel1-dc2" + + public_net { + ipv4_enabled = true + ipv4 = hcloud_primary_ip.primary_ip.id + ipv6_enabled = false + } + + ssh_keys = [ hcloud_ssh_key.redeploy.name ] + + # Startup script for the instance + # Installs docker, gcloud CLI, downloads docker images and starts the container + user_data = templatefile("${path.module}/../cloud-init.tpl", { + location = "${var.REGION}" + project_id = "${var.PROJECT_ID}" + repo_name = "${var.REPO_NAME}" + image_name = "${var.IMAGE_NAME}" + service_account_creds = "${replace(data.local_sensitive_file.service_account_creds.content, "\n", "")}" + }) +} + +resource "terraform_data" "redeploy" { + triggers_replace = timestamp() + + connection { + type = "ssh" + user = "root" + private_key = data.local_sensitive_file.ssh_private_key.content + host = hcloud_primary_ip.primary_ip.ip_address + } + + provisioner "file" { + source = "${path.module}/../redeploy.sh" + destination = "/tmp/redeploy.sh" + } + + provisioner "remote-exec" { + inline = [ + "#!/bin/bash", + "( tail -f -n1 /var/log/deploy-init.log & ) | grep -q 'Docker configuration file updated.'", + "source /etc/environment", + "chmod +x /tmp/redeploy.sh", + "/tmp/redeploy.sh" + ] + } +} diff --git a/module/move/willbe/template/deploy/deploy/hetzner/outputs.tf b/module/move/willbe/template/deploy/deploy/hetzner/outputs.tf.hbs similarity index 86% rename from module/move/willbe/template/deploy/deploy/hetzner/outputs.tf rename to module/move/willbe/template/deploy/deploy/hetzner/outputs.tf.hbs index f6d2ebd5e8..ba994920c7 100644 --- a/module/move/willbe/template/deploy/deploy/hetzner/outputs.tf +++ b/module/move/willbe/template/deploy/deploy/hetzner/outputs.tf.hbs @@ -1,5 +1,5 @@ locals { - ip = hcloud_server.uaconf.ipv4_address + ip = hcloud_server.{{docker_image_name}}.ipv4_address } # Output that we get after applying. diff --git a/module/move/willbe/template/deploy/deploy/hetzner/variables.tf b/module/move/willbe/template/deploy/deploy/hetzner/variables.tf index 92e5e44421..a6c27db413 100644 --- a/module/move/willbe/template/deploy/deploy/hetzner/variables.tf +++ b/module/move/willbe/template/deploy/deploy/hetzner/variables.tf @@ -25,5 +25,15 @@ variable "IMAGE_NAME" { # Google Cloud Platform credentials data "local_sensitive_file" "service_account_creds" { - filename = "${path.module}/../../key/service_account.json" + filename = "${path.module}/../../key/-service_account.json" +} + +# Private key for SSH connection +data "local_sensitive_file" "ssh_private_key" { + filename = "${path.module}/../../key/-rsa_ssh_key" +} + +# Public key for SSH connection +data "local_sensitive_file" "ssh_public_key" { + filename = "${path.module}/../../key/-rsa_ssh_key.pub" } diff --git a/module/move/willbe/template/deploy/deploy/redeploy.sh b/module/move/willbe/template/deploy/deploy/redeploy.sh new file mode 100644 index 0000000000..48695a43e1 --- /dev/null +++ b/module/move/willbe/template/deploy/deploy/redeploy.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +docker rm -f ${DOCKER_IMAGE_NAME} +docker rmi ${DOCKER_IMAGE} +docker pull ${DOCKER_IMAGE} +docker run -d --restart unless-stopped -p 80:80 --name=${DOCKER_IMAGE_NAME} ${DOCKER_IMAGE} diff --git a/module/move/willbe/template/deploy/key/.gitignore b/module/move/willbe/template/deploy/key/.gitignore index 38b7807347..96870e1f6b 100644 --- a/module/move/willbe/template/deploy/key/.gitignore +++ b/module/move/willbe/template/deploy/key/.gitignore @@ -2,3 +2,4 @@ !.gitignore !*.md !pack.sh +-* diff --git a/module/move/willbe/template/deploy/key/Readme.md b/module/move/willbe/template/deploy/key/Readme.md index 53c085c1cd..d46ad6df48 100644 --- a/module/move/willbe/template/deploy/key/Readme.md +++ b/module/move/willbe/template/deploy/key/Readme.md @@ -1,48 +1,82 @@ -# Deploy credentials +# Keys -A list of all keys you'd need to deploy your project on different hosts. +This document provides a concise example of an environment configuration script, used to set up environment variables for a project. +These variables configure application behavior without altering the code. -- [Deploy credentials](#deploy-credentials) - - [Files](#files) - - [Env vars](#env-vars) +- [Keys](#keys) + - [Examples](#examples) + - [`-gcp.sh`](#-gcpsh) + - [`-hetzner.sh`](#-hetznersh) + - [`-aws.sh`](#-awssh) + - [How to Run](#how-to-run) - [Retrieving keys](#retrieving-keys) - [How to get `service_account.json`](#how-to-get-service_accountjson) - [How to get `SECRET_STATE_ARCHIVE_KEY`](#how-to-get-secret_state_archive_key) - [How to get `SECRET_CSP_HETZNER`](#how-to-get-secret_csp_hetzner) - [How to get `SECRET_AWS_ACCESS_KEY_ID` and `SECRET_AWS_ACCESS_KEY`](#how-to-get-secret_aws_access_key_id-and-secret_aws_access_key) -## Files -All secrets can be provided as files in current directory: +## Examples -- [service_account.json](./service_account.json) - default credentials for the service account to use in deployment. -- [`SECRET_STATE_ARCHIVE_KEY`](./SECRET_STATE_ARCHIVE_KEY) - [📃] base64 encoded AES256 key to encrypt and decrypt .tfstate files. -- [`SECRET_CSP_HETZNER`](./SECRET_CSP_HETZNER) - [📃] Hetzner token for deploying a server. -- [`SECRET_AWS_ACCESS_KEY_ID`](./SECRET_AWS_ACCESS_KEY_ID) - [📃] Access Key ID from AWS Credentials. Created at the same time as the Access Key itself. -- [`SECRET_AWS_ACCESS_KEY`](./SECRET_AWS_ACCESS_KEY) - [📃] Access Key for AWS API. Has to be accompanied with respectful Access Key ID. +### `-gcp.sh` -## Env vars +Contents example for the file `-gcp.sh`. This is a required configuration for all deploy targets. -Some secrets can be presented as an env var: +```bash +#!/bin/bash +CSP=gce +SECRET_STATE_ARCHIVE_KEY=qK1/4m60aZvclYi4bZFeBl8GxpyWcJ2iEevHN+uMy7w= -- [`SECRET_STATE_ARCHIVE_KEY`](./SECRET_STATE_ARCHIVE_KEY) - [📃] base64 encoded AES256 key to encrypt and decrypt .tfstate files. -- [`SECRET_CSP_HETZNER`](./SECRET_CSP_HETZNER) - [📃] Hetzner token for deploying a server. -- [`SECRET_AWS_ACCESS_KEY_ID`](./SECRET_AWS_ACCESS_KEY_ID) - [📃] Access Key ID from AWS Credentials. Created at the same time as the Access Key itself. -- [`SECRET_AWS_ACCESS_KEY`](./SECRET_AWS_ACCESS_KEY) - [📃] Access Key for AWS API. Has to be accompanied with respectful Access Key ID. +FILE_PATH="$( realpath -qms "${BASH_SOURCE[0]:-$PWD}" )" +DIR_PATH="${FILE_PATH%/*}" +head -c -1 << EOF > ${DIR_PATH}/-service_account.json +{ + // Your service_account information +} +EOF +``` + +- `CSP`: (Optional) Specifies deployment to GCE. +- `SECRET_STATE_ARCHIVE_KEY`: Base64 encoded AES256 key to encrypt and decrypt .tfstate files. +- `-service_account.json`: Default credentials for the service account to use in deployment. + +### `-hetzner.sh` + +Contents example for the file `-hetzner.sh`: + +```bash +CSP=hetzner +SECRET_CSP_HETZNER=your_token_here +``` -Env vars have a higher priority then the files. +- `CSP`: Specifies deployment to Hetzner. +- `SECRET_CSP_HETZNER`: Hetzner token for deploying a server. -For ENV [📃] secrets values can be placed in files in this directory for automatic exporting to env during deployment. +### `-aws.sh` -Example of a file that will be pulled to env vars: +Contents example for the file `-aws.sh`: -File name: `SECRET_CSP_HETZNER` -File contents: +```bash +CSP=aws +SECRET_AWS_ACCESS_KEY_ID=aws_credentials_here +SECRET_AWS_ACCESS_KEY=aws_credentials_here ``` -hetzner_token_123 + +- `CSP`: Specifies deployment to AWS. +- `SECRET_AWS_ACCESS_KEY_ID`: Access Key ID from AWS Credentials. Created at the same time as the Access Key itself. +- `SECRET_AWS_ACCESS_KEY`: Access Key for AWS API. Has to be accompanied with respectful Access Key ID. + +## How to Run + +To apply these variables to your current shell session, use: + +```bash +. ./key/-gcp.sh +. ./key/-hetzner.sh ``` -Will export a variable to env like so `SECRET_CSP_HETZNER=hetzner_token_123` +This command sources the script, making the variables available in your current session and allowing deployment to Hetzner. +Ensure `-env.sh` is in the `key` directory relative to your current location. ## Retrieving keys diff --git a/module/move/willbe/template/workflow/standard_rust_push.yml b/module/move/willbe/template/workflow/standard_rust_push.yml index d2fd96bae2..a243d1affe 100644 --- a/module/move/willbe/template/workflow/standard_rust_push.yml +++ b/module/move/willbe/template/workflow/standard_rust_push.yml @@ -64,20 +64,32 @@ jobs : - name: Build module run: cd ${{ steps.rootpath.outputs.path }} && cargo build && cd - - name: Audit the modules + id: audit run: make audit continue-on-error: true - name: Generate documentation for the modules + id: documentation run: make doc open=no manifest_path=${{ inputs.manifest_path }} continue-on-error: true - name: Lint the modules + id: lint run: make lint manifest_path=${{ inputs.manifest_path }} warnings=no continue-on-error: true - name: Check the modules + id: check run: make check manifest_path=${{ inputs.manifest_path }} continue-on-error: true - name: Check the modules dependencies + id: udeps run: cargo +nightly udeps --all-targets --manifest-path ${{ inputs.manifest_path }} continue-on-error: true + # Added IDs for each step in the test job: This allows referencing the result of each step later. + # + # "Check for errors" step: Now checks the outcome status for each step. + # If any of them have a value of 'failure', this step will fail the job by returning exit 1. + - name: Check for errors + if: steps.audit.outcome != 'success' || steps.documentation.outcome != 'success' || steps.lint.outcome != 'success' || steps.check.outcome != 'success' || steps.udeps.outcome != 'success' + run: exit 1 # release: # if: contains( inputs.commit_message, '+test' ) || contains( inputs.commit_message, 'merge' ) @@ -125,6 +137,9 @@ jobs : # run: cargo miri test --manifest-path ${{ inputs.manifest_path }} will_test : +# This section ensures that `job` `will_test` will only be executed after `checkmate` and if `checkmate` fails, no tests will be run. + needs : + - checkmate if : contains( inputs.commit_message, '+test' ) || inputs.commiter_username == 'web-flow' || startsWith( inputs.commit_message, 'merge' ) concurrency : group : standard_rust_push_${{ inputs.module_name }}_${{ github.ref }}_${{ matrix.os }} diff --git a/module/move/willbe/tests/inc/action_tests/cicd_renew.rs b/module/move/willbe/tests/inc/action_tests/cicd_renew.rs index ffbbe5b570..75370b0db5 100644 --- a/module/move/willbe/tests/inc/action_tests/cicd_renew.rs +++ b/module/move/willbe/tests/inc/action_tests/cicd_renew.rs @@ -90,7 +90,7 @@ fn default_case() }; // Act - _ = action::cicd_renew( &temp ).unwrap(); + _ = action::cicd_renew::action( &temp ).unwrap(); dbg!( &file_path ); // Assert diff --git a/module/move/willbe/tests/inc/action_tests/features.rs b/module/move/willbe/tests/inc/action_tests/features.rs index 37a4b63cae..ea0e4e80a0 100644 --- a/module/move/willbe/tests/inc/action_tests/features.rs +++ b/module/move/willbe/tests/inc/action_tests/features.rs @@ -24,7 +24,7 @@ fn package_no_features() .form(); // Act - let report = willbe::action::features( options ).unwrap().to_string(); + let report = willbe::action::features::orphan::features( options ).unwrap().to_string(); // Assert assert!( report.contains( @@ -43,7 +43,7 @@ fn package_features() .form(); // Act - let report = willbe::action::features( options ).unwrap().to_string(); + let report = willbe::action::features::orphan::features( options ).unwrap().to_string(); // Assert assert!( report.contains( @@ -66,7 +66,7 @@ fn package_features_with_features_deps() .form(); // Act - let report = willbe::action::features( options ).unwrap().to_string(); + let report = willbe::action::features::orphan::features( options ).unwrap().to_string(); // Assert assert!( report.contains( @@ -89,7 +89,7 @@ fn workspace_no_features() .form(); // Act - let report = willbe::action::features( options ).unwrap().to_string(); + let report = willbe::action::features::orphan::features( options ).unwrap().to_string(); // Assert assert!( report.contains( @@ -118,7 +118,7 @@ fn workspace_features() .form(); // Act - let report = willbe::action::features( options ).unwrap().to_string(); + let report = willbe::action::features::orphan::features( options ).unwrap().to_string(); // Assert assert!( report.contains( @@ -156,7 +156,7 @@ fn workspace_features_with_features_deps() .form(); // Act - let report = willbe::action::features( options ).unwrap().to_string(); + let report = willbe::action::features::orphan::features( options ).unwrap().to_string(); // Assert assert!( report.contains( diff --git a/module/move/willbe/tests/inc/action_tests/list/data.rs b/module/move/willbe/tests/inc/action_tests/list/data.rs index 423baf654c..9100cf5dfb 100644 --- a/module/move/willbe/tests/inc/action_tests/list/data.rs +++ b/module/move/willbe/tests/inc/action_tests/list/data.rs @@ -44,7 +44,7 @@ mod chain_of_three_packages .form(); // Act - let output = action::list( args ).unwrap(); + let output = action::list_all( args ).unwrap(); // Assert let ListReport::Tree( trees ) = &output else { panic!( "Expected `Tree` format, but found another" ) }; @@ -85,7 +85,7 @@ mod chain_of_three_packages .form(); // Act - let output = action::list( args ).unwrap(); + let output = action::list_all( args ).unwrap(); // Assert let ListReport::List( names ) = &output else { panic!("Expected `Topological` format, but found another") }; @@ -106,7 +106,7 @@ mod chain_of_three_packages .form(); // Act - let output = action::list( args ).unwrap(); + let output = action::list_all( args ).unwrap(); // Assert let ListReport::List( names ) = &output else { panic!( "Expected `Topological` format, but found another" ) }; @@ -145,7 +145,7 @@ mod package_with_remote_dependency .form(); // Act - let output = action::list( args ).unwrap(); + let output = action::list_all( args ).unwrap(); // Assert let ListReport::Tree( trees ) = &output else { panic!( "Expected `Tree` format, but found another" ) }; @@ -183,7 +183,7 @@ mod package_with_remote_dependency .form(); // Act - let output = action::list( args ).unwrap(); + let output = action::list_all( args ).unwrap(); // Assert let ListReport::List( names ) = &output else { panic!( "Expected `Topological` format, but found another" ) }; @@ -208,7 +208,7 @@ mod package_with_remote_dependency .form(); // Act - let output = action::list( args ).unwrap(); + let output = action::list_all( args ).unwrap(); // Assert let ListReport::List( names ) = &output else { panic!( "Expected `Topological` format, but found another" ) }; @@ -242,7 +242,7 @@ mod workspace_with_cyclic_dependency .form(); // Act - let output = action::list( args ).unwrap(); + let output = action::list_all( args ).unwrap(); // Assert let ListReport::Tree( trees ) = &output else { panic!( "Expected `Tree` format, but found another" ) }; @@ -304,7 +304,7 @@ mod workspace_with_cyclic_dependency .form(); // Act - let output = action::list( args ); + let output = action::list_all( args ); // Assert diff --git a/module/move/willbe/tests/inc/action_tests/main_header.rs b/module/move/willbe/tests/inc/action_tests/main_header.rs index 82f1b89fba..6f65b44495 100644 --- a/module/move/willbe/tests/inc/action_tests/main_header.rs +++ b/module/move/willbe/tests/inc/action_tests/main_header.rs @@ -25,7 +25,7 @@ fn tag_shout_stay() let temp = arrange( "single_module" ); // Act - _ = action::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::readme_header_renew::orphan::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "Readme.md" ) ).unwrap(); @@ -45,7 +45,7 @@ fn branch_cell() let temp = arrange( "single_module" ); // Act - _ = action::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::readme_header_renew::orphan::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "Readme.md" ) ).unwrap(); @@ -64,7 +64,7 @@ fn discord_cell() let temp = arrange( "single_module" ); // Act - _ = action::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::readme_header_renew::orphan::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "Readme.md" ) ).unwrap(); @@ -83,7 +83,7 @@ fn gitpod_cell() let temp = arrange( "single_module" ); // Act - _ = action::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::readme_header_renew::orphan::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "Readme.md" ) ).unwrap(); @@ -102,7 +102,7 @@ fn docs_cell() let temp = arrange( "single_module" ); // Act - _ = action::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::readme_header_renew::orphan::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "Readme.md" ) ).unwrap(); @@ -121,7 +121,7 @@ fn without_fool_config() let temp = arrange( "single_module_without_master_branch_and_discord" ); // Act - _ = action::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::readme_header_renew::orphan::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "Readme.md" ) ).unwrap(); @@ -141,13 +141,13 @@ fn idempotency() let temp = arrange( "single_module" ); // Act - _ = action::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::readme_header_renew::orphan::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "Readme.md" ) ).unwrap(); let mut actual1 = String::new(); _ = file.read_to_string( &mut actual1 ).unwrap(); drop( file ); - _ = action::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::readme_header_renew::orphan::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "Readme.md" ) ).unwrap(); let mut actual2 = String::new(); _ = file.read_to_string( &mut actual2 ).unwrap(); @@ -164,5 +164,5 @@ fn without_needed_config() // Arrange let temp = arrange( "variadic_tag_configurations" ); // Act - _ = action::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::readme_header_renew::orphan::readme_header_renew( AbsolutePath::try_from( temp.path() ).unwrap() ).unwrap(); } \ No newline at end of file diff --git a/module/move/willbe/tests/inc/action_tests/readme_health_table_renew.rs b/module/move/willbe/tests/inc/action_tests/readme_health_table_renew.rs index cce1e9065a..909a186116 100644 --- a/module/move/willbe/tests/inc/action_tests/readme_health_table_renew.rs +++ b/module/move/willbe/tests/inc/action_tests/readme_health_table_renew.rs @@ -23,7 +23,7 @@ fn without_any_toml_configurations_test() // Arrange let temp = arrange( "without_any_toml_configurations" ); // Act - _ = action::readme_health_table_renew( &temp ).unwrap(); + _ = action::readme_health_table_renew::orphan::readme_health_table_renew( &temp ).unwrap(); } #[ test ] @@ -33,7 +33,7 @@ fn tags_should_stay() let temp = arrange( "without_module_toml_configurations" ); // Act - _ = action::readme_health_table_renew( &temp ).unwrap(); + _ = action::readme_health_table_renew::orphan::readme_health_table_renew( &temp ).unwrap(); // Assert let mut file = std::fs::File::open( temp.path().join( "readme.md" ) ).unwrap(); @@ -52,7 +52,7 @@ fn stability_experimental_by_default() let temp = arrange( "without_module_toml_configurations" ); // Act - _ = action::readme_health_table_renew( &temp ).unwrap(); + _ = action::readme_health_table_renew::orphan::readme_health_table_renew( &temp ).unwrap(); // Assert let mut file = std::fs::File::open( temp.path().join( "readme.md" ) ).unwrap(); @@ -70,7 +70,7 @@ fn stability_and_repository_from_module_toml() let temp = arrange( "without_workspace_toml_configurations" ); // Act - _ = action::readme_health_table_renew( &temp ).unwrap(); + _ = action::readme_health_table_renew::orphan::readme_health_table_renew( &temp ).unwrap(); // Assert let mut file = std::fs::File::open( temp.path().join( "readme.md" ) ).unwrap(); @@ -101,7 +101,7 @@ fn variadic_tag_configuration_test() let temp = arrange( "variadic_tag_configurations" ); // Act - _ = action::readme_health_table_renew( &temp ).unwrap(); + _ = action::readme_health_table_renew::orphan::readme_health_table_renew( &temp ).unwrap(); // Assert let mut file = std::fs::File::open( temp.path().join( "readme.md" ) ).unwrap(); @@ -121,7 +121,7 @@ fn module_cell() let temp = arrange( "full_config" ); // Act - _ = action::readme_health_table_renew( &temp ).unwrap(); + _ = action::readme_health_table_renew::orphan::readme_health_table_renew( &temp ).unwrap(); // Assert let mut file = std::fs::File::open( temp.path().join( "readme.md" ) ).unwrap(); @@ -139,7 +139,7 @@ fn stability_cell() let temp = arrange( "full_config" ); // Act - _ = action::readme_health_table_renew( &temp ).unwrap(); + _ = action::readme_health_table_renew::orphan::readme_health_table_renew( &temp ).unwrap(); // Assert let mut file = std::fs::File::open( temp.path().join( "readme.md" ) ).unwrap(); @@ -157,7 +157,7 @@ fn branches_cell() let temp = arrange( "full_config" ); // Act - _ = action::readme_health_table_renew( &temp ).unwrap(); + _ = action::readme_health_table_renew::orphan::readme_health_table_renew( &temp ).unwrap(); // Assert let mut file = std::fs::File::open( temp.path().join( "readme.md" ) ).unwrap(); @@ -175,7 +175,7 @@ fn docs_cell() let temp = arrange( "full_config" ); // Act - _ = action::readme_health_table_renew( &temp ).unwrap(); + _ = action::readme_health_table_renew::orphan::readme_health_table_renew( &temp ).unwrap(); // Assert let mut file = std::fs::File::open( temp.path().join( "readme.md" ) ).unwrap(); @@ -193,7 +193,7 @@ fn sample_cell() let temp = arrange( "full_config" ); // Act - _ = action::readme_health_table_renew( &temp ).unwrap(); + _ = action::readme_health_table_renew::orphan::readme_health_table_renew( &temp ).unwrap(); // Assert let mut file = std::fs::File::open( temp.path().join( "readme.md" ) ).unwrap(); diff --git a/module/move/willbe/tests/inc/action_tests/readme_modules_headers_renew.rs b/module/move/willbe/tests/inc/action_tests/readme_modules_headers_renew.rs index db82f365ba..1d4d012d5d 100644 --- a/module/move/willbe/tests/inc/action_tests/readme_modules_headers_renew.rs +++ b/module/move/willbe/tests/inc/action_tests/readme_modules_headers_renew.rs @@ -32,7 +32,9 @@ fn tags_should_stay() let temp = arrange( "single_module" ); // Act - _ = action::readme_modules_headers_renew( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::main_header::action( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); + // _ = action::main_header::action( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); + let mut file = std::fs::File::open( temp.path().join( "test_module" ).join( "Readme.md" ) ).unwrap(); let mut actual = String::new(); @@ -51,7 +53,7 @@ fn default_stability() let temp = arrange( "single_module" ); // Act - _ = action::readme_modules_headers_renew( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::main_header::action( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "test_module" ).join( "Readme.md" ) ).unwrap(); let mut actual = String::new(); @@ -70,7 +72,7 @@ fn docs() let temp = arrange( "single_module" ); // Act - _ = action::readme_modules_headers_renew( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::main_header::action( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "test_module" ).join( "Readme.md" ) ).unwrap(); let mut actual = String::new(); @@ -88,7 +90,7 @@ fn no_gitpod() let temp = arrange("single_module"); // Act - _ = action::readme_modules_headers_renew( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::main_header::action( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open(temp.path().join("test_module").join("Readme.md")).unwrap(); let mut actual = String::new(); @@ -105,7 +107,7 @@ fn with_gitpod() let temp = arrange( "single_module_with_example" ); // Act - _ = action::readme_modules_headers_renew( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::main_header::action( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "module" ).join( "test_module" ).join( "Readme.md" ) ).unwrap(); let mut actual = String::new(); @@ -123,7 +125,7 @@ fn discord() let temp = arrange( "single_module" ); // Act - _ = action::readme_modules_headers_renew( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::main_header::action( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "test_module" ).join( "Readme.md" ) ).unwrap(); let mut actual = String::new(); @@ -141,7 +143,7 @@ fn status() let temp = arrange( "single_module" ); // Act - _ = action::readme_modules_headers_renew( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::main_header::action( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "test_module" ).join( "Readme.md" ) ).unwrap(); let mut actual = String::new(); @@ -159,13 +161,13 @@ fn idempotency() let temp = arrange( "single_module" ); // Act - _ = action::readme_modules_headers_renew( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::main_header::action( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "test_module" ).join( "Readme.md" ) ).unwrap(); let mut actual1 = String::new(); _ = file.read_to_string( &mut actual1 ).unwrap(); drop( file ); - _ = action::readme_modules_headers_renew( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::main_header::action( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); let mut file = std::fs::File::open( temp.path().join( "test_module" ).join( "Readme.md" ) ).unwrap(); let mut actual2 = String::new(); _ = file.read_to_string( &mut actual2 ).unwrap(); @@ -180,7 +182,7 @@ fn with_many_members_and_varius_config() { let temp = arrange( "three_packages" ); - _ = action::readme_modules_headers_renew( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::main_header::action( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); let mut file_b = std::fs::File::open( temp.path().join( "b" ).join( "Readme.md" ) ).unwrap(); let mut file_c = std::fs::File::open( temp.path().join( "c" ).join( "Readme.md" ) ).unwrap(); @@ -207,5 +209,5 @@ fn without_needed_config() let temp = arrange( "variadic_tag_configurations" ); // Act - _ = action::readme_modules_headers_renew( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); + _ = action::main_header::action( CrateDir::try_from( temp.path() ).unwrap() ).unwrap(); } diff --git a/module/move/willbe/tests/inc/action_tests/test.rs b/module/move/willbe/tests/inc/action_tests/test.rs index 6d7d7898d9..67c926cb89 100644 --- a/module/move/willbe/tests/inc/action_tests/test.rs +++ b/module/move/willbe/tests/inc/action_tests/test.rs @@ -1,28 +1,24 @@ use super::*; -use the_module::*; +// qqq : for Bohdan : bad. don't import the_module::* use inc::helper:: { ProjectBuilder, WorkspaceBuilder, - // BINARY_NAME, }; use collection::BTreeSet; -// use std:: -// { -// fs::{ self, File }, -// io::Write, -// }; -// use path::{ Path, PathBuf }; use assert_fs::TempDir; -use action::test::{ test, TestsCommandOptions }; -use channel::*; -use optimization::*; +use the_module::action::test::{ test, TestsCommandOptions }; +use the_module::channel::*; +// use the_module::optimization::*; +use the_module::optimization::{ self, Optimization }; +use the_module::AbsolutePath; // qqq : for Petro : no astersisks import use willbe::test::TestVariant; + #[ test ] // if the test fails => the report is returned as an error ( Err(Report) ) fn fail_test() diff --git a/module/move/willbe/tests/inc/action_tests/workspace_renew.rs b/module/move/willbe/tests/inc/action_tests/workspace_renew.rs index 9dbfcea23d..4790c39f25 100644 --- a/module/move/willbe/tests/inc/action_tests/workspace_renew.rs +++ b/module/move/willbe/tests/inc/action_tests/workspace_renew.rs @@ -26,7 +26,7 @@ fn default_case() create_dir(temp.join("test_project_name" )).unwrap(); // Act - _ = workspace_renew( &temp.path().join( "test_project_name" ), WorkspaceTemplate::default(), "https://github.con/Username/TestRepository".to_string(), vec![ "master".to_string() ] ).unwrap(); + _ = workspace_renew::action( &temp.path().join( "test_project_name" ), WorkspaceTemplate::default(), "https://github.con/Username/TestRepository".to_string(), vec![ "master".to_string() ] ).unwrap(); // Assets assert!( temp_path.join( "module" ).exists() ); @@ -57,7 +57,7 @@ fn non_empty_dir() let temp = arrange( "single_module" ); // Act - let r = workspace_renew( temp.path(), WorkspaceTemplate::default(), "".to_string(), vec![] ); + let r = workspace_renew::action( temp.path(), WorkspaceTemplate::default(), "".to_string(), vec![] ); // Assert assert!( r.is_err() ); diff --git a/module/move/willbe/tests/inc/mod.rs b/module/move/willbe/tests/inc/mod.rs index ca9dbda05d..0b456a9b87 100644 --- a/module/move/willbe/tests/inc/mod.rs +++ b/module/move/willbe/tests/inc/mod.rs @@ -14,6 +14,8 @@ mod action_tests; mod helper; +mod package; + // aaa : for Petro : for Bohdan : for Nikita : sort out test files to be consistent with src files // sorted diff --git a/module/move/willbe/tests/inc/package.rs b/module/move/willbe/tests/inc/package.rs index 8a5fb2a2f0..bc83b38d89 100644 --- a/module/move/willbe/tests/inc/package.rs +++ b/module/move/willbe/tests/inc/package.rs @@ -1,3 +1,310 @@ +use std::*; +use std::io::Write; + +use crate::the_module::{ action, channel, package }; + +enum Dependency +{ + Normal { name: String, path: Option< path::PathBuf >, is_macro: bool }, + Dev { name: String, path: Option< path::PathBuf >, is_macro: bool }, +} + +impl Dependency +{ + fn as_toml( &self ) -> String + { + match self + { + Dependency::Normal { name, path, is_macro } if !is_macro => + if let Some( path ) = path + { + format!( "[dependencies.{name}]\npath = \"../{}\"", path.display().to_string().replace( "\\", "/" ) ) + } + else + { + format!( "[dependencies.{name}]\nversion = \"*\"" ) + } + Dependency::Normal { name, .. } => format!( "[dependencies.{name}]\nworkspace = true" ), + Dependency::Dev { name, path, is_macro } if !is_macro => + if let Some( path ) = path + { + format!( "[dev-dependencies.{name}]\npath = \"../{}\"", path.display().to_string().replace( "\\", "/" ) ) + } + else + { + format!( "[dev-dependencies.{name}]\nversion = \"*\"" ) + } + Dependency::Dev { name, .. } => format!( "[dev-dependencies.{name}]\nworkspace = true" ), + } + } +} + +struct TestPackage +{ + name: String, + dependencies: Vec< Dependency >, + path: Option< path::PathBuf >, +} + +impl TestPackage +{ + pub fn new( name: impl Into< String > ) -> Self + { + Self { name: name.into(), dependencies: vec![], path: None } + } + + pub fn dependency( mut self, name: impl Into< String > ) -> Self + { + self.dependencies.push( Dependency::Normal { name: name.into(), path: None, is_macro: false } ); + self + } + + pub fn macro_dependency( mut self, name: impl Into< String > ) -> Self + { + self.dependencies.push( Dependency::Normal { name: name.into(), path: None, is_macro: true } ); + self + } + + pub fn dev_dependency( mut self, name: impl Into< String > ) -> Self + { + self.dependencies.push( Dependency::Dev { name: name.into(), path: None, is_macro: false } ); + self + } + + pub fn macro_dev_dependency( mut self, name: impl Into< String > ) -> Self + { + self.dependencies.push( Dependency::Dev { name: name.into(), path: None, is_macro: true } ); + self + } + + pub fn create( &mut self, path: impl AsRef< path::Path > ) -> io::Result< () > + { + let path = path.as_ref().join( &self.name ); + + () = fs::create_dir_all( path.join( "src" ) )?; + () = fs::write( path.join( "src" ).join( "lib.rs" ), &[] )?; + + let cargo = format! + ( + r#"[package] +name = "{}" +version = "0.1.0" +edition = "2021" +{}"#, + self.name, + self.dependencies.iter().map( Dependency::as_toml ).fold( String::new(), | acc, d | + { + format!( "{acc}\n\n{d}" ) + }) + ); + () = fs::write( path.join( "Cargo.toml" ), cargo.as_bytes() )?; + + self.path = Some( path ); + + Ok( () ) + } +} + +impl Drop for TestPackage +{ + fn drop( &mut self ) + { + if let Some( path ) = &self.path + { + _ = fs::remove_dir_all( path ).ok(); + } + } +} + +struct TestWorkspace +{ + packages: Vec< TestPackage >, + path: path::PathBuf, +} + +impl TestWorkspace +{ + fn new( path: impl AsRef< path::Path > ) -> io::Result< Self > + { + let path = path.as_ref(); + () = fs::create_dir_all( path )?; + + let cargo = r#"[workspace] +resolver = "2" +members = [ + "members/*", +] +"#; + () = fs::write( path.join( "Cargo.toml" ), cargo.as_bytes() )?; + + Ok(Self { packages: vec![], path: path.into() }) + } + + fn find( &self, package_name: impl AsRef< str > ) -> Option< &TestPackage > + { + let name = package_name.as_ref(); + self.packages.iter().find( | p | p.name == name ) + } + + fn with_package( mut self, mut package: TestPackage ) -> io::Result< Self > + { + let mut macro_deps = collections::HashMap::new(); + for dep in &mut package.dependencies + { + match dep + { + Dependency::Normal { name, is_macro, .. } if *is_macro => + { + if let Some( package ) = self.find( &name ) + { + if let Some( path ) = &package.path + { + macro_deps.insert( name.clone(), path.clone() ); + continue; + } + } + eprintln!( "macro dependency {} not found. required for {}", name, package.name ); + } + Dependency::Normal { name, path, .. } => + { + if let Some( package ) = self.find( &name ) + { + if let Some( real_path ) = &package.path + { + let real_path = real_path.strip_prefix( self.path.join( "members" ) ).unwrap_or( real_path ); + *path = Some( real_path.into() ); + } + } + } + Dependency::Dev { name, is_macro, .. } if *is_macro => + { + if let Some( package ) = self.find( &name ) + { + if let Some( path ) = &package.path + { + macro_deps.insert( name.clone(), path.clone() ); + continue; + } + } + eprintln!( "macro dev-dependency {} not found. required for {}", name, package.name ); + } + Dependency::Dev { name, path, .. } => + { + if let Some( package ) = self.find( &name ) + { + if let Some( real_path ) = &package.path + { + let real_path = real_path.strip_prefix( self.path.join( "members" ) ).unwrap_or( real_path ); + *path = Some( real_path.into() ); + } + } + } + } + } + let mut cargo = fs::OpenOptions::new().append( true ).open( self.path.join( "Cargo.toml" ) )?; + for ( name, _ ) in macro_deps + { + writeln!( cargo, + r#"[workspace.dependencies.{name}] +version = "*" +path = "members/{name}""#, + )?; + } + package.create( self.path.join( "members" ) )?; + self.packages.push( package ); + + Ok( self ) + } + + fn with_packages( mut self, packages: impl IntoIterator< Item = TestPackage > ) -> io::Result< Self > + { + for package in packages { self = self.with_package( package )?; } + + Ok( self ) + } +} + +impl Drop for TestWorkspace +{ + fn drop( &mut self ) + { + _ = fs::remove_dir_all( &self.path ).ok(); + } +} + +#[ test ] +fn kos_plan() +{ + let tmp_folder = env::temp_dir().join( "publish_plan_kos_plan" ); + _ = fs::remove_dir_all( &tmp_folder ).ok(); + + let workspace = TestWorkspace::new( tmp_folder ).unwrap() + .with_packages( + [ + TestPackage::new( "a" ), + TestPackage::new( "b" ).dependency( "a" ), + TestPackage::new( "c" ).dependency( "a" ), + TestPackage::new( "d" ).dependency( "a" ), + TestPackage::new( "e" ).dependency( "b" ).macro_dev_dependency( "c" ),//.macro_dependency( "c" ), + ]).unwrap(); + let the_patterns: Vec< String > = workspace + .packages + .iter() + .flat_map( | p | p.path.as_ref().map( | p | p.to_string_lossy().into_owned() ) ) + .collect(); + dbg!(&the_patterns); + + let plan = action::publish_plan + ( + the_patterns, + channel::Channel::Stable, + false, + false, + true, + false, + ) + .unwrap(); + + let queue: Vec< &package::PackageName > = plan.plans.iter().map( | i | &i.package_name ).collect(); + dbg!(&queue); + + // We don’t consider dev dependencies when constructing the project graph, which results in this number of variations. + // If you'd like to modify this behavior, please check `entity/workspace_graph.rs` in the `module_dependency_filter`. + let expected_one_of= + [ + [ "a", "b", "d", "c", "e" ], + [ "a", "b", "c", "d", "e" ], + [ "a", "d", "b", "c", "e" ], + [ "a", "c", "b", "d", "e" ], + [ "a", "d", "c", "b", "e" ], + [ "a", "c", "d", "b", "e" ], + [ "a", "b", "d", "e", "c" ], + [ "a", "d", "b", "e", "c" ], + [ "a", "b", "e", "d", "c" ], + [ "a", "e", "b", "d", "c" ], + [ "a", "d", "e", "b", "c" ], + [ "a", "e", "d", "b", "c" ], + [ "a", "b", "c", "e", "d" ], + [ "a", "c", "b", "e", "d" ], + [ "a", "b", "e", "c", "d" ], + [ "a", "e", "b", "c", "d" ], + [ "a", "c", "e", "b", "d" ], + [ "a", "e", "c", "b", "d" ], + ]; + + let mut fail = true; + 'sequences: for sequence in expected_one_of + { + for index in 0 .. 5 + { + if *queue[ index ] != sequence[ index ].to_string().into() { continue 'sequences; } + } + fail = false; + break; + } + assert!( !fail ); +} + // use super::*; // use the_module:: // { diff --git a/module/move/willbe/tests/inc/tool/graph_test.rs b/module/move/willbe/tests/inc/tool/graph_test.rs index d6f5c38986..0ad57fa024 100644 --- a/module/move/willbe/tests/inc/tool/graph_test.rs +++ b/module/move/willbe/tests/inc/tool/graph_test.rs @@ -1,8 +1,9 @@ use super::*; -use the_module::*; -use graph::toposort; -use collection::HashMap; +// qqq : for Bohdan : bad. don't import the_module::* +// use the_module::*; +use the_module::graph::toposort; +use test_tools::collection::HashMap; use petgraph::Graph; use willbe::graph::topological_sort_with_grouping; diff --git a/module/move/wplot/License b/module/move/wplot/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/move/wplot/License +++ b/module/move/wplot/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/move/wplot/src/plot/abs/change.rs b/module/move/wplot/src/plot/abs/change.rs index 660a54e108..ad2a0219a2 100644 --- a/module/move/wplot/src/plot/abs/change.rs +++ b/module/move/wplot/src/plot/abs/change.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/wplot/src/plot/abs/changer.rs b/module/move/wplot/src/plot/abs/changer.rs index 3315e82b38..9c91ad95c2 100644 --- a/module/move/wplot/src/plot/abs/changer.rs +++ b/module/move/wplot/src/plot/abs/changer.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/wplot/src/plot/abs/context.rs b/module/move/wplot/src/plot/abs/context.rs index c666e3edca..a27efc6748 100644 --- a/module/move/wplot/src/plot/abs/context.rs +++ b/module/move/wplot/src/plot/abs/context.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. #[ cfg( not( feature = "no_std" ) ) ] mod private { diff --git a/module/move/wplot/src/plot/abs/identity.rs b/module/move/wplot/src/plot/abs/identity.rs index 48d9c0426a..9abecc7727 100644 --- a/module/move/wplot/src/plot/abs/identity.rs +++ b/module/move/wplot/src/plot/abs/identity.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. #[ cfg( not( feature = "no_std" ) ) ] mod private { diff --git a/module/move/wplot/src/plot/abs/registry.rs b/module/move/wplot/src/plot/abs/registry.rs index 026c0f5c20..c69f775dca 100644 --- a/module/move/wplot/src/plot/abs/registry.rs +++ b/module/move/wplot/src/plot/abs/registry.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. #[ cfg( not( feature = "no_std" ) ) ] mod private { diff --git a/module/move/wplot/src/plot/color.rs b/module/move/wplot/src/plot/color.rs index 5cf94b95c8..3ae327c824 100644 --- a/module/move/wplot/src/plot/color.rs +++ b/module/move/wplot/src/plot/color.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/context.rs b/module/move/wplot/src/plot/sys/context.rs index a59ae6343d..19bd3ce2a9 100644 --- a/module/move/wplot/src/plot/sys/context.rs +++ b/module/move/wplot/src/plot/sys/context.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::abs::registry::private::Registry; diff --git a/module/move/wplot/src/plot/sys/context_changer.rs b/module/move/wplot/src/plot/sys/context_changer.rs index e6a91ca8e5..c0f1df3442 100644 --- a/module/move/wplot/src/plot/sys/context_changer.rs +++ b/module/move/wplot/src/plot/sys/context_changer.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/drawing.rs b/module/move/wplot/src/plot/sys/drawing.rs index 673fd1fa74..9e668966be 100644 --- a/module/move/wplot/src/plot/sys/drawing.rs +++ b/module/move/wplot/src/plot/sys/drawing.rs @@ -1,6 +1,6 @@ pub(crate) mod changer; -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/drawing/change_new.rs b/module/move/wplot/src/plot/sys/drawing/change_new.rs index ab075de7fa..f7628c2566 100644 --- a/module/move/wplot/src/plot/sys/drawing/change_new.rs +++ b/module/move/wplot/src/plot/sys/drawing/change_new.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/drawing/changer.rs b/module/move/wplot/src/plot/sys/drawing/changer.rs index a7ba4c1b67..84c69db2c3 100644 --- a/module/move/wplot/src/plot/sys/drawing/changer.rs +++ b/module/move/wplot/src/plot/sys/drawing/changer.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/drawing/command.rs b/module/move/wplot/src/plot/sys/drawing/command.rs index f98cedfd22..998272ee16 100644 --- a/module/move/wplot/src/plot/sys/drawing/command.rs +++ b/module/move/wplot/src/plot/sys/drawing/command.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/drawing/queue.rs b/module/move/wplot/src/plot/sys/drawing/queue.rs index c68de594ba..c3148011bb 100644 --- a/module/move/wplot/src/plot/sys/drawing/queue.rs +++ b/module/move/wplot/src/plot/sys/drawing/queue.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/drawing/rect_change_new.rs b/module/move/wplot/src/plot/sys/drawing/rect_change_new.rs index 212ffb82c1..b682c0ead8 100644 --- a/module/move/wplot/src/plot/sys/drawing/rect_change_new.rs +++ b/module/move/wplot/src/plot/sys/drawing/rect_change_new.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/drawing/rect_change_region.rs b/module/move/wplot/src/plot/sys/drawing/rect_change_region.rs index 463259b6cf..29b6885e63 100644 --- a/module/move/wplot/src/plot/sys/drawing/rect_change_region.rs +++ b/module/move/wplot/src/plot/sys/drawing/rect_change_region.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/drawing/rect_changer.rs b/module/move/wplot/src/plot/sys/drawing/rect_changer.rs index bb25c465aa..7e39fb06fc 100644 --- a/module/move/wplot/src/plot/sys/drawing/rect_changer.rs +++ b/module/move/wplot/src/plot/sys/drawing/rect_changer.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/stroke_brush.rs b/module/move/wplot/src/plot/sys/stroke_brush.rs index 78ad289dc7..9f52539630 100644 --- a/module/move/wplot/src/plot/sys/stroke_brush.rs +++ b/module/move/wplot/src/plot/sys/stroke_brush.rs @@ -1,7 +1,7 @@ mod change_width; mod change_new; -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/stroke_brush/change_color.rs b/module/move/wplot/src/plot/sys/stroke_brush/change_color.rs index ae615f89a4..76bd951613 100644 --- a/module/move/wplot/src/plot/sys/stroke_brush/change_color.rs +++ b/module/move/wplot/src/plot/sys/stroke_brush/change_color.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/stroke_brush/change_new.rs b/module/move/wplot/src/plot/sys/stroke_brush/change_new.rs index 077f20f6ba..4e70ba7ee7 100644 --- a/module/move/wplot/src/plot/sys/stroke_brush/change_new.rs +++ b/module/move/wplot/src/plot/sys/stroke_brush/change_new.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/stroke_brush/change_width.rs b/module/move/wplot/src/plot/sys/stroke_brush/change_width.rs index cf5a548778..a7fcecdcb8 100644 --- a/module/move/wplot/src/plot/sys/stroke_brush/change_width.rs +++ b/module/move/wplot/src/plot/sys/stroke_brush/change_width.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/stroke_brush/changer.rs b/module/move/wplot/src/plot/sys/stroke_brush/changer.rs index 407b234fac..152dfebaab 100644 --- a/module/move/wplot/src/plot/sys/stroke_brush/changer.rs +++ b/module/move/wplot/src/plot/sys/stroke_brush/changer.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::own::*; diff --git a/module/move/wplot/src/plot/sys/target.rs b/module/move/wplot/src/plot/sys/target.rs index 58634c4e36..95d123186b 100644 --- a/module/move/wplot/src/plot/sys/target.rs +++ b/module/move/wplot/src/plot/sys/target.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::prelude::*; diff --git a/module/postponed/_video_experiment/License b/module/postponed/_video_experiment/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/postponed/_video_experiment/License +++ b/module/postponed/_video_experiment/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/postponed/automata_tools/License b/module/postponed/automata_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/postponed/automata_tools/License +++ b/module/postponed/automata_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/postponed/non_std/Cargo.toml b/module/postponed/non_std/Cargo.toml index 516d197d99..1f684f13cb 100644 --- a/module/postponed/non_std/Cargo.toml +++ b/module/postponed/non_std/Cargo.toml @@ -72,7 +72,7 @@ meta_default = [ "meta_mod_interface", # "meta_former", # "meta_options", - "meta_constructors", + #"meta_constructors", "meta_idents_concat", ] meta_full = [ @@ -82,7 +82,7 @@ meta_full = [ "meta_mod_interface", # "meta_former", # "meta_options", - "meta_constructors", + #"meta_constructors", "meta_idents_concat", ] meta_no_std = [ "wtools/meta_no_std" ] diff --git a/module/postponed/non_std/License b/module/postponed/non_std/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/postponed/non_std/License +++ b/module/postponed/non_std/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/postponed/std_tools/Cargo.toml b/module/postponed/std_tools/Cargo.toml index 44d29afa00..928fe93678 100644 --- a/module/postponed/std_tools/Cargo.toml +++ b/module/postponed/std_tools/Cargo.toml @@ -73,7 +73,7 @@ meta_default = [ "meta_mod_interface", # "meta_former", # "meta_options", - "meta_constructors", + #"meta_constructors", "meta_idents_concat", ] meta_full = [ @@ -83,7 +83,7 @@ meta_full = [ "meta_mod_interface", # "meta_former", # "meta_options", - "meta_constructors", + #"meta_constructors", "meta_idents_concat", ] meta_no_std = [ "wtools/meta_no_std" ] diff --git a/module/postponed/std_tools/License b/module/postponed/std_tools/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/postponed/std_tools/License +++ b/module/postponed/std_tools/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/postponed/std_x/Cargo.toml b/module/postponed/std_x/Cargo.toml index 5693aa40a1..2ee0a6f55c 100644 --- a/module/postponed/std_x/Cargo.toml +++ b/module/postponed/std_x/Cargo.toml @@ -75,7 +75,7 @@ meta_default = [ "meta_mod_interface", # "meta_former", # "meta_options", - "meta_constructors", + #"meta_constructors", "meta_idents_concat", ] meta_full = [ @@ -85,7 +85,7 @@ meta_full = [ "meta_mod_interface", # "meta_former", # "meta_options", - "meta_constructors", + #"meta_constructors", "meta_idents_concat", ] meta_no_std = [ "wtools/meta_no_std" ] diff --git a/module/postponed/std_x/License b/module/postponed/std_x/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/postponed/std_x/License +++ b/module/postponed/std_x/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/postponed/type_constructor/License b/module/postponed/type_constructor/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/postponed/type_constructor/License +++ b/module/postponed/type_constructor/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/postponed/type_constructor/src/type_constuctor/enumerable.rs b/module/postponed/type_constructor/src/type_constuctor/enumerable.rs index e17553d21c..fdfa45fb97 100644 --- a/module/postponed/type_constructor/src/type_constuctor/enumerable.rs +++ b/module/postponed/type_constructor/src/type_constuctor/enumerable.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/postponed/type_constructor/src/type_constuctor/helper.rs b/module/postponed/type_constructor/src/type_constuctor/helper.rs index 57c9986a69..a4dcf9011f 100644 --- a/module/postponed/type_constructor/src/type_constuctor/helper.rs +++ b/module/postponed/type_constructor/src/type_constuctor/helper.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::exposed::*; diff --git a/module/postponed/type_constructor/src/type_constuctor/make.rs b/module/postponed/type_constructor/src/type_constuctor/make.rs index 807974a4ca..2cdb6d6973 100644 --- a/module/postponed/type_constructor/src/type_constuctor/make.rs +++ b/module/postponed/type_constructor/src/type_constuctor/make.rs @@ -1,4 +1,4 @@ -// /// Internal namespace. +// /// Define a private namespace for all its items. // #[ cfg( feature = "make" ) ] // mod private // { diff --git a/module/postponed/type_constructor/src/type_constuctor/many.rs b/module/postponed/type_constructor/src/type_constuctor/many.rs index 0c81d87180..3ded63125c 100644 --- a/module/postponed/type_constructor/src/type_constuctor/many.rs +++ b/module/postponed/type_constructor/src/type_constuctor/many.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::exposed::*; diff --git a/module/postponed/type_constructor/src/type_constuctor/no_many.rs b/module/postponed/type_constructor/src/type_constuctor/no_many.rs index a36e9829ef..d810f74d08 100644 --- a/module/postponed/type_constructor/src/type_constuctor/no_many.rs +++ b/module/postponed/type_constructor/src/type_constuctor/no_many.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/postponed/type_constructor/src/type_constuctor/pair.rs b/module/postponed/type_constructor/src/type_constuctor/pair.rs index 090428e500..56b71bc2ff 100644 --- a/module/postponed/type_constructor/src/type_constuctor/pair.rs +++ b/module/postponed/type_constructor/src/type_constuctor/pair.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::exposed::*; diff --git a/module/postponed/type_constructor/src/type_constuctor/single.rs b/module/postponed/type_constructor/src/type_constuctor/single.rs index 7fcf8642f4..2fd3637235 100644 --- a/module/postponed/type_constructor/src/type_constuctor/single.rs +++ b/module/postponed/type_constructor/src/type_constuctor/single.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::exposed::*; diff --git a/module/postponed/type_constructor/src/type_constuctor/traits.rs b/module/postponed/type_constructor/src/type_constuctor/traits.rs index cd11c438ee..cf4838bee3 100644 --- a/module/postponed/type_constructor/src/type_constuctor/traits.rs +++ b/module/postponed/type_constructor/src/type_constuctor/traits.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/postponed/type_constructor/src/type_constuctor/types.rs b/module/postponed/type_constructor/src/type_constuctor/types.rs index 151b33ae42..d9d1de235a 100644 --- a/module/postponed/type_constructor/src/type_constuctor/types.rs +++ b/module/postponed/type_constructor/src/type_constuctor/types.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::exposed::*; diff --git a/module/postponed/type_constructor/src/type_constuctor/vectorized_from.rs b/module/postponed/type_constructor/src/type_constuctor/vectorized_from.rs index c7e366142a..c145e31404 100644 --- a/module/postponed/type_constructor/src/type_constuctor/vectorized_from.rs +++ b/module/postponed/type_constructor/src/type_constuctor/vectorized_from.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { diff --git a/module/postponed/type_constructor/tests/inc/mod.rs b/module/postponed/type_constructor/tests/inc/mod.rs index 199b42411a..da4554b46e 100644 --- a/module/postponed/type_constructor/tests/inc/mod.rs +++ b/module/postponed/type_constructor/tests/inc/mod.rs @@ -8,8 +8,8 @@ use super::*; // mod type_constructor; #[ cfg( feature = "enabled" ) ] -#[ cfg( any( feature = "prelude", feature = "dt_prelude" ) ) ] -mod prelude_test; +// #[ cfg( any( feature = "prelude", feature = "dt_prelude" ) ) ] +// mod prelude_test; // #[ allow( unused_imports ) ] // use super::*; diff --git a/module/postponed/type_constructor/tests/inc/prelude_test.rs b/module/postponed/type_constructor/tests/inc/prelude_test.rs index 4c6ace0d4b..1699fe6b0e 100644 --- a/module/postponed/type_constructor/tests/inc/prelude_test.rs +++ b/module/postponed/type_constructor/tests/inc/prelude_test.rs @@ -1,68 +1,68 @@ -#[ allow( unused_imports ) ] -use super::*; - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ cfg( feature = "prelude" ) ] -tests_impls! -{ - fn basic() - { - use the_module::prelude::*; - - /* test.case( "Vec" ) */ - let src = Vec::< i32 >::new(); - a_true!( src.is_empty() ); - - /* test.case( "DynList" ) */ - let src = DynList::< i32 >::new(); - a_true!( src.is_empty() ); - - /* test.case( "HashMap" ) */ - let src = HashMap::< i32, i32 >::new(); - a_true!( src.is_empty() ); - - /* test.case( "Map" ) */ - let src = Map::< i32, i32 >::new(); - a_true!( src.is_empty() ); - - /* test.case( "HashSet" ) */ - let src = HashSet::< i32 >::new(); - a_true!( src.is_empty() ); - - /* test.case( "Set" ) */ - let src = Set::< i32 >::new(); - a_true!( src.is_empty() ); - - /* test.case( "BTreeMap" ) */ - let src = BTreeMap::< i32, i32 >::new(); - a_true!( src.is_empty() ); - - /* test.case( "BTreeSet" ) */ - let src = BTreeSet::< i32 >::new(); - a_true!( src.is_empty() ); - - /* test.case( "BinaryHeap" ) */ - let src = BinaryHeap::< i32 >::new(); - a_true!( src.is_empty() ); - - /* test.case( "LinkedList" ) */ - let src = LinkedList::< i32 >::new(); - a_true!( src.is_empty() ); - - /* test.case( "VecDeque" ) */ - let src = VecDeque::< i32 >::new(); - a_true!( src.is_empty() ); - - } -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ cfg( feature = "prelude" ) ] -tests_index! -{ - basic, -} +// #[ allow( unused_imports ) ] +// use super::*; +// +// // +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// #[ cfg( feature = "prelude" ) ] +// tests_impls! +// { +// fn basic() +// { +// use the_module::prelude::*; +// +// /* test.case( "Vec" ) */ +// let src = Vec::< i32 >::new(); +// a_true!( src.is_empty() ); +// +// /* test.case( "DynList" ) */ +// let src = DynList::< i32 >::new(); +// a_true!( src.is_empty() ); +// +// /* test.case( "HashMap" ) */ +// let src = HashMap::< i32, i32 >::new(); +// a_true!( src.is_empty() ); +// +// /* test.case( "Map" ) */ +// let src = Map::< i32, i32 >::new(); +// a_true!( src.is_empty() ); +// +// /* test.case( "HashSet" ) */ +// let src = HashSet::< i32 >::new(); +// a_true!( src.is_empty() ); +// +// /* test.case( "Set" ) */ +// let src = Set::< i32 >::new(); +// a_true!( src.is_empty() ); +// +// /* test.case( "BTreeMap" ) */ +// let src = BTreeMap::< i32, i32 >::new(); +// a_true!( src.is_empty() ); +// +// /* test.case( "BTreeSet" ) */ +// let src = BTreeSet::< i32 >::new(); +// a_true!( src.is_empty() ); +// +// /* test.case( "BinaryHeap" ) */ +// let src = BinaryHeap::< i32 >::new(); +// a_true!( src.is_empty() ); +// +// /* test.case( "LinkedList" ) */ +// let src = LinkedList::< i32 >::new(); +// a_true!( src.is_empty() ); +// +// /* test.case( "VecDeque" ) */ +// let src = VecDeque::< i32 >::new(); +// a_true!( src.is_empty() ); +// +// } +// } +// +// // +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// #[ cfg( feature = "prelude" ) ] +// tests_index! +// { +// basic, +// } diff --git a/module/postponed/wautomata/License b/module/postponed/wautomata/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/postponed/wautomata/License +++ b/module/postponed/wautomata/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/postponed/wautomata/src/graph/abs/edge.rs b/module/postponed/wautomata/src/graph/abs/edge.rs index 550a350efb..214f8f10d9 100644 --- a/module/postponed/wautomata/src/graph/abs/edge.rs +++ b/module/postponed/wautomata/src/graph/abs/edge.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/postponed/wautomata/src/graph/abs/factory.rs b/module/postponed/wautomata/src/graph/abs/factory.rs index 737cbfdf5c..ddf6012168 100644 --- a/module/postponed/wautomata/src/graph/abs/factory.rs +++ b/module/postponed/wautomata/src/graph/abs/factory.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/postponed/wautomata/src/graph/abs/id_generator.rs b/module/postponed/wautomata/src/graph/abs/id_generator.rs index 943315c041..2090439804 100644 --- a/module/postponed/wautomata/src/graph/abs/id_generator.rs +++ b/module/postponed/wautomata/src/graph/abs/id_generator.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::prelude::*; diff --git a/module/postponed/wautomata/src/graph/abs/identity.rs b/module/postponed/wautomata/src/graph/abs/identity.rs index c7fdcb3797..1e9c21d2f9 100644 --- a/module/postponed/wautomata/src/graph/abs/identity.rs +++ b/module/postponed/wautomata/src/graph/abs/identity.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { // use crate::prelude::*; diff --git a/module/postponed/wautomata/src/graph/abs/node.rs b/module/postponed/wautomata/src/graph/abs/node.rs index b227581718..703bd0893d 100644 --- a/module/postponed/wautomata/src/graph/abs/node.rs +++ b/module/postponed/wautomata/src/graph/abs/node.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/postponed/wautomata/src/graph/algo/dfs.rs b/module/postponed/wautomata/src/graph/algo/dfs.rs index 0a75884e2c..13e7c81e84 100644 --- a/module/postponed/wautomata/src/graph/algo/dfs.rs +++ b/module/postponed/wautomata/src/graph/algo/dfs.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/postponed/wautomata/src/graph/canonical/edge.rs b/module/postponed/wautomata/src/graph/canonical/edge.rs index 3bf782aaee..4d02b207d4 100644 --- a/module/postponed/wautomata/src/graph/canonical/edge.rs +++ b/module/postponed/wautomata/src/graph/canonical/edge.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/postponed/wautomata/src/graph/canonical/factory_generative.rs b/module/postponed/wautomata/src/graph/canonical/factory_generative.rs index 766002bfb3..0548aa26c5 100644 --- a/module/postponed/wautomata/src/graph/canonical/factory_generative.rs +++ b/module/postponed/wautomata/src/graph/canonical/factory_generative.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/postponed/wautomata/src/graph/canonical/factory_readable.rs b/module/postponed/wautomata/src/graph/canonical/factory_readable.rs index d9505b7819..1cad2804dd 100644 --- a/module/postponed/wautomata/src/graph/canonical/factory_readable.rs +++ b/module/postponed/wautomata/src/graph/canonical/factory_readable.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/postponed/wautomata/src/graph/canonical/identity.rs b/module/postponed/wautomata/src/graph/canonical/identity.rs index 497da5ff54..6680ead861 100644 --- a/module/postponed/wautomata/src/graph/canonical/identity.rs +++ b/module/postponed/wautomata/src/graph/canonical/identity.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/postponed/wautomata/src/graph/canonical/node.rs b/module/postponed/wautomata/src/graph/canonical/node.rs index 94d7f7d313..ce0aa547bd 100644 --- a/module/postponed/wautomata/src/graph/canonical/node.rs +++ b/module/postponed/wautomata/src/graph/canonical/node.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use crate::prelude::*; diff --git a/module/postponed/wpublisher/License b/module/postponed/wpublisher/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/postponed/wpublisher/License +++ b/module/postponed/wpublisher/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/step/meta/src/module/terminal.rs b/module/step/meta/src/module/terminal.rs index 93289921c5..4a88acf6a9 100644 --- a/module/step/meta/src/module/terminal.rs +++ b/module/step/meta/src/module/terminal.rs @@ -1,4 +1,6 @@ +/// Mechanism to include tests only to terminal crate. +/// It exclude code in terminal module ( crate ), but include for aggregating module ( crate ). #[ macro_export ] macro_rules! only_for_terminal_module { @@ -8,6 +10,8 @@ macro_rules! only_for_terminal_module }; } +/// Mechanism to include tests only to aggregating crate. +/// It exclude code in terminal module ( crate ), but include for aggregating module ( crate ). #[ macro_export ] macro_rules! only_for_aggregating_module { diff --git a/module/step/meta/tests/_conditional/local_module.rs b/module/step/meta/tests/_conditional/local_module.rs index 93289921c5..4a88acf6a9 100644 --- a/module/step/meta/tests/_conditional/local_module.rs +++ b/module/step/meta/tests/_conditional/local_module.rs @@ -1,4 +1,6 @@ +/// Mechanism to include tests only to terminal crate. +/// It exclude code in terminal module ( crate ), but include for aggregating module ( crate ). #[ macro_export ] macro_rules! only_for_terminal_module { @@ -8,6 +10,8 @@ macro_rules! only_for_terminal_module }; } +/// Mechanism to include tests only to aggregating crate. +/// It exclude code in terminal module ( crate ), but include for aggregating module ( crate ). #[ macro_export ] macro_rules! only_for_aggregating_module { diff --git a/module/step/meta/tests/_conditional/wtools.rs b/module/step/meta/tests/_conditional/wtools.rs index e6bb553f35..ba669c790d 100644 --- a/module/step/meta/tests/_conditional/wtools.rs +++ b/module/step/meta/tests/_conditional/wtools.rs @@ -1,4 +1,6 @@ +/// Mechanism to include tests only to terminal crate. +/// It exclude code in terminal module ( crate ), but include for aggregating module ( crate ). #[ macro_export ] macro_rules! only_for_terminal_module { @@ -7,6 +9,8 @@ macro_rules! only_for_terminal_module } } +/// Mechanism to include tests only to aggregating crate. +/// It exclude code in terminal module ( crate ), but include for aggregating module ( crate ). #[ macro_export ] macro_rules! only_for_aggregating_module { diff --git a/module/template/layer/layer.rs b/module/template/layer/layer.rs index 45d766e897..b4b8322d92 100644 --- a/module/template/layer/layer.rs +++ b/module/template/layer/layer.rs @@ -1,4 +1,4 @@ -/// Internal namespace. +/// Define a private namespace for all its items. mod private { use super::super::*; diff --git a/module/template/template_alias/License b/module/template/template_alias/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/template/template_alias/License +++ b/module/template/template_alias/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/template/template_blank/License b/module/template/template_blank/License index 6d5ef8559f..0804aed8e3 100644 --- a/module/template/template_blank/License +++ b/module/template/template_blank/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/template/template_procedural_macro/License b/module/template/template_procedural_macro/License index e3e9e057cf..c32986cee3 100644 --- a/module/template/template_procedural_macro/License +++ b/module/template/template_procedural_macro/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/template/template_procedural_macro_meta/License b/module/template/template_procedural_macro_meta/License index e3e9e057cf..c32986cee3 100644 --- a/module/template/template_procedural_macro_meta/License +++ b/module/template/template_procedural_macro_meta/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/module/template/template_procedural_macro_runtime/License b/module/template/template_procedural_macro_runtime/License index e3e9e057cf..c32986cee3 100644 --- a/module/template/template_procedural_macro_runtime/License +++ b/module/template/template_procedural_macro_runtime/License @@ -1,4 +1,4 @@ -Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 +Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/step/Cargo.toml b/step/Cargo.toml index 70f00c8c96..6e37d39bd0 100644 --- a/step/Cargo.toml +++ b/step/Cargo.toml @@ -21,4 +21,4 @@ all-features = false willbe = { workspace = true, features = [ "full" ] } [dev-dependencies] -test_tools = { workspace = true } +# test_tools = { workspace = true }