Property

Struct Property 

pub struct Property {
    pub(crate) cprop: MQTTProperty,
}
Expand description

A single MQTT v5 property.

An MQTT v5 property consists of both a property “code” and a value. The code indicates what the property contains (Response Topic, Will Delay Interval, etc), and also the data type for the value. Each copde corresponds to a single, specific data type as described in the v5 spec, here: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901027

There are only a limited number of data types that are possible for properties: “Byte” - u8 “Two Byte Integer” - u16 “Four Byte Integer” - u32 “Binary Data” - Vec<u8> “UTF-8 Encoded String” - String “UTF-8 String Pair” - (String,String)

Fields§

§cprop: MQTTProperty

Implementations§

§

impl Property

pub fn new<T>(code: PropertyCode, val: T) -> Result<Property, Error>
where T: Any + 'static,

Creates a new property for a given code and value.

The type for the value must match the type expected for the given property code exactly, otherwise it will be rejected and return None.

pub fn new_byte(code: PropertyCode, val: u8) -> Result<Property, Error>

Creates a single-byte property

pub fn new_u16(code: PropertyCode, val: u16) -> Result<Property, Error>

Creates a 2-byte integer property

pub fn new_u32(code: PropertyCode, val: u32) -> Result<Property, Error>

Creates a 4-byte integer property

pub fn new_int(code: PropertyCode, val: i32) -> Result<Property, Error>

Creates a new integer property.

This works for any sized integer type, from byte on up.

pub fn new_binary<V>(code: PropertyCode, bin: V) -> Result<Property, Error>
where V: Into<Vec<u8>>,

Creates a new binary property.

pub fn new_string(code: PropertyCode, s: &str) -> Result<Property, Error>

Creates a new string property.

pub fn new_string_pair( code: PropertyCode, key: &str, val: &str, ) -> Result<Property, Error>

Creates a new string pair property.

pub fn property_code(&self) -> PropertyCode

Gets the MQTT code for the property.

pub fn property_type(&self) -> PropertyType

Gets the type of this property.

pub fn type_of(&self) -> TypeId

Gets the any::TypeId of this property.

pub fn get<T>(&self) -> Option<T>
where T: Any + 'static + Send + Default,

Gets the property value

pub fn get_byte(&self) -> Option<u8>

Gets the property value as a byte.

pub fn get_u16(&self) -> Option<u16>

Gets the property value as a u16.

pub fn get_u32(&self) -> Option<u32>

Gets the property value as a u16.

pub fn get_int(&self) -> Option<i32>

Gets the property value as an integer. This extracts an integer value from the property. It works with any of the int types, one, two, or four bytes. If the Property contains an integer type it will be returned as Some(val), otherwise it will return None.

pub fn get_binary(&self) -> Option<Vec<u8>>

Gets the property value as a binary blob.

pub fn get_string(&self) -> Option<String>

Gets the property value as a string.

pub fn get_string_pair(&self) -> Option<(String, String)>

Gets the property value as a string pair.

Trait Implementations§

§

impl Clone for Property

§

fn clone(&self) -> Property

Creates a clone of the property. For string any binary properties, this also clones the heap memory so that each property is managing separate allocations.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Property

§

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

Formats the value using the given formatter. Read more
§

impl Drop for Property

§

fn drop(&mut self)

Drops the property. For string any binary types, the heap memory will be freed.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more