Skip to content

Commit 4017a7e

Browse files
feat: Allow getting inner PathBuf from SafePathBuf (#14908)
* Allow getting inner PathBuf from SafePathBuf SafePathBuf implements AsRef<Path> which is ergonomic and useful. However, some APIs take owned PathBufs. This leads to clunky code where the caller has to get a &Path from the SafePathBuf then take ownership of that path. Ideally, if a user has a SafePathBuf and needs a PathBuf, they won't need to allocate again just to get the inner PathBuf back. * Apply suggestion from @Legend-Master
1 parent 093e2b4 commit 4017a7e

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch:enhance
3+
---
4+
5+
Implement retrieving inner PathBuf from SafePathBuf to ease using APIs that require an owned PathBuf

crates/tauri/src/path/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ impl FromStr for SafePathBuf {
7373
}
7474
}
7575

76+
impl From<SafePathBuf> for PathBuf {
77+
fn from(path: SafePathBuf) -> Self {
78+
path.0
79+
}
80+
}
81+
7682
impl<'de> Deserialize<'de> for SafePathBuf {
7783
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
7884
where

0 commit comments

Comments
 (0)