5个不稳定版本
| 0.3.1 | 2020年3月9日 |
|---|---|
| 0.3.0 | 2020年3月9日 |
| 0.2.0 | 2020年3月9日 |
| 0.1.1 | 2019年9月6日 |
| 0.1.0 | 2019年7月26日 |
2333在Rust模式中
每月下载27次
8KB
129 行
into-result
一个简单的便利特质,用于将某些内容转换为Result或Option。
默认情况下,这为Command::output Command::spawn和Command::status提供了改进的错误处理。这些方法仅在进程无法spawn时返回Err;需要进一步处理以检查命令是否具有成功的退出状态。IntoResult为您处理这些,将两种类型的失败合并到一个Result
use into_result::{IntoResult as _};
use std::process::Command;
Command::new("ls")
.spawn()
.into_result()
.expect("either failed to spawn command, or command returned non-zero exit status");
您可以通过示例来查看实际效果。
into-result还通过no-default-features支持no_std。您仍然会得到IntoResult特质和一个针对bool的实现。