pub struct Licensee { /* private fields */ }
Expand description
A convenience wrapper for a license and optional exception that can be checked against a license requirement to see if it satisfies the requirement placed by a license holder
let licensee = spdx::Licensee::parse("GPL-2.0").unwrap();
assert!(licensee.satisfies(&spdx::LicenseReq::from(spdx::license_id("GPL-2.0-only").unwrap())));
Implementations§
source§impl Licensee
impl Licensee
sourcepub fn new(license: LicenseItem, exception: Option<ExceptionId>) -> Self
pub fn new(license: LicenseItem, exception: Option<ExceptionId>) -> Self
Creates a licensee from its component parts. Note that use of SPDX’s
or_later
is completely ignored for licensees as it only applies
to the license holder(s), not the licensee
sourcepub fn parse(original: &str) -> Result<Self, ParseError>
pub fn parse(original: &str) -> Result<Self, ParseError>
Parses an simplified version of an SPDX license expression that can
contain at most 1 valid SDPX license with an optional exception joined
by a WITH
.
use spdx::Licensee;
// Normal single license
Licensee::parse("MIT").unwrap();
// SPDX allows license identifiers outside of the official license list
// via the LicenseRef- prefix
Licensee::parse("LicenseRef-My-Super-Extra-Special-License").unwrap();
// License and exception
Licensee::parse("Apache-2.0 WITH LLVM-exception").unwrap();
// `+` is only allowed to be used by license requirements from the license holder
Licensee::parse("Apache-2.0+").unwrap_err();
Licensee::parse("GPL-2.0").unwrap();
// GNU suffix license (GPL, AGPL, LGPL, GFDL) must not contain the suffix
Licensee::parse("GPL-3.0-or-later").unwrap_err();
// GFDL licenses are only allowed to contain the `invariants` suffix
Licensee::parse("GFDL-1.3-invariants").unwrap();
sourcepub fn satisfies(&self, req: &LicenseReq) -> bool
pub fn satisfies(&self, req: &LicenseReq) -> bool
Determines whether the specified license requirement is satisfied by this license (+exception)
let licensee = spdx::Licensee::parse("Apache-2.0 WITH LLVM-exception").unwrap();
assert!(licensee.satisfies(&spdx::LicenseReq {
license: spdx::LicenseItem::Spdx {
id: spdx::license_id("Apache-2.0").unwrap(),
// Means the license holder is fine with Apache-2.0 or higher
or_later: true,
},
exception: spdx::exception_id("LLVM-exception"),
}));
pub fn into_req(self) -> LicenseReq
Trait Implementations§
source§impl AsRef<LicenseReq> for Licensee
impl AsRef<LicenseReq> for Licensee
source§fn as_ref(&self) -> &LicenseReq
fn as_ref(&self) -> &LicenseReq
Converts this type into a shared reference of the (usually inferred) input type.
source§impl Ord for Licensee
impl Ord for Licensee
source§impl PartialEq<LicenseReq> for Licensee
impl PartialEq<LicenseReq> for Licensee
source§impl PartialOrd<LicenseReq> for Licensee
impl PartialOrd<LicenseReq> for Licensee
source§impl PartialOrd for Licensee
impl PartialOrd for Licensee
impl Eq for Licensee
impl StructuralPartialEq for Licensee
Auto Trait Implementations§
impl Freeze for Licensee
impl RefUnwindSafe for Licensee
impl Send for Licensee
impl Sync for Licensee
impl Unpin for Licensee
impl UnwindSafe for Licensee
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)