Trait midi2::TryRebufferInto

source ·
pub trait TryRebufferInto<T>: Sized {
    // Required method
    fn try_rebuffer_into(self) -> Result<T, BufferOverflow>;
}
Expand description

Attempt to convert a generic message into a different buffer specialisation.

The conversion may fail with a BufferOverflow error if the target message representation does not fit all of the message data.

use midi2::{TryRebufferInto, sysex7::Sysex7, error::BufferOverflow};

let borrowed: Sysex7<&[u32]> = Sysex7::try_from(&[
    0x3016_0001,
    0x0203_0405,
    0x3035_0607,
    0x0809_0A00,
][..]).expect("Valid data");

let arr4: Result<Sysex7<[u32; 4]>, BufferOverflow>  = borrowed
    .clone()
    .try_rebuffer_into();
arr4.expect("Buffer is large enough");

let arr2: Result<Sysex7<[u32; 2]>, BufferOverflow> = borrowed
    .clone()
    .try_rebuffer_into();
arr2.expect_err("Buffer is too small");

Note that this trait has a blanket implementation for all messages which implement TryRebufferFrom (similar to the standard core::convert::TryInto trait)

Required Methods§

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T, V> TryRebufferInto<V> for T
where V: TryRebufferFrom<T>,