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
use std::{error::Error as StdError, fmt};
#[allow(clippy::empty_enum)]
#[derive(Debug)]
pub enum Never {}
impl fmt::Display for Never {
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {}
}
}
impl StdError for Never {
fn description(&self) -> &str {
match *self {}
}
fn cause(&self) -> Option<&dyn StdError> {
match *self {}
}
}
pub trait TryFrom<T>: Sized {
type Error: Into<failure::Error>;
fn try_from(value: T) -> Result<Self, Self::Error>;
}
pub trait TryInto<T> {
type Error: Into<failure::Error>;
fn try_into(self) -> Result<T, Self::Error>;
}
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
{
type Error = <U as TryFrom<T>>::Error;
#[inline]
fn try_into(self) -> Result<U, Self::Error> {
U::try_from(self)
}
}
#[derive(Debug, Clone)]
pub struct Chain<L, R> {
pub(crate) left: L,
pub(crate) right: R,
}
impl<L, R> Chain<L, R> {
pub fn new(left: L, right: R) -> Self {
Self { left, right }
}
}
#[macro_export]
macro_rules! chain {
($e:expr) => ( $e );
($e:expr,) => ( $e );
($h:expr, $($t:expr),+) => ( $crate::util::Chain::new($h, chain!($($t),+)) );
($h:expr, $($t:expr,)+) => ( chain!($h, $($t),+) );
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum Either<L, R> {
Left(L),
Right(R),
}