ByteStr
A zero-copy, cheaply cloneable, and sliceable immutable UTF-8 encoded string type built on top of bytes::Bytes. Perfect for high-performance network programming and efficient string manipulation.
✨ Features
- 🚀 Zero-copy operations: Clone and slice without additional allocations
- ⚡ High performance: Built on the battle-tested
bytescrate - 🔄 Serde support: Optional serialization/deserialization (feature-gated)
- 📦
no_stdcompatible: Works in embedded and resource-constrained environments
🚀 Quick Start
Add this to your Cargo.toml:
[]
= "0.3"
Basic Usage
use ByteStr;
// Create from static string (zero-cost)
let s1 = from_static;
// Create from String (reuses allocation)
let s2 = from;
// Create from bytes with validation
let s3 = from_utf8?;
// Clone is cheap (just a reference count increment)
let cloned = s1.clone;
// Slice without copying
let original_str = s1.as_str;
let slice = s1.slice_ref; // "world"
// Or use convenient indexing syntax (returns &str)
let indexed_slice = &s1; // "world"
// All standard string operations work
assert_eq!;
assert!;
assert!;
assert_eq!;
Advanced Usage
use ByteStr;
use HashMap;
// Perfect for network protocols and caching
let mut cache: = new;
// Zero-copy slicing for parsing
🔧 Optional Features
Serde Support
Enable serialization/deserialization support:
[]
= { = "0.2", = ["serde"] }
use ByteStr;
use ;
let msg = Message ;
let json = to_string?;
let deserialized: Message = from_str?;
📄 License
This project is licensed under the MIT License.