pub struct FromUtf8Error { /* private fields */ }
Expand description
A possible error value when converting a String
from a UTF-8 byte vector.
This type is the error type for the from_utf8
method on String
. It
is designed in such a way to carefully avoid reallocations: the
into_bytes
method will give back the byte vector that was used in the
conversion attempt.
The Utf8Error
type provided by std::str
represents an error that may
occur when converting a slice of u8
s to a &str
. In this sense, it’s
an analogue to FromUtf8Error
, and you can get one from a FromUtf8Error
through the utf8_error
method.
§Examples
Implementations§
Source§impl FromUtf8Error
impl FromUtf8Error
Sourcepub fn into_utf8_lossy(self) -> String
🔬This is a nightly-only experimental API. (string_from_utf8_lossy_owned
#129436)
pub fn into_utf8_lossy(self) -> String
string_from_utf8_lossy_owned
#129436)Converts the bytes into a String
lossily, substituting invalid UTF-8
sequences with replacement characters.
See String::from_utf8_lossy
for more details on replacement of
invalid sequences, and String::from_utf8_lossy_owned
for the
String
function which corresponds to this function.
§Examples
1.0.0 · Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Returns the bytes that were attempted to convert to a String
.
This method is carefully constructed to avoid allocation. It will consume the error, moving out the bytes, so that a copy of the bytes does not need to be made.
§Examples
1.0.0 · Sourcepub fn utf8_error(&self) -> Utf8Error
pub fn utf8_error(&self) -> Utf8Error
Trait Implementations§
1.0.0 · Source§impl Clone for FromUtf8Error
impl Clone for FromUtf8Error
Source§fn clone(&self) -> FromUtf8Error
fn clone(&self) -> FromUtf8Error
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more