Skip to content

Commit

Permalink
Fix clippy warnings (#1618)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHecart authored Nov 29, 2024
1 parent dee257f commit 92fd3a6
Show file tree
Hide file tree
Showing 37 changed files with 281 additions and 312 deletions.
4 changes: 2 additions & 2 deletions commons/zenoh-buffers/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'s> BacktrackableWriter for &'s mut [u8] {
}

// Reader
impl<'a> HasReader for &'a [u8] {
impl HasReader for &[u8] {
type Reader = Self;

fn reader(self) -> Self::Reader {
Expand Down Expand Up @@ -196,7 +196,7 @@ impl<'a> BacktrackableReader for &'a [u8] {
}
}

impl<'a> SiphonableReader for &'a [u8] {
impl SiphonableReader for &[u8] {
fn siphon<W>(&mut self, writer: &mut W) -> Result<NonZeroUsize, DidntSiphon>
where
W: Writer,
Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-buffers/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl SplitBuffer for Vec<u8> {
}

// Writer
impl<'a> HasWriter for &'a mut Vec<u8> {
impl HasWriter for &mut Vec<u8> {
type Writer = Self;

fn writer(self) -> Self::Writer {
Expand Down
14 changes: 7 additions & 7 deletions commons/zenoh-buffers/src/zbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<'a> HasReader for &'a ZBuf {
}
}

impl<'a> Reader for ZBufReader<'a> {
impl Reader for ZBufReader<'_> {
fn read(&mut self, mut into: &mut [u8]) -> Result<NonZeroUsize, DidntRead> {
let mut read = 0;
while let Some(slice) = self.inner.slices.get(self.cursor.slice) {
Expand Down Expand Up @@ -299,7 +299,7 @@ impl<'a> Reader for ZBufReader<'a> {
}
}

impl<'a> BacktrackableReader for ZBufReader<'a> {
impl BacktrackableReader for ZBufReader<'_> {
type Mark = ZBufPos;

fn mark(&mut self) -> Self::Mark {
Expand All @@ -312,7 +312,7 @@ impl<'a> BacktrackableReader for ZBufReader<'a> {
}
}

impl<'a> SiphonableReader for ZBufReader<'a> {
impl SiphonableReader for ZBufReader<'_> {
fn siphon<W>(&mut self, writer: &mut W) -> Result<NonZeroUsize, DidntSiphon>
where
W: Writer,
Expand Down Expand Up @@ -345,7 +345,7 @@ impl<'a> SiphonableReader for ZBufReader<'a> {
}

#[cfg(feature = "std")]
impl<'a> io::Read for ZBufReader<'a> {
impl io::Read for ZBufReader<'_> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
match <Self as Reader>::read(self, buf) {
Ok(n) => Ok(n.get()),
Expand All @@ -354,7 +354,7 @@ impl<'a> io::Read for ZBufReader<'a> {
}
}

impl<'a> AdvanceableReader for ZBufReader<'a> {
impl AdvanceableReader for ZBufReader<'_> {
fn skip(&mut self, offset: usize) -> Result<(), DidntRead> {
let mut remaining_offset = offset;
while remaining_offset > 0 {
Expand Down Expand Up @@ -399,7 +399,7 @@ impl<'a> AdvanceableReader for ZBufReader<'a> {
}

#[cfg(feature = "std")]
impl<'a> io::Seek for ZBufReader<'a> {
impl io::Seek for ZBufReader<'_> {
fn seek(&mut self, pos: io::SeekFrom) -> io::Result<u64> {
let current_pos = self
.inner
Expand Down Expand Up @@ -570,7 +570,7 @@ impl BacktrackableWriter for ZBufWriter<'_> {
}

#[cfg(feature = "std")]
impl<'a> io::Write for ZBufWriter<'a> {
impl io::Write for ZBufWriter<'_> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
if buf.is_empty() {
return Ok(0);
Expand Down
4 changes: 2 additions & 2 deletions commons/zenoh-collections/src/single_or_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub struct Drain<'a, T> {
inner: DrainInner<'a, T>,
}

impl<'a, T> Iterator for Drain<'a, T> {
impl<T> Iterator for Drain<'_, T> {
type Item = T;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -209,7 +209,7 @@ impl<'a, T> Iterator for Drain<'a, T> {
}
}
}
impl<'a, T> Drop for Drain<'a, T> {
impl<T> Drop for Drain<'_, T> {
fn drop(&mut self) {
if let DrainInner::Single(_) = self.inner {
self.next();
Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-keyexpr/src/key_expr/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ impl<'a> Iterator for Chunks<'a> {
Some(unsafe { keyexpr::from_str_unchecked(next) })
}
}
impl<'a> DoubleEndedIterator for Chunks<'a> {
impl DoubleEndedIterator for Chunks<'_> {
fn next_back(&mut self) -> Option<Self::Item> {
if self.inner.is_empty() {
return None;
Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-keyexpr/src/key_expr/format/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<'a> TryFrom<&'a str> for Spec<'a> {
}
}
}
impl<'a> Spec<'a> {
impl Spec<'_> {
pub fn id(&self) -> &str {
&self.spec[..self.id_end as usize]
}
Expand Down
4 changes: 2 additions & 2 deletions commons/zenoh-keyexpr/src/key_expr/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Splitter<'a, S: ?Sized, D: ?Sized> {
s: Option<&'a S>,
d: &'a D,
}
impl<'a, S: ?Sized, D: ?Sized> Clone for Splitter<'a, S, D> {
impl<S: ?Sized, D: ?Sized> Clone for Splitter<'_, S, D> {
fn clone(&self) -> Self {
Self {
s: self.s,
Expand Down Expand Up @@ -84,7 +84,7 @@ impl<'a, S: Split<D> + ?Sized, D: ?Sized> Iterator for Splitter<'a, S, D> {
}
}

impl<'a, S: Split<D> + ?Sized, D: ?Sized> DoubleEndedIterator for Splitter<'a, S, D> {
impl<S: Split<D> + ?Sized, D: ?Sized> DoubleEndedIterator for Splitter<'_, S, D> {
fn next_back(&mut self) -> Option<Self::Item> {
match self.s {
Some(s) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use token_cell::prelude::{TokenCell, TokenCellTrait, TokenTrait};

use super::*;

impl<'a, T: HasChunk> HasChunk for &'a T {
impl<T: HasChunk> HasChunk for &T {
fn chunk(&self) -> &keyexpr {
T::chunk(self)
}
}
impl<'a, T: HasChunk> HasChunk for &'a mut T {
impl<T: HasChunk> HasChunk for &mut T {
fn chunk(&self) -> &keyexpr {
T::chunk(self)
}
Expand Down
4 changes: 2 additions & 2 deletions commons/zenoh-protocol/src/core/cowstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'a> From<&'a str> for CowStr<'a> {
CowStr::borrowed(value)
}
}
impl<'a> From<String> for CowStr<'a> {
impl From<String> for CowStr<'_> {
fn from(s: String) -> Self {
if s.is_empty() {
CowStr::borrowed("")
Expand All @@ -70,7 +70,7 @@ impl core::ops::Deref for CowStr<'_> {
}
}
}
impl<'a> Clone for CowStr<'a> {
impl Clone for CowStr<'_> {
fn clone(&self) -> Self {
self.as_str().to_owned().into()
}
Expand Down
61 changes: 30 additions & 31 deletions commons/zenoh-protocol/src/transport/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

pub mod flag {
pub const S: u8 = 1 << 5; // 0x20 Session close if S==1 close the whole session, close only the link otherwise
// pub const X: u8 = 1 << 6; // 0x40 Reserved
pub const Z: u8 = 1 << 7; // 0x80 Extensions if Z==1 then an extension will follow
}

// Reason for the Close message
pub mod reason {
pub const GENERIC: u8 = 0x00;
pub const UNSUPPORTED: u8 = 0x01;
pub const INVALID: u8 = 0x02;
pub const MAX_SESSIONS: u8 = 0x03;
pub const MAX_LINKS: u8 = 0x04;
pub const EXPIRED: u8 = 0x05;
pub const UNRESPONSIVE: u8 = 0x06;
}

pub fn reason_to_str(reason: u8) -> &'static str {
match reason {
reason::GENERIC => "GENERIC",
reason::UNSUPPORTED => "UNSUPPORTED",
reason::INVALID => "INVALID",
reason::MAX_SESSIONS => "MAX_SESSIONS",
reason::MAX_LINKS => "MAX_LINKS",
reason::EXPIRED => "EXPIRED",
reason::UNRESPONSIVE => "UNRESPONSIVE",
_ => "UNKNOWN",
}
}

/// # Close message
///
/// The [`Close`] message is sent in any of the following two cases:
Expand Down Expand Up @@ -50,37 +80,6 @@
/// the boundary of the serialized messages. The length is encoded as little-endian.
/// In any case, the length of a message must not exceed 65535 bytes.
///
pub mod flag {
pub const S: u8 = 1 << 5; // 0x20 Session close if S==1 close the whole session, close only the link otherwise
// pub const X: u8 = 1 << 6; // 0x40 Reserved
pub const Z: u8 = 1 << 7; // 0x80 Extensions if Z==1 then an extension will follow
}

// Reason for the Close message
pub mod reason {
pub const GENERIC: u8 = 0x00;
pub const UNSUPPORTED: u8 = 0x01;
pub const INVALID: u8 = 0x02;
pub const MAX_SESSIONS: u8 = 0x03;
pub const MAX_LINKS: u8 = 0x04;
pub const EXPIRED: u8 = 0x05;
pub const UNRESPONSIVE: u8 = 0x06;
}

pub fn reason_to_str(reason: u8) -> &'static str {
match reason {
reason::GENERIC => "GENERIC",
reason::UNSUPPORTED => "UNSUPPORTED",
reason::INVALID => "INVALID",
reason::MAX_SESSIONS => "MAX_SESSIONS",
reason::MAX_LINKS => "MAX_LINKS",
reason::EXPIRED => "EXPIRED",
reason::UNRESPONSIVE => "UNRESPONSIVE",
_ => "UNKNOWN",
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Close {
pub reason: u8,
Expand Down
12 changes: 6 additions & 6 deletions commons/zenoh-protocol/src/transport/fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ use zenoh_buffers::ZSlice;
use crate::core::Reliability;
pub use crate::transport::TransportSn;

pub mod flag {
pub const R: u8 = 1 << 5; // 0x20 Reliable if R==1 then the frame is reliable
pub const M: u8 = 1 << 6; // 0x40 More if M==1 then another fragment will follow
pub const Z: u8 = 1 << 7; // 0x80 Extensions if Z==1 then an extension will follow
}

/// # Fragment message
///
/// The [`Fragment`] message is used to transmit on the wire large [`crate::network::NetworkMessage`]
Expand Down Expand Up @@ -62,12 +68,6 @@ pub use crate::transport::TransportSn;
/// the boundary of the serialized messages. The length is encoded as little-endian.
/// In any case, the length of a message must not exceed 65535 bytes.
///
pub mod flag {
pub const R: u8 = 1 << 5; // 0x20 Reliable if R==1 then the frame is reliable
pub const M: u8 = 1 << 6; // 0x40 More if M==1 then another fragment will follow
pub const Z: u8 = 1 << 7; // 0x80 Extensions if Z==1 then an extension will follow
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Fragment {
pub reliability: Reliability,
Expand Down
12 changes: 6 additions & 6 deletions commons/zenoh-protocol/src/transport/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ use alloc::vec::Vec;

use crate::{core::Reliability, network::NetworkMessage, transport::TransportSn};

pub mod flag {
pub const R: u8 = 1 << 5; // 0x20 Reliable if R==1 then the frame is reliable
// pub const X: u8 = 1 << 6; // 0x40 Reserved
pub const Z: u8 = 1 << 7; // 0x80 Extensions if Z==1 then an extension will follow
}

/// # Frame message
///
/// The [`Frame`] message is used to transmit one ore more complete serialized
Expand Down Expand Up @@ -61,12 +67,6 @@ use crate::{core::Reliability, network::NetworkMessage, transport::TransportSn};
/// the boundary of the serialized messages. The length is encoded as little-endian.
/// In any case, the length of a message must not exceed 65535 bytes.
///
pub mod flag {
pub const R: u8 = 1 << 5; // 0x20 Reliable if R==1 then the frame is reliable
// pub const X: u8 = 1 << 6; // 0x40 Reserved
pub const Z: u8 = 1 << 7; // 0x80 Extensions if Z==1 then an extension will follow
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Frame {
pub reliability: Reliability,
Expand Down
Loading

0 comments on commit 92fd3a6

Please sign in to comment.