Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement FromStr for Expression and Licensee #69

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/expression.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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, Self::Err> {
Self::parse(s)
}
}

impl PartialEq for Expression {
fn eq(&self, o: &Self) -> bool {
// The expressions can be semantically the same but not
Expand Down
8 changes: 8 additions & 0 deletions src/licensee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, Self::Err> {
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
Expand Down
Loading