tokio_proto/streaming/multiplex/
frame.rs1use super::RequestId;
2
3#[derive(Debug, Clone)]
5pub enum Frame<T, B, E> {
6 Message {
8 id: RequestId,
10 message: T,
12 body: bool,
14 solo: bool,
17 },
18 Body {
20 id: RequestId,
22 chunk: Option<B>,
26 },
27 Error {
29 id: RequestId,
31 error: E,
33 },
34}
35
36impl<T, B, E> Frame<T, B, E> {
37 pub fn request_id(&self) -> RequestId {
39 match *self {
40 Frame::Message { id, .. } => id,
41 Frame::Body { id, .. } => id,
42 Frame::Error { id, .. } => id,
43 }
44 }
45
46 pub fn unwrap_msg(self) -> T {
48 match self {
49 Frame::Message { message, .. } => message,
50 Frame::Body { .. } => panic!("called `Frame::unwrap_msg()` on a `Body` value"),
51 Frame::Error { .. } => panic!("called `Frame::unwrap_msg()` on an `Error` value"),
52 }
53 }
54
55 pub fn unwrap_body(self) -> Option<B> {
57 match self {
58 Frame::Body { chunk, .. } => chunk,
59 Frame::Message { .. } => panic!("called `Frame::unwrap_body()` on a `Message` value"),
60 Frame::Error { .. } => panic!("called `Frame::unwrap_body()` on an `Error` value"),
61 }
62 }
63
64 pub fn unwrap_err(self) -> E {
66 match self {
67 Frame::Error { error, .. } => error,
68 Frame::Body { .. } => panic!("called `Frame::unwrap_err()` on a `Body` value"),
69 Frame::Message { .. } => panic!("called `Frame::unwrap_err()` on a `Message` value"),
70 }
71 }
72}