用法
pub fn into_err(self) -> E
返回包含的 Err
值,但从不Panics。
与 unwrap_err
不同,众所周知,此方法不会对其实现的结果类型产生Panics。因此,可以使用它来代替unwrap_err
作为维护性保障,如果稍后将Result
的ok 类型更改为可以实际发生的类型,它将无法编译。
例子
基本用法:
fn only_bad_news() -> Result<!, String> {
Err("Oops, it failed".into())
}
let error:String = only_bad_news().into_err();
println!("{}", error);
相关用法
- Rust core::result::Result.into_ok用法及代码示例
- Rust core::result::Result.into_ok_or_err用法及代码示例
- Rust core::result::Result.is_ok用法及代码示例
- Rust core::result::Result.iter_mut用法及代码示例
- Rust core::result::Result.iter用法及代码示例
- Rust core::result::Result.is_err用法及代码示例
- Rust core::result::Result.expect_err用法及代码示例
- Rust core::result::Result.as_ref用法及代码示例
- Rust core::result::Result.or用法及代码示例
- Rust core::result::Result.expect用法及代码示例
- Rust core::result::Result.unwrap用法及代码示例
- Rust core::result::Result.cloned用法及代码示例
- Rust core::result::Result.or_else用法及代码示例
- Rust core::result::Result.unwrap_or用法及代码示例
- Rust core::result::Result.unwrap_or_default用法及代码示例
- Rust core::result::Result.map_err用法及代码示例
- Rust core::result::Result.transpose用法及代码示例
- Rust core::result::Result.unwrap_err用法及代码示例
- Rust core::result::Result.err用法及代码示例
- Rust core::result::Result.map_or用法及代码示例
注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 core::result::Result.into_err。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。