Skip to content

Commit e01f358

Browse files
author
Ben Leadbetter
committed
Merge branch 'release/0.3.1'
2 parents e63b954 + 1012bfe commit e01f358

File tree

9 files changed

+50
-17
lines changed

9 files changed

+50
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 0.3.1
2+
docs: fix typos in readme
3+
fix: panic on empty flex-data text iterator
4+
fix: panic on empty ump-stream text iterator
5+
16
# 0.3.0
27
docs: fix further readme typos
38
feat: utility messages are integrated into top level aggregate

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "midi2"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
description = "Ergonomic, versatile, strong types wrapping MIDI 2.0 message data."
55
edition = "2021"
66
readme = "README.md"
@@ -35,7 +35,7 @@ utility = []
3535

3636
[dependencies]
3737
derive_more = { version = "0.99.17", features = ["from"], default-features = false }
38-
midi2_proc = { version = "0.3.0", path = "midi2_proc" }
38+
midi2_proc = { version = "0.3.1", path = "midi2_proc" }
3939
ux = "0.1.6"
4040

4141
[dev-dependencies]

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ You'll want to setup midi2 without default features to compile
156156
without the `std` feature.
157157

158158
```toml
159-
midi2 = { version = "0.3.0", default-features = false, features = ["channel-voice2", "sysex7"], }
159+
midi2 = { version = "0.3.1", default-features = false, features = ["channel-voice2", "sysex7"], }
160160
```
161161

162162
### Generic Representation
@@ -207,12 +207,10 @@ let buffer = [
207207
0x4441_5733,
208208
0x362D_3136,
209209
];
210-
let Ok(message) = UmpMessage::try_from(&buffer[..]) else {
211-
panic!();
212-
};
210+
let message = UmpMessage::try_from(&buffer[..]).expect("Valid data");
213211
```
214212

215-
Of course this means that such borrowed messages are imutable
213+
Of course this means that such borrowed messages are immutable
216214
and also have their lifetimes tied to the original buffer.
217215

218216
To remedy this messages can be `rebuffered` into a different
@@ -226,12 +224,12 @@ use midi2::{
226224

227225
let mut owned: NoteOn::<[u32; 4]> = {
228226
let buffer = [0x4898_5E03_u32, 0x6A14_E98A];
229-
// the borrowed message is imutable and cannot outlive `buffer`
227+
// the borrowed message is immutable and cannot outlive `buffer`
230228
let borrowed = NoteOn::try_from(&buffer[..]).expect("Data is valid");
231229
borrowed.try_rebuffer_into().expect("Buffer is large enough")
232230
};
233231

234-
// the owned message is mutable an liberated from the buffer lifetime.
232+
// the owned message is mutable and liberated from the buffer lifetime.
235233
owned.set_channel(u4::new(0x9));
236234
assert_eq!(owned.data(), &[0x4899_5E03, 0x6A14_E98A])
237235
```

midi2_proc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "midi2_proc"
33
description = "Internal procedural macro crate. Only intended for use with midi2"
4-
version = "0.3.0"
4+
version = "0.3.1"
55
edition = "2021"
66
readme = "README.md"
77
license = "MIT OR Apache-2.0"

src/flex_data/text.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ pub struct TextBytesIterator<'a> {
123123
impl<'a> core::iter::Iterator for TextBytesIterator<'a> {
124124
type Item = u8;
125125
fn next(&mut self) -> Option<Self::Item> {
126+
while !self.finished() && self.value() == 0 {
127+
self.advance();
128+
}
126129
if self.finished() {
127130
return None;
128131
}
129132
let ret = Some(self.value());
130133
self.advance();
131-
while !self.finished() && self.value() == 0 {
132-
self.advance();
133-
}
134134
ret
135135
}
136136

@@ -143,7 +143,7 @@ impl<'a> core::iter::FusedIterator for TextBytesIterator<'a> {}
143143

144144
impl<'a> TextBytesIterator<'a> {
145145
fn finished(&self) -> bool {
146-
self.buffer.len() / 4 <= self.packet_index
146+
self.packet_index == self.buffer.len() / 4 - 1 && self.byte_index == 11
147147
}
148148
fn advance(&mut self) {
149149
self.byte_index += 1;

src/flex_data/unknown_metadata_text.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,16 @@ mod tests {
389389
)
390390
}
391391

392+
#[test]
393+
fn read_empty_text_bytes() {
394+
assert_eq!(
395+
UnknownMetadataText::<std::vec::Vec<u32>>::new()
396+
.text_bytes()
397+
.collect::<std::vec::Vec<u8>>(),
398+
std::vec![],
399+
)
400+
}
401+
392402
#[test]
393403
#[cfg(feature = "std")]
394404
fn read_string() {

src/ump_stream/endpoint_name.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,14 @@ mod tests {
9797
let message = EndpointName::try_from(&buffer[..]).unwrap();
9898
assert_eq!(message.name(), "Gimme some signal 🔊 🙌");
9999
}
100+
101+
#[test]
102+
fn read_empty_bytes() {
103+
assert_eq!(
104+
EndpointName::<std::vec::Vec<u32>>::new()
105+
.name_bytes()
106+
.collect::<std::vec::Vec<u8>>(),
107+
std::vec![]
108+
);
109+
}
100110
}

src/ump_stream/function_block_name.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,14 @@ mod tests {
190190
0x9,
191191
);
192192
}
193+
194+
#[test]
195+
fn read_empty_bytes() {
196+
assert_eq!(
197+
FunctionBlockName::<std::vec::Vec<u32>>::new()
198+
.name_bytes()
199+
.collect::<std::vec::Vec<u8>>(),
200+
std::vec![],
201+
);
202+
}
193203
}

src/ump_stream/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,14 @@ pub struct TextBytesIterator<'a> {
268268
impl<'a> core::iter::Iterator for TextBytesIterator<'a> {
269269
type Item = u8;
270270
fn next(&mut self) -> Option<Self::Item> {
271+
while !self.finished() && self.value() == 0 {
272+
self.advance();
273+
}
271274
if self.finished() {
272275
return None;
273276
}
274277
let ret = Some(self.value());
275278
self.advance();
276-
while !self.finished() && self.value() == 0 {
277-
self.advance();
278-
}
279279
ret
280280
}
281281

0 commit comments

Comments
 (0)