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: strImplementations§
§impl MqttStr
impl MqttStr
pub const EMPTY: &'static Self
pub const EMPTY: &'static Self
The empty MQTT string.
pub const unsafe fn new_unchecked(s: &str) -> &Self
pub const unsafe fn new_unchecked(s: &str) -> &Self
Creates a new MQTT string without validating MQTT-specific invariants.
§Safety
The caller must guarantee that s satisfies the MQTT string invariants.
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 exactly
the single byte 0x00, so a byte scan is correct.
Exposed separately from new for a caller that already
knows the length invariant holds, 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.
Trait Implementations§
§impl AsRef<MqttStr> for MqttString
Available on crate feature alloc only.
impl AsRef<MqttStr> for MqttString
alloc only.§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 Borrow<MqttStr> for MqttString
Available on crate feature alloc only.
impl Borrow<MqttStr> for MqttString
alloc only.§impl PartialOrd for MqttStr
impl PartialOrd for MqttStr
§impl ToOwned for MqttStr
Available on crate feature alloc only.
impl ToOwned for MqttStr
alloc only.