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
use std::sync::{Arc, Mutex};
use crate::{Error, Limits, Result, State};
pub struct FormData<T> {
pub(crate) state: Arc<Mutex<State<T>>>,
}
impl<T> FormData<T> {
pub fn new(t: T, boundary: &str) -> Self {
Self {
state: Arc::new(Mutex::new(State::new(
t,
boundary.as_bytes(),
Limits::default(),
))),
}
}
pub fn with_limits(t: T, boundary: &str, limits: Limits) -> Self {
Self {
state: Arc::new(Mutex::new(State::new(t, boundary.as_bytes(), limits))),
}
}
pub fn state(&self) -> Arc<Mutex<State<T>>> {
self.state.clone()
}
pub fn set_max_buf_size(&self, max: usize) -> Result<()> {
self.state
.try_lock()
.map_err(|e| Error::TryLockError(e.to_string()))?
.limits_mut()
.buffer_size = max;
Ok(())
}
}