Skip to main content

ProtoValidation

Trait ProtoValidation 

Source
pub trait ProtoValidation {
    type Target: ?Sized;
    type Stored: Borrow<Self::Target>;
    type Validator: Validator<Self, Target = Self::Target> + Clone + Default;
    type ValidatorBuilder: ValidatorBuilderFor<Self, Validator = Self::Validator>;

    // Provided methods
    fn validator_builder() -> Self::ValidatorBuilder { ... }
    fn validator_from_closure<F, FinalBuilder>(config_fn: F) -> Self::Validator
       where F: FnOnce(Self::ValidatorBuilder) -> FinalBuilder,
             FinalBuilder: ValidatorBuilderFor<Self, Validator = Self::Validator> { ... }
}
Expand description

Trait implemented by targets of proto validators.

Implemented automatically with the proto_message, proto_oneof and proto_enum macros.

The actual target of the validation is in a dedicated associated Type because this trait is sometimes implemented by wrappers/proxies like Sint32.

Required Associated Types§

Source

type Target: ?Sized

The type that the implementor is actually going to be validated with.

Defined as a separate type to allow target types to support more than one implementor (for example, i32 can be the target for Sint32, Sfixed32 or for i32 itself).

Source

type Stored: Borrow<Self::Target>

The Stored type is needed for compatibility with the RepeatedValidator and MapValidator. It is the same as the Target in most cases, but not for String specifically, because the Target is str, but Stored is String.

Source

type Validator: Validator<Self, Target = Self::Target> + Clone + Default

Represent the default validator for this type.

Source

type ValidatorBuilder: ValidatorBuilderFor<Self, Validator = Self::Validator>

Represent the builder for the default validator of this type, to enable the utility methods validator_builder and validator_from_closure.

Provided Methods§

Source

fn validator_builder() -> Self::ValidatorBuilder

Returns the default validator builder for this type.

§Example
use protify::*;

assert_eq!(StringValidator::builder(), String::validator_builder());
Source

fn validator_from_closure<F, FinalBuilder>(config_fn: F) -> Self::Validator
where F: FnOnce(Self::ValidatorBuilder) -> FinalBuilder, FinalBuilder: ValidatorBuilderFor<Self, Validator = Self::Validator>,

Builds the default validator for this type from a closure which receives the validator builder as the argument.

§Example
use protify::*;

let validator = String::validator_from_closure(|v| v.min_len(3));
let validator2 = StringValidator::builder().min_len(3).build();

assert_eq!(validator, validator2);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ProtoValidation for CalendarPeriod

Available on crate feature common-types only.
Source§

impl ProtoValidation for DayOfWeek

Available on crate feature common-types only.
Source§

impl ProtoValidation for Month

Available on crate feature common-types only.
Source§

impl ProtoValidation for Code

Source§

impl ProtoValidation for bool

Source§

impl ProtoValidation for f32

Source§

impl ProtoValidation for f64

Source§

impl ProtoValidation for i32

Source§

impl ProtoValidation for i64

Source§

impl ProtoValidation for u32

Source§

impl ProtoValidation for u64

Source§

impl ProtoValidation for ()

Source§

impl ProtoValidation for String

Source§

impl ProtoValidation for Color

Available on crate feature common-types only.
Source§

impl ProtoValidation for Date

Available on crate feature common-types only.
Source§

impl ProtoValidation for DateTime

Available on crate feature common-types only.
Source§

impl ProtoValidation for Decimal

Available on crate feature common-types only.
Source§

impl ProtoValidation for Expr

Available on crate feature common-types only.
Source§

impl ProtoValidation for Fraction

Available on crate feature common-types only.
Source§

impl ProtoValidation for Interval

Available on crate feature common-types only.
Source§

impl ProtoValidation for LatLng

Available on crate feature common-types only.
Source§

impl ProtoValidation for LocalizedText

Available on crate feature common-types only.
Source§

impl ProtoValidation for Money

Available on crate feature common-types only.
Source§

impl ProtoValidation for PhoneNumber

Available on crate feature common-types only.
Source§

impl ProtoValidation for PostalAddress

Available on crate feature common-types only.
Source§

impl ProtoValidation for Quaternion

Available on crate feature common-types only.
Source§

impl ProtoValidation for TimeOfDay

Available on crate feature common-types only.
Source§

impl ProtoValidation for TimeZone

Available on crate feature common-types only.
Source§

impl ProtoValidation for Empty

Source§

impl ProtoValidation for Any

Source§

impl ProtoValidation for Duration

Source§

impl ProtoValidation for FieldMask

Source§

impl ProtoValidation for Timestamp

Source§

impl ProtoValidation for FieldViolation

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for Violation

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for Violation

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for BadRequest

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for DebugInfo

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for ErrorInfo

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for Help

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for HttpHeader

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for HttpRequest

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for HttpResponse

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for LocalizedMessage

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for PreconditionFailure

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for QuotaFailure

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for RequestInfo

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for ResourceInfo

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for RetryInfo

Available on crate feature rpc-types only.
Source§

impl ProtoValidation for Status

Source§

impl<K, V> ProtoValidation for BTreeMap<K, V>
where Self: Clone, K: ProtoValidation + Send + Sync + AsProtoType, V: ProtoValidation + Send + Sync + AsProtoType, K::Stored: Sized + Clone + IntoCelKey + Into<Subscript>, V::Stored: Sized + Clone + TryIntoCel,

Source§

impl<K, V, S> ProtoValidation for HashMap<K, V, S>
where S: BuildHasher + Default + Clone, Self: Clone, K: ProtoValidation + Send + Sync + AsProtoType, V: ProtoValidation + Send + Sync + AsProtoType, K::Stored: Sized + Clone + IntoCelKey + Into<Subscript>, V::Stored: Sized + Clone + TryIntoCel,

Source§

impl<T> ProtoValidation for Vec<T>
where T: ProtoValidation + Send + Sync, T::Stored: TryIntoCel + Sized + Clone,

Implementors§