Struct std::string::FromUtf8Error
1.0.0 · source · pub struct FromUtf8Error { /* private fields */ }Expand description
从 UTF-8 字节 vector 转换 String 时可能的错误值。
该类型是 String 上 from_utf8 方法的错误类型。
它的设计方式旨在避免重新分配: into_bytes 方法将返回转换尝试中使用的字节 vector。
std::str 提供的 Utf8Error 类型表示将 u8 的切片转换为 &str 时可能发生的错误。
从这个意义上讲,它是 FromUtf8Error 的类似物,您可以通过 utf8_error 方法从 FromUtf8Error 中获得一个。
Examples
基本用法:
// vector 中的一些无效字节
let bytes = vec![0, 159];
let value = String::from_utf8(bytes);
assert!(value.is_err());
assert_eq!(vec![0, 159], value.unwrap_err().into_bytes());RunImplementations§
source§impl FromUtf8Error
impl FromUtf8Error
sourcepub fn utf8_error(&self) -> Utf8Error
pub fn utf8_error(&self) -> Utf8Error
提取 Utf8Error 以获取有关转换失败的更多详细信息。
std::str 提供的 Utf8Error 类型表示将 u8 的切片转换为 &str 时可能发生的错误。
从这个意义上讲,它类似于 FromUtf8Error。
有关使用它的更多详细信息,请参见其文档。
Examples
基本用法:
// vector 中的一些无效字节
let bytes = vec![0, 159];
let error = String::from_utf8(bytes).unwrap_err().utf8_error();
// 第一个字节在这里无效
assert_eq!(1, error.valid_up_to());RunTrait Implementations§
source§impl Clone for FromUtf8Error
impl Clone for FromUtf8Error
source§fn clone(&self) -> FromUtf8Error
fn clone(&self) -> FromUtf8Error
返回值的副本。 Read more
source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
从
source 执行复制分配。 Read moresource§impl Debug for FromUtf8Error
impl Debug for FromUtf8Error
source§impl Display for FromUtf8Error
impl Display for FromUtf8Error
source§impl Error for FromUtf8Error
impl Error for FromUtf8Error
source§impl PartialEq<FromUtf8Error> for FromUtf8Error
impl PartialEq<FromUtf8Error> for FromUtf8Error
impl Eq for FromUtf8Error
impl StructuralEq for FromUtf8Error
impl StructuralPartialEq for FromUtf8Error
Auto Trait Implementations§
impl RefUnwindSafe for FromUtf8Error
impl Send for FromUtf8Error
impl Sync for FromUtf8Error
impl Unpin for FromUtf8Error
impl UnwindSafe for FromUtf8Error
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
从拥有的值中借用。 Read more