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, Native64RawRealStrictFinitePolicy}};
use try_create::ValidationPolicy;
// Define a policy that uses Native64RawRealStrictFinitePolicy
// (i.e. StrictFinitePolicy<f64, 53>) 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,
impl<RawReal: RawRealTrait, const PRECISION: u32> GuaranteesFiniteValues for DebugValidationPolicy<StrictFinitePolicy<RawReal, PRECISION>>where
StrictFinitePolicy<RawReal, PRECISION>: 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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.