AddrRule

Struct AddrRule 

Source
pub struct AddrRule<Mode> { /* private fields */ }
Expand description

Rule for address validation.

§Example

use wary::{Wary, Validate};

#[derive(Wary)]
struct Packet {
  #[validate(addr(ipv4))]
  src: String,
  #[validate(addr(ipv6))]
  dst: String,
}

let packet = Packet {
  src: "192.168.1.1".into(),
  dst: "2001:0db8:85a3:0000:0000:8a2e:0370:7334".into(),
};

assert!(packet.validate(&()).is_ok());

let packet = Packet {
  src: "1.2.3.4.5".into(),
  dst: "localhost".into(),
};

assert!(packet.validate(&()).is_err());

Implementations§

Source§

impl AddrRule<Ip>

Source

pub const fn new() -> AddrRule<Ip>

Source§

impl<M> AddrRule<M>

Source

pub const fn ipv4(self) -> AddrRule<IpV4>

Source

pub const fn ipv6(self) -> AddrRule<IpV6>

Source

pub const fn ip(self) -> AddrRule<Ip>

Trait Implementations§

Source§

impl<I> Rule<I> for AddrRule<Ip>
where I: AsRef<str>,

Source§

type Context = ()

Additional context required to validate the input.
Source§

fn validate(&self, _ctx: &Self::Context, item: &I) -> Result<()>

Validates the item. Read more
Source§

impl<I> Rule<I> for AddrRule<IpV4>
where I: AsRef<str>,

Source§

type Context = ()

Additional context required to validate the input.
Source§

fn validate(&self, _ctx: &Self::Context, item: &I) -> Result<()>

Validates the item. Read more
Source§

impl<I> Rule<I> for AddrRule<IpV6>
where I: AsRef<str>,

Source§

type Context = ()

Additional context required to validate the input.
Source§

fn validate(&self, _ctx: &Self::Context, item: &I) -> Result<()>

Validates the item. Read more

Auto Trait Implementations§

§

impl<Mode> Freeze for AddrRule<Mode>

§

impl<Mode> RefUnwindSafe for AddrRule<Mode>
where Mode: RefUnwindSafe,

§

impl<Mode> Send for AddrRule<Mode>
where Mode: Send,

§

impl<Mode> Sync for AddrRule<Mode>
where Mode: Sync,

§

impl<Mode> Unpin for AddrRule<Mode>
where Mode: Unpin,

§

impl<Mode> UnwindSafe for AddrRule<Mode>
where Mode: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Compare<Unset> for T
where T: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T