1 个稳定版本
| 1.0.0 | 2022年7月8日 |
|---|
#1148 在 开发工具
16KB
yeet! 宏
yeet-ops 是一个超级小巧的 crate,用于补充 do yeet 语句,该语句已在 https://github.com/rust-lang/rust/pull/96376 中实现
此 crate 需要 Rust 的 nightly 版本。
使用方法
只需将此添加到您的 Cargo.toml 依赖项中
yeet-ops = "^1.0.0"
然后您就可以使用了!
#![feature(yeet_expr)] // Needed!
use yeet_ops::yeet;
/// A function that yeets `None`
fn test() -> Option<i32> {
yeet!();
}
/// A function that yeets `Err(1)`
fn test2() -> Result<String, i32> {
yeet!(1);
}
fn main() {
// Did it yeet?
assert_eq!(test(), None);
assert_eq!(test2(), Err(1));
}