pub const fn value_of<C>() -> <C as Const>::Type
Expand description
Alias for Const::VALUE
. Prefer this function over accessing the const directly.
Using the associated constant through this function rather than directly often causes it to only be evaluated when the branch that it is used in is actually executed. This means that it may improve compile times, avoid errors for recursive consts and avoid evaluating panics.
For example:
ⓘ
struct Fallible;
impl Const for Fallible {
type Type = ();
const VALUE: Self::Type = panic!();
}
const _: () = if false { Fallible::VALUE }; // this gives a compile error
const _: () = if false { value_of::<Fallible>() }; // this compiles