1#[macro_export]
14macro_rules! byte_map {
15 ($($flag:expr,)*) => ([
16 $($flag != 0,)*
17 ])
18}
19
20#[macro_export]
21macro_rules! next {
22 ($bytes:ident) => ({
23 match $bytes.get_next() {
24 Some(b) => Ok(b),
25 None => Err(crate::WebError::from(crate::HttpError::Partial))
26 }
27 })
28}
29
30#[macro_export]
31macro_rules! must_have {
32 ($bytes:ident, $num:expr) => ({
33 if $bytes.remaining() >= $num {
34 Ok(())
35 } else {
36 Err(webparse::WebError::from(webparse::HttpError::Partial))
37 }
38 })
39}
40
41
42#[macro_export]
43macro_rules! peek {
44 ($bytes:ident) => ({
45 match $bytes.peek() {
46 Some(b) => Ok(b),
47 None => Err(WebError::from(crate::HttpError::Partial))
48 }
49 })
50}
51
52
53#[macro_export]
54macro_rules! expect {
55 ($bytes:ident.next() == $pat:pat => $ret:expr) => {
56 expect!(next!($bytes) => $pat |? $ret)
57 };
58 ($e:expr => $pat:pat_param |? $ret:expr) => {
59 match $e {
60 Ok(_v@$pat) => (),
61 Err(e) => return Err(e),
62 _ => return $ret
63 }
64 };
65}
66
67
68#[macro_export]
69macro_rules! try_advance {
70 ($flag:expr) => {
71 if !$flag {
72 return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "not enough"));
73 }
74 };
75}