[][src]Struct dangerous::Input

#[must_use = "input must be consumed"]pub struct 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]

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]

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]

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]

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]

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]

Create a reader to read a part of the input and return the rest without any errors.

Trait Implementations

impl AsRef<Input> for Input[src]

impl Debug for Input[src]

impl Display for Input[src]

impl Eq for Input[src]

impl PartialEq<[u8]> for Input[src]

impl<'_> PartialEq<[u8]> for &'_ Input[src]

impl PartialEq<Input> for Input[src]

impl PartialEq<Input> for [u8][src]

impl StructuralEq for Input[src]

impl StructuralPartialEq for Input[src]

Auto Trait Implementations

impl RefUnwindSafe for Input

impl Send for Input

impl Sync for Input

impl Unpin for Input

impl UnwindSafe for Input

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]