[−][src]Struct trust_dns_proto::serialize::binary::Restrict
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
fn checked_add(
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
[src]
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
fn checked_sub(
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
[src]
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
fn checked_mul(
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
[src]
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::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
fn checked_add(
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
[src]
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
fn checked_sub(
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
[src]
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
fn checked_mul(
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
[src]
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::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
fn checked_add(
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
[src]
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
fn checked_sub(
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
[src]
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
fn checked_mul(
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
[src]
&self,
arg: Self::Arg
) -> Result<Restrict<Self::Value>, Self::Arg>
impl<T: Clone> Clone for Restrict<T>
[src]
fn clone(&self) -> Restrict<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: Copy> Copy for Restrict<T>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,