diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2d1c2fa..ae8049a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,7 @@ on: workflow_dispatch: inputs: version: - description: "Version to release, for example 1.2.0" + description: "Version to release, for example 2.0.0" required: true type: string diff --git a/Cargo.toml b/Cargo.toml index 1d56b1b..b39e36d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cheetah-string" -version = "1.2.0" +version = "2.0.0" authors = ["mxsm "] edition = "2021" homepage = "https://github.com/mxsm/cheetah-string" diff --git a/README.md b/README.md index b6dd4f6..b330154 100644 --- a/README.md +++ b/README.md @@ -47,14 +47,14 @@ Add this to your `Cargo.toml`: ```toml [dependencies] -cheetah-string = "1.2.0" +cheetah-string = "2.0.0" ``` ### Optional Features ```toml [dependencies] -cheetah-string = { version = "1.2.0", features = ["bytes", "serde", "simd"] } +cheetah-string = { version = "2.0.0", features = ["bytes", "serde", "simd"] } ``` Available features: @@ -148,7 +148,7 @@ For new code, use: | Type | Role | |------|------| | `CheetahStr` | Immutable clone-cheap values such as topics, groups, names, and keys | -| `CheetahString` | Mutable string value with the 1.x compatibility API | +| `CheetahString` | Mutable string value with owned `String` construction semantics | | `CheetahBuilder` | Append-heavy construction followed by `finish_string()` or `finish_str()` | | `CheetahFinder` | Reusable substring search | | `CheetahBytes` | Byte semantics without a UTF-8 promise | @@ -159,15 +159,22 @@ For new code, use: - `new()`, `empty()`, `default()` - Create empty strings - `from(s)` - From `&str`, `String`, `&String`, `char`, etc. - `from_static_str(s)` - Zero-cost wrapper for `'static str` -- `from_string(s)` - From owned `String` with the 1.x shared-long-string policy -- `from_string_owned(s)` - Preserve `String` ownership and spare capacity for mutation -- `from_string_shared(s)` - Convert long owned strings to clone-cheap shared storage +- `from_string(s)` - From owned `String`, preserving ownership and spare capacity for mutation +- `from_string_owned(s)` - Same owned construction policy as `from_string` +- `from_string_shared(s)` - Convert long owned strings to clone-cheap shared storage; prefer `CheetahStr` for new immutable-key code - `try_from_bytes(b)` - Safe construction from bytes with UTF-8 validation - `CheetahStr` - Immutable clone-cheap string companion - `CheetahBuilder` - Append-heavy builder companion - `CheetahBytes` - Byte-oriented companion type available with the `bytes` feature - `with_capacity(n)` - Pre-allocate capacity +### 2.0 Migration Notes + +- Removed deprecated safe byte constructors: `from_vec`, `from_arc_vec`, and `from_bytes`. +- Use `try_from_vec`, `try_from_arc_vec`, `try_from_bytes`, or `try_from_bytes_buf` for checked UTF-8 construction. +- Use `from_utf8_unchecked_vec`, `from_utf8_unchecked_arc_vec`, `from_utf8_unchecked_bytes`, or `from_utf8_unchecked_bytes_buf` only when the caller can prove valid UTF-8. +- Use `CheetahStr` for immutable clone-cheap keys and `CheetahBuilder` for append-heavy construction. + ### Query Methods - `len()`, `is_empty()`, `as_str()`, `as_bytes()` - `starts_with()`, `ends_with()`, `contains()` - Support both `&str` and `char` patterns diff --git a/bench-results/README.md b/bench-results/README.md index 7891693..1a5441a 100644 --- a/bench-results/README.md +++ b/bench-results/README.md @@ -30,7 +30,7 @@ Minimum metadata for generated JSON artifacts: ```json { "crate": "cheetah-string", - "version": "1.2.0", + "version": "2.0.0", "profile": "release", "target": "x86_64-unknown-linux-gnu", "rustc": "rustc 1.xx.x", diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 0f4e8e5..2cdeb67 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -28,7 +28,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "cheetah-string" -version = "1.1.0" +version = "2.0.0" dependencies = [ "memchr", ] diff --git a/src/cheetah_string.rs b/src/cheetah_string.rs index e16b940..f1dd1fc 100644 --- a/src/cheetah_string.rs +++ b/src/cheetah_string.rs @@ -244,16 +244,6 @@ impl CheetahString { } } - #[deprecated( - since = "1.1.0", - note = "use try_from_vec for checked construction or from_utf8_unchecked_vec for an explicit unsafe constructor" - )] - pub fn from_vec(s: Vec) -> Self { - CheetahString::try_from_vec(s).expect( - "CheetahString::from_vec requires valid UTF-8; use try_from_vec for fallible construction", - ) - } - /// Creates a `CheetahString` from a byte vector without validating UTF-8. /// /// # Safety @@ -355,17 +345,6 @@ impl CheetahString { } } - #[deprecated( - since = "1.1.0", - note = "use try_from_arc_vec for checked construction or from_utf8_unchecked_arc_vec for an explicit unsafe constructor" - )] - #[inline] - pub fn from_arc_vec(s: Arc>) -> Self { - CheetahString::try_from_arc_vec(s).expect( - "CheetahString::from_arc_vec requires valid UTF-8; use try_from_arc_vec for fallible construction", - ) - } - /// Creates a `CheetahString` from a shared byte vector without validating UTF-8. /// /// # Safety @@ -410,7 +389,7 @@ impl CheetahString { #[inline] pub fn from_string(s: String) -> Self { - CheetahString::from_string_shared(s) + CheetahString::from_string_owned(s) } /// Creates a `CheetahString` from an owned `String` while preserving @@ -427,9 +406,8 @@ impl CheetahString { /// Creates a `CheetahString` from an owned `String` using shared storage /// for long immutable strings. /// - /// This is the same storage policy used by `from_string` in the 1.x line. - /// Use `from_string_owned` when spare capacity should be preserved for - /// later mutation. + /// New code that needs clone-cheap immutable strings should prefer + /// `CheetahStr`. #[inline] pub fn from_string_shared(s: String) -> Self { if s.len() <= INLINE_CAPACITY { @@ -477,18 +455,6 @@ impl CheetahString { } } - #[inline] - #[cfg(feature = "bytes")] - #[deprecated( - since = "1.1.0", - note = "use try_from_bytes_buf for checked construction or from_utf8_unchecked_bytes_buf for an explicit unsafe constructor" - )] - pub fn from_bytes(b: bytes::Bytes) -> Self { - CheetahString::try_from_bytes_buf(b).expect( - "CheetahString::from_bytes requires valid UTF-8; use try_from_bytes_buf for fallible construction", - ) - } - #[inline] #[cfg(feature = "bytes")] pub fn try_from_bytes_buf(b: bytes::Bytes) -> Result { diff --git a/src/lib.rs b/src/lib.rs index 41e45a7..14f8fb7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,8 +6,8 @@ //! `CheetahBuilder` is available for append-heavy construction. //! The `bytes` feature exposes `CheetahBytes` for byte-oriented data. //! It minimizes allocations across small, shared, and builder-oriented string workloads. -//! The `from_string_owned` and `from_string_shared` constructors make owned -//! mutation and clone-cheap sharing policies explicit. +//! `from_string` preserves owned storage for mutable string workflows. +//! Use `CheetahStr` for clone-cheap immutable values. //! Substring search uses `memchr`/`memmem` by default. //! //! # SIMD Acceleration @@ -25,7 +25,7 @@ //! To enable SIMD acceleration: //! ```toml //! [dependencies] -//! cheetah-string = { version = "1.2.0", features = ["simd"] } +//! cheetah-string = { version = "2.0.0", features = ["simd"] } //! ``` //! //! # Examples diff --git a/tests/mutation.rs b/tests/mutation.rs index 35cd414..631a682 100644 --- a/tests/mutation.rs +++ b/tests/mutation.rs @@ -49,6 +49,20 @@ fn from_string_owned_preserves_spare_capacity_for_push() { assert_eq!(s.as_bytes().as_ptr(), before); } +#[test] +fn from_string_defaults_to_owned_policy_in_v2() { + let mut raw = String::with_capacity(128); + raw.push_str("hello"); + + let mut s = CheetahString::from_string(raw); + let before = s.as_bytes().as_ptr(); + + s.push_str(" world"); + + assert_eq!(s, "hello world"); + assert_eq!(s.as_bytes().as_ptr(), before); +} + #[test] fn from_string_shared_keeps_long_immutable_inputs_clone_cheap() { let s = CheetahString::from_string_shared("a".repeat(128));