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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::{
fmt,
sync::{Arc, Mutex},
};
use crate::State;
pub struct Field<T> {
pub length: usize,
pub index: usize,
pub name: String,
pub filename: Option<String>,
pub content_type: Option<mime::Mime>,
pub headers: Option<http::HeaderMap>,
pub(crate) state: Option<Arc<Mutex<State<T>>>>,
}
impl<T> Field<T> {
pub fn empty() -> Self {
Self {
index: 0,
length: 0,
name: String::new(),
filename: None,
content_type: None,
headers: None,
state: None,
}
}
pub fn headers_mut(&mut self) -> &mut Option<http::HeaderMap> {
&mut self.headers
}
pub fn state_mut(&mut self) -> &mut Option<Arc<Mutex<State<T>>>> {
&mut self.state
}
pub fn consumed(&self) -> bool {
self.state.is_none()
}
}
impl<T> fmt::Debug for Field<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Field")
.field("name", &self.name)
.field("filename", &self.filename)
.field("content_type", &self.content_type)
.field("index", &self.index)
.field("length", &self.length)
.field("headers", &self.headers)
.field("consumed", &self.state.is_none())
.finish()
}
}