Skip to content

Commit

Permalink
docs: adds docs for new packets trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Leadbetter authored and BenLeadbetter committed May 14, 2024
1 parent a8558f5 commit 8631397
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,41 @@ impl<'a> core::iter::ExactSizeIterator for PacketsIterator<'a> {
}
}

/// Read the individual packets of a message represented with UMP packets.
///
/// ## Basic Usage
///
/// ```rust
/// use midi2::prelude::*;
///
/// let mut message = flex_data::ProjectName::<Vec<u32>>::new();
/// message.set_text("Shadows of the Forgotten Cathedral");
///
/// let mut packets = message.packets();
///
/// assert_eq!(packets.next(), Some(&[0xD0500101, 0x53686164, 0x6F777320, 0x6F662074][..]));
/// assert_eq!(packets.next(), Some(&[0xD0900101, 0x68652046, 0x6F72676F, 0x7474656E][..]));
/// assert_eq!(packets.next(), Some(&[0xD0D00101, 0x20436174, 0x68656472, 0x616C0000][..]));
/// assert_eq!(packets.next(), None);
/// ```
///
/// Packets may be shorter than 128 bytes for certain messages which are represented by shorter
/// packets.
///
/// ```rust
/// use midi2::prelude::*;
///
/// let mut message = sysex7::Sysex7::<Vec<u32>>::new();
/// message.set_payload((0..20).map(u7::new));
///
/// let mut packets = message.packets();
///
/// assert_eq!(packets.next(), Some(&[0x30160001, 0x2030405][..]));
/// assert_eq!(packets.next(), Some(&[0x30260607, 0x8090A0B][..]));
/// assert_eq!(packets.next(), Some(&[0x30260C0D, 0xE0F1011][..]));
/// assert_eq!(packets.next(), Some(&[0x30321213, 0x0][..]));
/// assert_eq!(packets.next(), None);
/// ```
pub trait Packets {
fn packets(&self) -> PacketsIterator;
}

0 comments on commit 8631397

Please sign in to comment.