diff options
Diffstat (limited to 'crates/vfs/src/vfs_path.rs')
-rw-r--r-- | crates/vfs/src/vfs_path.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs index dc3031ada..04a42264e 100644 --- a/crates/vfs/src/vfs_path.rs +++ b/crates/vfs/src/vfs_path.rs | |||
@@ -48,6 +48,37 @@ impl VfsPath { | |||
48 | (VfsPathRepr::VirtualPath(_), _) => false, | 48 | (VfsPathRepr::VirtualPath(_), _) => false, |
49 | } | 49 | } |
50 | } | 50 | } |
51 | |||
52 | // Don't make this `pub` | ||
53 | pub(crate) fn encode(&self, buf: &mut Vec<u8>) { | ||
54 | let tag = match &self.0 { | ||
55 | VfsPathRepr::PathBuf(_) => 0, | ||
56 | VfsPathRepr::VirtualPath(_) => 1, | ||
57 | }; | ||
58 | buf.push(tag); | ||
59 | match &self.0 { | ||
60 | VfsPathRepr::PathBuf(it) => { | ||
61 | let path: &std::ffi::OsStr = it.as_os_str(); | ||
62 | #[cfg(windows)] | ||
63 | { | ||
64 | use std::os::windows::ffi::OsStrExt; | ||
65 | for wchar in path.encode_wide() { | ||
66 | buf.extend(wchar.to_le_bytes().iter().copied()); | ||
67 | } | ||
68 | } | ||
69 | #[cfg(unix)] | ||
70 | { | ||
71 | use std::os::unix::ffi::OsStrExt; | ||
72 | buf.extend(path.as_bytes()); | ||
73 | } | ||
74 | #[cfg(not(any(windows, unix)))] | ||
75 | { | ||
76 | buf.extend(path.to_string_lossy().as_bytes()); | ||
77 | } | ||
78 | } | ||
79 | VfsPathRepr::VirtualPath(VirtualPath(s)) => buf.extend(s.as_bytes()), | ||
80 | } | ||
81 | } | ||
51 | } | 82 | } |
52 | 83 | ||
53 | #[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] | 84 | #[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] |