preprocess/validators/
does_not_contain.rs

1use super::Contains;
2use crate::utils::Error;
3
4/// Validates that the value does not contain the given needle.
5/// This is the opposite of [`Contains`].
6#[must_use = concat!(
7	"validation returns a new value instead of mutating the input.",
8	" The returned value will contain the validated value,",
9	" while the input will remain unchanged"
10)]
11pub fn validate_does_not_contain<T: Contains>(
12	value: T,
13	needle: &str,
14) -> Result<T, Error> {
15	(!value.contains(needle)).then_some(value).ok_or_else(|| {
16		Error::new(format!("Value does not contain the needle '{}'", needle))
17	})
18}