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
use std::fmt::{self, Display, Formatter};
use std::error::Error;
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Unknown(String);
impl Unknown {
#[inline]
pub fn new<T: Into<String>>(s: T) -> Unknown {
Unknown(s.into())
}
#[inline]
pub fn text(&self) -> &str {
&self.0
}
}
impl Display for Unknown {
#[inline]
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
if self.0.len() > 300 {
write!(f, "{}:\n\n{} [..]", self.description(), &self.0[..300])
} else {
write!(f, "{}:\n\n{}", self.description(), self.0)
}
}
}
impl Error for Unknown {
#[inline]
fn description(&self) -> &str {
"unable to recognize license from input"
}
}