pub struct DataUnescaper { /* private fields */ }
Expand description

Helper struct to unescape a data stream.

Note that one unescaper should be used for a single data stream. Creating a DataUnescaper is basically free, and not creating a new one would probably lead to initial \r\n being handled incorrectly.

Implementations

Creates a DataUnescaper.

The is_preceded_by_crlf argument is used to indicate whether, before the first buffer that is fed into unescape, the unescaper should assume that a \r\n was present.

Usually, one will want to set true as an argument, as starting a DataUnescaper mid-line is a rare use case.

Unescapes data coming from an EscapedDataReader.

This takes a data argument. It will modify the data argument, removing the escaping that could happen with it, and then returns a DataUnescapeRes.

It is possible that the end of data does not land on a boundary that allows yet to know whether data should be output or not. This is the reason why this returns a DataUnescapeRes. The returned value will contain:

  • .written, which is the number of unescaped bytes that have been written in data — that is, data[..res.written] is the unescaped data, and
  • .unhandled_idx, which is the number of bytes at the end of data that could not be handled yet for lack of more information — that is, data[res.unhandled_idx..] is data that should be at the beginning of the next call to data_unescape.

Note that the unhandled data’s length is never going to be longer than 4 bytes long (“\r\n.\r”, the longest sequence that can’t be interpreted yet), so it should not be an issue to just copy it to the next buffer’s start.

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 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.