Topic

Struct Topic 

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

A validated, borrowed MQTT topic name.

Topic names are used in PUBLISH packets to identify the subject of a message. They must not contain wildcard characters (+, #), must not be empty, and must satisfy the MqttStr constraints (≤ 65 535 bytes, no U+0000).

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

Tuple Fields§

§0: MqttStr

Implementations§

§

impl Topic

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

Create a topic name without validating topic-specific invariants.

§Safety

The caller must guarantee that s satisfies the topic name invariants: non-empty, no wildcard characters (+, #), and valid MqttStr.

pub const fn new(s: &MqttStr) -> Result<&Self, TopicError>

Validate and create a new topic name from a validated MqttStr.

This only checks non-empty and no wildcard characters; MqttStr guarantees length and null-character constraints.

§Errors

Returns TopicError if the string is empty or contains wildcard characters (+, #).

pub const fn as_mqtt_str(&self) -> &MqttStr

View the topic as an MqttStr.

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

View the topic as a string slice.

Trait Implementations§

§

impl AsRef<MqttStr> for Topic

§

fn as_ref(&self) -> &MqttStr

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

impl AsRef<Topic> for TopicBuf

Available on crate feature alloc only.
§

fn as_ref(&self) -> &Topic

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

impl AsRef<str> for Topic

§

fn as_ref(&self) -> &str

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

impl Borrow<Topic> for TopicBuf

Available on crate feature alloc only.
§

fn borrow(&self) -> &Topic

Immutably borrows from an owned value. Read more
§

impl Debug for Topic

§

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

Formats the value using the given formatter. Read more
§

impl Display for Topic

§

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

Formats the value using the given formatter. Read more
§

impl From<&Topic> for TopicBuf

Available on crate feature alloc only.
§

fn from(value: &Topic) -> Self

Converts to this type from the input type.
§

impl Hash for Topic

§

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

Feeds this value into the given Hasher. Read more
§

impl PartialEq for Topic

§

fn eq(&self, other: &Topic) -> 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.
§

impl ToOwned for Topic

Available on crate feature alloc only.
§

type Owned = TopicBuf

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> Self::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
§

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

§

type Error = ParseTopicError

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

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

Performs the conversion.
§

impl Eq for Topic

§

impl StructuralPartialEq for Topic

Auto Trait Implementations§

§

impl Freeze for Topic

§

impl RefUnwindSafe for Topic

§

impl Send for Topic

§

impl !Sized for Topic

§

impl Sync for Topic

§

impl Unpin for Topic

§

impl UnwindSafe for Topic

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