Struct spdx_expression::SpdxExpression
source · [−]pub struct SpdxExpression { /* private fields */ }Expand description
Main struct for SPDX License Expressions.
Implementations
sourceimpl SpdxExpression
impl SpdxExpression
sourcepub fn parse(expression: &str) -> Result<Self, SpdxExpressionError>
pub fn parse(expression: &str) -> Result<Self, SpdxExpressionError>
Parse Self from a string. The input expression needs to be a syntactically valid SPDX
expression, NONE or NOASSERTION. The parser accepts license identifiers that are not
valid SPDX.
Examples
let expression = SpdxExpression::parse("MIT")?;License expressions need to be syntactically valid, but they can include license
identifiers not on the SPDX license list or not specified with LicenseRef.
let expression = SpdxExpression::parse("MIT OR InvalidLicenseId")?;Errors
Returns SpdxExpressionError if the license expression is not syntactically valid.
sourcepub fn identifiers(&self) -> HashSet<String>
pub fn identifiers(&self) -> HashSet<String>
Get all license and exception identifiers from the SpdxExpression.
Examples
let expression = SpdxExpression::parse("MIT OR Apache-2.0")?;
let licenses = expression.identifiers();
assert_eq!(licenses, HashSet::from_iter(["Apache-2.0".to_string(), "MIT".to_string()]));let expression = SpdxExpression::parse("MIT OR GPL-2.0-only WITH Classpath-exception-2.0")?;
let licenses = expression.identifiers();
assert_eq!(
licenses,
HashSet::from_iter([
"MIT".to_string(),
"GPL-2.0-only".to_string(),
"Classpath-exception-2.0".to_string()
])
);sourcepub fn licenses(&self) -> HashSet<&SimpleExpression>
pub fn licenses(&self) -> HashSet<&SimpleExpression>
Get all simple license expressions in Self. For licenses with exceptions, returns the
license without the exception
Examples
let expression = SpdxExpression::parse(
"(MIT OR Apache-2.0 AND (GPL-2.0-only WITH Classpath-exception-2.0 OR ISC))",
)
.unwrap();
let licenses = expression.licenses();
assert_eq!(
licenses
.iter()
.map(|&license| license.identifier.as_str())
.collect::<HashSet<_>>(),
HashSet::from_iter(["Apache-2.0", "GPL-2.0-only", "ISC", "MIT"])
);sourcepub fn exceptions(&self) -> HashSet<&str>
pub fn exceptions(&self) -> HashSet<&str>
Get all exception identifiers for Self.
Examples
let expression = SpdxExpression::parse(
"(MIT OR Apache-2.0 AND (GPL-2.0-only WITH Classpath-exception-2.0 OR ISC))",
)
.unwrap();
let exceptions = expression.exceptions();
assert_eq!(exceptions, HashSet::from_iter(["Classpath-exception-2.0"]));Trait Implementations
sourceimpl Clone for SpdxExpression
impl Clone for SpdxExpression
sourcefn clone(&self) -> SpdxExpression
fn clone(&self) -> SpdxExpression
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for SpdxExpression
impl Debug for SpdxExpression
sourceimpl Display for SpdxExpression
impl Display for SpdxExpression
sourceimpl PartialEq<SpdxExpression> for SpdxExpression
impl PartialEq<SpdxExpression> for SpdxExpression
sourcefn eq(&self, other: &SpdxExpression) -> bool
fn eq(&self, other: &SpdxExpression) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &SpdxExpression) -> bool
fn ne(&self, other: &SpdxExpression) -> bool
This method tests for !=.
impl Eq for SpdxExpression
impl StructuralEq for SpdxExpression
impl StructuralPartialEq for SpdxExpression
Auto Trait Implementations
impl RefUnwindSafe for SpdxExpression
impl Send for SpdxExpression
impl Sync for SpdxExpression
impl Unpin for SpdxExpression
impl UnwindSafe for SpdxExpression
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more