pub struct TimeLogValidator { /* private fields */ }Expand description
The main validator that runs all validators. Add the other validators to this one with
TimeLogValidator::with_validator, then call TimeLogValidator::validate to run the validation.
§Example
let time_logs = [
TimeLog{ summary: None, ..Default::default() },
TimeLog{ summary: Some("Code Review".to_string()), ..Default::default() }
];
let mut validator = TimeLogValidator::new()
.with_validator(ExcessiveHoursValidator::new(10))
.with_validator(HasSummaryValidator);
let results = validator.validate(&time_logs);
// Assertions to check the results, you don't need to do this in your code
assert!(results[0].has_problems(&ValidationProblem::MissingSummary));
assert!(!results[0].has_problems(&ValidationProblem::ExcessiveHours{ max_hours: 10 }));
assert!(results[1].is_valid());
for result in results {
if result.is_valid() { continue; }
for problem in &result.problems {
match problem {
ValidationProblem::ExcessiveHours { max_hours } => println!("Time spent exceeds maximum of {max_hours} hours"),
ValidationProblem::MissingSummary => println!("No summary was entered"),
_ => {}
}
}
}Implementations§
Source§impl TimeLogValidator
impl TimeLogValidator
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new TimeLogValidator.
Sourcepub fn with_validator(self, validator: impl Validator + 'static) -> Self
pub fn with_validator(self, validator: impl Validator + 'static) -> Self
Sourcepub fn validate<'a>(
&mut self,
time_logs: &'a [TimeLog],
) -> Vec<ValidationResult<'a>>
pub fn validate<'a>( &mut self, time_logs: &'a [TimeLog], ) -> Vec<ValidationResult<'a>>
Run all validators on the given time logs.
Trait Implementations§
Source§impl Default for TimeLogValidator
impl Default for TimeLogValidator
Auto Trait Implementations§
impl Freeze for TimeLogValidator
impl !RefUnwindSafe for TimeLogValidator
impl !Send for TimeLogValidator
impl !Sync for TimeLogValidator
impl Unpin for TimeLogValidator
impl !UnwindSafe for TimeLogValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more