[][src]Struct tinyvec_string::arraystring::FromUtf8Error

pub struct FromUtf8Error<A: ByteArray> { /* fields omitted */ }

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

impl<A: ByteArray> FromUtf8Error<A>[src]

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

Notable traits for &'_ mut [u8]

impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
[src]

Returns a slice of u8s 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());

pub fn into_bytes(self) -> ArrayVec<A>[src]

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());

pub fn utf8_error(&self) -> Utf8Error[src]

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

impl<A: Clone + ByteArray> Clone for FromUtf8Error<A>[src]

impl<A: Copy + ByteArray> Copy for FromUtf8Error<A>[src]

impl<A: ByteArray> Debug for FromUtf8Error<A>[src]

impl<A: ByteArray> Display for FromUtf8Error<A>[src]

impl<A: Eq + ByteArray> Eq for FromUtf8Error<A>[src]

impl<A: ByteArray> Error for FromUtf8Error<A>[src]

This is supported with target feature std only.

impl<A: PartialEq + ByteArray> PartialEq<FromUtf8Error<A>> for FromUtf8Error<A>[src]

impl<A: ByteArray> StructuralEq for FromUtf8Error<A>[src]

impl<A: ByteArray> StructuralPartialEq for FromUtf8Error<A>[src]

Auto Trait Implementations

impl<A> RefUnwindSafe for FromUtf8Error<A> where
    A: RefUnwindSafe
[src]

impl<A> Send for FromUtf8Error<A> where
    A: Send
[src]

impl<A> Sync for FromUtf8Error<A> where
    A: Sync
[src]

impl<A> Unpin for FromUtf8Error<A> where
    A: Unpin
[src]

impl<A> UnwindSafe for FromUtf8Error<A> where
    A: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.