pub trait DurationArgument: Sealed + Sized {
// Required methods
fn require_positive(self, path: &str) -> ArgumentResult<Self>;
fn require_less_than(self, path: &str, bound: Self) -> ArgumentResult<Self>;
fn require_at_most(self, path: &str, bound: Self) -> ArgumentResult<Self>;
fn require_greater_than(
self,
path: &str,
bound: Self,
) -> ArgumentResult<Self>;
fn require_at_least(self, path: &str, bound: Self) -> ArgumentResult<Self>;
}Expand description
Validates standard-library duration arguments without losing their unit.
Every successful method returns the original duration. Comparison failures
retain both the actual duration and bound as unit-bearing
ArgumentValue values.
The trait is sealed and implemented only for Duration.
Required Methods§
Sourcefn require_positive(self, path: &str) -> ArgumentResult<Self>
fn require_positive(self, path: &str) -> ArgumentResult<Self>
Requires this duration to be strictly greater than zero.
Success returns the original duration. A zero duration returns
ArgumentErrorKind::Comparison with a GreaterThan(Duration::ZERO)
constraint at path.
Sourcefn require_less_than(self, path: &str, bound: Self) -> ArgumentResult<Self>
fn require_less_than(self, path: &str, bound: Self) -> ArgumentResult<Self>
Requires this duration to be strictly less than bound.
Success returns the original duration. An unsatisfied comparison
returns ArgumentErrorKind::Comparison at path with the exact
duration bound.
Sourcefn require_at_most(self, path: &str, bound: Self) -> ArgumentResult<Self>
fn require_at_most(self, path: &str, bound: Self) -> ArgumentResult<Self>
Requires this duration to be less than or equal to bound.
Success returns the original duration. An unsatisfied comparison
returns ArgumentErrorKind::Comparison at path with the exact
duration bound.
Sourcefn require_greater_than(self, path: &str, bound: Self) -> ArgumentResult<Self>
fn require_greater_than(self, path: &str, bound: Self) -> ArgumentResult<Self>
Requires this duration to be strictly greater than bound.
Success returns the original duration. An unsatisfied comparison
returns ArgumentErrorKind::Comparison at path with the exact
duration bound.
Sourcefn require_at_least(self, path: &str, bound: Self) -> ArgumentResult<Self>
fn require_at_least(self, path: &str, bound: Self) -> ArgumentResult<Self>
Requires this duration to be greater than or equal to bound.
Success returns the original duration. An unsatisfied comparison
returns ArgumentErrorKind::Comparison at path with the exact
duration bound.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl DurationArgument for Duration
impl DurationArgument for Duration
Source§fn require_positive(self, path: &str) -> ArgumentResult<Self>
fn require_positive(self, path: &str) -> ArgumentResult<Self>
Requires a nonzero duration and preserves its exact value.
Source§fn require_less_than(self, path: &str, bound: Self) -> ArgumentResult<Self>
fn require_less_than(self, path: &str, bound: Self) -> ArgumentResult<Self>
Requires a duration strictly below the supplied bound.
Source§fn require_at_most(self, path: &str, bound: Self) -> ArgumentResult<Self>
fn require_at_most(self, path: &str, bound: Self) -> ArgumentResult<Self>
Requires a duration at or below the supplied bound.
Source§fn require_greater_than(self, path: &str, bound: Self) -> ArgumentResult<Self>
fn require_greater_than(self, path: &str, bound: Self) -> ArgumentResult<Self>
Requires a duration strictly above the supplied bound.
Source§fn require_at_least(self, path: &str, bound: Self) -> ArgumentResult<Self>
fn require_at_least(self, path: &str, bound: Self) -> ArgumentResult<Self>
Requires a duration at or above the supplied bound.