使用旧Rust 2015
0.1.0 |
|
---|
#4 在 #lift
10KB
65 行
lift-fail
一个用于处理可迭代集合中failure
的库。
关于
有时你可能需要在一次执行多项任务时处理失败情况,通常在并行工作时。如果某些任务失败怎么办?如果某些任务没有失败怎么办?如果一切顺利怎么办?如果你使用failure
crate来处理错误,这个库可以帮助你处理这种情况。
入门
在您的Cargo.toml
中添加以下内容
[dependencies]
lift-fail = "0.1"
然后在您的lib.rs
或main.rs
文件中
extern crate lift_fail
然后您需要的地方
use lift_fail::lift_fail;
以下是一个基本的使用示例
#[macro_use] extern crate failure;
extern crate lift_fail;
use lift_fail::lift_fail;
fn main() {
let example_vec = vec![
Ok(1),
Err(format_err!("Uh oh")),
Ok(2),
Err(format_err!("Oh no")),
];
match lift_fail(example_vec) {
// We have errors in our vec so we know we won't get a vector of just the
// correct values. We're lifting up the errors into one.
Ok(_) => unreachable!(),
Err(e) => println!("{}", e.cause()),
}
}
示例
请参阅examples
目录以了解如何以其他方式使用此库。
贡献
有关更多信息,请参阅CONTRIBUTING.md
许可证
根据您选择
- Apache许可证第2版 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
。
许可协议
除非您明确说明,否则根据Apache-2.0许可证定义,您有意提交给作品作为贡献的内容应按上述方式双重许可,无需任何附加条款或条件。
依赖项
~64KB