Using associated constants within struct defintion

I was writing some simple RingBuffer for my needs, and wanted to try to avoid using generic array hacks using simple trait and its associated constant

Interestingly enough when attempting to refer to the trait constant, despite trait bounds in struct itself, it fails to resolve.
Anyone knows if there is associated issue to such problem in rustlang?

pub trait Capacity {
    const CAPACITY: usize;

pub struct MyStruct<T, C> where C: Capacity {
    inner: [T; C::CAPACITY],
error[E0599]: no associated item named `CAPACITY` found for type `C` in the current scope
 --> src/
7 |     inner: [T; C::CAPACITY],
  |                   ^^^^^^^^ associated item not found in `C`
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `CAPACITY`, perhaps you need to implement it:
          candidate #1: `Capacity`

This is a compiler bug.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.