Struct EncodingBuffer

Source
pub struct EncodingBuffer { /* private fields */ }
Expand description

EncodingBuffer for a Mail providing a buffer for encodable traits.

Implementations§

Source§

impl EncodingBuffer

Source

pub fn new(mail_type: MailType) -> Self

Create a new buffer only allowing input compatible with a the specified mail type.

Source

pub fn mail_type(&self) -> MailType

Returns the mail type for which the buffer was created.

Source

pub fn writer(&mut self) -> EncodingWriter<'_>

returns a new EncodingWriter which contains a mutable reference to the current string buffer

Source

pub fn write_header_line<FN>(&mut self, func: FN) -> Result<(), EncodingError>
where FN: FnOnce(&mut EncodingWriter<'_>) -> Result<(), EncodingError>,

calls the provided function with a EncodingWriter cleaning up afterwards

After calling func with the EncodingWriter following cleanup is performed:

  • if func returned an error handle.undo_header() is called, this won’t undo anything before a finish_header() call but will discard partial writes
  • if func succeeded handle.finish_header() is called
Source

pub fn write_blank_line(&mut self)

Source

pub fn write_body_unchecked(&mut self, body: &impl AsRef<[u8]>)

writes a body to the internal buffer, without verifying it’s correctness

Source

pub fn as_str(&self) -> Result<&str, EncodingError>

§Error

This can fail if a body does not contain valid utf8.

Source

pub fn to_string(&self) -> Result<String, EncodingError>

Converts the internal buffer into an utf-8 string if possible.

Source

pub fn to_string_lossy(&self) -> Cow<'_, str>

Lossy conversion of the internal buffer to an string.

Source

pub fn as_slice(&self) -> &[u8]

Return a slice view to the underlying buffer.

Trait Implementations§

Source§

impl Into<(MailType, Vec<u8>)> for EncodingBuffer

Source§

fn into(self) -> (MailType, Vec<u8>)

Converts this type into the (usually inferred) input type.
Source§

impl Into<Vec<u8>> for EncodingBuffer

Source§

fn into(self) -> Vec<u8>

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.