pub struct FromUtf8Error<const N: usize> { /* private fields */ }
Expand description
A possible error value when converting a StackStr
from a UTF-8 byte vector.
This type is the error type for the from_utf8
method on StackStr
. 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.
§Examples
use stack_buf::{StackStr, stack_vec};
// some invalid bytes, in a vector
let bytes = stack_vec![0, 159];
let value = StackStr::<2>::from_utf8(bytes);
assert!(value.is_err());
assert_eq!(stack_vec![0, 159], value.unwrap_err().into_bytes());
Implementations§
Source§impl<const N: usize> FromUtf8Error<N>
impl<const N: usize> FromUtf8Error<N>
Sourcepub fn into_bytes(self) -> StackVec<u8, N> ⓘ
pub fn into_bytes(self) -> StackVec<u8, N> ⓘ
Returns the bytes that were attempted to convert to a StackStr
.
§Examples
use stack_buf::{stack_vec, StackStr};
// some invalid bytes, in a vector
let bytes = stack_vec![0, 159];
let value = StackStr::<2>::from_utf8(bytes);
assert_eq!(stack_vec![0, 159], value.unwrap_err().into_bytes());
Sourcepub const fn utf8_error(&self) -> Utf8Error
pub const fn utf8_error(&self) -> Utf8Error
Fetch a Utf8Error
to get more details about the conversion failure.
§Examples
use stack_buf::{StackStr, stack_vec};
// some invalid bytes, in a vector
let bytes = stack_vec![0, 159];
let error = StackStr::<2>::from_utf8(bytes).unwrap_err().utf8_error();
// the first byte is invalid here
assert_eq!(1, error.valid_up_to());
Trait Implementations§
Source§impl<const N: usize> Clone for FromUtf8Error<N>
impl<const N: usize> Clone for FromUtf8Error<N>
Source§fn clone(&self) -> FromUtf8Error<N>
fn clone(&self) -> FromUtf8Error<N>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<const N: usize> Debug for FromUtf8Error<N>
impl<const N: usize> Debug for FromUtf8Error<N>
Source§impl<const N: usize> Display for FromUtf8Error<N>
impl<const N: usize> Display for FromUtf8Error<N>
Source§impl<const N: usize> Error for FromUtf8Error<N>
Available on crate features std
and str
only.
impl<const N: usize> Error for FromUtf8Error<N>
Available on crate features
std
and str
only.1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl<const N: usize> PartialEq for FromUtf8Error<N>
impl<const N: usize> PartialEq for FromUtf8Error<N>
impl<const N: usize> Eq for FromUtf8Error<N>
impl<const N: usize> StructuralPartialEq for FromUtf8Error<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for FromUtf8Error<N>
impl<const N: usize> RefUnwindSafe for FromUtf8Error<N>
impl<const N: usize> Send for FromUtf8Error<N>
impl<const N: usize> Sync for FromUtf8Error<N>
impl<const N: usize> Unpin for FromUtf8Error<N>
impl<const N: usize> UnwindSafe for FromUtf8Error<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more