1 个不稳定版本
0.1.0 | 2024 年 8 月 11 日 |
---|
#244 在 科学
108 每月下载量
26KB
616 行
选择
Rust 类型系统中仿射加法合取的实现。
这可以用来将互斥的函数参数分组,以便它们可以有重叠的捕获。
使用方法
以下使用 Result
的代码不起作用,因为它
Ok(0)
.map(|x: i32| sender.send(x + 1))
.map_err(|y: i32| sender.send(y - 1));
//! ^^^^^^^^ use of moved value: `sender`
而使用 Either
并传递一个包含两个函数的 Choice
,通过在同一个对象中存储两个分支来绕过这个问题。
Either::Left(0).choose_map(Exclusive::new(
sender,
|s| move |x: i32| s.send(x + 1),
|s| move |y: i32| s.send(y - 1),
));
依赖项
~1.5MB
~35K SLoC