Struct rmpv::Utf8String

source ·
pub struct Utf8String { /* private fields */ }
Expand description

Represents an UTF-8 MessagePack string type.

According to the MessagePack spec, string objects may contain invalid byte sequence and the behavior of a deserializer depends on the actual implementation when it received invalid byte sequence. Deserializers should provide functionality to get the original byte array so that applications can decide how to handle the object.

Summarizing, it’s prohibited to instantiate a string type with invalid UTF-8 sequences, however it is possible to obtain an underlying bytes that were attempted to convert to a String. This may happen when trying to unpack strings that were decoded using older MessagePack spec with raw types instead of string/binary.

Implementations§

source§

impl Utf8String

source

pub fn is_str(&self) -> bool

Returns true if the string is valid UTF-8.

source

pub fn is_err(&self) -> bool

Returns true if the string contains invalid UTF-8 sequence.

source

pub fn as_str(&self) -> Option<&str>

Returns the string reference if the string is valid UTF-8, or else None.

source

pub fn as_err(&self) -> Option<&Utf8Error>

Returns the underlying Utf8Error if the string contains invalud UTF-8 sequence, or else None.

source

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

Returns a byte slice of this Utf8String’s contents.

source

pub fn into_str(self) -> Option<String>

Consumes this object, yielding the string if the string is valid UTF-8, or else None.

source

pub fn into_bytes(self) -> Vec<u8>

Converts a Utf8String into a byte vector.

source

pub fn as_ref(&self) -> Utf8StringRef<'_>

Trait Implementations§

source§

impl Clone for Utf8String

source§

fn clone(&self) -> Utf8String

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Utf8String

source§

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

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

impl Display for Utf8String

source§

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

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

impl<'a> From<&'a str> for Utf8String

source§

fn from(val: &str) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Cow<'a, str>> for Utf8String

source§

fn from(val: Cow<'a, str>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<String> for Utf8String

source§

fn from(val: String) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Utf8StringRef<'a>> for Utf8String

source§

fn from(val: Utf8StringRef<'a>) -> Self

Converts to this type from the input type.
source§

impl PartialEq for Utf8String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<Value> for Utf8String

§

type Error = Value

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

fn try_from(val: Value) -> Result<Utf8String, Self::Error>

Performs the conversion.
source§

impl StructuralPartialEq for Utf8String

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

§

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

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.