Writer

Struct Writer 

pub struct Writer<'a> {
    buf: &'a mut [MaybeUninit<u8>],
}
Expand description

MQTT wire format writer.

Fields§

§buf: &'a mut [MaybeUninit<u8>]

Implementations§

§

impl<'a> Writer<'a>

pub const fn new(buf: &'a mut [u8]) -> Self

Creates a new writer over an initialized buffer.

pub const fn new_uninit(buf: &'a mut [MaybeUninit<u8>]) -> Self

Creates a new writer over the given buffer.

pub const fn into_uninit(self) -> &'a mut [MaybeUninit<u8>]

Returns the remaining unwritten portion of the buffer.

const unsafe fn split_off_at_mut_unchecked( &mut self, index: usize, ) -> &'a mut [MaybeUninit<u8>]

Splits off a prefix of the buffer for writing, returning a mutable slice to it and advancing self.buf past it.

§Safety

The caller must guarantee that index is a valid split point of self.buf, and that the returned slice is fully written before any further use of self.

const unsafe fn write_slice_unchecked(&mut self, bytes: &[u8])

Writes a copy of the given slice into the buffer.

§Safety

The caller must guarantee that self.buf has at least bytes.len() bytes available.

pub const fn write_slice(&mut self, bytes: &[u8]) -> Result<(), EncodeError>

Writes a copy of the given slice into the buffer.

§Errors

Returns EncodeError::InsufficientSpace if the buffer cannot fit the bytes.

pub const fn u8(&mut self, value: u8) -> Result<(), EncodeError>

Writes a single byte.

§Errors

Returns EncodeError::InsufficientSpace if the buffer is full.

pub const fn u16(&mut self, value: u16) -> Result<(), EncodeError>

Writes a big-endian u16.

§Errors

Returns EncodeError::InsufficientSpace if the buffer has fewer than 2 bytes free.

pub const fn u32(&mut self, value: u32) -> Result<(), EncodeError>

Writes a big-endian u32.

§Errors

Returns EncodeError::InsufficientSpace if the buffer has fewer than 4 bytes free.

pub const fn vbi(&mut self, value: Vbi) -> Result<(), EncodeError>

Writes a Variable Byte Integer (1–4 bytes).

§Errors

Returns EncodeError::InsufficientSpace if the buffer cannot fit the encoded value.

pub const fn binary(&mut self, bytes: &MqttBytes) -> Result<(), EncodeError>

Writes a length-prefixed binary data.

§Errors

Returns EncodeError::InsufficientSpace if the buffer cannot fit the length prefix and data.

pub const fn string(&mut self, s: &MqttStr) -> Result<(), EncodeError>

Writes a length-prefixed UTF-8 string with additional MQTT validation.

§Errors

Returns EncodeError::InsufficientSpace if the buffer cannot fit the string.

Auto Trait Implementations§

§

impl<'a> Freeze for Writer<'a>

§

impl<'a> RefUnwindSafe for Writer<'a>

§

impl<'a> Send for Writer<'a>

§

impl<'a> Sync for Writer<'a>

§

impl<'a> Unpin for Writer<'a>

§

impl<'a> !UnwindSafe for Writer<'a>

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.