api: verify: rename Verify to TestMinMax

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-07-29 14:30:32 +02:00
parent 20b8c709c6
commit f1f4c14819
2 changed files with 5 additions and 9 deletions

View File

@ -592,7 +592,7 @@ fn named_struct_impl_verify(
if let Some(ref minimum) = field.def.minimum {
body.extend(quote_spanned! { minimum.span() =>
let minimum = #minimum;
if !::proxmox::api::verify::Verify::test_minimum(&self.#field_ident, &minimum) {
if !::proxmox::api::verify::TestMinMax::test_minimum(&self.#field_ident, &minimum) {
error_string.push_str(
&format!("field {} out of range, must be >= {}", #field_str, minimum)
);
@ -603,7 +603,7 @@ fn named_struct_impl_verify(
if let Some(ref maximum) = field.def.maximum {
body.extend(quote_spanned! { maximum.span() =>
let maximum = #maximum;
if !::proxmox::api::verify::Verify::test_maximum(&self.#field_ident, &maximum) {
if !::proxmox::api::verify::TestMinMax::test_maximum(&self.#field_ident, &maximum) {
error_string.push_str(
&format!("field {} out of range, must be <= {}", #field_str, maximum)
);

View File

@ -40,12 +40,12 @@ pub mod mark {
pub struct Special;
}
pub trait Verify<Other> {
pub trait TestMinMax<Other> {
fn test_minimum(&self, minimum: &Other) -> bool;
fn test_maximum(&self, maximum: &Other) -> bool;
}
impl<Other> Verify<Other> for Other
impl<Other> TestMinMax<Other> for Other
where
Other: Ord,
{
@ -60,7 +60,7 @@ where
}
}
impl<Other> Verify<Other> for Option<Other>
impl<Other> TestMinMax<Other> for Option<Other>
where
Other: Ord,
{
@ -74,7 +74,3 @@ where
self.as_ref().map(|x| *x <= *maximum).unwrap_or(true)
}
}
pub fn test_minimum<U, T: Verify<U>>(value: &T, minimum: &U) -> bool {
value.test_minimum(minimum)
}