Skip to content

Commit 988bd00

Browse files
carllercheThomasdezeeuw
authored andcommitted
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.
1 parent 958200c commit 988bd00

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
@@ -29,7 +29,7 @@ include = [
2929
# For documentation of features see the `mio::features` module.
3030
[features]
3131
# By default Mio only provides a shell implementation.
32-
default = []
32+
default = ["log"]
3333

3434
# Enables the `Poll` and `Registry` types.
3535
os-poll = []
@@ -43,7 +43,7 @@ os-ext = [
4343
net = []
4444

4545
[dependencies]
46-
log = "0.4.8"
46+
log = { version = "0.4.8", optional = true }
4747

4848
[target.'cfg(unix)'.dependencies]
4949
libc = "0.2.121"

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, EPOLLPRI, 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::{self, MaybeUninit};
43
use std::ops::{Deref, DerefMut};
54
use std::os::unix::io::{AsRawFd, RawFd};

0 commit comments

Comments
 (0)