#![allow(clippy::module_name_repetitions)]
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> {
#[must_use]
pub fn new(t: T, boundary: &str) -> Self {
Self {
state: Arc::new(Mutex::new(State::new(
t,
boundary.as_bytes(),
Limits::default(),
))),
}
}
#[must_use]
pub fn with_limits(t: T, boundary: &str, limits: Limits) -> Self {
Self {
state: Arc::new(Mutex::new(State::new(t, boundary.as_bytes(), limits))),
}
}
#[must_use]
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(())
}
}