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
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//! A license library.

#[macro_use]
extern crate bitflags;

mod apache2;
pub mod conditions;
mod kind;
pub mod limitations;
mod mit;
pub mod permissions;

pub use apache2::Apache2;
pub use kind::LicenseKind;
pub use mit::Mit;

use std::ffi::OsStr;

use conditions::Conditions;
use limitations::Limitations;
use permissions::Permissions;

/// Trait implemented by all licenses.
pub trait License {
    /// The name of the license.
    ///
    /// Corresponds to the *Full name* column from https://spdx.org/licenses/.
    fn name(&self) -> &str;

    /// The identifier of the license.
    ///
    /// Corresponds to the *Identifier* column from https://spdx.org/licenses/.
    fn id(&self) -> &str;

    /// Says if the license is OSI approved.
    ///
    /// Corresponds to the *OSI Approved?* column from https://spdx.org/licenses/.
    fn is_osi_approved(&self) -> bool;

    /// The license text.
    fn license(&self) -> &str;

    /// The permissions of the license.
    fn permissions(&self) -> Permissions;

    /// The conditions of the license.
    fn conditions(&self) -> Conditions;

    /// The limitations of the license.
    fn limitations(&self) -> Limitations;

    /// The homepage of the license.
    #[inline]
    fn homepage(&self) -> Option<&str> {
        None
    }
}

impl License for Box<License> {
    #[inline]
    fn name(&self) -> &str {
        (**self).name()
    }

    #[inline]
    fn id(&self) -> &str {
        (**self).id()
    }

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

    #[inline]
    fn license(&self) -> &str {
        (**self).license()
    }

    #[inline]
    fn permissions(&self) -> Permissions {
        (**self).permissions()
    }

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

    #[inline]
    fn limitations(&self) -> Limitations {
        (**self).limitations()
    }

    #[inline]
    fn homepage(&self) -> Option<&str> {
        (**self).homepage()
    }
}

impl AsRef<str> for Box<License> {
    fn as_ref(&self) -> &str {
        self.license()
    }
}

impl AsRef<OsStr> for Box<License> {
    fn as_ref(&self) -> &OsStr {
        self.license().as_ref()
    }
}

impl AsRef<[u8]> for Box<License> {
    fn as_ref(&self) -> &[u8] {
        self.license().as_ref()
    }
}

impl<'a> License for &'a License {
    #[inline]
    fn name(&self) -> &str {
        (**self).name()
    }

    #[inline]
    fn id(&self) -> &str {
        (**self).id()
    }

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

    #[inline]
    fn license(&self) -> &str {
        (**self).license()
    }

    #[inline]
    fn permissions(&self) -> Permissions {
        (**self).permissions()
    }

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

    #[inline]
    fn limitations(&self) -> Limitations {
        (**self).limitations()
    }

    #[inline]
    fn homepage(&self) -> Option<&str> {
        (**self).homepage()
    }
}

impl<'a> AsRef<str> for &'a License {
    fn as_ref(&self) -> &str {
        self.license()
    }
}

impl<'a> AsRef<OsStr> for &'a License {
    fn as_ref(&self) -> &OsStr {
        self.license().as_ref()
    }
}

impl<'a> AsRef<[u8]> for &'a License {
    fn as_ref(&self) -> &[u8] {
        self.license().as_ref()
    }
}