type-fn 0.2.0

Allows for simpler coding of type-level logic, e.g. for type-number systems.
Documentation
  • Coverage
  • 14.71%
    5 out of 34 items documented0 out of 23 items with examples
  • Size
  • Source code size: 10.04 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 775.68 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • TudbuT/type-fn
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • TudbuT

type-fn

type-fn allows you to more simply create logic at the type level.

Example

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;
}