tidepool_codegen/
yield_type.rs1#[derive(Debug, PartialEq, Eq)]
3pub enum Yield {
4 Done(*mut u8),
6 Request {
9 tag: u64,
10 request: *mut u8,
11 continuation: *mut u8,
12 },
13 Error(YieldError),
15}
16
17impl std::fmt::Display for Yield {
18 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 match self {
20 Yield::Done(ptr) => write!(f, "Done({:p})", ptr),
21 Yield::Request {
22 tag,
23 request,
24 continuation,
25 } => {
26 write!(
27 f,
28 "Request(tag={}, req={:p}, cont={:p})",
29 tag, request, continuation
30 )
31 }
32 Yield::Error(e) => write!(f, "Error({})", e),
33 }
34 }
35}
36
37#[derive(Debug, PartialEq, Eq, Clone, Copy)]
38pub enum YieldError {
39 UnexpectedTag(u8),
41 UnexpectedConTag(u64),
43 BadValFields(u16),
45 BadEFields(u16),
47 BadUnionFields(u16),
49 NullPointer,
51 DivisionByZero,
53 Overflow,
55}
56
57impl std::fmt::Display for YieldError {
58 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59 match self {
60 YieldError::UnexpectedTag(tag) => write!(f, "unexpected heap tag: {}", tag),
61 YieldError::UnexpectedConTag(tag) => write!(f, "unexpected constructor tag: {}", tag),
62 YieldError::BadValFields(n) => {
63 write!(f, "Val constructor has {} fields, expected >= 1", n)
64 }
65 YieldError::BadEFields(n) => write!(f, "E constructor has {} fields, expected 2", n),
66 YieldError::BadUnionFields(n) => {
67 write!(f, "Union constructor has {} fields, expected 2", n)
68 }
69 YieldError::NullPointer => write!(f, "null pointer in effect result"),
70 YieldError::DivisionByZero => write!(f, "division by zero"),
71 YieldError::Overflow => write!(f, "arithmetic overflow"),
72 }
73 }
74}
75
76impl std::error::Error for YieldError {}