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
use futures::never::Never;
use crate::exit::Exit;
impl From<()> for Exit {
fn from((): ()) -> Self {
Self::normal()
}
}
impl From<Never> for Exit {
fn from(infallible: Never) -> Self {
unreachable!(
"Whoa! We have an actual value of type `Infallible/Never`. Can I print it? Look — {:?}",
infallible
)
}
}
impl<IntoExit> From<Option<IntoExit>> for Exit
where
IntoExit: Into<Exit>,
{
fn from(option: Option<IntoExit>) -> Self {
option.map(Into::into).unwrap_or_else(Self::normal)
}
}
impl<IntoExit1, IntoExit2> From<Result<IntoExit1, IntoExit2>> for Exit
where
IntoExit1: Into<Exit>,
IntoExit2: Into<Exit>,
{
fn from(result: Result<IntoExit1, IntoExit2>) -> Self {
match result {
Ok(value) => value.into(),
Err(value) => value.into(),
}
}
}