Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed Nov 29, 2023
1 parent fb7e187 commit b5f69cb
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
23 changes: 14 additions & 9 deletions io/zenoh-transport/src/common/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//
use std::{
num::{NonZeroU8, NonZeroUsize},
sync::Arc,
};
use std::num::{NonZeroU8, NonZeroUsize};
use zenoh_buffers::{
buffer::Buffer,
reader::{DidntRead, HasReader},
Expand All @@ -26,13 +23,15 @@ use zenoh_codec::{
RCodec, WCodec,
};
use zenoh_protocol::{
common::imsg,
network::NetworkMessage,
transport::{fragment::FragmentHeader, frame::FrameHeader, BatchSize, TransportMessage},
};
use zenoh_result::{zerror, ZResult};
use zenoh_result::ZResult;
#[cfg(feature = "transport_compression")]
use {std::sync::Arc, zenoh_protocol::common::imsg, zenoh_result::zerror};

// Split the inner buffer into (length, header, payload) inmutable slices
#[cfg(feature = "transport_compression")]
macro_rules! zsplit {
($slice:expr, $header:expr) => {{
match $header.get() {
Expand All @@ -52,6 +51,7 @@ pub struct BatchConfig {

impl BatchConfig {
fn header(&self) -> BatchHeader {
#[allow(unused_mut)] // No need for mut when "transport_compression" is disabled
let mut h = 0;
#[cfg(feature = "transport_compression")]
if self.is_compression {
Expand All @@ -67,15 +67,16 @@ impl BatchConfig {
pub struct BatchHeader(Option<NonZeroU8>);

impl BatchHeader {
#[cfg(feature = "transport_compression")]
const INDEX: usize = 0;

#[cfg(feature = "transport_compression")]
const COMPRESSION: u8 = 1;

fn new(h: u8) -> Self {
Self(NonZeroU8::new(h))
}

#[cfg(feature = "transport_compression")]
const fn is_empty(&self) -> bool {
self.0.is_none()
}
Expand Down Expand Up @@ -195,6 +196,7 @@ impl WBatch {

// Split (length, header, payload) internal buffer slice
#[inline(always)]
#[cfg(feature = "transport_compression")]
fn split(&self) -> (&[u8], &[u8]) {
zsplit!(self.buffer.as_slice(), self.header)
}
Expand Down Expand Up @@ -295,17 +297,19 @@ pub struct RBatch {
// The batch codec
codec: Zenoh080Batch,
// It contains 1 byte as additional header, e.g. to signal the batch is compressed
#[cfg(feature = "transport_compression")]
header: BatchHeader,
}

impl RBatch {
pub fn new<T>(config: BatchConfig, buffer: T) -> Self
pub fn new<T>(#[allow(unused_variables)] config: BatchConfig, buffer: T) -> Self
where
T: Into<ZSlice>,
{
Self {
buffer: buffer.into(),
codec: Zenoh080Batch::new(),
#[cfg(feature = "transport_compression")]
header: config.header(),
}
}
Expand All @@ -317,11 +321,12 @@ impl RBatch {

// Split (length, header, payload) internal buffer slice
#[inline(always)]
#[cfg(feature = "transport_compression")]
fn split(&self) -> (&[u8], &[u8]) {
zsplit!(self.buffer.as_slice(), self.header)
}

pub fn initialize<C, T>(&mut self, buff: C) -> ZResult<()>
pub fn initialize<C, T>(&mut self, #[allow(unused_variables)] buff: C) -> ZResult<()>
where
C: Fn() -> T + Copy,
T: ZSliceBuffer + 'static,
Expand Down
4 changes: 3 additions & 1 deletion io/zenoh-transport/src/multicast/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ use std::{
sync::Arc,
time::{Duration, Instant},
};
use zenoh_buffers::{BBuf, ZSlice, ZSliceBuffer};
#[cfg(feature = "transport_compression")]
use zenoh_buffers::BBuf;
use zenoh_buffers::{ZSlice, ZSliceBuffer};
use zenoh_core::zlock;
use zenoh_link::{Link, LinkMulticast, Locator};
use zenoh_protocol::{
Expand Down
4 changes: 3 additions & 1 deletion io/zenoh-transport/src/multicast/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ use async_std::sync::Mutex;
use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
#[cfg(feature = "transport_compression")]
use zenoh_config::CompressionMulticastConf;
#[cfg(feature = "shared-memory")]
use zenoh_config::SharedMemoryConf;
use zenoh_config::{CompressionMulticastConf, Config, LinkTxConf};
use zenoh_config::{Config, LinkTxConf};
use zenoh_core::zasynclock;
use zenoh_link::*;
use zenoh_protocol::core::ZenohId;
Expand Down
4 changes: 4 additions & 0 deletions io/zenoh-transport/src/unicast/establishment/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct StateTransport {
ext_lowlatency: ext::lowlatency::StateAccept,
}

#[cfg(any(feature = "transport_auth", feature = "transport_compression"))]
struct StateLink {
#[cfg(feature = "transport_auth")]
ext_auth: ext::auth::StateAccept,
Expand All @@ -64,6 +65,7 @@ struct StateLink {

struct State {
transport: StateTransport,
#[cfg(any(feature = "transport_auth", feature = "transport_compression"))]
link: StateLink,
}

Expand Down Expand Up @@ -441,6 +443,7 @@ impl<'a, 'b: 'a> AcceptFsm for &'a mut AcceptLink<'b> {
ext_shm: cookie.ext_shm,
ext_lowlatency: cookie.ext_lowlatency,
},
#[cfg(any(feature = "transport_auth", feature = "transport_compression"))]
link: StateLink {
#[cfg(feature = "transport_auth")]
ext_auth: cookie.ext_auth,
Expand Down Expand Up @@ -638,6 +641,7 @@ pub(crate) async fn accept_link(link: &LinkUnicast, manager: &TransportManager)
manager.config.unicast.is_lowlatency,
),
},
#[cfg(any(feature = "transport_auth", feature = "transport_compression"))]
link: StateLink {
#[cfg(feature = "transport_auth")]
ext_auth: manager
Expand Down
3 changes: 3 additions & 0 deletions io/zenoh-transport/src/unicast/establishment/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct StateTransport {
ext_lowlatency: ext::lowlatency::StateOpen,
}

#[cfg(any(feature = "transport_auth", feature = "transport_compression"))]
struct StateLink {
#[cfg(feature = "transport_auth")]
ext_auth: ext::auth::StateOpen,
Expand All @@ -59,6 +60,7 @@ struct StateLink {

struct State {
transport: StateTransport,
#[cfg(any(feature = "transport_auth", feature = "transport_compression"))]
link: StateLink,
}

Expand Down Expand Up @@ -549,6 +551,7 @@ pub(crate) async fn open_link(

ext_lowlatency: ext::lowlatency::StateOpen::new(manager.config.unicast.is_lowlatency),
},
#[cfg(any(feature = "transport_auth", feature = "transport_compression"))]
link: StateLink {
#[cfg(feature = "transport_auth")]
ext_auth: manager
Expand Down
4 changes: 3 additions & 1 deletion io/zenoh-transport/src/unicast/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use crate::common::batch::{BatchConfig, Decode, Encode, Finalize, RBatch, WBatch};
use std::fmt;
use std::sync::Arc;
use zenoh_buffers::{BBuf, ZSlice, ZSliceBuffer};
#[cfg(feature = "transport_compression")]
use zenoh_buffers::BBuf;
use zenoh_buffers::{ZSlice, ZSliceBuffer};
use zenoh_link::{Link, LinkUnicast};
use zenoh_protocol::transport::{BatchSize, Close, TransportMessage};
use zenoh_result::{zerror, ZResult};
Expand Down
6 changes: 3 additions & 3 deletions io/zenoh-transport/src/unicast/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ use crate::{
};
use async_std::{prelude::FutureExt, sync::Mutex, task};
use std::{collections::HashMap, sync::Arc, time::Duration};
#[cfg(feature = "transport_compression")]
use zenoh_config::CompressionUnicastConf;
#[cfg(feature = "shared-memory")]
use zenoh_config::SharedMemoryConf;
use zenoh_config::{
CompressionUnicastConf, Config, LinkTxConf, QoSUnicastConf, TransportUnicastConf,
};
use zenoh_config::{Config, LinkTxConf, QoSUnicastConf, TransportUnicastConf};
use zenoh_core::{zasynclock, zcondfeat};
use zenoh_crypto::PseudoRng;
use zenoh_link::*;
Expand Down

0 comments on commit b5f69cb

Please sign in to comment.