Module serde_ext

Module serde_ext 

Source
Expand description

Serde helpers and notes.

Built‑in Serialize (feature serde):

  • StrictPath → system path string
  • VirtualPath → 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§

WithBoundary
Deserialize a StrictPath with PathBoundary context.
WithVirtualRoot
Deserialize a VirtualPath with virtual root context.