pub struct ZDuration { /* private fields */ }poem-openapi only.Expand description
Schema for std::time::Duration. Created via vld::duration().
Accepts a non-negative JSON number of seconds (3, 1.5) or a string:
10s / 1.5s, 250ms (integer milliseconds) or an ISO 8601 duration
(RFC 3339 grammar): PT15S, PT1.5S, P3DT4H30M, PT1H, P2W.
ISO durations take weeks alone (P2W), or days and a time part T with
hours, minutes and seconds, each optional but in that order; only the last
number may have a fraction (PT1.5H, P0,5D; . or ,, up to 9 digits).
A day is 86 400 s (no daylight-saving shifts). Years and months (P1Y,
P2M, P1Y2M3D) are not a fixed length, so they fail with
invalid_format (duration_calendar_unit) — use a date library for
calendar arithmetic.
Negative numbers fail with too_small (origin duration, minimum 0);
anything else with invalid_type.
§Example
use vld::prelude::*;
use std::time::Duration;
let d = vld::duration().max_secs(60);
assert_eq!(d.parse("1.5").unwrap(), Duration::from_millis(1500));
assert_eq!(d.parse(r#""PT2.25S""#).unwrap(), Duration::from_millis(2250));
assert_eq!(d.parse(r#""250ms""#).unwrap(), Duration::from_millis(250));
assert!(d.parse("-1").is_err());
let long = vld::duration();
assert_eq!(long.parse(r#""P1DT2H30M""#).unwrap(), Duration::from_secs(95_400));
let err = long.parse(r#""P1M""#).unwrap_err();
assert_eq!(err.issues[0].code.key(), "invalid_format");Implementations§
Trait Implementations§
Source§impl CollectNestedSchemas for ZDuration
Available on crate feature openapi only.
impl CollectNestedSchemas for ZDuration
openapi only.Source§impl JsonSchema for ZDuration
Available on crate feature openapi only.JSON Schema. min/max become minimum/maximum (seconds) on the
number branch and x-minSeconds/x-maxSeconds on the string branch.
impl JsonSchema for ZDuration
openapi only.JSON Schema. min/max become minimum/maximum (seconds) on the
number branch and x-minSeconds/x-maxSeconds on the string branch.
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
Source§fn is_required(&self) -> bool
fn is_required(&self) -> bool
required array. Read moreSource§impl VldSchema for ZDuration
impl VldSchema for ZDuration
Source§fn parse_value(&self, value: &Value) -> Result<Duration, VldError>
fn parse_value(&self, value: &Value) -> Result<Duration, VldError>
serde_json::Value.Source§fn parse_missing(&self) -> Result<Self::Output, VldError>
fn parse_missing(&self) -> Result<Self::Output, VldError>
Source§fn parse<I>(&self, input: &I) -> Result<Self::Output, VldError>
fn parse<I>(&self, input: &I) -> Result<Self::Output, VldError>
serde_json::Value, etc.)Source§fn validate<T>(&self, value: &T) -> Result<Self::Output, VldError>where
T: Serialize,
fn validate<T>(&self, value: &T) -> Result<Self::Output, VldError>where
T: Serialize,
Source§fn is_valid<T>(&self, value: &T) -> boolwhere
T: Serialize,
fn is_valid<T>(&self, value: &T) -> boolwhere
T: Serialize,
Source§fn optional(self) -> ZOptional<Self>
fn optional(self) -> ZOptional<Self>
None.Source§fn with_default(self, value: Self::Output) -> ZDefault<Self>
fn with_default(self, value: Self::Output) -> ZDefault<Self>
Source§fn blank_as(self, value: Self::Output) -> ZDefault<Self>
fn blank_as(self, value: Self::Output) -> ZDefault<Self>
with_default, and a blank string (empty or
whitespace only) also becomes value: legacy stores that write ""
or null for “unset”. Read moreSource§fn refine<F>(self, check: F, message: &str) -> ZRefine<Self, F>
fn refine<F>(self, check: F, message: &str) -> ZRefine<Self, F>
Source§fn rule_msg<R>(self, rule: R, msg: impl Into<String>) -> ZRule<Self, R>
fn rule_msg<R>(self, rule: R, msg: impl Into<String>) -> ZRule<Self, R>
rule with a custom error message.Source§fn try_transform<F, U, E>(self, f: F) -> ZTryTransform<Self, F, U>
fn try_transform<F, U, E>(self, f: F) -> ZTryTransform<Self, F, U>
Err becomes a
validation issue (Custom { code: "transform" }, message = the error). Read moreSource§fn transform<F, U>(self, f: F) -> ZTransform<Self, F, U>
fn transform<F, U>(self, f: F) -> ZTransform<Self, F, U>
Source§fn catch(self, fallback: Self::Output) -> ZCatch<Self>
fn catch(self, fallback: Self::Output) -> ZCatch<Self>
Source§fn pipe<S>(self, next: S) -> ZPipe<Self, S>
fn pipe<S>(self, next: S) -> ZPipe<Self, S>
Source§fn describe(self, description: &str) -> ZDescribe<Self>
fn describe(self, description: &str) -> ZDescribe<Self>
Source§fn super_refine<F>(self, check: F) -> ZSuperRefine<Self, F>
fn super_refine<F>(self, check: F) -> ZSuperRefine<Self, F>
Source§fn or<B>(self, other: B) -> ZUnion2<Self, B>where
B: VldSchema,
fn or<B>(self, other: B) -> ZUnion2<Self, B>where
B: VldSchema,
Either<Self::Output, B::Output>.Source§fn and<B>(self, other: B) -> ZIntersection<Self, B>where
B: VldSchema,
fn and<B>(self, other: B) -> ZIntersection<Self, B>where
B: VldSchema,
Auto Trait Implementations§
impl Forget for ZDuration
impl Freeze for ZDuration
impl Move for ZDuration
impl RefUnwindSafe for ZDuration
impl Send for ZDuration
impl Sync for ZDuration
impl Unpin for ZDuration
impl UnsafeUnpin for ZDuration
impl UnwindSafe for ZDuration
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DynSchema for T
impl<T> DynSchema for T
Source§fn dyn_parse(&self, value: &Value) -> Result<Value, VldError>
fn dyn_parse(&self, value: &Value) -> Result<Value, VldError>
value and return the output serialized back to JSON.Source§fn dyn_parse_missing(&self) -> Result<Value, VldError>
fn dyn_parse_missing(&self) -> Result<Value, VldError>
VldSchema::parse_missing of the erased schema.Source§fn dyn_json_schema(&self) -> Value
fn dyn_json_schema(&self) -> Value
openapi only.Source§fn dyn_is_required(&self) -> bool
fn dyn_is_required(&self) -> bool
openapi only.required array.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more