X-Git-Url: https://code.octet-stream.net/m17rt/blobdiff_plain/7b7b572052951018da4d6d0f5753d627836236ad..bc6fb90d7053082e7aaf261f4da8905c49e9fe01:/m17core/src/kiss.rs?ds=sidebyside diff --git a/m17core/src/kiss.rs b/m17core/src/kiss.rs index ec30296..37d3d0b 100644 --- a/m17core/src/kiss.rs +++ b/m17core/src/kiss.rs @@ -215,15 +215,13 @@ impl KissFrame { .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; @@ -237,13 +235,11 @@ impl KissFrame { /// Return the header byte of the KISS frame, skipping over 0 or more prepended FENDs. fn header_byte(&self) -> Result { - 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) } } @@ -393,6 +389,12 @@ impl KissBuffer { } } +impl Default for KissBuffer { + fn default() -> Self { + Self::new() + } +} + #[derive(Debug, PartialEq, Eq, Clone)] pub enum KissError { MalformedKissFrame, @@ -541,7 +543,7 @@ mod tests { 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(); @@ -555,7 +557,7 @@ mod tests { 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(); @@ -569,7 +571,7 @@ mod tests { 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();