Ver Fonte

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

Tony há 11 meses atrás
pai
commit
431ca2c776
2 ficheiros alterados com 17 adições e 1 exclusões
  1. 5 0
      .changes/safe-path-buf-from-str.md
  2. 12 1
      crates/tauri/src/path/mod.rs

+ 5 - 0
.changes/safe-path-buf-from-str.md

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

+ 12 - 1
crates/tauri/src/path/mod.rs

@@ -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