MicroStr
A lightweight, stack-allocated string with fixed capacity and UTF-8 support.
Ideal for no_std environments, embedded systems, and performance-critical code.
[]
= "0.1"
Features
- ✅ No heap allocations — fully stack-based.
- ✅ UTF-8 safe — always valid string content.
- ✅
no_stdby default — works withoutstd. - ✅ Const generic capacity — size known at compile time.
- ✅ Truncation-aware — safely appends strings without overflow.
- ✅ Seamless
stdintegration — supportsDisplay,Debug,From<String>, etc. - ✅ Optional
serdesupport — JSON (de)serialization with length checking.
Usage
use MicroStr;
// Create a string with capacity of 16 bytes
let mut s: = new;
s.push_str;
s.push;
assert_eq!;
assert_eq!; // 6 Unicode chars
assert_eq!; // 6 bytes
assert!; // Truncated safely
You can also use it like a regular &str thanks to Deref:
if s.starts_with
Features
Enable optional features in Cargo.toml:
[]
= { = "0.1", = ["std", "serde"] }
| Feature | Description |
|---|---|
std (default: on) |
Enables Display, Debug, From<String>, and ToString. Required for serde. |
serde |
Enables .to_json() and StackString::from_json() with capacity checks. |
Example with serde
Why MicroStr?
- Predictable performance: No allocations, no heap usage.
- Memory safety: Always valid UTF-8, no buffer overflows.
- Great for constrained environments: Embedded, kernels, WASM.
- Easy migration: Drop-in replacement for
Stringin many cases.
API Documentation
📚 Full documentation: https://docs.rs/microstr
License
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.