Trait Factorial

Source
pub trait Factorial {
    // Required method
    fn factorial(n: u64) -> Self;
}
Expand description

Computes the factorial of a u64.

Required Methods§

Source

fn factorial(n: u64) -> Self

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Factorial for u8

Source§

fn factorial(n: u64) -> u8

Computes the factorial of a number.

If the input is too large, the function panics. For a function that returns None instead, try checked_factorial.

$$ f(n) = n! = 1 \times 2 \times 3 \times \cdots \times n. $$

$n! = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Factorial for u16

Source§

fn factorial(n: u64) -> u16

Computes the factorial of a number.

If the input is too large, the function panics. For a function that returns None instead, try checked_factorial.

$$ f(n) = n! = 1 \times 2 \times 3 \times \cdots \times n. $$

$n! = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Factorial for u32

Source§

fn factorial(n: u64) -> u32

Computes the factorial of a number.

If the input is too large, the function panics. For a function that returns None instead, try checked_factorial.

$$ f(n) = n! = 1 \times 2 \times 3 \times \cdots \times n. $$

$n! = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Factorial for u64

Source§

fn factorial(n: u64) -> u64

Computes the factorial of a number.

If the input is too large, the function panics. For a function that returns None instead, try checked_factorial.

$$ f(n) = n! = 1 \times 2 \times 3 \times \cdots \times n. $$

$n! = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Factorial for u128

Source§

fn factorial(n: u64) -> u128

Computes the factorial of a number.

If the input is too large, the function panics. For a function that returns None instead, try checked_factorial.

$$ f(n) = n! = 1 \times 2 \times 3 \times \cdots \times n. $$

$n! = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Factorial for usize

Source§

fn factorial(n: u64) -> usize

Computes the factorial of a number.

If the input is too large, the function panics. For a function that returns None instead, try checked_factorial.

$$ f(n) = n! = 1 \times 2 \times 3 \times \cdots \times n. $$

$n! = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Implementors§