http_box/util/mod.rs
1// +-----------------------------------------------------------------------------------------------+
2// | Copyright 2016 Sean Kerr |
3// | |
4// | Licensed under the Apache License, Version 2.0 (the "License"); |
5// | you may not use this file except in compliance with the License. |
6// | You may obtain a copy of the License at |
7// | |
8// | http://www.apache.org/licenses/LICENSE-2.0 |
9// | |
10// | Unless required by applicable law or agreed to in writing, software |
11// | distributed under the License is distributed on an "AS IS" BASIS, |
12// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13// | See the License for the specific language governing permissions and |
14// | limitations under the License. |
15// +-----------------------------------------------------------------------------------------------+
16
17//! Utility functions for handling encoded data, query strings, and header fields.
18
19macro_rules! submit_error {
20 ($iter:expr, $error:expr) => ({
21 bs_jump!($iter.context, bs_available!($iter.context));
22
23 (*$iter.on_error)($error($iter.context.byte));
24
25 return None;
26 });
27}
28
29macro_rules! submit_name {
30 ($iter:expr) => ({
31 return Some((
32 unsafe {
33 let mut s = String::with_capacity($iter.name.len());
34
35 s.as_mut_vec().extend_from_slice(&$iter.name);
36 s
37 },
38 None
39 ));
40 });
41}
42macro_rules! submit_name_value {
43 ($name:expr, $value:expr) => ({
44 return Some((
45 unsafe {
46 let mut s = String::with_capacity($name.len());
47
48 s.as_mut_vec().extend_from_slice(&$name);
49 s
50 },
51 unsafe {
52 let mut s = String::with_capacity($value.len());
53
54 s.as_mut_vec().extend_from_slice(&$value);
55 Some(s)
56 }
57 ));
58 });
59
60 ($iter:expr) => ({
61 return Some((
62 unsafe {
63 let mut s = String::with_capacity($iter.name.len());
64
65 s.as_mut_vec().extend_from_slice(&$iter.name);
66 s
67 },
68 unsafe {
69 let mut s = String::with_capacity($iter.value.len());
70
71 s.as_mut_vec().extend_from_slice(&$iter.value);
72 Some(s)
73 }
74 ));
75 });
76}
77
78// -------------------------------------------------------------------------------------------------
79
80mod decode;
81mod field;
82mod query;
83
84#[cfg(test)]
85mod test;
86
87pub use util::decode::{ DecodeError, decode };
88pub use util::field::{ FieldError, FieldIterator };
89pub use util::query::{ QueryError, QueryIterator };