Skip to main content

Writer

Struct Writer 

pub struct Writer<S> {
    sink: S,
}
Expand description

Writes MQTT wire-format fields into a Sink.

Every method fails only with the sink’s error. A failed method can leave part of its field in the sink.

Fields§

§sink: S

Implementations§

§

impl<S: Sink> Writer<S>

pub const fn new(sink: S) -> Self

Creates a writer over sink.

pub fn into_inner(self) -> S

Returns the sink.

pub fn bytes(&mut self, bytes: &[u8]) -> Result<(), S::Error>

Writes bytes as they are.

§Errors

Returns the sink’s error if it cannot take the bytes.

pub fn u8(&mut self, value: u8) -> Result<(), S::Error>

Writes one byte.

§Errors

Returns the sink’s error if it cannot take the byte.

pub fn u16(&mut self, value: u16) -> Result<(), S::Error>

Writes a big-endian u16.

§Errors

Returns the sink’s error if it cannot take 2 bytes.

pub fn u32(&mut self, value: u32) -> Result<(), S::Error>

Writes a big-endian u32.

§Errors

Returns the sink’s error if it cannot take 4 bytes.

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

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

§Errors

Returns the sink’s error if it cannot take the encoded value.

pub fn binary(&mut self, data: &MqttBytes) -> Result<(), S::Error>

Writes length-prefixed binary data.

§Errors

Returns the sink’s error if it cannot take the prefix and data.

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

Writes a length-prefixed UTF-8 string.

§Errors

Returns the sink’s error if it cannot take the prefix and string.

pub fn string_pair(&mut self, k: &MqttStr, v: &MqttStr) -> Result<(), S::Error>

Writes a pair of length-prefixed strings.

§Errors

Returns the sink’s error if it cannot take both strings.

§

impl Writer<Counter>

pub fn measure<E, F>(encode: F) -> Result<usize, E>
where F: FnOnce(&mut Self) -> Result<(), E>,

Measures the encoded length of whatever encode writes.

§Errors

Returns the error of encode. Counting itself never fails.

Trait Implementations§

§

impl<S: Debug> Debug for Writer<S>

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> Freeze for Writer<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Writer<S>
where S: RefUnwindSafe,

§

impl<S> Send for Writer<S>
where S: Send,

§

impl<S> Sync for Writer<S>
where S: Sync,

§

impl<S> Unpin for Writer<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for Writer<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for Writer<S>
where S: UnwindSafe,

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 = !

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.