[−][src]Struct bcder::decode::LimitedSource
A source that can be limited to a certain number of octets.
This type wraps another source and allows access to be limited to a certain number of octets. It will never provide access to more than that number of octets. Any attempt to advance over more octets will fail with a malformed error.
The limit is, however, independent of the underlying source. It can be larger than the number of octets actually available in the source.
The limit can be changed or even removed at any time.
Implementations
impl<S> LimitedSource<S>
[src]
pub fn new(source: S) -> Self
[src]
Creates a new limited source for the given source.
The return limited source will have no limit just yet.
pub fn unwrap(self) -> S
[src]
Unwraps the value and returns the source it was created from.
pub fn limit(&self) -> Option<usize>
[src]
Returns the current limit.
Returns None
if there is no limit. Otherwise, the number returned
is the number of remaining octets before the limit is reached. This
does not necessarily mean that that many octets are actually
available in the underlying source.
pub fn limit_further(&mut self, limit: Option<usize>) -> Option<usize>
[src]
Sets a more strict limit.
The method will panic (!) if you are trying to set a new limit that
is larger than the current limit or if you are trying to remove
the limit by passing None
if there currently is a limit set.
Returns the old limit.
pub fn set_limit(&mut self, limit: Option<usize>)
[src]
Unconditionally sets a new limit.
If you pass None
, the limit will be removed.
impl<S: Source> LimitedSource<S>
[src]
pub fn skip_all(&mut self) -> Result<(), S::Err>
[src]
Skip over all remaining octets until the current limit is reached.
If there currently is no limit, the method will panic. Otherwise it will simply advance to the end of the limit which may be something the underlying source doesn’t like and thus produce an error.
pub fn take_all(&mut self) -> Result<Bytes, S::Err>
[src]
Returns a bytes value containing all octets until the current limit.
If there currently is no limit, the method will panic. Otherwise it tries to acquire a bytes value for the octets from the current position to the end of the limit and advance to the end of the limit. This may result in an error by the underlying source.
pub fn exhausted(&mut self) -> Result<(), S::Err>
[src]
Checks whether the end of the limit has been reached.
If a limit is currently set, the method will return a malformed error if it is larger than zero, i.e., if there are octets left to advance over before reaching the limit.
If there is no limit set, the method will try to access one single octet and return a malformed error if that is actually possible, i.e., if there are octets left in the underlying source.
Trait Implementations
impl<S: Clone> Clone for LimitedSource<S>
[src]
pub fn clone(&self) -> LimitedSource<S>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<S: Debug> Debug for LimitedSource<S>
[src]
impl<S: Source> Source for LimitedSource<S>
[src]
type Err = S::Err
The error produced by the source. Read more
pub fn request(&mut self, len: usize) -> Result<usize, Self::Err>
[src]
pub fn advance(&mut self, len: usize) -> Result<(), Self::Err>
[src]
pub fn slice(&self) -> &[u8]
[src]
pub fn bytes(&self, start: usize, end: usize) -> Bytes
[src]
pub fn take_u8(&mut self) -> Result<u8, Self::Err>
[src]
pub fn take_opt_u8(&mut self) -> Result<Option<u8>, Self::Err>
[src]
Auto Trait Implementations
impl<S> RefUnwindSafe for LimitedSource<S> where
S: RefUnwindSafe,
[src]
S: RefUnwindSafe,
impl<S> Send for LimitedSource<S> where
S: Send,
[src]
S: Send,
impl<S> Sync for LimitedSource<S> where
S: Sync,
[src]
S: Sync,
impl<S> Unpin for LimitedSource<S> where
S: Unpin,
[src]
S: Unpin,
impl<S> UnwindSafe for LimitedSource<S> where
S: UnwindSafe,
[src]
S: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
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.
pub 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>,