3 个版本
0.1.2 | 2023 年 11 月 15 日 |
---|---|
0.1.1 | 2023 年 11 月 14 日 |
0.1.0 | 2023 年 11 月 14 日 |
1057 在 Rust 模式
7KB
89 行
type-fn
type-fn 允许您更简单地创建类型级别的逻辑。
示例
无符号加法、减法和乘法
struct Zero;
struct Succ<T>(PhantomData<T>);
type_fn! {
fn Add<Lhs, Rhs>;
fn Sub<Lhs, Rhs>;
fn Mul<Lhs, Rhs>;
}
type_fn_impl! {
fn<TypeFn> Add< => Zero, Rhs> => Rhs;
fn<TypeFn> Add<N => Succ<N>, Rhs>
where
Add<N, Rhs>: + TypeFn,
=> Succ<<Add<N, Rhs> as TypeFn>::Ret>;
fn<TypeFn> Sub<Lhs, => Zero> => Lhs;
fn<TypeFn> Sub<Lhs => Succ<Lhs>, Rhs => Succ<Rhs>>
where
Sub<Lhs, Rhs> : + TypeFn,
=> <Sub<Lhs, Rhs> as TypeFn>::Ret;
fn<TypeFn> Mul< => Zero, Rhs> => Zero;
fn<TypeFn> Mul<Lhs => Succ<Lhs>, Rhs>
where
Mul<Lhs, Rhs>: + TypeFn,
Add<Rhs, <Mul<Lhs, Rhs> as TypeFn>::Ret>: + TypeFn,
=> <Add<Rhs, <Mul<Lhs, Rhs> as TypeFn>::Ret> as TypeFn>::Ret;
}