Skip to content

Implement Frame generically over arbitrary N channels #179

@rawler

Description

@rawler

Currently, the Frame trait is only implemented for [S; N] where S: Sample for N = 1-32. While realistically more than sufficient, it makes it difficult for dependent code to be generic over Frames of arbitrary N.

I.E. the (admittedly contrived) example of

fn do_something(f: &impl Frame) {}

struct MyFilter<const CHANNELS: usize> {
    buffer: [f32; CHANNELS]
}

impl<const CHANNELS: usize> MyFilter<CHANNELS> {
    pub fn emit(&self) {
        do_something(&self.buffer)
    }
}

will fail compilation with error:

error[E0277]: the trait bound `[f32; CHANNELS]: Frame` is not satisfied
  --> examples/bleh.rs:13:22
   |
13 |         do_something(&self.buffer)
   |         ------------ ^^^^^^^^^^^^ the trait `Frame` is not implemented for `[f32; CHANNELS]`
   |         |
   |         required by a bound introduced by this call
   |
   = help: the following other types implement trait `Frame`:
             [S; 10]
             [S; 11]
             [S; 12]
             [S; 13]
             [S; 14]
             [S; 15]
             [S; 16]
             [S; 17]
           and 24 others
note: required by a bound in `do_something`
  --> examples/bleh.rs:3:26
   |
3  | fn do_something(f: &impl Frame) {
   |                          ^^^^^ required by this bound in `do_something`

For more information about this error, try `rustc --explain E0277`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions