diff --git a/dns/src/lib.rs b/dns/src/lib.rs index a1713611..3be8cea1 100644 --- a/dns/src/lib.rs +++ b/dns/src/lib.rs @@ -192,7 +192,7 @@ pub struct ResourceRecord<'a> { } // https://www.rfc-editor.org/rfc/rfc1035#section-4.1.4 -fn read_labels<'l, E, Reader: Read + Seek>( +fn read_labels<'l, E, Reader: Read + Seek>( reader: &mut Reader, labels: &'l mut [u8], ) -> Result, Error> { diff --git a/hl/CHANGELOG.md b/hl/CHANGELOG.md index 86629fe2..3148da7b 100644 --- a/hl/CHANGELOG.md +++ b/hl/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Changed the name of the `embedded-hal` feature to `eh0`. +- Changed `Seek::seek` to `Seek::seek`, moving the seek error generic from the `Seek` trait to the `seek` method. ## [0.9.0] - 2022-05-03 ### Added diff --git a/hl/src/io.rs b/hl/src/io.rs index 26b09868..0b4a6b40 100644 --- a/hl/src/io.rs +++ b/hl/src/io.rs @@ -66,7 +66,7 @@ impl SeekFrom { /// similar to [`std::io::Seek`]. /// /// [`std::io::Seek`]: https://doc.rust-lang.org/stable/std/io/trait.Seek.html -pub trait Seek { +pub trait Seek { /// Seek to an offset, in bytes, within the socket buffer. /// /// Seeking beyond the limits will result [`Error::UnexpectedEof`]. @@ -78,7 +78,7 @@ pub trait Seek { /// the UDP datagram length, whichever is less. /// * [`TcpWriter`](crate::TcpWriter) is limited by socket free size. /// * [`TcpReader`](crate::TcpReader) is limited by the received size. - fn seek(&mut self, pos: SeekFrom) -> Result<(), Error>; + fn seek(&mut self, pos: SeekFrom) -> Result<(), Error>; /// Rewind to the beginning of the stream. /// diff --git a/hl/src/tcp.rs b/hl/src/tcp.rs index cca218d2..bb120618 100644 --- a/hl/src/tcp.rs +++ b/hl/src/tcp.rs @@ -58,7 +58,7 @@ use w5500_ll::{ /// ``` #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct TcpReader<'w, W5500: Registers> { +pub struct TcpReader<'w, W5500> { pub(crate) w5500: &'w mut W5500, pub(crate) sn: Sn, pub(crate) head_ptr: u16, @@ -66,8 +66,8 @@ pub struct TcpReader<'w, W5500: Registers> { pub(crate) ptr: u16, } -impl<'w, W5500: Registers> Seek for TcpReader<'w, W5500> { - fn seek(&mut self, pos: SeekFrom) -> Result<(), Error> { +impl<'w, W5500> Seek for TcpReader<'w, W5500> { + fn seek(&mut self, pos: SeekFrom) -> Result<(), Error> { self.ptr = pos.new_ptr(self.ptr, self.head_ptr, self.tail_ptr)?; Ok(()) } @@ -158,7 +158,7 @@ impl<'a, W5500: Registers> Read for TcpReader<'a, W5500> { /// ``` #[derive(Debug, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct TcpWriter<'w, W5500: Registers> { +pub struct TcpWriter<'w, W5500> { pub(crate) w5500: &'w mut W5500, pub(crate) sn: Sn, pub(crate) head_ptr: u16, @@ -166,8 +166,8 @@ pub struct TcpWriter<'w, W5500: Registers> { pub(crate) ptr: u16, } -impl<'w, W5500: Registers> Seek for TcpWriter<'w, W5500> { - fn seek(&mut self, pos: SeekFrom) -> Result<(), Error> { +impl<'w, W5500> Seek for TcpWriter<'w, W5500> { + fn seek(&mut self, pos: SeekFrom) -> Result<(), Error> { self.ptr = pos.new_ptr(self.ptr, self.head_ptr, self.tail_ptr)?; Ok(()) } diff --git a/hl/src/udp.rs b/hl/src/udp.rs index 766ce0d2..87e03efa 100644 --- a/hl/src/udp.rs +++ b/hl/src/udp.rs @@ -78,13 +78,13 @@ impl UdpHeader { /// ``` #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct UdpReader<'w, W: Registers> { - inner: TcpReader<'w, W>, +pub struct UdpReader<'w, W5500> { + inner: TcpReader<'w, W5500>, header: UdpHeader, } -impl<'w, W5500: Registers> Seek for UdpReader<'w, W5500> { - fn seek(&mut self, pos: SeekFrom) -> Result<(), Error> { +impl<'w, W5500> Seek for UdpReader<'w, W5500> { + fn seek(&mut self, pos: SeekFrom) -> Result<(), Error> { self.inner.seek(pos) } @@ -162,7 +162,7 @@ impl<'w, W5500: Registers> Read for UdpReader<'w, W5500> { /// ``` #[derive(Debug, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct UdpWriter<'w, W5500: Registers> { +pub struct UdpWriter<'w, W5500> { pub(crate) w5500: &'w mut W5500, pub(crate) sn: Sn, pub(crate) head_ptr: u16, @@ -170,8 +170,8 @@ pub struct UdpWriter<'w, W5500: Registers> { pub(crate) ptr: u16, } -impl<'w, W5500: Registers> Seek for UdpWriter<'w, W5500> { - fn seek(&mut self, pos: SeekFrom) -> Result<(), Error> { +impl<'w, W5500> Seek for UdpWriter<'w, W5500> { + fn seek(&mut self, pos: SeekFrom) -> Result<(), Error> { self.ptr = pos.new_ptr(self.ptr, self.head_ptr, self.tail_ptr)?; Ok(()) } diff --git a/mqtt/src/lib.rs b/mqtt/src/lib.rs index ae897081..229400b2 100644 --- a/mqtt/src/lib.rs +++ b/mqtt/src/lib.rs @@ -193,7 +193,7 @@ fn write_variable_byte_integer>( /// This is returned by [`Client::process`]. #[derive(Debug, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum Event + Seek> { +pub enum Event + Seek> { /// A hint to call [`Client::process`] after this many seconds have elapsed. /// /// This is just a hint and does not have to be used. diff --git a/mqtt/src/publish.rs b/mqtt/src/publish.rs index 8ce41611..1c32451f 100644 --- a/mqtt/src/publish.rs +++ b/mqtt/src/publish.rs @@ -47,7 +47,7 @@ pub fn send_publish>( /// [`Client::process`]: crate::Client::process #[derive(Debug, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct PublishReader + Seek> { +pub struct PublishReader + Seek> { pub(crate) reader: Reader, pub(crate) topic_len: u16, pub(crate) topic_idx: u16, @@ -56,7 +56,7 @@ pub struct PublishReader + Seek> { pub(crate) _reader_error: PhantomData, } -impl + Seek> PublishReader { +impl + Seek> PublishReader { /// Length of the topic in bytes. #[inline] pub fn topic_len(&self) -> u16 { diff --git a/mqtt/src/recv.rs b/mqtt/src/recv.rs index a8b441ef..e80886d1 100644 --- a/mqtt/src/recv.rs +++ b/mqtt/src/recv.rs @@ -6,7 +6,7 @@ use crate::{ PROPERTY_LEN_LEN, }; -pub(crate) fn recv + Seek>( +pub(crate) fn recv + Seek>( mut reader: Reader, state_timeout: &mut StateTimeout, ) -> Result>, Error> { diff --git a/tls/src/io.rs b/tls/src/io.rs index 59d144c2..57a04526 100644 --- a/tls/src/io.rs +++ b/tls/src/io.rs @@ -181,8 +181,8 @@ pub struct TlsWriter<'w, 'ks, W5500: Registers> { pub(crate) ptr: u16, } -impl<'w, 'ks, W5500: Registers> Seek for TlsWriter<'w, 'ks, W5500> { - fn seek(&mut self, pos: SeekFrom) -> Result<(), HlError> { +impl<'w, 'ks, W5500: Registers> Seek for TlsWriter<'w, 'ks, W5500> { + fn seek(&mut self, pos: SeekFrom) -> Result<(), HlError> { self.ptr = pos.new_ptr(self.ptr, self.head_ptr, self.tail_ptr)?; Ok(()) } @@ -319,8 +319,8 @@ fn wrapping_add_signed(ptr: u16, offset: i16) -> u16 { ptr.wrapping_add(offset as u16) } -impl<'buf, 'ptr> Seek for TlsReader<'buf, 'ptr> { - fn seek(&mut self, pos: SeekFrom) -> Result<(), HlError> { +impl<'buf, 'ptr> Seek for TlsReader<'buf, 'ptr> { + fn seek(&mut self, pos: SeekFrom) -> Result<(), HlError> { match pos { SeekFrom::Start(n) => { if n > self.stream_len() {