pub struct DebugValidationPolicy<P: ValidationPolicy>(/* private fields */);
Expand description
A validation policy that is active only in debug builds.
This struct acts as a wrapper around another ValidationPolicy
.
- In debug builds (
#[cfg(debug_assertions)]
), it delegates validation directly to the inner policyP
. - In release builds (
#[cfg(not(debug_assertions))]
), it becomes a “no-op” (no operation), meaning itsvalidate
andvalidate_ref
methods do nothing and always returnOk
.
This is useful for enforcing strict, potentially expensive validations during development and testing, while eliminating their performance overhead in production code.
§Generic Parameters
P
: The innerValidationPolicy
to use during debug builds.
§Example
ⓘ
use num_valid::validation::{DebugValidationPolicy, StrictFinitePolicy};
use try_create::ValidationPolicy;
// Define a policy that uses StrictFinitePolicy only in debug builds.
type MyPolicy = DebugValidationPolicy<Native64RawRealStrictFinitePolicy>;
let nan_value = f64::NAN;
let result = MyPolicy::validate(nan_value);
#[cfg(debug_assertions)]
{
// In debug mode, the validation fails because StrictFinitePolicy catches NaN.
assert!(result.is_err());
}
#[cfg(not(debug_assertions))]
{
// In release mode, the validation is skipped and always succeeds.
assert!(result.is_ok());
}
Trait Implementations§
Source§impl<P: ValidationPolicy> ValidationPolicy for DebugValidationPolicy<P>
impl<P: ValidationPolicy> ValidationPolicy for DebugValidationPolicy<P>
Source§type Value = <P as ValidationPolicy>::Value
type Value = <P as ValidationPolicy>::Value
The type of the value to be validated.
Source§type Error = <P as ValidationPolicy>::Error
type Error = <P as ValidationPolicy>::Error
The type of the error returned if validation fails.
Source§impl<P> ValidationPolicyComplex for DebugValidationPolicy<P>where
P: ValidationPolicyComplex,
impl<P> ValidationPolicyComplex for DebugValidationPolicy<P>where
P: ValidationPolicyComplex,
Source§impl<P> ValidationPolicyReal for DebugValidationPolicy<P>where
P: ValidationPolicyReal,
impl<P> ValidationPolicyReal for DebugValidationPolicy<P>where
P: ValidationPolicyReal,
Auto Trait Implementations§
impl<P> Freeze for DebugValidationPolicy<P>
impl<P> RefUnwindSafe for DebugValidationPolicy<P>where
P: RefUnwindSafe,
impl<P> Send for DebugValidationPolicy<P>where
P: Send,
impl<P> Sync for DebugValidationPolicy<P>where
P: Sync,
impl<P> Unpin for DebugValidationPolicy<P>where
P: Unpin,
impl<P> UnwindSafe for DebugValidationPolicy<P>where
P: UnwindSafe,
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