[go: up one dir, main page]

 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use std::fmt::{self, Display, Formatter};
use std::ffi::OsStr;
use License;
use permissions::*;
use conditions::*;
use limitations::*;

/// The [MIT License](https://opensource.org/licenses/MIT).
#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct Mit(pub(crate) String);

impl Mit {
    /// Returns a MIT license.
    #[inline]
    pub fn new(year: i32, name: &str) -> Mit {
        Mit(format!(include_str!("../files/MIT"), year, name))
    }
}

impl License for Mit {
    #[inline]
    fn name(&self) -> &str {
        "MIT License"
    }

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

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

    #[inline]
    fn text(&self) -> &str {
        &self.0
    }

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

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

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

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

impl Default for Mit {
    #[inline]
    fn default() -> Self {
        Mit(format!(include_str!("../files/MIT"), "<year>", "<name>"))
    }
}

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

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

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

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