midi2-dev / bl-midi2-rs

Ergonomic, versatile, strong types wrapping MIDI 2.0 message data.
https://crates.io/crates/midi2
Apache License 2.0
18 stars 2 forks source link

`Packets` trait #9

Closed BenLeadbetter closed 1 month ago

BenLeadbetter commented 2 months ago

Is would be good to implement a Packets trait for midi2 message wrappers.

Something like the following:

pub struct PacketsIterator<'a>;

impl<'a> core::iter::Iterator for PacketsIterator<'a> {
    type Item = &'a [u32];
    ...
}

pub trait Packets<B: Ump>: Data<B> {
    fn packets(&self) -> PacketsIterator;
}

The trait could potentially even be implemented via a blanket impl for all messages which also implement Data.

impl<B: Ump, M: Data<B>> Packets<B> for M {
    fn packets(&self) -> PacketsIterator { ... }
}