Generic const struct value access

I have this crazy struct. Is it possible to directly retrieve the 42 value from a function?
Self::VALUE does not work.

pub struct Example<const VALUE: u8>
{
}

impl Example<42>
{
    fn value(&self) -> u8
    {
        // ??
    }
}

You need to add it yourself:

impl<const V: u8> Example<V> {
    const VALUE: u8 = V;
}
1 Like

okidoki!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.