diff options
author | Kirill Bulatov <[email protected]> | 2020-09-03 21:18:23 +0100 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-09-09 23:42:20 +0100 |
commit | 17870a3e2c39770a99f9ab5ce090abbe1dc334d2 (patch) | |
tree | 85e98d57518fd2735820e9b70f16a7e2ab54d082 /crates/vfs/src/vfs_path.rs | |
parent | 4bed588001a1d6cd5c83a3eefc6ef77c439de40b (diff) |
Better API
Diffstat (limited to 'crates/vfs/src/vfs_path.rs')
-rw-r--r-- | crates/vfs/src/vfs_path.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs index 944a702df..7b965bb4c 100644 --- a/crates/vfs/src/vfs_path.rs +++ b/crates/vfs/src/vfs_path.rs | |||
@@ -49,6 +49,16 @@ impl VfsPath { | |||
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | pub fn file_name_and_extension(&self) -> Option<(&str, &str)> { | ||
53 | match &self.0 { | ||
54 | VfsPathRepr::PathBuf(p) => p | ||
55 | .file_stem() | ||
56 | .zip(p.extension()) | ||
57 | .and_then(|(name, extension)| Some((name.to_str()?, extension.to_str()?))), | ||
58 | VfsPathRepr::VirtualPath(p) => p.file_name_and_extension(), | ||
59 | } | ||
60 | } | ||
61 | |||
52 | // Don't make this `pub` | 62 | // Don't make this `pub` |
53 | pub(crate) fn encode(&self, buf: &mut Vec<u8>) { | 63 | pub(crate) fn encode(&self, buf: &mut Vec<u8>) { |
54 | let tag = match &self.0 { | 64 | let tag = match &self.0 { |
@@ -268,4 +278,9 @@ impl VirtualPath { | |||
268 | res.0 = format!("{}/{}", res.0, path); | 278 | res.0 = format!("{}/{}", res.0, path); |
269 | Some(res) | 279 | Some(res) |
270 | } | 280 | } |
281 | |||
282 | pub fn file_name_and_extension(&self) -> Option<(&str, &str)> { | ||
283 | // TODO kb check if is a file | ||
284 | Some(("test_mod_1", "rs")) | ||
285 | } | ||
271 | } | 286 | } |