[−][src]Struct dangerous::Input
Input
is an immutable wrapper around bytes to be processed.
It can only be created via dangerous::input()
as so to clearly point out
where untrusted / dangerous input is consumed.
It is used along with Reader
to process the input.
Formatting
Input
implements both fmt::Debug
and fmt::Display
with support for
pretty printing. See InputDisplay
for formatting options.
Implementations
impl Input
[src]
pub const fn len(&self) -> usize
[src]
Returns the underlying byte slice length.
pub const fn is_empty(&self) -> bool
[src]
Returns true
if the underlying byte slice length is zero.
pub fn is_within(&self, parent: &Input) -> bool
[src]
Returns true
if the underlying byte slice for parent
contains that
of self
in the same section of memory with no bounds out of range.
pub const fn display(&self) -> InputDisplay<'_>
[src]
Returns an InputDisplay
for formatting.
pub const fn as_dangerous(&self) -> &[u8]
[src]
Returns the underlying byte slice.
The naming of this function is to a degree hyperbole, and should not be necessarily taken as proof of something dangerous or memory unsafe. It is named this way simply for users to clearly note where the panic-free guarantees end when handling the input.
pub fn to_dangerous_non_empty<'i, E>(&'i self) -> Result<&'i [u8], E> where
E: From<ExpectedLength<'i>>,
[src]
E: From<ExpectedLength<'i>>,
Returns the underlying byte slice if it is not empty.
See as_dangerous
for naming.
Errors
Returns ExpectedLength
if the the input is empty.
pub fn to_dangerous_str<'i, E>(&'i self) -> Result<&'i str, E> where
E: From<ExpectedValid<'i>>,
E: From<ExpectedLength<'i>>,
[src]
E: From<ExpectedValid<'i>>,
E: From<ExpectedLength<'i>>,
Decodes the underlying byte slice into a UTF-8 str
slice.
See as_dangerous
for naming.
Errors
Returns ExpectedValid
if the the input could never be valid UTF-8
and ExpectedLength
if a UTF-8 code point was cut short. This is
useful when parsing potentially incomplete buffers.
pub fn to_dangerous_non_empty_str<'i, E>(&'i self) -> Result<&'i str, E> where
E: From<ExpectedValid<'i>>,
E: From<ExpectedLength<'i>>,
[src]
E: From<ExpectedValid<'i>>,
E: From<ExpectedLength<'i>>,
Decodes the underlying byte slice into a UTF-8 str
slice.
See as_dangerous
for naming.
Errors
Returns ExpectedValid
if the the input could never be valid UTF-8 and
ExpectedLength
if a UTF-8 code point was cut short or the input is
empty. This is useful when parsing potentially incomplete buffers.
pub fn read_all<'i, F, T, E>(&'i self, f: F) -> Result<T, E> where
F: FnOnce(&mut Reader<'i, E>) -> Result<T, E>,
E: FromContext<'i>,
E: From<ExpectedLength<'i>>,
[src]
F: FnOnce(&mut Reader<'i, E>) -> Result<T, E>,
E: FromContext<'i>,
E: From<ExpectedLength<'i>>,
Create a reader with the expectation all of the input is read.
Errors
Returns an error if either the provided function does, or there is trailing input.
pub fn read_partial<'i, F, T, E>(&'i self, f: F) -> Result<(T, &'i Input), E> where
F: FnOnce(&mut Reader<'i, E>) -> Result<T, E>,
E: FromContext<'i>,
[src]
F: FnOnce(&mut Reader<'i, E>) -> Result<T, E>,
E: FromContext<'i>,
Create a reader to read a part of the input and return the rest.
Errors
Returns an error if the provided function does.
pub fn read_infallible<'i, F, T>(&'i self, f: F) -> (T, &'i Input) where
F: FnOnce(&mut Reader<'i, Infallible>) -> T,
[src]
F: FnOnce(&mut Reader<'i, Infallible>) -> T,
Create a reader to read a part of the input and return the rest without any errors.