forked from Proxmox/proxmox
api: verify: rename Verify to TestMinMax
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
20b8c709c6
commit
f1f4c14819
@ -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)
|
||||
);
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user