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
#[derive(Debug, Clone)]
pub enum Frame<T, B, E> {
Message {
message: T,
body: bool,
},
Body {
chunk: Option<B>,
},
Error {
error: E,
},
}
impl<T, B, E> Frame<T, B, E> {
pub fn unwrap_msg(self) -> T {
match self {
Frame::Message { message, .. } => message,
Frame::Body { .. } => panic!("called `Frame::unwrap_msg()` on a `Body` value"),
Frame::Error { .. } => panic!("called `Frame::unwrap_msg()` on an `Error` value"),
}
}
pub fn unwrap_body(self) -> Option<B> {
match self {
Frame::Body { chunk } => chunk,
Frame::Message { .. } => panic!("called `Frame::unwrap_body()` on a `Message` value"),
Frame::Error { .. } => panic!("called `Frame::unwrap_body()` on an `Error` value"),
}
}
pub fn unwrap_err(self) -> E {
match self {
Frame::Error { error } => error,
Frame::Body { .. } => panic!("called `Frame::unwrap_err()` on a `Body` value"),
Frame::Message { .. } => panic!("called `Frame::unwrap_err()` on a `Message` value"),
}
}
}