#How do I convince the compiler that a function argument will always be known at compile time?

11 messages · Page 1 of 1 (latest)

exotic magnet
#
pub fn foo<const C: Color>(arg: &i32) -> i32
```This is called a const generic. You'd call it like `foo::<Color::White>(5)`
exotic magnet
#

Dang I thought they allowed enums by now

#

Yeah, the other thing you could do is turn your enum into a trait instead.

fierce tusk
#

c/c++ enums are just sugar for constant integers, define a couple u8s and you're set

storm relic
#

Note you could just pass it as a normal argument llvm, will optimize the runtime check away if its a constant argument

golden swift
#

Have you actually checked?

finite fulcrum
#

pass it as arg + inline always and you're good to go

finite fulcrum
#

you still can

#

it's not that pretty

#

but you can make an _impl that is inline always