summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManfred Endres <manfred.endres@tslarusso.de>2019-12-16 20:18:00 +0100
committerAndrew Gallant <jamslam@gmail.com>2020-02-17 17:16:28 -0500
commit804b43ecd8bd37fde4fc81f49d1f9bb659aeac1c (patch)
treedec62d433fb92104fb9c79cef73825d89cc4689c
parent2263b8ac9293073dbf7bf29691889ade53042650 (diff)
globset: implement FromStr for Glob
The `globset::Glob` type [`new`] function creates a new value with an `&str` parameter which returns an `Result<Glob, Error>` object. This is exactly what [`std::str::FromStr::from_str`][`std::str::FromStr`] defines. Libraries like [`clap`] use [`std::str::FromStr`] to create objects from provided commandline arguments. This change makes this library usable without a newtype wrapper. [`std::str::FromStr`]: https://doc.rust-lang.org/std/str/trait.FromStr.html [`clap`]: https://docs.rs/clap/2.33.0/clap/macro.value_t.html [`new`]: https://docs.rs/globset/0.4.4/globset/struct.Glob.html#method.new Closes #1447
-rw-r--r--globset/src/glob.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/globset/src/glob.rs b/globset/src/glob.rs
index e327d998..c8dedba2 100644
--- a/globset/src/glob.rs
+++ b/globset/src/glob.rs
@@ -103,6 +103,14 @@ impl fmt::Display for Glob {
}
}
+impl str::FromStr for Glob {
+ type Err = Error;
+
+ fn from_str(glob: &str) -> Result<Self, Self::Err> {
+ Self::new(glob)
+ }
+}
+
/// A matcher for a single pattern.
#[derive(Clone, Debug)]
pub struct GlobMatcher {