Skip to main content

Fact

Trait Fact 

Source
pub trait Fact: Nat {
    type Result: Nat;
}
Expand description

§Factorial!

Did I hear shouting? Or was that just this epic compile-time factorial operator?!

assert_eq!(<Zero as Fact>::Result::eval(), 1);
assert_eq!(<One as Fact>::Result::eval(), 1);
assert_eq!(<Two as Fact>::Result::eval(), 2);
assert_eq!(<Three as Fact>::Result::eval(), 6);
assert_eq!(<Four as Fact>::Result::eval(), 24);
assert_eq!(<Five as Fact>::Result::eval(), 120);
// assert_eq!(<Six as Fact>::Result::eval(), 720); -- `rustc` gives up about here :((

(Ok, fine, yes, the recursion limit is on like 20,000,000.)

Required Associated Types§

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Fact for Zero

Source§

impl<T, U> Fact for Succ<T>
where T: Fact<Result = U> + Nat, U: Times<Succ<T>> + Nat,

Source§

type Result = <U as Times<Succ<T>>>::Result