Struct FromUtf8Error
pub struct FromUtf8Error { /* private fields */ }
An error that may occur when converting a Vec<u8> to a String.
This error includes the original Vec<u8> that failed to convert to a
String. This permits callers to recover the allocation used even if it
it not valid UTF-8.
Examples
Basic usage:
use ;
let bytes = Vecfrom_slice;
let err = bytes.into_string.unwrap_err;
assert_eq!;
assert_eq!;
// At no point in this example is an allocation performed.
let bytes = Vecfrom;
assert_eq!;
Implementations
impl FromUtf8Error
fn as_bytes(&self) -> &[u8]Return the original bytes as a slice that failed to convert to a
String.Examples
Basic usage:
use ; let bytes = Vecfrom_slice; let err = bytes.into_string.unwrap_err; // At no point in this example is an allocation performed. assert_eq!;fn into_vec(self) -> Vec<u8>Consume this error and return the original byte string that failed to convert to a
String.Examples
Basic usage:
use ; let bytes = Vecfrom_slice; let err = bytes.into_string.unwrap_err; let original = err.into_vec; // At no point in this example is an allocation performed. assert_eq!;fn utf8_error(&self) -> &Utf8ErrorReturn the underlying UTF-8 error that occurred. This error provides information on the nature and location of the invalid UTF-8 detected.
Examples
Basic usage:
use ; let bytes = Vecfrom_slice; let err = bytes.into_string.unwrap_err; assert_eq!; assert_eq!;
Trait Implementations
impl Debug for FromUtf8Error
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Display for FromUtf8Error
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for FromUtf8Error
impl Error for FromUtf8Error
fn description(&self) -> &str
impl PartialEq for FromUtf8Error
fn eq(&self, other: &FromUtf8Error) -> bool
impl StructuralPartialEq for FromUtf8Error
Auto Trait Implementations
impl Freeze for FromUtf8Error
impl RefUnwindSafe for FromUtf8Error
impl Send for FromUtf8Error
impl Sync for FromUtf8Error
impl Unpin for FromUtf8Error
impl UnsafeUnpin for FromUtf8Error
impl UnwindSafe for FromUtf8Error
Blanket Implementations
impl<T> Any for FromUtf8Error
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for FromUtf8Error
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for FromUtf8Error
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for FromUtf8Error
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToString for FromUtf8Error
where
T: Display + ?Sized,
fn to_string(&self) -> String
impl<T, U> Into<U> for FromUtf8Error
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for FromUtf8Error
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for FromUtf8Error
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>