當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Rust IntoInnerError.into_error用法及代碼示例

本文簡要介紹rust語言中 std::io::IntoInnerError.into_error 的用法。

用法

pub fn into_error(self) -> Error

使用 IntoInnerError 並返回導致調用 BufWriter::into_inner() 失敗的錯誤。與 error 不同,這可用於獲取底層錯誤的所有權。

示例

use std::io::{BufWriter, ErrorKind, Write};

let mut not_enough_space = [0u8; 10];
let mut stream = BufWriter::new(not_enough_space.as_mut());
write!(stream, "this cannot be actually written").unwrap();
let into_inner_err = stream.into_inner().expect_err("now we discover it's too small");
let err = into_inner_err.into_error();
assert_eq!(err.kind(), ErrorKind::WriteZero);

相關用法


注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 std::io::IntoInnerError.into_error。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。