| Crates.io | microstr |
| lib.rs | microstr |
| version | 0.4.0 |
| created_at | 2025-08-11 13:19:45.071381+00 |
| updated_at | 2025-08-15 11:41:49.644727+00 |
| description | Stack-allocated string with fixed capacity |
| homepage | |
| repository | https://github.com/DanilaMint/microstr |
| max_upload_size | |
| id | 1790162 |
| size | 37,178 |
A lightweight, stack-allocated string with fixed capacity and UTF-8 support.
Ideal for no_std environments, embedded systems, and performance-critical code.
[dependencies]
microstr = "0.4"
no_std by default — works without std.std integration — supports Display, Debug, From<String>, etc.serde support — JSON (de)serialization with length checking.use microstr::MicroStr;
// Create a string with capacity of 16 bytes
let mut s: MicroStr<16> = MicroStr::new();
s.push_str("Hello");
s.push('!');
assert_eq!(s.as_str(), "Hello!");
assert_eq!(s.len(), 6); // 6 Unicode chars
assert_eq!(s.bytes_len(), 6); // 6 bytes
assert_eq!(s.push_str(" this won't fit entirely"), Err(10)); // Truncated safely
You can also use it like a regular &str thanks to Deref:
if s.starts_with("Hello") {
println!("Greeting: {}", s);
}
Enable optional features in Cargo.toml:
[dependencies]
microstr = { version = "0.4", features = ["std", "serde"] }
| Feature | Description |
|---|---|
std (default: on) |
Enables Display, Debug, From<String>, and ToString. |
String in many cases.microstr!heapless::String| Feature | microstr |
heapless::String |
|---|---|---|
| UTF-8 safety | ✅ Always valid | ✅ Always valid |
no_std |
✅ Yes | ✅ Yes |
| Truncation on write | ✅ Yes (safe) | ❌ Returns Err on overflow |
const fn support |
✅ from_const, new |
Limited |
| Macro convenience | ✅ microstr! |
❌ No built-in macro |
microstr prioritizes zero-cost truncation and ease of use in embedded contexts.
📚 Full documentation: https://docs.rs/microstr
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.