MqttStr

Struct MqttStr 

#[repr(transparent)]
pub struct MqttStr(str);
Expand description

A UTF-8 string that satisfies all MQTT v5 requirements:

  • Well-formed UTF-8 (guaranteed by Rust’s str)
  • No surrogate code points U+D800..U+DFFF (guaranteed by Rust’s str)
  • No null character U+0000 [MQTT-1.5.4-2]
  • At most 65 535 bytes

This is an unsized type like str. Use &MqttStr for borrowed references and MqttString for owned values.

Tuple Fields§

§0: str

Implementations§

Source§

impl MqttStr

Source

pub const EMPTY: &'static MqttStr

The empty MQTT string.

Source

pub const unsafe fn new_unchecked(s: &str) -> &MqttStr

Create a new MQTT string without validating MQTT-specific invariants.

§Safety

The caller must guarantee that s satisfies the MQTT string invariants.

Source

pub const fn new(s: &str) -> Result<&MqttStr, DataError>

Validate and wrap a &str.

§Errors

Returns DataError::TooLong if s exceeds 65 535 bytes, or DataError::ContainsNull if s contains U+0000.

Source

pub const fn as_mqtt_bytes(&self) -> &MqttBytes

Returns this string as MqttBytes.

Source

pub const fn as_str(&self) -> &str

Returns the underlying &str.

Source

pub const fn len(&self) -> usize

Returns the length in bytes.

Source

pub const fn len_u16(&self) -> u16

Returns the length as a u16 for encoding.

Source

pub const fn encoded_len(&self) -> usize

Returns the number of bytes needed to encode this value.

Source

pub const fn is_empty(&self) -> bool

Returns true if the string is empty.

Source

pub const fn as_bytes(&self) -> &[u8]

Returns the raw UTF-8 bytes.

Trait Implementations§

Source§

impl AsRef<MqttStr> for MqttString

Source§

fn as_ref(&self) -> &MqttStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<MqttStr> for Topic

Source§

fn as_ref(&self) -> &MqttStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<MqttStr> for TopicBuf

Source§

fn as_ref(&self) -> &MqttStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<MqttStr> for TopicFilter

Source§

fn as_ref(&self) -> &MqttStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<MqttStr> for TopicFilterBuf

Source§

fn as_ref(&self) -> &MqttStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<str> for MqttStr

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<MqttStr> for MqttString

Source§

fn borrow(&self) -> &MqttStr

Immutably borrows from an owned value. Read more
Source§

impl Debug for MqttStr

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for MqttStr

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Hash for MqttStr

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
Source§

impl PartialEq for MqttStr

Source§

fn eq(&self, other: &MqttStr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToOwned for MqttStr

Source§

type Owned = MqttString

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> <MqttStr as ToOwned>::Owned

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

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<'a> TryFrom<&'a str> for &'a MqttStr

Source§

type Error = DataError

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

fn try_from( value: &'a str, ) -> Result<&'a MqttStr, <&'a MqttStr as TryFrom<&'a str>>::Error>

Performs the conversion.
Source§

impl Eq for MqttStr

Source§

impl StructuralPartialEq for MqttStr

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more