Skip to content

Commit

Permalink
enhance(core): add FromStr impl for SafePathBuf (#10870)
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master authored Sep 3, 2024
1 parent 27d0183 commit 431ca2c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/safe-path-buf-from-str.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:enhance
---

Add `FromStr` impl for `SafePathBuf`
13 changes: 12 additions & 1 deletion crates/tauri/src/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 431ca2c

Please sign in to comment.