README.md
1<!-- markdownlint-disable no-inline-html first-line-heading -->
2
3<div align="center">
4
5# ` spdx`
6
7**Helper crate for [SPDX](https://spdx.org/about) [license expressions](https://spdx.org/spdx-specification-21-web-version#h.jxpfx0ykyb60)**
8
9[](https://embark.dev)
10[](https://discord.gg/dAuKfZS)
11[](https://crates.io/crates/spdx)
12[](https://docs.rs/spdx)
13[](https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html)
14[](https://spdx.org/licenses/)
15[](https://deps.rs/repo/github/EmbarkStudios/spdx)
16[](https://github.com/EmbarkStudios/spdx/actions?workflow=CI)
17
18</div>
19
20## Usage
21
22```rust
23use spdx::Expression;
24
25fn main() {
26 let this_is_fine = Expression::parse("MIT OR Apache-2.0").unwrap();
27
28 assert!(this_is_fine.evaluate(|req| {
29 if let spdx::LicenseItem::Spdx { id, .. } = req.license {
30 // Both MIT and Apache-2.0 are OSI approved, so this expression
31 // evaluates to true
32 return id.is_osi_approved();
33 }
34
35 false
36 }));
37
38 assert!(!this_is_fine.evaluate(|req| {
39 if let spdx::LicenseItem::Spdx { id, .. } = req.license {
40 // This is saying we don't accept any licenses that are OSI approved
41 // so the expression will evaluate to false as both sides of the OR
42 // are now rejected
43 return !id.is_osi_approved();
44 }
45
46 false
47 }));
48
49 // `NOPE` is not a valid SPDX license identifier, so this expression
50 // will fail to parse
51 let _this_is_not = Expression::parse("MIT OR NOPE").unwrap_err();
52}
53```
54
55## Updating SPDX list
56
57You 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](https://github.com/spdx/license-list-data).
58
59## Contributing
60
61[](CODE_OF_CONDUCT.md)
62
63We welcome community contributions to this project.
64
65Please read our [Contributor Guide](CONTRIBUTING.md) for more information on how to get started.
66
67## License
68
69Licensed under either of
70
71* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
72* MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
73
74at your option.
75
76### Contribution
77
78Unless 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.
79