Expand description
§About
This crate’s main purpose is to parse and evaluate SPDX license expressions. It also optionally provides the ability to scan text data for SPDX license information. Each version of this crate contains a specific version of the official SPDX license list which can be retrieved via the spdx::identifiers::VERSION constant.
§Features
text- Includes the full canonical text of each licensedetection- Allows analysis of text to determine if it might be an SPDX license text, or have an SPDX license headerdetection-cache- Allows de/serialization of aStorefor quicker loadingdetection-inline-cache- Inlines aStorecache into this crate, which allows easier loading in downstream crates at the cost of increased binary sizedetection-parallel- Performs license detection in parallel within the same text
§Usage
use spdx::Expression;
let this_is_fine = Expression::parse("MIT OR Apache-2.0").unwrap();
assert!(this_is_fine.evaluate(|req| {
if let spdx::LicenseItem::Spdx { id, .. } = req.license {
// Both MIT and Apache-2.0 are OSI approved, so this expression
// evaluates to true
return id.is_osi_approved();
}
false
}));
assert!(!this_is_fine.evaluate(|req| {
if let spdx::LicenseItem::Spdx { id, .. } = req.license {
// This is saying we don't accept any licenses that are OSI approved
// so the expression will evaluate to false as both sides of the OR
// are now rejected
return !id.is_osi_approved();
}
false
}));
// `NOPE` is not a valid SPDX license identifier, so this expression
// will fail to parse
let _this_is_not = Expression::parse("MIT OR NOPE").unwrap_err();§Updating SPDX list
You can update the list of SPDX identifiers for licenses and exceptions by running the update program cargo run --manifest-path=update/Cargo.toml -- v3.6 where v3.6 is the tag in the SPDX data repo.
§Contributing
We welcome community contributions to this project.
Please read our Contributor Guide for more information on how to get started.
§License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
§Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Re-exports§
pub use error::ParseError;pub use expression::Expression;pub use lexer::ParseMode;
Modules§
- detection
detection - Allows analysis of text to determine if it resembles a license This module is basically an inling of askalono
- error
- Error types
- expression
- Types used in SPDX expressions, notably
Expression - flags
- Flags that can apply to licenses and/or license exceptions
- identifiers
- Auto-generated lists of license identifiers and exception identifiers
- lexer
- Contains types for lexing an SPDX license expression
- text
text - Auto-generated full canonical text of each license
Structs§
- Addition
Ref - A user supplied
AddtionRef-<user string>to specify additional text to associate with a license that falls outside the SPDX license list - Exception
- An SPDX exception
- Exception
Id - Unique identifier for a particular exception
- License
- An SPDX license
- License
Id - Unique identifier for a particular license
- License
Ref - SPDX allows the use of
LicenseRef-<user supplied string>to provide arbitrary licenses that aren’t a part of the official SPDX license list - License
Req - Represents a single license requirement.
- Licensee
- A convenience wrapper for a license and optional additional text that can be checked against a license requirement to see if it satisfies the requirement placed by a license holder
Enums§
- Addition
Item - A single addition term in a addition expression, according to the SPDX spec.
- License
Item - A single license term in a license expression, according to the SPDX spec.
Functions§
- exception_
id - Attempts to find an
ExceptionIdfor the string - gnu_
license_ id - Attempts to find a GNU license from its base name.
- imprecise_
license_ id - Find license partially matching the name, e.g. “apache” => “Apache-2.0”
- license_
id - Attempts to find a
LicenseIdgiven a short id. - license_
version - Returns the version number of the SPDX list from which the license and exception identifiers are sourced from