diff --git a/src/expression.rs b/src/expression.rs index dfef32a..7daa54d 100644 --- a/src/expression.rs +++ b/src/expression.rs @@ -1,7 +1,7 @@ mod minimize; mod parser; -use crate::LicenseReq; +use crate::{error::ParseError, LicenseReq}; pub use minimize::MinimizeError; use smallvec::SmallVec; use std::fmt; @@ -231,6 +231,13 @@ impl fmt::Display for Expression { } } +impl std::str::FromStr for Expression { + type Err = ParseError; + fn from_str(s: &str) -> Result { + Self::parse(s) + } +} + impl PartialEq for Expression { fn eq(&self, o: &Self) -> bool { // The expressions can be semantically the same but not diff --git a/src/licensee.rs b/src/licensee.rs index e0db102..6ec77aa 100644 --- a/src/licensee.rs +++ b/src/licensee.rs @@ -25,6 +25,14 @@ impl fmt::Display for Licensee { } } +impl std::str::FromStr for Licensee { + type Err = ParseError; + + fn from_str(s: &str) -> Result { + Self::parse(s) + } +} + impl Licensee { /// Creates a licensee from its component parts. Note that use of SPDX's /// `or_later` is completely ignored for licensees as it only applies