Crates.io | type-fn |
lib.rs | type-fn |
version | |
source | src |
created_at | 2023-11-14 19:35:37.403597 |
updated_at | 2025-01-29 05:30:19.610943 |
description | Allows for simpler coding of type-level logic, e.g. for type-number systems. |
homepage | |
repository | https://github.com/tudbut/type-fn |
max_upload_size | |
id | 1035299 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
type-fn allows you to more simply create logic at the type level.
Unsigned addition, subtraction, and multiplication:
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;
}