use crate::ModelError;
#[derive(Debug)]
pub(crate) struct Full;
#[derive(Debug)]
pub(crate) struct Problems {
errors: Vec<ModelError>,
capacity: usize,
}
impl Problems {
pub(crate) fn new(capacity: usize) -> Self {
Self {
errors: Vec::new(),
capacity: capacity.max(1),
}
}
pub(crate) fn report(&mut self, error: ModelError) -> Result<(), Full> {
self.errors.push(error);
if self.errors.len() >= self.capacity {
Err(Full)
} else {
Ok(())
}
}
pub(crate) fn unit(&mut self, result: Result<(), ModelError>) -> Result<bool, Full> {
match result {
Ok(()) => Ok(true),
Err(error) => self.report(error).map(|()| false),
}
}
pub(crate) fn into_errors(self) -> Vec<ModelError> {
self.errors
}
}