Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hl: move seek generic from trait to method #212

Merged
merged 1 commit into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E> + Seek<E>>(
fn read_labels<'l, E, Reader: Read<E> + Seek>(
reader: &mut Reader,
labels: &'l mut [u8],
) -> Result<Option<&'l str>, Error<E>> {
Expand Down
1 change: 1 addition & 0 deletions hl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<E>::seek` to `Seek::seek<E>`, moving the seek error generic from the `Seek` trait to the `seek` method.

## [0.9.0] - 2022-05-03
### Added
Expand Down
4 changes: 2 additions & 2 deletions hl/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E> {
pub trait Seek {
/// Seek to an offset, in bytes, within the socket buffer.
///
/// Seeking beyond the limits will result [`Error::UnexpectedEof`].
Expand All @@ -78,7 +78,7 @@ pub trait Seek<E> {
/// 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<E>>;
fn seek<E>(&mut self, pos: SeekFrom) -> Result<(), Error<E>>;

/// Rewind to the beginning of the stream.
///
Expand Down
12 changes: 6 additions & 6 deletions hl/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ 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,
pub(crate) tail_ptr: u16,
pub(crate) ptr: u16,
}

impl<'w, W5500: Registers> Seek<W5500::Error> for TcpReader<'w, W5500> {
fn seek(&mut self, pos: SeekFrom) -> Result<(), Error<W5500::Error>> {
impl<'w, W5500> Seek for TcpReader<'w, W5500> {
fn seek<E>(&mut self, pos: SeekFrom) -> Result<(), Error<E>> {
self.ptr = pos.new_ptr(self.ptr, self.head_ptr, self.tail_ptr)?;
Ok(())
}
Expand Down Expand Up @@ -158,16 +158,16 @@ impl<'a, W5500: Registers> Read<W5500::Error> 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,
pub(crate) tail_ptr: u16,
pub(crate) ptr: u16,
}

impl<'w, W5500: Registers> Seek<W5500::Error> for TcpWriter<'w, W5500> {
fn seek(&mut self, pos: SeekFrom) -> Result<(), Error<W5500::Error>> {
impl<'w, W5500> Seek for TcpWriter<'w, W5500> {
fn seek<E>(&mut self, pos: SeekFrom) -> Result<(), Error<E>> {
self.ptr = pos.new_ptr(self.ptr, self.head_ptr, self.tail_ptr)?;
Ok(())
}
Expand Down
14 changes: 7 additions & 7 deletions hl/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<W5500::Error> for UdpReader<'w, W5500> {
fn seek(&mut self, pos: SeekFrom) -> Result<(), Error<W5500::Error>> {
impl<'w, W5500> Seek for UdpReader<'w, W5500> {
fn seek<E>(&mut self, pos: SeekFrom) -> Result<(), Error<E>> {
self.inner.seek(pos)
}

Expand Down Expand Up @@ -162,16 +162,16 @@ impl<'w, W5500: Registers> Read<W5500::Error> 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,
pub(crate) tail_ptr: u16,
pub(crate) ptr: u16,
}

impl<'w, W5500: Registers> Seek<W5500::Error> for UdpWriter<'w, W5500> {
fn seek(&mut self, pos: SeekFrom) -> Result<(), Error<W5500::Error>> {
impl<'w, W5500> Seek for UdpWriter<'w, W5500> {
fn seek<E>(&mut self, pos: SeekFrom) -> Result<(), Error<E>> {
self.ptr = pos.new_ptr(self.ptr, self.head_ptr, self.tail_ptr)?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion mqtt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fn write_variable_byte_integer<E, Writer: Write<E>>(
/// This is returned by [`Client::process`].
#[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Event<E, Reader: Read<E> + Seek<E>> {
pub enum Event<E, Reader: Read<E> + 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.
Expand Down
4 changes: 2 additions & 2 deletions mqtt/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn send_publish<E, Writer: Write<E>>(
/// [`Client::process`]: crate::Client::process
#[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PublishReader<E, Reader: Read<E> + Seek<E>> {
pub struct PublishReader<E, Reader: Read<E> + Seek> {
pub(crate) reader: Reader,
pub(crate) topic_len: u16,
pub(crate) topic_idx: u16,
Expand All @@ -56,7 +56,7 @@ pub struct PublishReader<E, Reader: Read<E> + Seek<E>> {
pub(crate) _reader_error: PhantomData<E>,
}

impl<E, Reader: Read<E> + Seek<E>> PublishReader<E, Reader> {
impl<E, Reader: Read<E> + Seek> PublishReader<E, Reader> {
/// Length of the topic in bytes.
#[inline]
pub fn topic_len(&self) -> u16 {
Expand Down
2 changes: 1 addition & 1 deletion mqtt/src/recv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
PROPERTY_LEN_LEN,
};

pub(crate) fn recv<E, Reader: Read<E> + Seek<E>>(
pub(crate) fn recv<E, Reader: Read<E> + Seek>(
mut reader: Reader,
state_timeout: &mut StateTimeout,
) -> Result<Option<Event<E, Reader>>, Error<E>> {
Expand Down
8 changes: 4 additions & 4 deletions tls/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ pub struct TlsWriter<'w, 'ks, W5500: Registers> {
pub(crate) ptr: u16,
}

impl<'w, 'ks, W5500: Registers> Seek<W5500::Error> for TlsWriter<'w, 'ks, W5500> {
fn seek(&mut self, pos: SeekFrom) -> Result<(), HlError<W5500::Error>> {
impl<'w, 'ks, W5500: Registers> Seek for TlsWriter<'w, 'ks, W5500> {
fn seek<E>(&mut self, pos: SeekFrom) -> Result<(), HlError<E>> {
self.ptr = pos.new_ptr(self.ptr, self.head_ptr, self.tail_ptr)?;
Ok(())
}
Expand Down Expand Up @@ -319,8 +319,8 @@ fn wrapping_add_signed(ptr: u16, offset: i16) -> u16 {
ptr.wrapping_add(offset as u16)
}

impl<'buf, 'ptr> Seek<Infallible> for TlsReader<'buf, 'ptr> {
fn seek(&mut self, pos: SeekFrom) -> Result<(), HlError<Infallible>> {
impl<'buf, 'ptr> Seek for TlsReader<'buf, 'ptr> {
fn seek<Infallible>(&mut self, pos: SeekFrom) -> Result<(), HlError<Infallible>> {
match pos {
SeekFrom::Start(n) => {
if n > self.stream_len() {
Expand Down