29 releases

new 0.10.7 Nov 15, 2024
0.10.6 May 31, 2024
0.10.4 Feb 26, 2024
0.10.2 Jul 14, 2023
0.1.0 Jun 19, 2019

#34 in Parser implementations

Download history 75549/week @ 2024-07-26 72320/week @ 2024-08-02 73087/week @ 2024-08-09 75806/week @ 2024-08-16 72877/week @ 2024-08-23 75703/week @ 2024-08-30 82604/week @ 2024-09-06 76514/week @ 2024-09-13 71715/week @ 2024-09-20 69933/week @ 2024-09-27 78454/week @ 2024-10-04 66599/week @ 2024-10-11 78458/week @ 2024-10-18 72065/week @ 2024-10-25 79570/week @ 2024-11-01 80311/week @ 2024-11-08

322,743 downloads per month
Used in 152 crates (32 directly)

MIT/Apache

1MB
5K SLoC

🆔 spdx

Helper crate for SPDX license expressions

Embark Embark Crates.io Docs Minimum Stable Rust Version SPDX Version dependency status Build Status

Usage

use spdx::Expression;

fn main() {
    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

Contributor Covenant

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

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.

Dependencies