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
use errors::Result;
use std::fmt;
use {Diagnostics, Flavor, Translate, Translator};
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(bound = "F::Type: ::serde::Serialize")]
pub enum RpChannel<F: 'static>
where
F: Flavor,
{
Unary { ty: F::Type },
Streaming { ty: F::Type },
}
impl<F: 'static> RpChannel<F>
where
F: Flavor,
{
pub fn ty(&self) -> &F::Type {
use self::RpChannel::*;
match *self {
Unary { ref ty, .. } | Streaming { ref ty, .. } => ty,
}
}
pub fn is_streaming(&self) -> bool {
use self::RpChannel::*;
match *self {
Unary { .. } => false,
Streaming { .. } => true,
}
}
}
impl<F: 'static> fmt::Display for RpChannel<F>
where
F: Flavor,
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
if self.is_streaming() {
write!(fmt, "stream {:?}", self.ty())
} else {
write!(fmt, "{:?}", self.ty())
}
}
}
impl<F: 'static, T> Translate<T> for RpChannel<F>
where
F: Flavor,
T: Translator<Source = F>,
{
type Source = F;
type Out = RpChannel<T::Target>;
fn translate(self, diag: &mut Diagnostics, translator: &T) -> Result<RpChannel<T::Target>> {
use self::RpChannel::*;
let out = match self {
Unary { ty } => Unary {
ty: translator.translate_type(diag, ty)?,
},
Streaming { ty } => Streaming {
ty: translator.translate_type(diag, ty)?,
},
};
Ok(out)
}
}