Expand description
Serde helpers and notes.
Built‑in Serialize (feature serde):
StrictPath→ system path stringVirtualPath→ virtual root string (e.g., “/a/b.txt”)
Deserialization requires context (a PathBoundary or VirtualRoot). Use the context helpers
below to deserialize with context, or deserialize to String and validate explicitly.
Example: Deserialize a single StrictPath with context
use strict_path::{PathBoundary, StrictPath};
use strict_path::serde_ext::WithBoundary;
use serde::de::DeserializeSeed;
let boundary: PathBoundary = PathBoundary::try_new(td.path())?;
let mut de = serde_json::Deserializer::from_str("\"a/b.txt\"");
let jp: StrictPath = WithBoundary(&boundary).deserialize(&mut de)?;
// OS-agnostic assertion: file name should be "b.txt"
assert_eq!(jp.strictpath_file_name().unwrap().to_string_lossy(), "b.txt");Example: Deserialize a single VirtualPath with context
use strict_path::{VirtualPath, VirtualRoot};
use strict_path::serde_ext::WithVirtualRoot;
use serde::de::DeserializeSeed;
let vroot: VirtualRoot = VirtualRoot::try_new(td.path())?;
let mut de = serde_json::Deserializer::from_str("\"a/b.txt\"");
let vp: VirtualPath = WithVirtualRoot(&vroot).deserialize(&mut de)?;
assert_eq!(vp.virtualpath_display().to_string(), "/a/b.txt");Structs§
- With
Boundary - Deserialize a
StrictPathwith PathBoundary context. - With
Virtual Root - Deserialize a
VirtualPathwith virtual root context.