1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::fmt::{self, Display, Formatter};
use std::ffi::OsStr;
use License;
use permissions::*;
use conditions::*;
use limitations::*;

/// The [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).
#[derive(Clone, Copy, Debug, Default, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct Apache2;

impl License for Apache2 {
    #[inline]
    fn name(&self) -> &str {
        "Apache License 2.0"
    }

    #[inline]
    fn id(&self) -> &str {
        "Apache-2.0"
    }

    #[inline]
    fn is_osi_approved(&self) -> bool {
        true
    }

    #[inline]
    fn text(&self) -> &str {
        include_str!("../files/APACHE-2")
    }

    #[inline]
    fn permissions(&self) -> Permissions {
        COMMERCIAL_USE | DISTRIBUTION | MODIFICATION | PATENT_RIGHTS | PRIVATE_USE
    }

    #[inline]
    fn conditions(&self) -> Conditions {
        LICENSE_AND_COPYRIGHT_NOTICE | DOCUMENT_CHANGES
    }

    #[inline]
    fn limitations(&self) -> Limitations {
        NO_LIABILITY | NO_TRADEMARK_RIGHTS | NO_WARRANTY
    }

    #[inline]
    fn homepage(&self) -> Option<&str> {
        Some("https://www.apache.org/licenses/LICENSE-2.0")
    }
}

impl Display for Apache2 {
    #[inline]
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        write!(f, "{}", self.text())
    }
}

impl AsRef<str> for Apache2 {
    #[inline]
    fn as_ref(&self) -> &str {
        self.text()
    }
}

impl AsRef<OsStr> for Apache2 {
    #[inline]
    fn as_ref(&self) -> &OsStr {
        self.text().as_ref()
    }
}

impl AsRef<[u8]> for Apache2 {
    #[inline]
    fn as_ref(&self) -> &[u8] {
        self.text().as_bytes()
    }
}