#unconstrained generic constant

6 messages · Page 1 of 1 (latest)

fiery river
#
trait Trait {
    const CONST: usize;
}

pub struct Struct<T>
where 
  T: Trait
{
  data: [bool; T::CONST],
}

This throws an error.

unconstrained generic constant
try adding a `where` bound using this expression: `where [(); T::CONST]:`

Can this be done, or is not yet implemented. I do not understand hint provided by error message.

cloud glen
#

you can't have fields in traits if that is what you are trying to do

fiery river
#

That is not what I am trying to do. I have const item in trait which is possible and with generic_const_exprs I though I could use that item to describe length of array.

cloud glen
#

then you just add the where bound

#
pub struct Struct<T>
where
    T: Trait,
    [(); T::CONST]:,
{
    data: [bool; T::CONST],
}
#

the syntax is a little weird but 🤷‍♂️