strict_path/path/virtual_path/display.rs
1//! `VirtualPathDisplay` — formats a `VirtualPath` as a rooted, forward-slash string.
2//!
3//! Returns the virtual (user-facing) view, not the real system path. The real path is
4//! intentionally hidden to prevent leaking host filesystem structure in API responses,
5//! error messages, or multi-tenant UIs. Use `strictpath_display()` when the real path
6//! is needed (e.g., for system administrators or internal logging).
7use super::VirtualPath;
8use std::fmt;
9
10pub struct VirtualPathDisplay<'vpath, Marker>(pub(super) &'vpath VirtualPath<Marker>);
11
12impl<'vpath, Marker> fmt::Display for VirtualPathDisplay<'vpath, Marker> {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 // Sanitize each Normal component at display time so that virtual_path
15 // stores raw OS names (preserving correct navigation via virtual_join).
16 use std::path::Component;
17 let mut parts: Vec<String> = Vec::new();
18 for comp in self.0.virtual_path.components() {
19 if let Component::Normal(name) = comp {
20 let s = name.to_string_lossy();
21 parts.push(super::sanitize_display_component(&s));
22 }
23 }
24 if parts.is_empty() {
25 write!(f, "/")
26 } else {
27 write!(f, "/{}", parts.join("/"))
28 }
29 }
30}