From 804b43ecd8bd37fde4fc81f49d1f9bb659aeac1c Mon Sep 17 00:00:00 2001 From: Manfred Endres Date: Mon, 16 Dec 2019 20:18:00 +0100 Subject: [PATCH] globset: implement FromStr for Glob The `globset::Glob` type [`new`] function creates a new value with an `&str` parameter which returns an `Result` 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 --- globset/src/glob.rs | 8 ++++++++ 1 file changed, 8 insertions(+) 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::new(glob) + } +} + /// A matcher for a single pattern. #[derive(Clone, Debug)] pub struct GlobMatcher {