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
This commit is contained in:
Joshua Megnauth
2026-03-24 04:35:05 -04:00
committed by GitHub
parent 093e2b47c0
commit 4017a7ed73
2 changed files with 11 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"tauri": patch:enhance
---
Implement retrieving inner PathBuf from SafePathBuf to ease using APIs that require an owned PathBuf

View File

@@ -73,6 +73,12 @@ impl FromStr for SafePathBuf {
}
}
impl From<SafePathBuf> for PathBuf {
fn from(path: SafePathBuf) -> Self {
path.0
}
}
impl<'de> Deserialize<'de> for SafePathBuf {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where