当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust Result.contains_err用法及代码示例


本文简要介绍rust语言中 std::result::Result.contains_err 的用法。

用法

pub fn contains_err<F>(&self, f: &F) -> bool where    F: PartialEq<E>,

如果结果是包含给定值的 Err 值,则返回 true

例子

#![feature(result_contains_err)]

let x: Result<u32, &str> = Ok(2);
assert_eq!(x.contains_err(&"Some error message"), false);

let x: Result<u32, &str> = Err("Some error message");
assert_eq!(x.contains_err(&"Some error message"), true);

let x: Result<u32, &str> = Err("Some other error message");
assert_eq!(x.contains_err(&"Some error message"), false);

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 std::result::Result.contains_err。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。