Struct bcder::decode::LimitedSource

source ·
pub struct LimitedSource<S> { /* private fields */ }
Expand description

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§

Creates a new limited source for the given source.

The return limited source will have no limit just yet.

Unwraps the value and returns the source it was created from.

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.

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.

Unconditionally sets a new limit.

If you pass None, the limit will be removed.

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.

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.

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The error produced by the source. Read more
Request at least len bytes to be available. Read more
Advance the source by len bytes. Read more
Returns a bytes slice with the available data. Read more
Produces a Bytes value from part of the data. Read more
Takes a single octet from the source. Read more
Takes an optional octet from the source. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.