Skip to content

Commit 431ca2c

Browse files
enhance(core): add FromStr impl for SafePathBuf (#10870)
1 parent 27d0183 commit 431ca2c

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

.changes/safe-path-buf-from-str.md

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+
Add `FromStr` impl for `SafePathBuf`

crates/tauri/src/path/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use std::path::{Component, Display, Path, PathBuf};
5+
use std::{
6+
path::{Component, Display, Path, PathBuf},
7+
str::FromStr,
8+
};
69

710
use crate::Runtime;
811

@@ -51,6 +54,14 @@ impl AsRef<Path> for SafePathBuf {
5154
}
5255
}
5356

57+
impl FromStr for SafePathBuf {
58+
type Err = &'static str;
59+
60+
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
61+
Self::new(s.into())
62+
}
63+
}
64+
5465
impl<'de> Deserialize<'de> for SafePathBuf {
5566
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
5667
where

0 commit comments

Comments
 (0)