combined_str
A no_std Rust library providing CombinedStr, a zero-copy, const-generic string combinator that holds N string slices and presents them as a single logical string — without allocating.
Features
no_stdcompatible — works in embedded and bare-metal environments- Zero-copy — holds
&strreferences, no heap allocation required allocfeature — enables conversion toStringandCow<str>, plus+=/+operators and equality comparisonsDisplay— prints all segments as one contiguous string- Iterator — iterate over the individual
&strsegments
Usage
[]
= "0.1"
Basic example
use strs;
let s = strs!;
println!; // hello, world
assert_eq!;
assert!;
Construction from an array or &str
use CombinedStr;
let s = from;
let s = from; // single segment
Zero-allocation equality comparison
use strs;
assert!;
Appending to a String or Cow<str> (requires alloc feature)
use strs;
let mut owned = Stringfrom;
owned += strs!;
assert_eq!;
Equality with String and Cow<str> (requires alloc feature)
use Cow;
use strs;
assert!;
assert!;
// symmetric
assert!;
assert!;
Converting to String or Cow<str> (requires alloc feature)
use Cow;
use strs;
let s: String = strs!.into;
assert_eq!;
let c: = strs!.into;
assert_eq!;
API
CombinedStr<'a, N>
| Method | Description |
|---|---|
len() -> usize |
Total byte length across all segments |
is_empty() -> bool |
True if total length is zero |
as_bytes() -> [&[u8]; N] |
Byte slices for each segment |
as_pointer() -> [*const u8; N] |
Raw pointers for each segment |
as_ref() -> &[&str] |
Underlying segments as a slice |
Implements: Display, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoIterator, Default, From<[&str; N]>, From<&str> (N=1), PartialEq<str>.
With alloc: From<CombinedStr> for String, From<CombinedStr> for Cow<str>, AddAssign/Add for String and Cow<str>, PartialEq<String>, PartialEq<Cow<str>> (all symmetric).
strs! macro
Constructs a CombinedStr from a comma-separated list of string expressions:
use strs;
let s = strs!;
Feature flags
| Flag | Default | Description |
|---|---|---|
alloc |
enabled | Enables String/Cow support via the alloc crate |
License
MIT OR Apache-2.0