#![no_std]
#![doc(html_root_url = "https://docs.rs/license")]
#![deny(missing_docs, unsafe_code)]
#[cfg(feature = "serde")]
mod serde;
use core::fmt::{self, Debug, Display, Formatter};
use core::str::FromStr;
pub mod licenses {
include!(concat!(env!("OUT_DIR"), "/licenses.rs"));
}
pub mod exceptions {
include!(concat!(env!("OUT_DIR"), "/exceptions.rs"));
}
pub trait License {
fn id(&self) -> &'static str;
fn name(&self) -> &'static str;
fn text(&self) -> &'static str;
fn header(&self) -> Option<&'static str>;
fn is_osi_approved(&self) -> bool;
fn is_fsf_libre(&self) -> bool;
fn is_deprecated(&self) -> bool;
fn comments(&self) -> Option<&'static str>;
fn see_also(&self) -> &'static [&'static str];
}
pub trait Exception {
fn id(&self) -> &'static str;
fn name(&self) -> &'static str;
fn text(&self) -> &'static str;
fn is_deprecated(&self) -> bool;
fn comments(&self) -> Option<&'static str>;
fn see_also(&self) -> &'static [&'static str];
}
impl Display for dyn License {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
Display::fmt(self.name(), f)
}
}
impl Display for dyn Exception {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
Display::fmt(self.name(), f)
}
}
impl Debug for dyn License {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
Debug::fmt(self.id(), f)
}
}
impl Debug for dyn Exception {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
Debug::fmt(self.id(), f)
}
}
impl FromStr for &dyn License {
type Err = ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
licenses::parse_id(s).ok_or(ParseError(()))
}
}
impl FromStr for &dyn Exception {
type Err = ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
exceptions::parse_id(s).ok_or(ParseError(()))
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ParseError(());
impl Display for ParseError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
Display::fmt("SPDX id not found", f)
}
}