Struct trust_dns_proto::serialize::binary::Restrict[][src]

pub struct Restrict<T>(_);

Untrusted types will be wrapped in this type.

To gain access to the data, some form of verification through one of the public methods is necessary.

Implementations

impl<T> Restrict<T>[src]

pub fn new(restricted: T) -> Self[src]

Create a new restricted type

pub fn verify<'a, F: Fn(&'a T) -> bool>(&'a self, f: F) -> Verified<'a, T>[src]

It is the responsibility of this function to verify the contained type is valid.

use trust_dns_proto::serialize::binary::Restrict;

let unrestricted = Restrict::new(0).verify(|r| *r == 0).then(|r| *r + 1).unwrap();
assert!(unrestricted == 1);

Returns

If f returns true then the value is valid and a chainable Verified type is returned

pub fn verify_unwrap<F: Fn(&T) -> bool>(self, f: F) -> Result<T, T>[src]

It is the responsibility of this function to verify the contained type is valid.

use trust_dns_proto::serialize::binary::Restrict;

let unrestricted = Restrict::new(0).verify_unwrap(|r| *r == 0).unwrap();
assert!(unrestricted == 0);

Returns

If f returns true then the value is valid and Ok(T) is returned. Otherwise Err(T) is returned.

pub fn unverified(self) -> T[src]

Unwraps the value without verifying the data, akin to Result::unwrap and Option::unwrap, but will not panic

pub fn map<R, F: Fn(T) -> R>(self, f: F) -> Restrict<R>[src]

Map the internal type of the restriction

use trust_dns_proto::serialize::binary::Restrict;

let restricted = Restrict::new(0).map(|b| vec![b, 1]);
assert!(restricted.verify(|v| v == &[0, 1]).is_valid());
assert!(!restricted.verify(|v| v == &[1, 0]).is_valid());

Trait Implementations

impl<T: Clone> Clone for Restrict<T>[src]

impl<T: Copy> Copy for Restrict<T>[src]

impl RestrictedMath for Restrict<usize>[src]

type Arg = usize

Argument for the math operations

type Value = usize

Return value, generally the same as Arg

impl RestrictedMath for Restrict<u8>[src]

type Arg = u8

Argument for the math operations

type Value = u8

Return value, generally the same as Arg

impl RestrictedMath for Restrict<u16>[src]

type Arg = u16

Argument for the math operations

type Value = u16

Return value, generally the same as Arg

Auto Trait Implementations

impl<T> RefUnwindSafe for Restrict<T> where
    T: RefUnwindSafe

impl<T> Send for Restrict<T> where
    T: Send

impl<T> Sync for Restrict<T> where
    T: Sync

impl<T> Unpin for Restrict<T> where
    T: Unpin

impl<T> UnwindSafe for Restrict<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,