Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cheetah-string"
version = "1.2.0"
version = "2.0.0"
authors = ["mxsm <mxsm@apache.org>"]
edition = "2021"
homepage = "https://github.com/mxsm/cheetah-string"
Expand Down
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 |
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bench-results/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 3 additions & 37 deletions src/cheetah_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>) -> 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
Expand Down Expand Up @@ -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<Vec<u8>>) -> 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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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<Self, Utf8Error> {
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading