[][src]Trait verify::Validator

pub trait Validator<S: Span>: Sized {
    type Error: Error;
    type ValidateSeq: ValidateSeq<S, Error = Self::Error>;
    type ValidateMap: ValidateMap<S, Error = Self::Error>;
    fn with_span(self, span: Option<S>) -> Self;
fn validate_bool(self, v: bool) -> Result<(), Self::Error>;
fn validate_i8(self, v: i8) -> Result<(), Self::Error>;
fn validate_i16(self, v: i16) -> Result<(), Self::Error>;
fn validate_i32(self, v: i32) -> Result<(), Self::Error>;
fn validate_i64(self, v: i64) -> Result<(), Self::Error>;
fn validate_i128(self, v: i128) -> Result<(), Self::Error>;
fn validate_u8(self, v: u8) -> Result<(), Self::Error>;
fn validate_u16(self, v: u16) -> Result<(), Self::Error>;
fn validate_u32(self, v: u32) -> Result<(), Self::Error>;
fn validate_u64(self, v: u64) -> Result<(), Self::Error>;
fn validate_u128(self, v: u128) -> Result<(), Self::Error>;
fn validate_f32(self, v: f32) -> Result<(), Self::Error>;
fn validate_f64(self, v: f64) -> Result<(), Self::Error>;
fn validate_char(self, v: char) -> Result<(), Self::Error>;
fn validate_str(self, v: &str) -> Result<(), Self::Error>;
fn validate_bytes(self, v: &[u8]) -> Result<(), Self::Error>;
fn validate_none(self) -> Result<(), Self::Error>;
fn validate_some<V: ?Sized>(self, value: &V) -> Result<(), Self::Error>
    where
        V: Validate<Span = S>
;
fn validate_unit(self) -> Result<(), Self::Error>;
fn validate_unit_struct(self, name: &'static str) -> Result<(), Self::Error>;
fn validate_unit_variant(
        self,
        name: &'static str,
        variant_index: u32,
        variant: &'static str
    ) -> Result<(), Self::Error>;
fn validate_seq(
        self,
        len: Option<usize>
    ) -> Result<Self::ValidateSeq, Self::Error>;
fn validate_map(
        self,
        len: Option<usize>
    ) -> Result<Self::ValidateMap, Self::Error>;
fn validate_tag<V: ?Sized>(&mut self, tag: &V) -> Result<(), Self::Error>
    where
        V: Validate<Span = S> + ToString
; }

Values that implement Validate can validate themselves against types that implement this trait.

It is modelled after Serde Serializer, and works in a very similar fashion.

Associated Types

type Error: Error

The error returned by the validator.

type ValidateSeq: ValidateSeq<S, Error = Self::Error>

The type returned for validating sequences.

The span type and error must match the Validator's.

type ValidateMap: ValidateMap<S, Error = Self::Error>

The type returned for validating maps.

The span type and error must match the Validator's.

Loading content...

Required methods

fn with_span(self, span: Option<S>) -> Self

Set the span for the current value that is being validated.

In some cases this is needed to ensure that the validator returns the correct span in its errors.

fn validate_bool(self, v: bool) -> Result<(), Self::Error>

Validate a bool value.

fn validate_i8(self, v: i8) -> Result<(), Self::Error>

Validate an i8 value.

fn validate_i16(self, v: i16) -> Result<(), Self::Error>

Validate an i16 value.

fn validate_i32(self, v: i32) -> Result<(), Self::Error>

Validate an i32 value.

fn validate_i64(self, v: i64) -> Result<(), Self::Error>

Validate an i64 value.

fn validate_i128(self, v: i128) -> Result<(), Self::Error>

Validate an i128 value.

fn validate_u8(self, v: u8) -> Result<(), Self::Error>

Validate an u8 value.

fn validate_u16(self, v: u16) -> Result<(), Self::Error>

Validate an u16 value.

fn validate_u32(self, v: u32) -> Result<(), Self::Error>

Validate an u32 value.

fn validate_u64(self, v: u64) -> Result<(), Self::Error>

Validate an u64 value.

fn validate_u128(self, v: u128) -> Result<(), Self::Error>

Validate an u128 value.

fn validate_f32(self, v: f32) -> Result<(), Self::Error>

Validate an f32 value.

fn validate_f64(self, v: f64) -> Result<(), Self::Error>

Validate an f64 value.

fn validate_char(self, v: char) -> Result<(), Self::Error>

Validate a single char value.

fn validate_str(self, v: &str) -> Result<(), Self::Error>

Validate a string value.

fn validate_bytes(self, v: &[u8]) -> Result<(), Self::Error>

Validate slice of bytes.

fn validate_none(self) -> Result<(), Self::Error>

Validate a None value.

fn validate_some<V: ?Sized>(self, value: &V) -> Result<(), Self::Error> where
    V: Validate<Span = S>, 

Validate a Some value.

fn validate_unit(self) -> Result<(), Self::Error>

Validate an empty tuple ().

fn validate_unit_struct(self, name: &'static str) -> Result<(), Self::Error>

Validate a zero-sized struct.

fn validate_unit_variant(
    self,
    name: &'static str,
    variant_index: u32,
    variant: &'static str
) -> Result<(), Self::Error>

Validate a unit enum variant.

fn validate_seq(
    self,
    len: Option<usize>
) -> Result<Self::ValidateSeq, Self::Error>

Validate a sequence.

fn validate_map(
    self,
    len: Option<usize>
) -> Result<Self::ValidateMap, Self::Error>

Validate a map.

fn validate_tag<V: ?Sized>(&mut self, tag: &V) -> Result<(), Self::Error> where
    V: Validate<Span = S> + ToString

Validate a tag for a map value.

This exists in order to support Serde's "externally tagged" types, for example { "TAG": ... }.

Loading content...

Implementors

Loading content...