strict_path/path/virtual_path/
display.rs1use super::VirtualPath;
2use std::fmt;
3
4pub struct VirtualPathDisplay<'a, Marker>(pub(super) &'a VirtualPath<Marker>);
5
6impl<'a, Marker> fmt::Display for VirtualPathDisplay<'a, Marker> {
7 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8 let s_lossy = self.0.virtual_path.to_string_lossy();
10 let s_norm: std::borrow::Cow<'_, str> = {
11 #[cfg(windows)]
12 {
13 std::borrow::Cow::Owned(s_lossy.replace('\\', "/"))
14 }
15 #[cfg(not(windows))]
16 {
17 std::borrow::Cow::Borrowed(&s_lossy)
18 }
19 };
20 if s_norm.starts_with('/') {
21 write!(f, "{s_norm}")
22 } else {
23 write!(f, "/{s_norm}")
24 }
25 }
26}