Struct trust_dns_proto::serialize::binary::Restrict
source · pub struct Restrict<T>(/* private fields */);
Expand description
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§
source§impl<T> Restrict<T>
impl<T> Restrict<T>
sourcepub fn verify<'a, F: Fn(&'a T) -> bool>(&'a self, f: F) -> Verified<'a, T>
pub fn verify<'a, F: Fn(&'a T) -> bool>(&'a self, f: F) -> Verified<'a, T>
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
sourcepub fn verify_unwrap<F: Fn(&T) -> bool>(self, f: F) -> Result<T, T>
pub fn verify_unwrap<F: Fn(&T) -> bool>(self, f: F) -> Result<T, T>
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.
sourcepub fn unverified(self) -> T
pub fn unverified(self) -> T
Unwraps the value without verifying the data, akin to Result::unwrap and Option::unwrap, but will not panic
sourcepub fn map<R, F: Fn(T) -> R>(self, f: F) -> Restrict<R>
pub fn map<R, F: Fn(T) -> R>(self, f: F) -> Restrict<R>
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§
source§impl RestrictedMath for Restrict<u16>
impl RestrictedMath for Restrict<u16>
source§impl RestrictedMath for Restrict<u8>
impl RestrictedMath for Restrict<u8>
source§impl RestrictedMath for Restrict<usize>
impl RestrictedMath for Restrict<usize>
impl<T: Copy> Copy for Restrict<T>
Auto Trait Implementations§
impl<T> Freeze for Restrict<T>where
T: Freeze,
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)