Struct MqttStr
#[repr(transparent)]pub struct MqttStr(str);Expand description
A UTF-8 string that meets the 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: strImplementations§
§impl MqttStr
impl MqttStr
pub const EMPTY: &'static Self
pub const EMPTY: &'static Self
The empty MQTT string.
pub(super) const fn from_validated(s: &str) -> &Self
pub(super) const fn from_validated(s: &str) -> &Self
Wraps s, which the caller has already validated.
pub const fn new(s: &str) -> Result<&Self, DataError>
pub const fn new(s: &str) -> Result<&Self, DataError>
Validates and wraps a &str.
§Errors
Returns DataError::TooLong if s exceeds 65 535 bytes, or
DataError::ContainsNull if s contains U+0000.
pub(crate) const fn contains_null(bytes: &[u8]) -> bool
pub(crate) const fn contains_null(bytes: &[u8]) -> bool
Whether bytes contains the null character U+0000, forbidden by
[MQTT-1.5.4-2]. In valid UTF-8 the null character is always the one
byte 0x00, so a byte scan is correct.
Exposed separately from new for a caller that has already
checked the length, e.g. after reading a
length-prefixed field off the wire, so it does not have to re-check a
bound it already enforced.
pub const fn as_mqtt_bytes(&self) -> &MqttBytes
pub const fn as_mqtt_bytes(&self) -> &MqttBytes
Returns this string as MqttBytes.
pub const fn encoded_len(&self) -> usize
pub const fn encoded_len(&self) -> usize
Returns the number of bytes needed to encode this value.
§impl MqttStr
impl MqttStr
pub fn try_to_owned(&self) -> Result<MqttString, TryReserveError>
Available on crate feature alloc only.
pub fn try_to_owned(&self) -> Result<MqttString, TryReserveError>
alloc only.Copies the string into an MqttString without panicking if the
allocation fails.
§Errors
Returns TryReserveError if the allocation fails.
Trait Implementations§
§impl AsRef<MqttStr> for TopicFilter
impl AsRef<MqttStr> for TopicFilter
§impl AsRef<MqttStr> for TopicFilterBuf
Available on crate feature alloc only.
impl AsRef<MqttStr> for TopicFilterBuf
alloc only.§impl AsRef<MqttStr> for MqttString
Available on crate feature alloc only.
impl AsRef<MqttStr> for MqttString
alloc only.§impl Borrow<MqttStr> for MqttString
Available on crate feature alloc only.
impl Borrow<MqttStr> for MqttString
alloc only.impl Eq for MqttStr
§impl PartialOrd for MqttStr
impl PartialOrd for MqttStr
impl StructuralPartialEq for MqttStr
§impl ToOwned for MqttStr
Available on crate feature alloc only.
impl ToOwned for MqttStr
alloc only.