.iter()
.enumerate()
.skip_while(|(_, b)| **b == FEND)
- .skip(1)
- .next()
+ .nth(1)
.ok_or(KissError::MalformedKissFrame)?
.0;
let end = self.data[start..]
.iter()
.enumerate()
- .skip_while(|(_, b)| **b != FEND)
- .next()
+ .find(|(_, b)| **b == FEND)
.ok_or(KissError::MalformedKissFrame)?
.0
+ start;
/// Return the header byte of the KISS frame, skipping over 0 or more prepended FENDs.
fn header_byte(&self) -> Result<u8, KissError> {
- Ok(self
- .data
+ self.data
.iter()
- .skip_while(|b| **b == FEND)
- .next()
+ .find(|b| **b != FEND)
.cloned()
- .ok_or(KissError::MalformedKissFrame)?)
+ .ok_or(KissError::MalformedKissFrame)
}
}
}
}
+impl Default for KissBuffer {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum KissError {
MalformedKissFrame,
fn test_buffer_double() {
let mut buffer = KissBuffer::new();
let buf = buffer.buf_remaining();
- buf[0..8].copy_from_slice(&[FEND, 0x10, 0x01, FEND, FEND, 0x20, 02, FEND]);
+ buf[0..8].copy_from_slice(&[FEND, 0x10, 0x01, FEND, FEND, 0x20, 0x02, FEND]);
buffer.did_write(8);
let next = buffer.next_frame().unwrap();
fn test_buffer_double_shared_fend() {
let mut buffer = KissBuffer::new();
let buf = buffer.buf_remaining();
- buf[0..7].copy_from_slice(&[FEND, 0x10, 0x01, FEND, 0x20, 02, FEND]);
+ buf[0..7].copy_from_slice(&[FEND, 0x10, 0x01, FEND, 0x20, 0x02, FEND]);
buffer.did_write(7);
let next = buffer.next_frame().unwrap();
fn test_buffer_extra_fend() {
let mut buffer = KissBuffer::new();
let buf = buffer.buf_remaining();
- buf[0..10].copy_from_slice(&[FEND, FEND, FEND, 0x10, 0x01, FEND, FEND, 0x20, 02, FEND]);
+ buf[0..10].copy_from_slice(&[FEND, FEND, FEND, 0x10, 0x01, FEND, FEND, 0x20, 0x02, FEND]);
buffer.did_write(10);
let next = buffer.next_frame().unwrap();