enhance(core): add FromStr impl for SafePathBuf (#10870)

This commit is contained in:
Tony 2024-09-03 10:20:31 +08:00 committed by GitHub
parent 27d0183431
commit 431ca2c776
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"tauri": patch:enhance
---
Add `FromStr` impl for `SafePathBuf`

View File

@ -2,7 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use std::path::{Component, Display, Path, PathBuf};
use std::{
path::{Component, Display, Path, PathBuf},
str::FromStr,
};
use crate::Runtime;
@ -51,6 +54,14 @@ impl AsRef<Path> for SafePathBuf {
}
}
impl FromStr for SafePathBuf {
type Err = &'static str;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
Self::new(s.into())
}
}
impl<'de> Deserialize<'de> for SafePathBuf {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where