Struct tinyvec_string::arraystring::FromUtf8Error [−][src]
pub struct FromUtf8Error<A: ByteArray> { /* fields omitted */ }
Expand description
A possible error value when converting an ArrayString
from a UTF-8 byte
vector.
This type is the error type for the from_utf8
method on ArrayString
.
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
use tinyvec::{array_vec, ArrayVec};
// some invalid bytes, in a vector
let bytes: ArrayVec<[u8; 2]> = array_vec![0, 159];
let value = ArrayString::from_utf8(bytes);
assert_eq!(Err(array_vec![0, 159]), value.map_err(|e| e.into_bytes()));
Implementations
Returns a slice of u8
s bytes that were attempted to convert to an
ArrayString
.
Examples
use tinyvec::{array_vec, ArrayVec};
// some invalid bytes, in a vector
let bytes: ArrayVec<[u8; 2]> = array_vec![0, 159];
let value = ArrayString::from_utf8(bytes);
assert_eq!(&[0, 159], value.unwrap_err().as_bytes());
Returns the bytes that were attempted to convert to a String
.
Examples
use tinyvec::{array_vec, ArrayVec};
// some invalid bytes, in a vector
let bytes: ArrayVec<[u8; 2]> = array_vec![0, 159];
let value = ArrayString::from_utf8(bytes);
assert_eq!(array_vec![0, 159], value.unwrap_err().into_bytes());
Fetch a Utf8Error
to get more details about the conversion failure.
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
. See its documentation for more details
on using it.
Examples
use tinyvec::{array_vec, ArrayVec};
// some invalid bytes, in a vector
let bytes: ArrayVec<[u8; 2]> = array_vec![0, 159];
let error = ArrayString::from_utf8(bytes).unwrap_err().utf8_error();
// the first byte is invalid here
assert_eq!(1, error.valid_up_to());
Trait Implementations
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl<A> RefUnwindSafe for FromUtf8Error<A> where
A: RefUnwindSafe,
impl<A> Send for FromUtf8Error<A> where
A: Send,
impl<A> Sync for FromUtf8Error<A> where
A: Sync,
impl<A> Unpin for FromUtf8Error<A> where
A: Unpin,
impl<A> UnwindSafe for FromUtf8Error<A> where
A: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more