File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ license = "MIT"
77name = " wmidi"
88readme = " README.md"
99repository = " https://github.com/RustAudio/wmidi"
10- version = " 4.0.7 "
10+ version = " 4.0.8 "
1111
1212[lib ]
1313# Required to pass flags to criterion benchmark.
Original file line number Diff line number Diff line change @@ -158,8 +158,7 @@ impl<'a> TryFrom<&'a [u8]> for MidiMessage<'a> {
158158}
159159
160160impl < ' a > MidiMessage < ' a > {
161- /// Construct a midi message from bytes. Use `MidiMessage::try_from(bytes)` instead.
162- #[ deprecated( since = "2.0.0" , note = "Use MidiMessage::try_from instead." ) ]
161+ /// Construct a midi message from bytes.
163162 pub fn from_bytes ( bytes : & ' a [ u8 ] ) -> Result < Self , Error > {
164163 MidiMessage :: try_from ( bytes)
165164 }
@@ -356,6 +355,16 @@ impl<'a> MidiMessage<'a> {
356355 let data_bytes = unsafe { U7 :: from_bytes_unchecked ( & bytes[ 1 ..end_i] ) } ;
357356 Ok ( MidiMessage :: SysEx ( data_bytes) )
358357 }
358+
359+ /// Convert the message to a vector of bytes. Prefer using
360+ /// `copy_to_slice` if possible for better performance.
361+ #[ cfg( feature = "std" ) ]
362+ pub fn to_vec ( & self ) -> Vec < u8 > {
363+ let mut data = vec ! [ 0 ; self . bytes_size( ) ] ;
364+ // Unwrapping is ok as data has enough capacity for the data.
365+ self . copy_to_slice ( & mut data) . unwrap ( ) ;
366+ data
367+ }
359368}
360369
361370#[ cfg( feature = "std" ) ]
You can’t perform that action at this time.
0 commit comments