preprocess 0.5.10

Preprocesses a struct with built-in preprocessors
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use super::Contains;
use crate::utils::Error;

/// Validates that the value does not contain the given needle.
/// This is the opposite of [`Contains`].
#[must_use = concat!(
	"validation returns a new value instead of mutating the input.",
	" The returned value will contain the validated value,",
	" while the input will remain unchanged"
)]
pub fn validate_does_not_contain<T: Contains>(
	value: T,
	needle: &str,
) -> Result<T, Error> {
	(!value.contains(needle)).then_some(value).ok_or_else(|| {
		Error::new(format!("Value does not contain the needle '{}'", needle))
	})
}