Trait midi2::TryFromBytes
source · pub trait TryFromBytes<T>: Sized {
// Required method
fn try_from_bytes(other: T) -> Result<Self, BufferOverflow>;
}Expand description
Attempt to convert a message from a Bytes backing buffer to a Ump backing buffer.
The conversion may fail with a BufferOverflow error if the target buffer is not large enough to contain the data.
use midi2::{TryFromBytes, Data, sysex7::Sysex7};
let bytes_message = Sysex7::try_from(&[
0xF0_u8, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xF7,
][..]).expect("Valid data");
let ump_message = Sysex7::<[u32; 4]>::try_from_bytes(bytes_message.clone());
assert_eq!(ump_message.expect("Buffer is large enough").data(), &[
0x3016_0001,
0x0203_0405,
0x3034_0607,
0x0809_0000,
]);
let small_ump_message = Sysex7::<[u32; 2]>::try_from_bytes(bytes_message.clone());
small_ump_message.expect_err("Buffer is too small");Required Methods§
fn try_from_bytes(other: T) -> Result<Self, BufferOverflow>
Object Safety§
This trait is not object safe.