diff --git a/.clippy.toml b/.clippy.toml index f631664..1d4c5dc 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1,5 +1,4 @@ -msrv = "1.73" # MSRV -warn-on-all-wildcard-imports = true +allow-print-in-tests = true allow-expect-in-tests = true allow-unwrap-in-tests = true allow-dbg-in-tests = true diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 1725e3e..c184420 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -3,6 +3,7 @@ 'before 5am on the first day of the month', ], semanticCommits: 'enabled', + commitMessageLowerCase: 'never', configMigration: true, dependencyDashboard: true, customManagers: [ @@ -17,29 +18,28 @@ '^\\.github/workflows/rust-next.yml$', ], matchStrings: [ - 'MSRV.*?(?\\d+\\.\\d+(\\.\\d+)?)', - '(?\\d+\\.\\d+(\\.\\d+)?).*?MSRV', + 'STABLE.*?(?\\d+\\.\\d+(\\.\\d+)?)', + '(?\\d+\\.\\d+(\\.\\d+)?).*?STABLE', ], - depNameTemplate: 'rust', + depNameTemplate: 'STABLE', packageNameTemplate: 'rust-lang/rust', datasourceTemplate: 'github-releases', }, ], packageRules: [ { - commitMessageTopic: 'MSRV', + commitMessageTopic: 'Rust Stable', matchManagers: [ 'custom.regex', ], matchPackageNames: [ - 'rust', + 'STABLE', ], - minimumReleaseAge: '126 days', // 3 releases * 6 weeks per release * 7 days per week - internalChecksFilter: 'strict', extractVersion: '^(?\\d+\\.\\d+)', // Drop the patch version schedule: [ '* * * * *', ], + automerge: true, }, // Goals: // - Keep version reqs low, ignoring compatible normal/build dependencies @@ -72,6 +72,7 @@ matchCurrentVersion: '>=1.0.0', matchUpdateTypes: [ 'minor', + 'patch', ], enabled: false, }, @@ -99,6 +100,7 @@ matchCurrentVersion: '>=1.0.0', matchUpdateTypes: [ 'minor', + 'patch', ], automerge: true, groupName: 'compatible (dev)', diff --git a/.github/settings.yml b/.github/settings.yml index c84ca00..1531033 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -42,14 +42,18 @@ labels: color: '#c2e0c6' description: "Help wanted!" -branches: - - name: master - protection: - required_pull_request_reviews: null - required_conversation_resolution: true - required_status_checks: - # Required. Require branches to be up to date before merging. - strict: false - contexts: ["CI", "Lint Commits", "Spell Check with Typos"] - enforce_admins: false - restrictions: null +# This serves more as documentation. +# Branch protection API was replaced by rulesets but settings isn't updated. +# See https://github.com/repository-settings/app/issues/825 +# +# branches: +# - name: master +# protection: +# required_pull_request_reviews: null +# required_conversation_resolution: true +# required_status_checks: +# # Required. Require branches to be up to date before merging. +# strict: false +# contexts: ["CI", "Spell Check with Typos"] +# enforce_admins: false +# restrictions: null diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 442e637..35b3da8 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -17,6 +17,10 @@ env: CARGO_TERM_COLOR: always CLICOLOR: 1 +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + jobs: security_audit: permissions: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e680595..506b537 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,16 +14,22 @@ env: CARGO_TERM_COLOR: always CLICOLOR: 1 +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + jobs: ci: permissions: contents: none name: CI - needs: [test, miri, msrv, docs, rustfmt, clippy] + needs: [test, miri, msrv, lockfile, docs, rustfmt, clippy] runs-on: ubuntu-latest + if: "always()" steps: - - name: Done - run: exit 0 + - name: Failed + run: exit 1 + if: "contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped')" test: name: Test strategy: @@ -66,14 +72,11 @@ jobs: sudo apt-get update sudo apt-get install gcc-multilib - uses: Swatinem/rust-cache@v2 + - uses: taiki-e/install-action@cargo-hack - name: Build - run: cargo test --target ${{ matrix.target }} --no-run --workspace --all-features - - name: Default features - run: cargo test --target ${{ matrix.target }} --workspace - - name: All features - run: cargo test --target ${{ matrix.target }} --workspace --all-features - - name: No-default features - run: cargo test --target ${{ matrix.target }} --workspace --no-default-features --features std + run: cargo test --target ${{ matrix.target }} --workspace --no-run + - name: Test + run: cargo hack test --target ${{ matrix.target }} --feature-powerset --workspace miri: name: Miri runs-on: ubuntu-latest @@ -95,7 +98,7 @@ jobs: - name: No-default features run: cargo miri test --no-default-features --features std msrv: - name: "Check MSRV: 1.73" + name: "Check MSRV" runs-on: ubuntu-latest steps: - name: Checkout repository @@ -103,14 +106,11 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@stable with: - toolchain: "1.73" # MSRV + toolchain: stable - uses: Swatinem/rust-cache@v2 + - uses: taiki-e/install-action@cargo-hack - name: Default features - run: cargo check --workspace --all-targets - - name: All features - run: cargo check --workspace --all-targets --all-features - - name: No-default features - run: cargo check --workspace --all-targets --no-default-features --features std + run: cargo hack check --feature-powerset --locked --rust-version --ignore-private --workspace --all-targets lockfile: runs-on: ubuntu-latest steps: @@ -122,7 +122,7 @@ jobs: toolchain: stable - uses: Swatinem/rust-cache@v2 - name: "Is lockfile updated?" - run: cargo fetch --locked + run: cargo update --workspace --locked docs: name: Docs runs-on: ubuntu-latest @@ -132,7 +132,7 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@stable with: - toolchain: stable + toolchain: "1.76" # STABLE - uses: Swatinem/rust-cache@v2 - name: Check documentation env: @@ -147,9 +147,7 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@stable with: - # Not MSRV because its harder to jump between versions and people are - # more likely to have stable - toolchain: stable + toolchain: "1.76" # STABLE components: rustfmt - uses: Swatinem/rust-cache@v2 - name: Check formatting @@ -165,13 +163,13 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@stable with: - toolchain: "1.73" # MSRV + toolchain: "1.76" # STABLE components: clippy - uses: Swatinem/rust-cache@v2 - name: Install SARIF tools - run: cargo install clippy-sarif --version 0.3.4 --locked # Held back due to msrv + run: cargo install clippy-sarif --locked - name: Install SARIF tools - run: cargo install sarif-fmt --version 0.3.4 --locked # Held back due to msrv + run: cargo install sarif-fmt --locked - name: Check run: > cargo clippy --workspace --all-features --all-targets --message-format=json -- -D warnings --allow deprecated @@ -186,3 +184,22 @@ jobs: wait-for-processing: true - name: Report status run: cargo clippy --workspace --all-features --all-targets -- -D warnings --allow deprecated + coverage: + name: Coverage + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + - uses: Swatinem/rust-cache@v2 + - name: Install cargo-tarpaulin + run: cargo install cargo-tarpaulin + - name: Gather coverage + run: cargo tarpaulin --output-dir coverage --out lcov + - name: Publish to Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/committed.yml b/.github/workflows/committed.yml index 0462558..e7a50fb 100644 --- a/.github/workflows/committed.yml +++ b/.github/workflows/committed.yml @@ -11,6 +11,10 @@ env: CARGO_TERM_COLOR: always CLICOLOR: 1 +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + jobs: committed: name: Lint Commits diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index e5b3bd4..3d04055 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -12,6 +12,10 @@ env: CARGO_TERM_COLOR: always CLICOLOR: 1 +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + jobs: pre-commit: permissions: diff --git a/.github/workflows/rust-next.yml b/.github/workflows/rust-next.yml index a59c85b..93c2afc 100644 --- a/.github/workflows/rust-next.yml +++ b/.github/workflows/rust-next.yml @@ -12,12 +12,16 @@ env: CARGO_TERM_COLOR: always CLICOLOR: 1 +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + jobs: test: name: Test strategy: matrix: - os: ["ubuntu-latest", "windows-latest", "macos-latest"] + os: ["ubuntu-latest", "windows-latest", "macos-latest", "macos-14"] rust: ["stable", "beta"] include: - os: ubuntu-latest @@ -32,12 +36,11 @@ jobs: with: toolchain: ${{ matrix.rust }} - uses: Swatinem/rust-cache@v2 - - name: Default features - run: cargo test --workspace - - name: All features - run: cargo test --workspace --all-features - - name: No-default features - run: cargo test --workspace --no-default-features --features std + - uses: taiki-e/install-action@cargo-hack + - name: Build + run: cargo test --workspace --no-run + - name: Test + run: cargo hack test --feature-powerset --workspace latest: name: "Check latest dependencies" runs-on: ubuntu-latest @@ -49,11 +52,10 @@ jobs: with: toolchain: stable - uses: Swatinem/rust-cache@v2 + - uses: taiki-e/install-action@cargo-hack - name: Update dependencues run: cargo update - - name: Default features - run: cargo test --workspace --all-targets - - name: All features - run: cargo test --workspace --all-targets --all-features - - name: No-default features - run: cargo test --workspace --no-default-features --features std + - name: Build + run: cargo test --workspace --no-run + - name: Test + run: cargo hack test --feature-powerset --workspace diff --git a/.github/workflows/spelling.yml b/.github/workflows/spelling.yml index 12f7585..8e58d9e 100644 --- a/.github/workflows/spelling.yml +++ b/.github/workflows/spelling.yml @@ -10,6 +10,10 @@ env: CARGO_TERM_COLOR: always CLICOLOR: 1 +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + jobs: spelling: name: Spell Check with Typos diff --git a/Cargo.lock b/Cargo.lock index a9ea32f..11707b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,17 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "automod" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edf3ee19dbc0a46d740f6f0926bde8c50f02bdbc7b536842da28f6ac56513a8b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + [[package]] name = "bit-set" version = "0.5.2" @@ -348,6 +359,7 @@ dependencies = [ name = "kstring" version = "2.0.0" dependencies = [ + "automod", "criterion", "document-features", "proptest", @@ -471,11 +483,11 @@ checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "proc-macro2" -version = "1.0.36" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -506,9 +518,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.17" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "632d02bff7f874a36f33ea8bb416cd484b90cc66c1194b1a1110d067a7013f58" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -680,7 +692,7 @@ checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.90", ] [[package]] @@ -711,6 +723,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "syn" +version = "2.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tempfile" version = "3.3.0" @@ -741,6 +764,12 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + [[package]] name = "unicode-xid" version = "0.2.2" @@ -794,7 +823,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn", + "syn 1.0.90", "wasm-bindgen-shared", ] @@ -816,7 +845,7 @@ checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.90", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.toml index 9a18a6a..75deab7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,76 @@ include = [ "examples/**/*" ] +[workspace.lints.rust] +rust_2018_idioms = "warn" +unreachable_pub = "warn" +unsafe_op_in_unsafe_fn = "warn" +unused_lifetimes = "warn" +unused_macro_rules = "warn" +unused_qualifications = "warn" + +[workspace.lints.clippy] +bool_assert_comparison = "allow" +branches_sharing_code = "allow" +checked_conversions = "warn" +collapsible_else_if = "allow" +create_dir = "warn" +dbg_macro = "warn" +debug_assert_with_mut_call = "warn" +doc_markdown = "warn" +empty_enum = "warn" +enum_glob_use = "warn" +expl_impl_clone_on_copy = "warn" +explicit_deref_methods = "warn" +explicit_into_iter_loop = "warn" +fallible_impl_from = "warn" +filter_map_next = "warn" +flat_map_option = "warn" +float_cmp_const = "warn" +fn_params_excessive_bools = "warn" +from_iter_instead_of_collect = "warn" +if_same_then_else = "allow" +implicit_clone = "warn" +imprecise_flops = "warn" +inconsistent_struct_constructor = "warn" +inefficient_to_string = "warn" +infinite_loop = "warn" +invalid_upcast_comparisons = "warn" +items_after_statements = "warn" +large_digit_groups = "warn" +large_stack_arrays = "warn" +large_types_passed_by_value = "warn" +let_and_return = "allow" # sometimes good to name what you are returning +linkedlist = "warn" +lossy_float_literal = "warn" +macro_use_imports = "warn" +match_wildcard_for_single_variants = "warn" +mem_forget = "warn" +mutex_integer = "warn" +needless_continue = "warn" +needless_for_each = "warn" +negative_feature_names = "warn" +path_buf_push_overwrite = "warn" +ptr_as_ptr = "warn" +rc_mutex = "warn" +redundant_feature_names = "warn" +ref_option_ref = "warn" +rest_pat_in_fully_bound_structs = "warn" +same_functions_in_if_condition = "warn" +self_named_module_files = "warn" +semicolon_if_nothing_returned = "warn" +single_match_else = "warn" +str_to_string = "warn" +string_add = "warn" +string_add_assign = "warn" +string_lit_as_bytes = "warn" +string_to_string = "warn" +todo = "warn" +trait_duplication_in_bounds = "warn" +verbose_file_reads = "warn" +wildcard_imports = "warn" +zero_sized_map_values = "warn" + [package] name = "kstring" version = "2.0.0" @@ -68,6 +138,7 @@ document-features = { version = "0.2", optional = true } [dev-dependencies] criterion = "0.5" proptest = "1.4.0" +automod = "1.0.14" [[bench]] name = "clone" @@ -79,3 +150,6 @@ harness = false [profile.release] debug = 1 + +[lints] +workspace = true diff --git a/benches/access.rs b/benches/access.rs index c863ad4..1b283b6 100644 --- a/benches/access.rs +++ b/benches/access.rs @@ -45,13 +45,13 @@ fn bench_access(c: &mut Criterion) { |b, _| { let uut = StringCow::Borrowed(*fixture); let uut = criterion::black_box(uut); - b.iter(|| uut.is_empty()) + b.iter(|| uut.is_empty()); }, ); group.bench_with_input(BenchmarkId::new("StringCow::Owned", len), &len, |b, _| { let uut = StringCow::Owned(String::from(*fixture)); let uut = criterion::black_box(uut); - b.iter(|| uut.is_empty()) + b.iter(|| uut.is_empty()); }); group.bench_with_input( BenchmarkId::new("KString::from_static", len), @@ -59,13 +59,13 @@ fn bench_access(c: &mut Criterion) { |b, _| { let uut = kstring::KString::from_static(fixture); let uut = criterion::black_box(uut); - b.iter(|| uut.is_empty()) + b.iter(|| uut.is_empty()); }, ); group.bench_with_input(BenchmarkId::new("KString::from_ref", len), &len, |b, _| { let uut = kstring::KString::from_ref(fixture); let uut = criterion::black_box(uut); - b.iter(|| uut.is_empty()) + b.iter(|| uut.is_empty()); }); group.bench_with_input( BenchmarkId::new("KString::from_string", len), @@ -73,7 +73,7 @@ fn bench_access(c: &mut Criterion) { |b, _| { let uut = kstring::KString::from_string(String::from(*fixture)); let uut = criterion::black_box(uut); - b.iter(|| uut.is_empty()) + b.iter(|| uut.is_empty()); }, ); #[cfg(not(feature = "unstable_bench_subset"))] diff --git a/benches/clone.rs b/benches/clone.rs index 23bc30f..3ae3ad2 100644 --- a/benches/clone.rs +++ b/benches/clone.rs @@ -44,14 +44,14 @@ fn bench_clone(c: &mut Criterion) { |b, _| { let uut = StringCow::Borrowed(*fixture); let uut = criterion::black_box(uut); - b.iter(|| uut.clone()) + b.iter(|| uut.clone()); }, ); group.bench_with_input(BenchmarkId::new("StringCow::Owned", len), &len, |b, _| { let fixture = String::from(*fixture); let uut = StringCow::Owned(fixture); let uut = criterion::black_box(uut); - b.iter(|| uut.clone()) + b.iter(|| uut.clone()); }); group.bench_with_input( BenchmarkId::new("KString::from_static", len), @@ -59,14 +59,14 @@ fn bench_clone(c: &mut Criterion) { |b, _| { let uut = kstring::KString::from_static(fixture); let uut = criterion::black_box(uut); - b.iter(|| uut.clone()) + b.iter(|| uut.clone()); }, ); group.bench_with_input(BenchmarkId::new("KString::from_ref", len), &len, |b, _| { let fixture = String::from(*fixture); let uut = kstring::KString::from_ref(&fixture); let uut = criterion::black_box(uut); - b.iter(|| uut.clone()) + b.iter(|| uut.clone()); }); group.bench_with_input( BenchmarkId::new("KString::from_string", len), @@ -75,7 +75,7 @@ fn bench_clone(c: &mut Criterion) { let fixture = String::from(*fixture); let uut = kstring::KString::from_string(fixture); let uut = criterion::black_box(uut); - b.iter(|| uut.clone()) + b.iter(|| uut.clone()); }, ); #[cfg(not(feature = "unstable_bench_subset"))] diff --git a/src/backend.rs b/src/backend.rs index 3827082..21fb2e7 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -1,5 +1,5 @@ #[cfg(feature = "arc")] -pub(crate) type DefaultStr = crate::backend::ArcStr; +pub(crate) type DefaultStr = ArcStr; #[cfg(not(feature = "arc"))] pub(crate) type DefaultStr = crate::backend::BoxedStr; diff --git a/src/lib.rs b/src/lib.rs index 94fdc23..d4e352d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,6 +38,8 @@ #![cfg_attr(feature = "document-features", doc = document_features::document_features!())] #![cfg_attr(not(feature = "unsafe"), forbid(unsafe_code))] #![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![warn(clippy::print_stderr)] +#![warn(clippy::print_stdout)] #[cfg(not(feature = "std"))] compile_error!("`std` feature is required; reserved for future `no_std` support"); diff --git a/src/stack.rs b/src/stack.rs index c6e8849..f647b7c 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -96,10 +96,12 @@ impl StackString { #[must_use] #[cfg(feature = "unsafe")] pub unsafe fn new_unchecked(s: &str) -> Self { - let len = s.as_bytes().len() as u8; - debug_assert!(Self::CAPACITY <= Len::MAX.into()); - let buffer = StrBuffer::new_unchecked(s); - Self { len, buffer } + unsafe { + let len = s.as_bytes().len() as u8; + debug_assert!(Self::CAPACITY <= Len::MAX.into()); + let buffer = StrBuffer::new_unchecked(s); + Self { len, buffer } + } } /// Extracts a string slice containing the entire `StackString`. @@ -425,28 +427,34 @@ impl StrBuffer { #[inline] #[cfg(feature = "unsafe")] pub(crate) unsafe fn new_unchecked(s: &str) -> Self { - let len = s.as_bytes().len(); - debug_assert!(len <= CAPACITY); - let mut buffer = Self::default(); - buffer - .0 - .get_unchecked_mut(..len) - .copy_from_slice(s.as_bytes()); - buffer + unsafe { + let len = s.as_bytes().len(); + debug_assert!(len <= CAPACITY); + let mut buffer = Self::default(); + buffer + .0 + .get_unchecked_mut(..len) + .copy_from_slice(s.as_bytes()); + buffer + } } #[inline] #[cfg(feature = "unsafe")] pub(crate) unsafe fn as_str_unchecked(&self, len: usize) -> &str { - let slice = self.0.get_unchecked(..len); - std::str::from_utf8_unchecked(slice) + unsafe { + let slice = self.0.get_unchecked(..len); + std::str::from_utf8_unchecked(slice) + } } #[inline] #[cfg(feature = "unsafe")] pub(crate) unsafe fn as_mut_str_unchecked(&mut self, len: usize) -> &mut str { - let slice = self.0.get_unchecked_mut(..len); - std::str::from_utf8_unchecked_mut(slice) + unsafe { + let slice = self.0.get_unchecked_mut(..len); + std::str::from_utf8_unchecked_mut(slice) + } } } diff --git a/src/string.rs b/src/string.rs index 907032d..06248c8 100644 --- a/src/string.rs +++ b/src/string.rs @@ -4,7 +4,7 @@ use crate::stack::StackString; use crate::KStringCowBase; use crate::KStringRef; -pub(crate) type StdString = std::string::String; +pub(crate) type StdString = String; /// A UTF-8 encoded, immutable string. pub type KString = KStringBase; @@ -499,7 +499,7 @@ mod inner { #[cfg(feature = "unsafe")] mod inner { - use super::*; + use super::{Cow, KStringRef, StackString, StdString}; pub(super) union KStringInner { tag: TagVariant, @@ -511,14 +511,14 @@ mod inner { impl KStringInner { /// Create a reference to a `'static` data. #[inline] - pub const fn from_static(other: &'static str) -> Self { + pub(crate) const fn from_static(other: &'static str) -> Self { Self { singleton: SingletonVariant::new(other), } } #[inline] - pub fn try_inline(other: &str) -> Option { + pub(crate) fn try_inline(other: &str) -> Option { StackString::try_new(other).map(|inline| Self { inline: InlineVariant::new(inline), }) @@ -679,7 +679,7 @@ mod inner { if tag.is_owned() { unsafe { // SAFETY: `tag` ensures we are using the right variant - std::mem::ManuallyDrop::drop(&mut self.owned) + std::mem::ManuallyDrop::drop(&mut self.owned); } } } @@ -697,7 +697,7 @@ mod inner { #[allow(unused)] const TARGET_SIZE: usize = std::mem::size_of::(); - type Target = crate::string::StdString; + type Target = StdString; #[allow(unused)] const MAX_CAPACITY: usize = TARGET_SIZE - LEN_SIZE - TAG_SIZE; diff --git a/src/string_cow.rs b/src/string_cow.rs index 627e5da..ddfc286 100644 --- a/src/string_cow.rs +++ b/src/string_cow.rs @@ -4,7 +4,7 @@ use crate::KStringBase; use crate::KStringRef; use crate::KStringRefInner; -type StdString = std::string::String; +type StdString = String; type BoxedStr = Box; /// A reference to a UTF-8 encoded, immutable string. diff --git a/src/string_ref.rs b/src/string_ref.rs index 4e373f0..3e6ad7e 100644 --- a/src/string_ref.rs +++ b/src/string_ref.rs @@ -3,7 +3,7 @@ use std::fmt; use crate::KStringBase; use crate::KStringCowBase; -type StdString = std::string::String; +type StdString = String; type BoxedStr = Box; /// A reference to a UTF-8 encoded, immutable string. diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs new file mode 100644 index 0000000..4441374 --- /dev/null +++ b/tests/testsuite/main.rs @@ -0,0 +1 @@ +automod::dir!("tests/testsuite"); diff --git a/tests/string.rs b/tests/testsuite/string.rs similarity index 100% rename from tests/string.rs rename to tests/testsuite/string.rs