Skip to content

Commit

Permalink
Fix unused variables warnings when not using log
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb-leinz committed Jan 25, 2024
1 parent 5f53135 commit 6887535
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
50 changes: 40 additions & 10 deletions src/log.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,68 @@
#[allow(unused_macros)]
macro_rules! trace {
($($arg:tt)*) => {
($($arg:expr),*) => {
#[cfg(feature = "log")]
log::trace!($($arg)*);
log::trace!($($arg),*);
#[cfg(not(feature = "log"))]
{
$(
let _ = $arg;
)*
}
};
}

#[allow(unused_macros)]
macro_rules! debug {
($($arg:tt)*) => {
($($arg:expr),*) => {
#[cfg(feature = "log")]
log::debug!($($arg)*);
log::debug!($($arg),*);
#[cfg(not(feature = "log"))]
{
$(
let _ = $arg;
)*
}
};
}

macro_rules! info {
($($arg:tt)*) => {
($($arg:expr),*) => {
#[cfg(feature = "log")]
log::info!($($arg)*);
log::info!($($arg),*);
#[cfg(not(feature = "log"))]
{
$(
let _ = $arg;
)*
}
};
}

#[allow(unused_macros)]
macro_rules! warn {
($($arg:tt)*) => {
($($arg:expr),*) => {
#[cfg(feature = "log")]
log::warn!($($arg)*);
log::warn!($($arg),*);
#[cfg(not(feature = "log"))]
{
$(
let _ = $arg;
)*
}
};
}

macro_rules! error {
($($arg:tt)*) => {
($($arg:expr),*) => {
#[cfg(feature = "log")]
log::error!($($arg)*);
log::error!($($arg),*);
#[cfg(not(feature = "log"))]
{
$(
let _ = $arg;
)*
}
};
}

Expand Down
16 changes: 8 additions & 8 deletions src/tokio/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@ where
let mut result = Err(e);

for (i, duration) in (options.retries_to_attempt_fn)().enumerate() {
let _reconnect_num = i + 1;
let reconnect_num = i + 1;

info!(
"Will re-perform initial connect attempt #{} in {:?}.",
_reconnect_num, duration
reconnect_num, duration
);

sleep(duration).await;

info!("Attempting reconnect #{} now.", _reconnect_num);
info!("Attempting reconnect #{} now.", reconnect_num);

match T::establish(ctor_arg.clone()).await {
Ok(tcp) => {
Expand Down Expand Up @@ -236,11 +236,11 @@ where
let future_instant = sleep(next_duration);

reconnect_status.attempts_tracker.attempt_num += 1;
let _cur_num = reconnect_status.attempts_tracker.attempt_num;
let cur_num = reconnect_status.attempts_tracker.attempt_num;

let reconnect_attempt = async move {
future_instant.await;
info!("Attempting reconnect #{} now.", _cur_num);
info!("Attempting reconnect #{} now.", cur_num);
T::establish(ctor_arg).await
};

Expand All @@ -256,7 +256,7 @@ where
}

fn poll_disconnect(mut self: Pin<&mut Self>, cx: &mut Context) {
let (attempt, _attempt_num) = match &mut self.status {
let (attempt, attempt_num) = match &mut self.status {
Status::Connected => unreachable!(),
Status::Disconnected(ref mut status) => (
Pin::new(&mut status.reconnect_attempt),
Expand All @@ -273,8 +273,8 @@ where
(self.options.on_connect_callback)();
self.underlying_io = underlying_io;
}
Poll::Ready(Err(_err)) => {
error!("Connection attempt #{} failed: {:?}", _attempt_num, _err);
Poll::Ready(Err(err)) => {
error!("Connection attempt #{} failed: {:?}", attempt_num, err);
self.on_disconnect(cx);
}
Poll::Pending => {}
Expand Down

0 comments on commit 6887535

Please sign in to comment.