pub struct ZInteger<T>where
T: IntType,{ /* private fields */ }utoipa-5 only.Expand description
Schema for a sized integer (i8..u64, isize, usize). Created via
vld::i8() … vld::u64(); ZInt
(vld::number().int()) is ZInteger<i64>.
Integers are read exactly (no f64 round-trip; u64 values above
i64::MAX included). Floats with a fraction fail with not_int; values
outside the type’s range fail with too_small / too_big (origin
number) naming the type’s bound.
JSON Schema: {"type": "integer", "format": "int8" … "uint64"} with
minimum / maximum from the type range intersected with the user bounds.
§Example
use vld::prelude::*;
let port: u16 = vld::u16().min(1).parse("8080").unwrap();
assert_eq!(port, 8080);
assert!(vld::u16().parse("70000").is_err()); // above u16::MAX
assert!(vld::u8().parse("-1").is_err());
assert!(vld::i32().parse("1.5").is_err());
assert_eq!(vld::u64().parse("18446744073709551615").unwrap(), u64::MAX);Implementations§
Source§impl<T> ZInteger<T>where
T: IntType,
impl<T> ZInteger<T>where
T: IntType,
Sourcepub fn new() -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn new() -> ZInteger<T>
poem-openapi only.Create the schema (the same as its vld:: constructor function).
Sourcepub fn type_error(self, msg: impl Into<String>) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn type_error(self, msg: impl Into<String>) -> ZInteger<T>
poem-openapi only.Set a custom error message for type mismatch (non-number input).
Sourcepub fn int_error(self, msg: impl Into<String>) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn int_error(self, msg: impl Into<String>) -> ZInteger<T>
poem-openapi only.Set a custom error message for when the number is not an integer.
§Example
use vld::prelude::*;
let schema = vld::number().int().int_error("Whole numbers only!");
let err = schema.parse("3.5").unwrap_err();
assert!(err.issues[0].message.contains("Whole numbers only!"));Sourcepub fn with_messages<F>(self, f: F) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn with_messages<F>(self, f: F) -> ZInteger<T>
poem-openapi only.Override error messages in bulk by check key.
Same keys as ZNumber::with_messages, plus "not_int" for the
integer check itself.
Sourcepub fn coerce(self) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn coerce(self) -> ZInteger<T>
poem-openapi only.Coerce strings ("42") and booleans to integers.
Sourcepub fn one_of(self, values: &[T]) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn one_of(self, values: &[T]) -> ZInteger<T>
poem-openapi only.Must equal one of values; see ZNumber::one_of.
use vld::prelude::*;
let level = vld::u8().one_of(&[1, 2, 4]);
assert_eq!(level.parse("4").unwrap(), 4);
assert!(level.parse("3").is_err());Sourcepub fn clamp(self) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn clamp(self) -> ZInteger<T>
poem-openapi only.Clamp instead of failing; see ZNumber::clamp. Also saturates to
the integer type’s range.
Sourcepub fn min(self, val: T) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn min(self, val: T) -> ZInteger<T>
poem-openapi only.Minimum value (inclusive).
Sourcepub fn max(self, val: T) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn max(self, val: T) -> ZInteger<T>
poem-openapi only.Maximum value (inclusive).
Sourcepub fn gt(self, val: T) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn gt(self, val: T) -> ZInteger<T>
poem-openapi only.Greater than (exclusive).
Sourcepub fn gte(self, val: T) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn gte(self, val: T) -> ZInteger<T>
poem-openapi only.Greater than or equal (inclusive). Same as min.
Sourcepub fn lt(self, val: T) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn lt(self, val: T) -> ZInteger<T>
poem-openapi only.Less than (exclusive).
Sourcepub fn lte(self, val: T) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn lte(self, val: T) -> ZInteger<T>
poem-openapi only.Less than or equal (inclusive). Same as max.
Sourcepub fn positive(self) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn positive(self) -> ZInteger<T>
poem-openapi only.Must be positive (> 0).
Sourcepub fn negative(self) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn negative(self) -> ZInteger<T>
poem-openapi only.Must be negative (< 0).
Sourcepub fn non_negative(self) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn non_negative(self) -> ZInteger<T>
poem-openapi only.Must be non-negative (>= 0).
Sourcepub fn non_positive(self) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn non_positive(self) -> ZInteger<T>
poem-openapi only.Must be non-positive (<= 0).
Sourcepub fn safe(self) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn safe(self) -> ZInteger<T>
poem-openapi only.Must be within JavaScript’s safe integer range.
Sourcepub fn multiple_of(self, val: T) -> ZInteger<T>
Available on crate feature poem-openapi only.
pub fn multiple_of(self, val: T) -> ZInteger<T>
poem-openapi only.Must be a multiple of the given value (0 never matches).
Trait Implementations§
Source§impl<T> CollectNestedSchemas for ZInteger<T>where
T: IntType,
Available on crate feature openapi only.
impl<T> CollectNestedSchemas for ZInteger<T>where
T: IntType,
openapi only.Source§impl<T> JsonSchema for ZInteger<T>where
T: IntType,
Available on crate feature openapi only.{"type": "integer"} plus bounds; typed integers (vld::u8(), …) add
format and the type range.
impl<T> JsonSchema for ZInteger<T>where
T: IntType,
openapi only.{"type": "integer"} plus bounds; typed integers (vld::u8(), …) add
format and the type range.
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<T> VldSchema for ZInteger<T>where
T: IntType,
impl<T> VldSchema for ZInteger<T>where
T: IntType,
Source§fn parse_value(&self, value: &Value) -> Result<T, VldError>
fn parse_value(&self, value: &Value) -> Result<T, 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<T> !RefUnwindSafe for ZInteger<T>
impl<T> !UnwindSafe for ZInteger<T>
impl<T> Forget for ZInteger<T>
impl<T> Freeze for ZInteger<T>
impl<T> Move for ZInteger<T>
impl<T> Send for ZInteger<T>
impl<T> Sync for ZInteger<T>
impl<T> Unpin for ZInteger<T>
impl<T> UnsafeUnpin for ZInteger<T>
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