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

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.

Methods

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 th function to verfy 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 th function to verfy 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 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

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

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

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

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

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

Blanket Implementations

impl<T> From for T
[src]

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

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

type Owned = T

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

impl<T> Erased for T