Much ado about const

const fn

const fn foo(x: usize) -> i32 {
    2 - (0, [1,2,3][x]).1 & std::mem::size_of::<i32>() as i32
}

const FOO: i32 = foo(1);

fn main() {
    println!("{}", FOO);
    println!("{}", foo(2));
}

const generics

struct RectangularArray<T, const A: i32, const B: i32> { ... }

const X: i32 = 7;

let x: RectangularArray<i32, 2, 4>;
let y: RectangularArray<i32, X, {2 * 2}>;
Ieee754<5>
Ieee754<80>
IntRange<1, 10>
IntWithout<(2, 3, 5, 7, 11)>
Vec<2>
Vec<3>
Vec<4>
fn append<T, const N: usize, const M: usize>(vn: [T; N], vm: [T; M]) -> [T; N + M]

Const? Const const!

By bstrie

Const? Const const!

  • 63
Loading comments...

More from bstrie