Compare commits
30 commits
Author | SHA1 | Date | |
---|---|---|---|
|
baec846f70 | ||
|
0412b22678 | ||
|
b28bd9fc2d | ||
b86b2adda9 | |||
|
e9cdd00a61 | ||
e29d2ea4d4 | |||
21ea6ee2f9 | |||
94f241596a | |||
6f56c691d5 | |||
13888a3f75 | |||
380b64b21f | |||
9c93a8bc75 | |||
d4e582fe2c | |||
8561bee50a | |||
0b2bd30279 | |||
d00f3337f9 | |||
885de22736 | |||
7e2cb47e19 | |||
c48543d5d3 | |||
6dc172d6a1 | |||
|
d2e0db259d | ||
|
62fe8fc56b | ||
a9b1eea294 | |||
48713e4e60 | |||
2c93e13230 | |||
96e7d4ebdd | |||
9dfe83119f | |||
7f2f8bdd5b | |||
64dd15fcb9 | |||
04f550d660 |
33 changed files with 1171 additions and 30 deletions
|
@ -16,21 +16,23 @@ jobs:
|
|||
release-plz:
|
||||
name: Release-plz
|
||||
runs-on: docker
|
||||
|
||||
container:
|
||||
image:
|
||||
git.kemitix.net/kemitix/rust:v4.0.1
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Run release-plz release-pr
|
||||
uses: https://git.kemitix.net/kemitix/rust@v2.5.0
|
||||
with:
|
||||
args: release-plz release-pr --backend gitea --git-token ${{ secrets.FORGEJO_TOKEN }}
|
||||
env:
|
||||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||
- name: Run release-plz release
|
||||
uses: https://git.kemitix.net/kemitix/rust@v2.5.0
|
||||
with:
|
||||
args: release-plz release --backend gitea --git-token ${{ secrets.FORGEJO_TOKEN }}
|
||||
run: release-plz release-pr --backend gitea --git-token ${{ secrets.FORGEJO_TOKEN }}
|
||||
env:
|
||||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||
|
||||
- name: Run release-plz release
|
||||
run: release-plz release --backend gitea --git-token ${{ secrets.FORGEJO_TOKEN }}
|
||||
env:
|
||||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||
|
|
|
@ -16,6 +16,10 @@ jobs:
|
|||
build:
|
||||
runs-on: docker
|
||||
|
||||
container:
|
||||
image:
|
||||
git.kemitix.net/kemitix/rust:v4.0.1
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
toolchain:
|
||||
|
@ -26,36 +30,27 @@ jobs:
|
|||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Ignored Files
|
||||
run: check-for-ignored
|
||||
|
||||
- name: Check TODOs
|
||||
uses: kemitix/todo-checker@v1.1.0
|
||||
uses: https://git.kemitix.net/kemitix/forgejo-todo-checker@v1.3.0
|
||||
|
||||
- name: Machete
|
||||
uses: https://git.kemitix.net/kemitix/rust@v2.5.0
|
||||
with:
|
||||
args: ${{ matrix.toolchain.name }} cargo machete
|
||||
run: cargo +${{ matrix.toolchain.name }} machete
|
||||
|
||||
- name: Format
|
||||
uses: https://git.kemitix.net/kemitix/rust@v2.5.0
|
||||
with:
|
||||
args: ${{ matrix.toolchain.name }} cargo fmt --all -- --check
|
||||
run: cargo +${{ matrix.toolchain.name }} fmt --all --check
|
||||
|
||||
- name: Clippy
|
||||
uses: https://git.kemitix.net/kemitix/rust@v2.5.0
|
||||
with:
|
||||
args: ${{ matrix.toolchain.name }} cargo hack --feature-powerset clippy
|
||||
run: cargo +${{ matrix.toolchain.name }} hack --feature-powerset clippy
|
||||
|
||||
- name: Build
|
||||
uses: https://git.kemitix.net/kemitix/rust@v2.5.0
|
||||
with:
|
||||
args: ${{ matrix.toolchain.name }} cargo hack --feature-powerset build
|
||||
run: cargo +${{ matrix.toolchain.name }} hack --feature-powerset build
|
||||
|
||||
- name: Test
|
||||
uses: https://git.kemitix.net/kemitix/rust@v2.5.0
|
||||
with:
|
||||
args: ${{ matrix.toolchain.name }} cargo hack --feature-powerset test
|
||||
run: cargo +${{ matrix.toolchain.name }} hack --feature-powerset test
|
||||
|
||||
- name: Mutations
|
||||
uses: https://git.kemitix.net/kemitix/rust@v2.5.0
|
||||
with:
|
||||
args: ${{ matrix.toolchain.name }} cargo mutants -vV --in-place
|
||||
run: cargo +${{ matrix.toolchain.name }} mutants -vV --in-place
|
||||
|
||||
|
|
14
Cargo.toml
14
Cargo.toml
|
@ -7,4 +7,18 @@ description = "Common utils incubator"
|
|||
license = "MIT"
|
||||
repository = "https://git.kemitix.net/kemitix/kx-utils"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
use-kameo = ["kameo", "tracing", "tokio"]
|
||||
use-kxio = ["kxio"]
|
||||
|
||||
[dependencies]
|
||||
derive_more = { version = "1.0", features = ["as_ref", "constructor", "deref", "display", "from"] }
|
||||
kxio = { version = "5.0", optional = true }
|
||||
kameo = { version = "0.14", optional = true }
|
||||
tracing = { version = "0.1", optional = true }
|
||||
serde = { version = "1.0" , features = ["derive"]}
|
||||
tokio = { version = "1.43", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1.0"
|
||||
|
|
16
README.md
Normal file
16
README.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# kx-utils
|
||||
|
||||
A personal Rust library to incubate various utilities while
|
||||
they are developed and used before potentially migrating to
|
||||
another crate.
|
||||
|
||||
```bash
|
||||
cargo add kx_utils --features use-kameo use-kxio
|
||||
```
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
kx_utils = { version = "0.1", features = ["use-kameo", "use-kxio"] }
|
||||
```
|
||||
|
||||
See [docs](https://docs.rs/kx_utils) for documentation on this crate.
|
6
justfile
6
justfile
|
@ -8,8 +8,10 @@ build:
|
|||
cargo machete
|
||||
# cargo build
|
||||
cargo tarpaulin --engine llvm --tests --line --skip-clean --out Html Lcov
|
||||
# cargo llvm-cov --html --tests
|
||||
# rm *.profraw
|
||||
cargo llvm-cov --html --tests
|
||||
if test -f *.profraw ; then
|
||||
for RAW in *.profraw ; do rm $RAW ; done
|
||||
fi
|
||||
# cargo test
|
||||
# cargo doc
|
||||
# cargo test --example get
|
||||
|
|
22
lcov.info
22
lcov.info
|
@ -0,0 +1,22 @@
|
|||
TN:
|
||||
SF:/Volumes/workplace/projects/kx-utils/src/experimental/to_string.rs
|
||||
FN:7,s
|
||||
FNF:1
|
||||
FNDA:0,s
|
||||
DA:7,0
|
||||
DA:8,0
|
||||
LF:2
|
||||
LH:0
|
||||
end_of_record
|
||||
TN:
|
||||
SF:/Volumes/workplace/projects/kx-utils/src/newtype.rs
|
||||
FNF:0
|
||||
DA:37,9
|
||||
DA:38,9
|
||||
DA:42,1
|
||||
DA:43,1
|
||||
DA:47,0
|
||||
DA:48,0
|
||||
LF:6
|
||||
LH:4
|
||||
end_of_record
|
2
mutants.out/caught.txt
Normal file
2
mutants.out/caught.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
src/experimental/to_string.rs:6:5: replace s -> String with String::new()
|
||||
src/experimental/to_string.rs:6:5: replace s -> String with "xyzzy".into()
|
40
mutants.out/debug.log
Normal file
40
mutants.out/debug.log
Normal file
|
@ -0,0 +1,40 @@
|
|||
0.068595833s DEBUG cargo_mutants::copy_tree: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/copy_tree.rs:61: walk_builder=WalkBuilder { paths: ["/Volumes/workplace/projects/kx-utils"], ig_builder: IgnoreBuilder { dir: "", overrides: Override(Gitignore { set: GlobSet { len: 0, strats: [] }, root: "", globs: [], num_ignores: 0, num_whitelists: 0, matches: None }), types: Types { defs: [], selections: [], has_selected: false, glob_to_selection: [], set: GlobSet { len: 0, strats: [] }, matches: Pool(Pool { stacks: [CacheLine(Mutex { data: [], poisoned: false, .. }), CacheLine(Mutex { data: [], poisoned: false, .. }), CacheLine(Mutex { data: [], poisoned: false, .. }), CacheLine(Mutex { data: [], poisoned: false, .. }), CacheLine(Mutex { data: [], poisoned: false, .. }), CacheLine(Mutex { data: [], poisoned: false, .. }), CacheLine(Mutex { data: [], poisoned: false, .. }), CacheLine(Mutex { data: [], poisoned: false, .. })], owner: 0, owner_val: UnsafeCell { .. } }) }, explicit_ignores: [], custom_ignore_filenames: [], opts: IgnoreOptions { hidden: false, ignore: false, parents: true, git_global: true, git_ignore: true, git_exclude: true, ignore_case_insensitive: false, require_git: true } }, max_depth: None, max_filesize: None, follow_links: false, threads: 0, skip: None }
|
||||
0.069747167s DEBUG ignore::gitignore: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ignore-0.4.23/src/gitignore.rs:393: opened gitignore file: /Volumes/workplace/projects/kx-utils/.gitignore
|
||||
0.069811042s DEBUG globset: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/globset-0.4.15/src/lib.rs:453: built glob set; 4 literals, 1 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
|
||||
0.070098375s DEBUG ignore::gitignore: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ignore-0.4.23/src/gitignore.rs:393: opened gitignore file: /Volumes/workplace/projects/kx-utils/.git/info/exclude
|
||||
0.070220750s DEBUG ignore::walk: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ignore-0.4.23/src/walk.rs:1799: ignoring /Volumes/workplace/projects/kx-utils/default_8294860151924637757_0_48306.profraw: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Volumes/workplace/projects/kx-utils/.gitignore"), original: "*.profraw", actual: "**/*.profraw", is_whitelist: false, is_only_dir: false })))
|
||||
0.070238000s DEBUG ignore::walk: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ignore-0.4.23/src/walk.rs:1799: ignoring /Volumes/workplace/projects/kx-utils/Cargo.lock: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Volumes/workplace/projects/kx-utils/.gitignore"), original: "/Cargo.lock", actual: "Cargo.lock", is_whitelist: false, is_only_dir: false })))
|
||||
0.071286625s DEBUG ignore::walk: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ignore-0.4.23/src/walk.rs:1799: ignoring /Volumes/workplace/projects/kx-utils/target: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Volumes/workplace/projects/kx-utils/.gitignore"), original: "/target", actual: "target", is_whitelist: false, is_only_dir: false })))
|
||||
0.071319167s DEBUG ignore::walk: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ignore-0.4.23/src/walk.rs:1799: ignoring /Volumes/workplace/projects/kx-utils/default_8294860151924637757_0_48305.profraw: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Volumes/workplace/projects/kx-utils/.gitignore"), original: "*.profraw", actual: "**/*.profraw", is_whitelist: false, is_only_dir: false })))
|
||||
0.075786208s DEBUG ignore::walk: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ignore-0.4.23/src/walk.rs:1799: ignoring /Volumes/workplace/projects/kx-utils/tarpaulin-report.html: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Volumes/workplace/projects/kx-utils/.gitignore"), original: "/tarpaulin-report.html", actual: "tarpaulin-report.html", is_whitelist: false, is_only_dir: false })))
|
||||
0.079508500s DEBUG ignore::gitignore: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ignore-0.4.23/src/gitignore.rs:393: opened gitignore file: /Volumes/workplace/projects/kx-utils/.jj/.gitignore
|
||||
0.079544125s DEBUG globset: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/globset-0.4.15/src/lib.rs:448: glob converted to regex: Glob { glob: "*", re: "(?-u)^[^/]*$", opts: GlobOptions { case_insensitive: false, literal_separator: true, backslash_escape: true, empty_alternates: false }, tokens: Tokens([ZeroOrMore]) }
|
||||
0.079551708s DEBUG globset: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/globset-0.4.15/src/lib.rs:453: built glob set; 0 literals, 0 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 1 regexes
|
||||
0.082407542s DEBUG ignore::walk: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ignore-0.4.23/src/walk.rs:1799: ignoring /Volumes/workplace/projects/kx-utils/default_11387971333932778517_0_48306.profraw: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Volumes/workplace/projects/kx-utils/.gitignore"), original: "*.profraw", actual: "**/*.profraw", is_whitelist: false, is_only_dir: false })))
|
||||
0.085733625s DEBUG cargo_mutants::copy_tree: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/copy_tree.rs:104: Copied source tree total_bytes=6897 total_files=12 temp_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"
|
||||
0.086060375s DEBUG cargo_mutants::lab: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/lab.rs:55: starting jobserver n_tasks=10
|
||||
0.086475292s DEBUG cargo_mutants::lab: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/lab.rs:267: test_packages=Explicit([Package { name: "kx-utils", version: "0.1.0", relative_dir: "", top_sources: ["src/lib.rs"] }])
|
||||
0.086506792s DEBUG run{phase=Build}: cargo_mutants::process: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/process.rs:81: start process quoted_argv=/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo test --no-run --verbose --package=kx-utils@0.1.0
|
||||
2.414707583s DEBUG run{phase=Build}: cargo_mutants::cargo: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/cargo.rs:60: process_status=Success elapsed=2.328216584s
|
||||
2.414832125s DEBUG run{phase=Test}: cargo_mutants::process: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/process.rs:81: start process quoted_argv=/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo test --verbose --package=kx-utils@0.1.0
|
||||
3.207732542s DEBUG run{phase=Test}: cargo_mutants::cargo: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/cargo.rs:60: process_status=Success elapsed=792.935959ms
|
||||
3.208277542s DEBUG cargo_mutants::lab: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/lab.rs:318: outcome=Success
|
||||
3.208391292s INFO cargo_mutants::timeouts: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/timeouts.rs:66: Auto-set test timeout to 20s
|
||||
3.208422958s DEBUG cargo_mutants::lab: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/lab.rs:87: timeouts=Timeouts { build: None, test: Some(20s) }
|
||||
3.208521667s TRACE cargo_mutants::lab: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/lab.rs:99: start thread thread_id=ThreadId(3)
|
||||
3.209107583s DEBUG worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with String::new()"}: cargo_mutants::lab: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/lab.rs:267: test_packages=Explicit([Package { name: "kx-utils", version: "0.1.0", relative_dir: "", top_sources: ["src/lib.rs"] }])
|
||||
3.209480542s TRACE worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with String::new()"}: cargo_mutants::mutate: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/mutate.rs:192: Apply mutant self=Mutant { function: Some(Function { function_name: "s", return_type: "-> String", span: Span(4, 1, 7, 2) }), replacement: "String::new()", genre: FnValue, span: Span(6, 5, 6, 13), package_name: "kx-utils" }
|
||||
3.209895875s DEBUG worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with String::new()"}:run{phase=Build}: cargo_mutants::process: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/process.rs:81: start process quoted_argv=/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo test --no-run --verbose --package=kx-utils@0.1.0
|
||||
3.429110958s DEBUG worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with String::new()"}:run{phase=Build}: cargo_mutants::cargo: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/cargo.rs:60: process_status=Success elapsed=219.264291ms
|
||||
3.429179333s DEBUG worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with String::new()"}:run{phase=Test}: cargo_mutants::process: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/process.rs:81: start process quoted_argv=/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo test --verbose --package=kx-utils@0.1.0
|
||||
4.023179667s DEBUG worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with String::new()"}:run{phase=Test}: cargo_mutants::cargo: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/cargo.rs:60: process_status=Failure(101) elapsed=594.02875ms
|
||||
4.023441167s TRACE worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with String::new()"}: cargo_mutants::mutate: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/mutate.rs:197: Revert mutant self=Mutant { function: Some(Function { function_name: "s", return_type: "-> String", span: Span(4, 1, 7, 2) }), replacement: "String::new()", genre: FnValue, span: Span(6, 5, 6, 13), package_name: "kx-utils" }
|
||||
4.025507458s DEBUG worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with String::new()"}: cargo_mutants::lab: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/lab.rs:318: outcome=CaughtMutant
|
||||
4.026335958s DEBUG worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with \"xyzzy\".into()"}: cargo_mutants::lab: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/lab.rs:267: test_packages=Explicit([Package { name: "kx-utils", version: "0.1.0", relative_dir: "", top_sources: ["src/lib.rs"] }])
|
||||
4.026890167s TRACE worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with \"xyzzy\".into()"}: cargo_mutants::mutate: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/mutate.rs:192: Apply mutant self=Mutant { function: Some(Function { function_name: "s", return_type: "-> String", span: Span(4, 1, 7, 2) }), replacement: "\"xyzzy\".into()", genre: FnValue, span: Span(6, 5, 6, 13), package_name: "kx-utils" }
|
||||
4.029045042s DEBUG worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with \"xyzzy\".into()"}:run{phase=Build}: cargo_mutants::process: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/process.rs:81: start process quoted_argv=/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo test --no-run --verbose --package=kx-utils@0.1.0
|
||||
4.251897708s DEBUG worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with \"xyzzy\".into()"}:run{phase=Build}: cargo_mutants::cargo: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/cargo.rs:60: process_status=Success elapsed=222.934084ms
|
||||
4.252008208s DEBUG worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with \"xyzzy\".into()"}:run{phase=Test}: cargo_mutants::process: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/process.rs:81: start process quoted_argv=/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo test --verbose --package=kx-utils@0.1.0
|
||||
4.902286167s DEBUG worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with \"xyzzy\".into()"}:run{phase=Test}: cargo_mutants::cargo: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/cargo.rs:60: process_status=Failure(101) elapsed=650.303625ms
|
||||
4.902502208s TRACE worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with \"xyzzy\".into()"}: cargo_mutants::mutate: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/mutate.rs:197: Revert mutant self=Mutant { function: Some(Function { function_name: "s", return_type: "-> String", span: Span(4, 1, 7, 2) }), replacement: "\"xyzzy\".into()", genre: FnValue, span: Span(6, 5, 6, 13), package_name: "kx-utils" }
|
||||
4.904781292s DEBUG worker thread{build_dir="/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp"}:mutant{name="src/experimental/to_string.rs: replace s -> String with \"xyzzy\".into()"}: cargo_mutants::lab: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-mutants-25.0.0/src/lab.rs:318: outcome=CaughtMutant
|
|
@ -0,0 +1,18 @@
|
|||
--- src/experimental/to_string.rs
|
||||
+++ replace s -> String with String::new()
|
||||
@@ -1,14 +1,14 @@
|
||||
//
|
||||
#![allow(unused)]
|
||||
|
||||
/// Converts the parameter into a [String] using the [Into] trait.
|
||||
pub fn s(v: impl Into<String>) -> String {
|
||||
- v.into()
|
||||
+ String::new() /* ~ changed by cargo-mutants ~ */
|
||||
}
|
||||
|
||||
/// Converts the parameter into a [String] by calling `.to_string()`.
|
||||
#[macro_export]
|
||||
macro_rules! s {
|
||||
($value:expr) => {
|
||||
$value.to_string()
|
||||
};
|
|
@ -0,0 +1,18 @@
|
|||
--- src/experimental/to_string.rs
|
||||
+++ replace s -> String with "xyzzy".into()
|
||||
@@ -1,14 +1,14 @@
|
||||
//
|
||||
#![allow(unused)]
|
||||
|
||||
/// Converts the parameter into a [String] using the [Into] trait.
|
||||
pub fn s(v: impl Into<String>) -> String {
|
||||
- v.into()
|
||||
+ "xyzzy".into() /* ~ changed by cargo-mutants ~ */
|
||||
}
|
||||
|
||||
/// Converts the parameter into a [String] by calling `.to_string()`.
|
||||
#[macro_export]
|
||||
macro_rules! s {
|
||||
($value:expr) => {
|
||||
$value.to_string()
|
||||
};
|
6
mutants.out/lock.json
Normal file
6
mutants.out/lock.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"cargo_mutants_version": "25.0.0",
|
||||
"start_time": "2025-01-10T19:33:52.31986Z",
|
||||
"hostname": "bcd07498eccc",
|
||||
"username": "campbjpa"
|
||||
}
|
33
mutants.out/log/baseline.log
Normal file
33
mutants.out/log/baseline.log
Normal file
|
@ -0,0 +1,33 @@
|
|||
|
||||
*** baseline
|
||||
|
||||
*** /Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo test --no-run --verbose --package=kx-utils@0.1.0
|
||||
Updating crates.io index
|
||||
Locking 173 packages to latest compatible versions
|
||||
Compiling kx-utils v0.1.0 (/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp)
|
||||
Running `/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name kx_utils --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --cfg 'feature="default"' --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values("default", "kameo", "kxio", "tokio", "use-kameo", "use-kxio"))' -C metadata=b343ff8365c9a2e5 -C extra-filename=-b343ff8365c9a2e5 --out-dir /private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps -L dependency=/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps`
|
||||
Running `/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name kx_utils --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --test --cfg 'feature="default"' --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values("default", "kameo", "kxio", "tokio", "use-kameo", "use-kxio"))' -C metadata=a7cd675016a5a0c5 -C extra-filename=-a7cd675016a5a0c5 --out-dir /private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps -L dependency=/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps`
|
||||
Finished `test` profile [unoptimized + debuginfo] target(s) in 2.25s
|
||||
Executable `/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps/kx_utils-a7cd675016a5a0c5`
|
||||
|
||||
*** result: Success
|
||||
|
||||
*** /Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo test --verbose --package=kx-utils@0.1.0
|
||||
Fresh kx-utils v0.1.0 (/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp)
|
||||
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.03s
|
||||
Running `/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps/kx_utils-a7cd675016a5a0c5`
|
||||
|
||||
running 1 test
|
||||
test experimental::to_string::tests::s_converts_to_string ... ok
|
||||
|
||||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
|
||||
|
||||
Doc-tests kx_utils
|
||||
Running `/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustdoc --edition=2021 --crate-type lib --color auto --crate-name kx_utils --test src/lib.rs --test-run-directory /private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp -L dependency=/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps -L dependency=/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps --extern kx_utils=/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps/libkx_utils-b343ff8365c9a2e5.rlib -C embed-bitcode=no --cfg 'feature="default"' --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values("default", "kameo", "kxio", "tokio", "use-kameo", "use-kxio"))' --error-format human`
|
||||
|
||||
running 0 tests
|
||||
|
||||
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
|
||||
|
||||
|
||||
*** result: Success
|
|
@ -0,0 +1,60 @@
|
|||
|
||||
*** src/experimental/to_string.rs:6:5: replace s -> String with String::new()
|
||||
|
||||
*** mutation diff:
|
||||
--- src/experimental/to_string.rs
|
||||
+++ replace s -> String with String::new()
|
||||
@@ -1,14 +1,14 @@
|
||||
//
|
||||
#![allow(unused)]
|
||||
|
||||
/// Converts the parameter into a [String] using the [Into] trait.
|
||||
pub fn s(v: impl Into<String>) -> String {
|
||||
- v.into()
|
||||
+ String::new() /* ~ changed by cargo-mutants ~ */
|
||||
}
|
||||
|
||||
/// Converts the parameter into a [String] by calling `.to_string()`.
|
||||
#[macro_export]
|
||||
macro_rules! s {
|
||||
($value:expr) => {
|
||||
$value.to_string()
|
||||
};
|
||||
|
||||
|
||||
*** /Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo test --no-run --verbose --package=kx-utils@0.1.0
|
||||
Dirty kx-utils v0.1.0 (/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp): the file `src/experimental/to_string.rs` has changed (1736537635.464795042s, 1s after last build at 1736537634.431619659s)
|
||||
Compiling kx-utils v0.1.0 (/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp)
|
||||
Running `/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name kx_utils --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --test --cfg 'feature="default"' --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values("default", "kameo", "kxio", "tokio", "use-kameo", "use-kxio"))' -C metadata=a7cd675016a5a0c5 -C extra-filename=-a7cd675016a5a0c5 --out-dir /private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps -L dependency=/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps`
|
||||
Running `/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name kx_utils --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --cfg 'feature="default"' --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values("default", "kameo", "kxio", "tokio", "use-kameo", "use-kxio"))' -C metadata=b343ff8365c9a2e5 -C extra-filename=-b343ff8365c9a2e5 --out-dir /private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps -L dependency=/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps`
|
||||
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.16s
|
||||
Executable `/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps/kx_utils-a7cd675016a5a0c5`
|
||||
|
||||
*** result: Success
|
||||
|
||||
*** /Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo test --verbose --package=kx-utils@0.1.0
|
||||
Fresh kx-utils v0.1.0 (/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp)
|
||||
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.02s
|
||||
Running `/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps/kx_utils-a7cd675016a5a0c5`
|
||||
|
||||
running 1 test
|
||||
test experimental::to_string::tests::s_converts_to_string ... FAILED
|
||||
|
||||
failures:
|
||||
|
||||
---- experimental::to_string::tests::s_converts_to_string stdout ----
|
||||
thread 'experimental::to_string::tests::s_converts_to_string' panicked at src/experimental/to_string.rs:25:9:
|
||||
assertion `left == right` failed
|
||||
left: ""
|
||||
right: "123"
|
||||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
||||
|
||||
|
||||
failures:
|
||||
experimental::to_string::tests::s_converts_to_string
|
||||
|
||||
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
|
||||
|
||||
error: test failed, to rerun pass `-p kx-utils --lib`
|
||||
|
||||
*** result: Failure(101)
|
|
@ -0,0 +1,60 @@
|
|||
|
||||
*** src/experimental/to_string.rs:6:5: replace s -> String with "xyzzy".into()
|
||||
|
||||
*** mutation diff:
|
||||
--- src/experimental/to_string.rs
|
||||
+++ replace s -> String with "xyzzy".into()
|
||||
@@ -1,14 +1,14 @@
|
||||
//
|
||||
#![allow(unused)]
|
||||
|
||||
/// Converts the parameter into a [String] using the [Into] trait.
|
||||
pub fn s(v: impl Into<String>) -> String {
|
||||
- v.into()
|
||||
+ "xyzzy".into() /* ~ changed by cargo-mutants ~ */
|
||||
}
|
||||
|
||||
/// Converts the parameter into a [String] by calling `.to_string()`.
|
||||
#[macro_export]
|
||||
macro_rules! s {
|
||||
($value:expr) => {
|
||||
$value.to_string()
|
||||
};
|
||||
|
||||
|
||||
*** /Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo test --no-run --verbose --package=kx-utils@0.1.0
|
||||
Dirty kx-utils v0.1.0 (/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp): the file `src/experimental/to_string.rs` has changed (1736537636.283385525s, 1s after last build at 1736537635.522517927s)
|
||||
Compiling kx-utils v0.1.0 (/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp)
|
||||
Running `/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name kx_utils --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --test --cfg 'feature="default"' --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values("default", "kameo", "kxio", "tokio", "use-kameo", "use-kxio"))' -C metadata=a7cd675016a5a0c5 -C extra-filename=-a7cd675016a5a0c5 --out-dir /private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps -L dependency=/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps`
|
||||
Running `/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name kx_utils --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --cfg 'feature="default"' --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values("default", "kameo", "kxio", "tokio", "use-kameo", "use-kxio"))' -C metadata=b343ff8365c9a2e5 -C extra-filename=-b343ff8365c9a2e5 --out-dir /private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps -L dependency=/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps`
|
||||
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.16s
|
||||
Executable `/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps/kx_utils-a7cd675016a5a0c5`
|
||||
|
||||
*** result: Success
|
||||
|
||||
*** /Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo test --verbose --package=kx-utils@0.1.0
|
||||
Fresh kx-utils v0.1.0 (/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp)
|
||||
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.02s
|
||||
Running `/private/var/folders/0y/3lxyqsyd7gn7vywhmzkz50840000gq/T/cargo-mutants-kx-utils-sephjM.tmp/target/debug/deps/kx_utils-a7cd675016a5a0c5`
|
||||
|
||||
running 1 test
|
||||
test experimental::to_string::tests::s_converts_to_string ... FAILED
|
||||
|
||||
failures:
|
||||
|
||||
---- experimental::to_string::tests::s_converts_to_string stdout ----
|
||||
thread 'experimental::to_string::tests::s_converts_to_string' panicked at src/experimental/to_string.rs:25:9:
|
||||
assertion `left == right` failed
|
||||
left: "xyzzy"
|
||||
right: "123"
|
||||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
||||
|
||||
|
||||
failures:
|
||||
experimental::to_string::tests::s_converts_to_string
|
||||
|
||||
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
|
||||
|
||||
error: test failed, to rerun pass `-p kx-utils --lib`
|
||||
|
||||
*** result: Failure(101)
|
0
mutants.out/missed.txt
Normal file
0
mutants.out/missed.txt
Normal file
62
mutants.out/mutants.json
Normal file
62
mutants.out/mutants.json
Normal file
|
@ -0,0 +1,62 @@
|
|||
[
|
||||
{
|
||||
"package": "kx-utils",
|
||||
"file": "src/experimental/to_string.rs",
|
||||
"function": {
|
||||
"function_name": "s",
|
||||
"return_type": "-> String",
|
||||
"span": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 2
|
||||
}
|
||||
}
|
||||
},
|
||||
"span": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 13
|
||||
}
|
||||
},
|
||||
"replacement": "String::new()",
|
||||
"genre": "FnValue"
|
||||
},
|
||||
{
|
||||
"package": "kx-utils",
|
||||
"file": "src/experimental/to_string.rs",
|
||||
"function": {
|
||||
"function_name": "s",
|
||||
"return_type": "-> String",
|
||||
"span": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 2
|
||||
}
|
||||
}
|
||||
},
|
||||
"span": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 13
|
||||
}
|
||||
},
|
||||
"replacement": "\"xyzzy\".into()",
|
||||
"genre": "FnValue"
|
||||
}
|
||||
]
|
169
mutants.out/outcomes.json
Normal file
169
mutants.out/outcomes.json
Normal file
|
@ -0,0 +1,169 @@
|
|||
{
|
||||
"outcomes": [
|
||||
{
|
||||
"scenario": "Baseline",
|
||||
"summary": "Success",
|
||||
"log_path": "log/baseline.log",
|
||||
"diff_path": null,
|
||||
"phase_results": [
|
||||
{
|
||||
"phase": "Build",
|
||||
"duration": 2.328253875,
|
||||
"process_status": "Success",
|
||||
"argv": [
|
||||
"/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo",
|
||||
"test",
|
||||
"--no-run",
|
||||
"--verbose",
|
||||
"--package=kx-utils@0.1.0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"phase": "Test",
|
||||
"duration": 0.792992334,
|
||||
"process_status": "Success",
|
||||
"argv": [
|
||||
"/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo",
|
||||
"test",
|
||||
"--verbose",
|
||||
"--package=kx-utils@0.1.0"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"scenario": {
|
||||
"Mutant": {
|
||||
"package": "kx-utils",
|
||||
"file": "src/experimental/to_string.rs",
|
||||
"function": {
|
||||
"function_name": "s",
|
||||
"return_type": "-> String",
|
||||
"span": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 2
|
||||
}
|
||||
}
|
||||
},
|
||||
"span": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 13
|
||||
}
|
||||
},
|
||||
"replacement": "String::new()",
|
||||
"genre": "FnValue"
|
||||
}
|
||||
},
|
||||
"summary": "CaughtMutant",
|
||||
"log_path": "log/src__experimental__to_string.rs_line_6_col_5.log",
|
||||
"diff_path": "diff/src__experimental__to_string.rs_line_6_col_5.diff",
|
||||
"phase_results": [
|
||||
{
|
||||
"phase": "Build",
|
||||
"duration": 0.21928975,
|
||||
"process_status": "Success",
|
||||
"argv": [
|
||||
"/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo",
|
||||
"test",
|
||||
"--no-run",
|
||||
"--verbose",
|
||||
"--package=kx-utils@0.1.0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"phase": "Test",
|
||||
"duration": 0.594096084,
|
||||
"process_status": {
|
||||
"Failure": 101
|
||||
},
|
||||
"argv": [
|
||||
"/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo",
|
||||
"test",
|
||||
"--verbose",
|
||||
"--package=kx-utils@0.1.0"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"scenario": {
|
||||
"Mutant": {
|
||||
"package": "kx-utils",
|
||||
"file": "src/experimental/to_string.rs",
|
||||
"function": {
|
||||
"function_name": "s",
|
||||
"return_type": "-> String",
|
||||
"span": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 2
|
||||
}
|
||||
}
|
||||
},
|
||||
"span": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 13
|
||||
}
|
||||
},
|
||||
"replacement": "\"xyzzy\".into()",
|
||||
"genre": "FnValue"
|
||||
}
|
||||
},
|
||||
"summary": "CaughtMutant",
|
||||
"log_path": "log/src__experimental__to_string.rs_line_6_col_5_001.log",
|
||||
"diff_path": "diff/src__experimental__to_string.rs_line_6_col_5_001.diff",
|
||||
"phase_results": [
|
||||
{
|
||||
"phase": "Build",
|
||||
"duration": 0.222958292,
|
||||
"process_status": "Success",
|
||||
"argv": [
|
||||
"/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo",
|
||||
"test",
|
||||
"--no-run",
|
||||
"--verbose",
|
||||
"--package=kx-utils@0.1.0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"phase": "Test",
|
||||
"duration": 0.650389375,
|
||||
"process_status": {
|
||||
"Failure": 101
|
||||
},
|
||||
"argv": [
|
||||
"/Users/campbjpa/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo",
|
||||
"test",
|
||||
"--verbose",
|
||||
"--package=kx-utils@0.1.0"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"total_mutants": 2,
|
||||
"missed": 0,
|
||||
"caught": 2,
|
||||
"timeout": 0,
|
||||
"unviable": 0,
|
||||
"success": 0
|
||||
}
|
0
mutants.out/timeout.txt
Normal file
0
mutants.out/timeout.txt
Normal file
0
mutants.out/unviable.txt
Normal file
0
mutants.out/unviable.txt
Normal file
6
renovate.json
Normal file
6
renovate.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:recommended"
|
||||
]
|
||||
}
|
209
src/experimental/kameo/actor.rs
Normal file
209
src/experimental/kameo/actor.rs
Normal file
|
@ -0,0 +1,209 @@
|
|||
//
|
||||
|
||||
/// Called when the actor starts, before it processes any messages.
|
||||
///
|
||||
/// Messages sent internally by the actor during `on_start` are prioritized and processed
|
||||
/// before any externally sent messages, even if external messages are received first.
|
||||
///
|
||||
/// This ensures that the actor can properly initialize before handling external messages.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use kx_utils::on_actor_start;
|
||||
/// struct ServerActor;
|
||||
/// impl kameo::Actor for ServerActor {
|
||||
/// type Mailbox = kameo::mailbox::unbounded::UnboundedMailbox<Self>;
|
||||
///
|
||||
/// on_actor_start!(this, actor_ref, {
|
||||
/// // handle start here
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! on_actor_start {
|
||||
($this:ident, $actor_ref:ident, $body:expr) => {
|
||||
#[allow(unused_variables)]
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn on_start(
|
||||
&mut self,
|
||||
actor_ref: kameo::actor::ActorRef<Self>,
|
||||
) -> std::result::Result<(), kameo::error::BoxError> {
|
||||
tracing::debug!(?actor_ref, "{}", <Self as kameo::Actor>::name());
|
||||
let $this = self;
|
||||
let $actor_ref = actor_ref;
|
||||
$body
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! default_on_actor_start {
|
||||
($this:ident, $actor_ref:ident) => {
|
||||
$crate::on_actor_start!($this, $actor_ref, { Ok(()) });
|
||||
};
|
||||
}
|
||||
|
||||
/// Called swhen the actor encounters a panic or an error during "tell" message handling.
|
||||
///
|
||||
/// This method gives the actor an opportunity to clean up or reset its state and determine
|
||||
/// whether it should be stopped or continue processing messages.
|
||||
///
|
||||
/// # Parameters
|
||||
/// - `err`: The panic or error that occurred.
|
||||
///
|
||||
/// # Returns
|
||||
/// - `Some(ActorStopReason)`: Stops the actor.
|
||||
/// - `None`: Allows the actor to continue processing messages.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use kx_utils::on_actor_panic;
|
||||
/// struct ServerActor;
|
||||
/// impl kameo::Actor for ServerActor {
|
||||
/// type Mailbox = kameo::mailbox::unbounded::UnboundedMailbox<Self>;
|
||||
///
|
||||
/// on_actor_panic!(this, actor_ref, err, {
|
||||
/// // handle panic here
|
||||
/// Ok(None)
|
||||
/// });
|
||||
/// }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! on_actor_panic {
|
||||
($this:ident, $actor_ref:ident, $err:ident, $body:expr) => {
|
||||
#[allow(unused_variables)]
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn on_panic(
|
||||
&mut self,
|
||||
actor_ref: kameo::actor::WeakActorRef<Self>,
|
||||
err: kameo::error::PanicError,
|
||||
) -> std::result::Result<Option<kameo::error::ActorStopReason>, kameo::error::BoxError> {
|
||||
tracing::debug!(?actor_ref, %err, "{}", <Self as kameo::Actor>::name());
|
||||
let $this = self;
|
||||
let $actor_ref = actor_ref;
|
||||
let $err = err;
|
||||
$body
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! default_on_actor_panic {
|
||||
($this:ident, $actor_ref:ident, $err:ident) => {
|
||||
$crate::on_actor_panic!($this, $actor_ref, $err, {
|
||||
Ok(Some(kameo::error::ActorStopReason::Panicked($err)))
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/// Called when a linked actor dies.
|
||||
///
|
||||
/// By default, the actor will stop if the reason for the linked actor's death is anything other
|
||||
/// than `Normal`. You can customize this behavior in the implementation.
|
||||
///
|
||||
/// # Returns
|
||||
/// Whether the actor should stop or continue processing messages.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use kx_utils::on_actor_link_died;
|
||||
/// struct ServerActor;
|
||||
/// impl kameo::Actor for ServerActor {
|
||||
/// type Mailbox = kameo::mailbox::unbounded::UnboundedMailbox<Self>;
|
||||
///
|
||||
/// on_actor_link_died!(this, actor_ref, id, reason, {
|
||||
/// // handle link death here
|
||||
/// Ok(None)
|
||||
/// });
|
||||
/// }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! on_actor_link_died {
|
||||
($this:ident, $actor_ref:ident, $id:ident, $reason:ident, $body:expr) => {
|
||||
#[allow(unused_variables)]
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn on_link_died(
|
||||
&mut self,
|
||||
actor_ref: kameo::actor::WeakActorRef<Self>,
|
||||
id: kameo::actor::ActorID,
|
||||
reason: kameo::error::ActorStopReason,
|
||||
) -> std::result::Result<Option<kameo::error::ActorStopReason>, kameo::error::BoxError> {
|
||||
tracing::debug!(?actor_ref, %id, %reason, "{}", <Self as kameo::Actor>::name());
|
||||
let $this = self;
|
||||
let $actor_ref = actor_ref;
|
||||
let $id = id;
|
||||
let $reason = reason;
|
||||
$body
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! default_on_actor_link_died {
|
||||
($this:ident, $actor_ref:ident, $id:ident, $reason:ident) => {
|
||||
$crate::on_actor_link_died!($this, $actor_ref, $id, $reason, {
|
||||
match &$reason {
|
||||
kameo::error::ActorStopReason::Normal => Ok(None),
|
||||
kameo::error::ActorStopReason::Killed
|
||||
| kameo::error::ActorStopReason::Panicked(_)
|
||||
| kameo::error::ActorStopReason::LinkDied { .. } => {
|
||||
Ok(Some(kameo::error::ActorStopReason::LinkDied {
|
||||
id: $id,
|
||||
reason: Box::new($reason),
|
||||
}))
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/// Called before the actor stops.
|
||||
///
|
||||
/// This allows the actor to perform any necessary cleanup or release resources before being fully stopped.
|
||||
///
|
||||
/// # Parameters
|
||||
/// - `reason`: The reason why the actor is being stopped.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use kx_utils::on_actor_stop;
|
||||
/// struct ServerActor;
|
||||
/// impl kameo::Actor for ServerActor {
|
||||
/// type Mailbox = kameo::mailbox::unbounded::UnboundedMailbox<Self>;
|
||||
///
|
||||
/// on_actor_stop!(this, actor_ref, reason, {
|
||||
/// // handle stop here
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! on_actor_stop {
|
||||
($this:ident, $actor_ref:ident, $reason:ident, $body:expr) => {
|
||||
#[allow(unused_variables)]
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn on_stop(
|
||||
&mut self,
|
||||
actor_ref: kameo::actor::WeakActorRef<Self>,
|
||||
reason: kameo::error::ActorStopReason,
|
||||
) -> std::result::Result<(), kameo::error::BoxError> {
|
||||
tracing::debug!(?actor_ref, %reason, "{}", <Self as kameo::Actor>::name());
|
||||
let $this = self;
|
||||
let $actor_ref = actor_ref;
|
||||
let $reason = reason;
|
||||
$body
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! default_on_actor_stop {
|
||||
($this:ident, $actor_ref:ident, $reason:ident) => {
|
||||
$crate::on_actor_stop!($this, $actor_ref, $reason, { Ok(()) });
|
||||
};
|
||||
}
|
15
src/experimental/kameo/message.rs
Normal file
15
src/experimental/kameo/message.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
#[macro_export]
|
||||
macro_rules! message {
|
||||
($name:ident, $value:ty, $docs:literal) => {
|
||||
$crate::newtype!($name, $value, $docs);
|
||||
};
|
||||
($name:ident, $docs:literal) => {
|
||||
$crate::newtype!($name, $docs);
|
||||
};
|
||||
($name:ident, $value:ty => $result:ty, $docs:literal) => {
|
||||
$crate::newtype!($name, $value, $docs);
|
||||
};
|
||||
($name:ident => $result:ty, $docs:literal) => {
|
||||
$crate::newtype!($name, $docs);
|
||||
};
|
||||
}
|
5
src/experimental/kameo/mod.rs
Normal file
5
src/experimental/kameo/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
//
|
||||
mod actor;
|
||||
mod message;
|
||||
mod send;
|
||||
mod spawn;
|
64
src/experimental/kameo/send.rs
Normal file
64
src/experimental/kameo/send.rs
Normal file
|
@ -0,0 +1,64 @@
|
|||
//
|
||||
#[macro_export]
|
||||
macro_rules! tell {
|
||||
($actor_ref:expr, $message:expr) => {
|
||||
tell!(stringify!($actor_ref), $actor_ref, $message)
|
||||
};
|
||||
($actor_name:expr, $actor_ref:expr, $message:expr) => {{
|
||||
tracing::debug!(actor = $actor_name, msg = stringify!($message), "send");
|
||||
$actor_ref.tell($message).await
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! ask {
|
||||
($actor_ref:expr, $message:expr) => {
|
||||
ask!(stringify!($actor_ref), $actor_ref, $message)
|
||||
};
|
||||
($actor_name:expr, $actor_ref:expr, $message:expr) => {{
|
||||
tracing::debug!(actor = $actor_name, msg = stringify!($message), "send");
|
||||
$actor_ref.ask($message).await
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! subscribe {
|
||||
($message_bus:expr, $actor_ref:expr) => {
|
||||
subscribe!(
|
||||
stringify!($message_bus),
|
||||
$message_bus,
|
||||
stringify!($actor_ref),
|
||||
$actor_ref
|
||||
)
|
||||
};
|
||||
($message_bus:expr, $actor_name:expr, $actor_ref:expr) => {
|
||||
subscribe!(
|
||||
stringify!($message_bus),
|
||||
$message_bus,
|
||||
$actor_name,
|
||||
$actor_ref
|
||||
)
|
||||
};
|
||||
($bus_name:expr, $message_bus:expr, $actor_ref:expr) => {
|
||||
subscribe!($bus_name, $message_bus, stringify!($actor_ref), $actor_ref)
|
||||
};
|
||||
($bus_name:expr, $message_bus:expr, $actor_name:expr, $actor_ref:expr) => {{
|
||||
tracing::debug!(msg_bus = $bus_name, actor = $actor_name, "subscribe");
|
||||
$message_bus
|
||||
.tell(kameo::actor::pubsub::Subscribe($actor_ref))
|
||||
.await
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! publish {
|
||||
($message_bus:expr, $message:expr) => {
|
||||
publish!(stringify!($message_bus), $message_bus, $message)
|
||||
};
|
||||
($bus_name:expr, $message_bus:expr, $message:expr) => {{
|
||||
tracing::debug!(bus = $bus_name, msg = stringify!($message), "publish");
|
||||
$message_bus
|
||||
.tell(kameo::actor::pubsub::Publish($message))
|
||||
.await
|
||||
}};
|
||||
}
|
43
src/experimental/kameo/spawn.rs
Normal file
43
src/experimental/kameo/spawn.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
//
|
||||
/// spawns a new actor and sets up bi-directional links
|
||||
#[macro_export]
|
||||
macro_rules! spawn {
|
||||
($parent:expr, $actor:expr) => {{
|
||||
tracing::debug!("spawning : {}", $crate::stringify_expr!($actor));
|
||||
let new_actor_ref = kameo::spawn($actor);
|
||||
new_actor_ref.link(&$parent).await;
|
||||
$parent.link(&new_actor_ref).await;
|
||||
tracing::debug!("spawned : {}", $crate::stringify_expr!($actor));
|
||||
new_actor_ref
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! stringify_expr {
|
||||
($expr:expr) => {
|
||||
stringify!($expr).lines().collect::<Vec<_>>().join(" ")
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_line_breaks() {
|
||||
let out = stringify_expr!([
|
||||
"line 1", "line 2", "line 3", "line 1", "line 2", "line 3", "line 1", "line 2", "line 3",
|
||||
"line 1", "line 2", "line 3",
|
||||
]);
|
||||
let expected = r#"["line 1", "line 2", "line 3", "line 1", "line 2", "line 3", "line 1", "line 2", "line 3", "line 1", "line 2", "line 3",]"#;
|
||||
|
||||
assert_eq!(out, expected);
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! spawn_in_thread {
|
||||
($parent:expr, $actor:expr) => {{
|
||||
tracing::debug!("spawning in thread : {}", $crate::stringify_expr!($actor));
|
||||
let new_actor_ref = kameo::actor::spawn_in_thread($actor);
|
||||
new_actor_ref.link(&$parent).await;
|
||||
$parent.link(&new_actor_ref).await;
|
||||
tracing::debug!("spawned in thread : {}", $crate::stringify_expr!($actor));
|
||||
new_actor_ref
|
||||
}};
|
||||
}
|
2
src/experimental/kxio/mod.rs
Normal file
2
src/experimental/kxio/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
//
|
||||
mod net;
|
36
src/experimental/kxio/net/backoff.rs
Normal file
36
src/experimental/kxio/net/backoff.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
#[macro_export]
|
||||
macro_rules! backoff {
|
||||
($backoff_secs:expr) => {{
|
||||
$backoff_secs *= 2;
|
||||
let jitter = rand::random::<u64>() % 10;
|
||||
let backoff_secs = 60.min($backoff_secs + jitter);
|
||||
tracing::debug(?backoff_secs, "Too many requests, backing off for {}s");
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(backoff_secs)).await;
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! with_exponential_backoff {
|
||||
($operation:expr) => {{
|
||||
let mut backoff_secs = 1;
|
||||
loop {
|
||||
match $operation {
|
||||
Err(kxio::net::Error::Reqwest(err))
|
||||
if err.status() == Some(kxio::net::StatusCode::TOO_MANY_REQUESTS) =>
|
||||
{
|
||||
$crate::backoff!(backoff_secs)
|
||||
}
|
||||
Err(kxio::net::Error::ResponseError { response })
|
||||
if response.status() == kxio::net::StatusCode::TOO_MANY_REQUESTS =>
|
||||
{
|
||||
$crate::backoff!(backoff_secs)
|
||||
}
|
||||
Ok(response) if response.status() == kxio::net::StatusCode::TOO_MANY_REQUESTS => {
|
||||
$crate::backoff!(backoff_secs)
|
||||
}
|
||||
result => break result,
|
||||
}
|
||||
}
|
||||
}};
|
||||
}
|
2
src/experimental/kxio/net/mod.rs
Normal file
2
src/experimental/kxio/net/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
//
|
||||
mod backoff;
|
72
src/experimental/marker.rs
Normal file
72
src/experimental/marker.rs
Normal file
|
@ -0,0 +1,72 @@
|
|||
//
|
||||
|
||||
/// Defines a marker type with [Clone], [Copy], [Debug], [Display] nad [PartialEq].
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use kx_utils::marker;
|
||||
/// marker!(Token, "Has no inner value");
|
||||
/// let token = Token;
|
||||
/// ```
|
||||
///
|
||||
/// This is the equivalent of:
|
||||
///
|
||||
/// ```rust
|
||||
/// #[doc = "Has no inner value"]
|
||||
/// #[derive(
|
||||
/// Clone,
|
||||
/// Copy,
|
||||
/// Debug,
|
||||
/// derive_more::Display,
|
||||
/// PartialEq,
|
||||
/// )]
|
||||
/// pub struct Token;
|
||||
/// let token = Token;
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! marker {
|
||||
($name:ident, $docs:literal) => {
|
||||
#[doc = $docs]
|
||||
#[derive(Clone, Copy, Debug, derive_more::Display, PartialEq)]
|
||||
pub struct $name;
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// a newtype with no inner value
|
||||
marker!(A, "a type");
|
||||
|
||||
#[test]
|
||||
fn marker_is_equals() {
|
||||
assert_eq!(A, A);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marker_is_clone() {
|
||||
let a1 = A;
|
||||
#[allow(clippy::clone_on_copy)]
|
||||
let a2 = a1.clone();
|
||||
assert_eq!(a1, a2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marker_is_copy() {
|
||||
let a1 = A;
|
||||
let a2 = a1;
|
||||
fn consume(_a: A) {}
|
||||
consume(a1);
|
||||
assert_eq!(a2, a1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marker_is_debug() {
|
||||
assert_eq!(format!("{:?}", A), "A");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marker_is_display() {
|
||||
assert_eq!(format!("{}", A), "A");
|
||||
}
|
||||
}
|
18
src/experimental/mod.rs
Normal file
18
src/experimental/mod.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
//
|
||||
|
||||
/// Macros for use with the [kameo](https://crates.io/crates/kameo) async actor framework.
|
||||
#[cfg(feature = "use-kameo")]
|
||||
pub mod kameo;
|
||||
|
||||
/// Macros for use with the [kxio](https://crates.io/crates/kxio) injectable IO crate.
|
||||
#[cfg(feature = "use-kxio")]
|
||||
pub mod kxio;
|
||||
|
||||
/// Macro for valueless new type.
|
||||
mod marker;
|
||||
|
||||
/// Macro and function for converting a value to a [String]
|
||||
mod to_string;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
pub use to_string::s;
|
32
src/experimental/to_string.rs
Normal file
32
src/experimental/to_string.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
//
|
||||
#![allow(unused)]
|
||||
|
||||
/// Converts the parameter into a [String] using the [Into] trait.
|
||||
///
|
||||
/// Requires parameter to implement a [From] or [Into] trait to allow it be transformed.
|
||||
pub fn s(v: impl Into<String>) -> String {
|
||||
v.into()
|
||||
}
|
||||
|
||||
/// Converts the parameter into a [String] by calling `.to_string()`.
|
||||
///
|
||||
/// Unlike the [s] function, the value only need to have a [to_string] method. Preusmably it will
|
||||
/// return a [String], but this macro doesn't make that gaurantee.
|
||||
#[macro_export]
|
||||
macro_rules! s {
|
||||
($value:expr) => {
|
||||
$value.to_string()
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn s_converts_to_string() {
|
||||
let v = 123.to_string();
|
||||
let result = s("123");
|
||||
assert_eq!(result, v);
|
||||
}
|
||||
}
|
|
@ -1 +1,3 @@
|
|||
//
|
||||
pub mod experimental;
|
||||
mod newtype;
|
||||
|
|
116
src/newtype.rs
Normal file
116
src/newtype.rs
Normal file
|
@ -0,0 +1,116 @@
|
|||
//
|
||||
/// Defines a new type that wraps another type.
|
||||
///
|
||||
/// You can specify an optional number of additional traits to be derived after the wrapped type.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use kx_utils::newtype;
|
||||
/// newtype!(Username, String, derive_more::Display, "The login name for the user");
|
||||
/// let username = Username::new("bob");
|
||||
/// assert_eq!(username.as_ref(), "bob");
|
||||
/// assert_eq!(format!("{username}"), r"bob"); // because `derive_more::Display`
|
||||
/// assert_eq!(format!("{username:?}"), r#"Username("bob")"#);
|
||||
/// let peeled = username.peel(); // moves value out of `username`
|
||||
/// assert_eq!(peeled, "bob".to_string());
|
||||
/// ```
|
||||
///
|
||||
/// In this example, [Username] also derives [derive_more::Display].
|
||||
#[macro_export]
|
||||
macro_rules! newtype {
|
||||
($name:ident, $type:ty $(, $derive:ty)*, $docs:literal) => {
|
||||
#[doc = $docs]
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
derive_more::From,
|
||||
PartialEq,
|
||||
Eq,
|
||||
derive_more::AsRef,
|
||||
serde::Serialize,
|
||||
serde::Deserialize,
|
||||
$($derive),*
|
||||
)]
|
||||
pub struct $name($type);
|
||||
impl $name {
|
||||
pub fn new(value: impl Into<$type>) -> Self {
|
||||
Self(value.into())
|
||||
}
|
||||
#[allow(clippy::missing_const_for_fn)]
|
||||
#[must_use]
|
||||
pub fn peel(self) -> $type {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
impl From<$name> for $type {
|
||||
fn from(value: $name) -> $type {
|
||||
value.peel()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use derive_more::Display;
|
||||
|
||||
// a newtype with a String inner value
|
||||
newtype!(A, String, "a type");
|
||||
|
||||
#[test]
|
||||
fn newtype_reflexive() {
|
||||
let a = A::new("bob");
|
||||
assert_eq!(a, a);
|
||||
}
|
||||
#[test]
|
||||
fn newtype_new_is_equal_from() {
|
||||
assert_eq!(A::new("bob"), A::from("bob".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newtype_is_clone() {
|
||||
let a1 = A::new("bob");
|
||||
let a2 = a1.clone();
|
||||
assert_eq!(a1, a2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newtype_is_debug() {
|
||||
assert_eq!(format!("{:?}", A::new("bob")), r#"A("bob")"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newtype_with_derive_display_is_display() {
|
||||
newtype!(B, String, Display, "displayable");
|
||||
assert_eq!(format!("{}", B::new("bob")), r"bob");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newtype_is_peelable() {
|
||||
let a = A::new("bob");
|
||||
assert_eq!(a.peel(), "bob");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newtype_as_ref() {
|
||||
let a = A::new("bob");
|
||||
let b: &str = a.as_ref();
|
||||
assert_eq!(b, "bob");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newtype_serialize() {
|
||||
let a = A::new("bob");
|
||||
let s = serde_json::to_string(&a).unwrap();
|
||||
assert_eq!(s, "\"bob\"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newtype_deserialize() {
|
||||
let a = A::new("bob");
|
||||
let s: A = serde_json::from_str("\"bob\"").unwrap();
|
||||
assert_eq!(s, a);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue