Expand description
§ZCString
ZCString is a wrapper around arcstr::Substr designed for zero-copy
parsing using a thread-local context. It allows you to track a “source”
string and derive substrings from it without unnecessary allocations.
serde_json is currently supported by default.
§Main Functionality
- Context-aware creation: Uses a thread-local
SOURCEto check if a new string is actually a sub-slice of an existing managed string. - RAII Guards: Provides a
SourceGuardto safely manage the lifecycle of the thread-local source. - Serde Integration: Optional (defaults to on) support for efficient
zero-copy deserialization via the
serdefeature flag.
§Crate Features
defaultBy default, serde and std are enabled.serde(Optional): Enables serialization and deserialization support viaserdeandserde_json.std(Optional): EnablesFrom<String>implementations.
§serde_json example
use arcstr::literal;
use serde::Deserialize;
use std::error::Error;
use zcstring::{ZCString, serde_json_from_zcstring};
#[derive(Debug, Deserialize)]
struct Animal {
animal: ZCString,
color: ZCString,
}
fn main() -> Result<(), Box<dyn Error>> {
let json = literal!(r#"{"animal":"cat", "color": "red"}"#);
// ZCString::from below is zero-copy from the ArcStr json
// when done struct members will point to memory within
// the json string.
let animal = serde_json_from_zcstring::<Animal>(json.into())?;
println!("animal: {:?}", animal);
Ok(())
}Structs§
- Source
Guard - An RAII guard used to manage the lifecycle of the thread-local string source.
- ZCString
- ZCString wrapper struct
- ZCString
Iter Wrapper - str iterator wrapper automatically converts &str to ZCString maintaining source references.
Enums§
- Reader
Error std
Functions§
- serde_
json_ from_ zcstring serde_json - Parses a JSON string into type
Twhile using the providedZCStringas the context for any zero-copy deserialization.