Skip to content

Commit 375294b

Browse files
committed
make log an optional dependency
Currently, Mio depends on `log`. In rust-lang/log#552, the `log` maintainers aim to increase `log`'s MSRV to 1.60. This MSRV increase would impact Mio, which in turn, would impact Tokio. As of 1.25, Tokio supports Rust 1.49 with the intent of supporting it until March 2024. This commit makes `log` an optional dependency for those who wish to maintain a lower MSRV. Backport of commit 44df449
1 parent df992df commit 375294b

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ include = [
3232
# For documentation of features see the `mio::features` module.
3333
[features]
3434
# By default Mio only provides a shell implementation.
35-
default = []
35+
default = ["log"]
3636

3737
# Enables the `Poll` and `Registry` types.
3838
os-poll = []
@@ -50,7 +50,7 @@ pipe = ["os-ext"] # Replaced with "os-ext" feature.
5050
os-util = ["os-ext"]# Replaced with "os-ext" feature.
5151

5252
[dependencies]
53-
log = "0.4.8"
53+
log = { version = "0.4.8", optional = true }
5454

5555
[target.'cfg(unix)'.dependencies]
5656
libc = "0.2.86"

src/macros.rs

+24
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,27 @@ macro_rules! cfg_any_os_ext {
6868
)*
6969
}
7070
}
71+
72+
macro_rules! trace {
73+
($($t:tt)*) => {
74+
#[cfg(feature = "log")]
75+
log::trace!($($t)*)
76+
}
77+
}
78+
79+
macro_rules! error {
80+
($($t:tt)*) => {
81+
#[cfg(feature = "log")]
82+
{
83+
log::error!($($t)*)
84+
}
85+
86+
// Silence warnings
87+
#[cfg(not(feature = "log"))]
88+
{
89+
if false {
90+
format!($($t)*);
91+
}
92+
}
93+
}
94+
}

src/poll.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{event, sys, Events, Interest, Token};
2-
use log::trace;
32
#[cfg(unix)]
43
use std::os::unix::io::{AsRawFd, RawFd};
54
use std::time::Duration;

src/sys/unix/selector/epoll.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::{Interest, Token};
22

33
use libc::{EPOLLET, EPOLLIN, EPOLLOUT, EPOLLRDHUP};
4-
use log::error;
54
use std::os::unix::io::{AsRawFd, RawFd};
65
#[cfg(debug_assertions)]
76
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};

src/sys/unix/selector/kqueue.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{Interest, Token};
2-
use log::error;
32
use std::mem::MaybeUninit;
43
use std::ops::{Deref, DerefMut};
54
use std::os::unix::io::{AsRawFd, RawFd};

0 commit comments

Comments
 (0)