Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup import statements #1746

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/tcp_listenfd_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
// cargo +nightly build --target wasm32-wasi --example tcp_listenfd_server --features="os-poll net"
// wasmtime run --tcplisten 127.0.0.1:9000 --env 'LISTEN_FDS=1' target/wasm32-wasi/debug/examples/tcp_listenfd_server.wasm

use mio::event::Event;
use mio::net::{TcpListener, TcpStream};
use mio::{Events, Interest, Poll, Registry, Token};
use std::collections::HashMap;
use std::io::{self, Read, Write};
use std::str::from_utf8;

use mio::event::Event;
use mio::net::{TcpListener, TcpStream};
use mio::{Events, Interest, Poll, Registry, Token};

// Setup some tokens to allow us to identify which event is for which socket.
const SERVER: Token = Token(0);

Expand Down
7 changes: 4 additions & 3 deletions examples/tcp_server.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// You can run this example from the root of the mio repo:
// cargo run --example tcp_server --features="os-poll net"
use mio::event::Event;
use mio::net::{TcpListener, TcpStream};
use mio::{Events, Interest, Poll, Registry, Token};
use std::collections::HashMap;
use std::io::{self, Read, Write};
use std::str::from_utf8;

use mio::event::Event;
use mio::net::{TcpListener, TcpStream};
use mio::{Events, Interest, Poll, Registry, Token};

// Setup some tokens to allow us to identify which event is for which socket.
const SERVER: Token = Token(0);

Expand Down
3 changes: 2 additions & 1 deletion examples/udp_server.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// You can run this example from the root of the mio repo:
// cargo run --example udp_server --features="os-poll net"
use std::io;

use log::warn;
use mio::{Events, Interest, Poll, Token};
use std::io;

// A token to allow us to identify which event is for the `UdpSocket`.
const UDP_SOCKET: Token = Token(0);
Expand Down
4 changes: 2 additions & 2 deletions src/event/event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{sys, Token};

use std::fmt;

use crate::{sys, Token};

/// A readiness event.
///
/// `Event` is a readiness state paired with a [`Token`]. It is returned by
Expand Down
4 changes: 2 additions & 2 deletions src/event/events.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::fmt;

use crate::event::Event;
use crate::sys;

use std::fmt;

/// A collection of readiness events.
///
/// `Events` is passed as an argument to [`Poll::poll`] and will be used to
Expand Down
6 changes: 3 additions & 3 deletions src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ mod event;
mod events;
mod source;

pub use self::event::Event;
pub use self::events::{Events, Iter};
pub use self::source::Source;
pub use event::Event;
pub use events::{Events, Iter};
pub use source::Source;
4 changes: 2 additions & 2 deletions src/event/source.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{Interest, Registry, Token};

use std::io;

use crate::{Interest, Registry, Token};

/// An event source that may be registered with [`Registry`].
///
/// Types that implement `event::Source` can be registered with
Expand Down
6 changes: 3 additions & 3 deletions src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
//! give is to always call receive with a large enough buffer.

mod tcp;
pub use self::tcp::{TcpListener, TcpStream};
pub use tcp::{TcpListener, TcpStream};

#[cfg(not(target_os = "wasi"))]
mod udp;
#[cfg(not(target_os = "wasi"))]
pub use self::udp::UdpSocket;
pub use udp::UdpSocket;

#[cfg(unix)]
mod uds;
#[cfg(unix)]
pub use self::uds::{SocketAddr, UnixDatagram, UnixListener, UnixStream};
pub use uds::{SocketAddr, UnixDatagram, UnixListener, UnixStream};
4 changes: 2 additions & 2 deletions src/net/tcp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod listener;
pub use self::listener::TcpListener;
pub use listener::TcpListener;

mod stream;
pub use self::stream::TcpStream;
pub use stream::TcpStream;
7 changes: 3 additions & 4 deletions src/net/uds/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
mod datagram;
pub use self::datagram::UnixDatagram;
pub use datagram::UnixDatagram;

mod listener;
pub use self::listener::UnixListener;
pub use listener::UnixListener;

mod stream;
pub use self::stream::UnixStream;

pub use crate::sys::SocketAddr;
pub use stream::UnixStream;
12 changes: 6 additions & 6 deletions src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,34 @@ cfg_os_poll! {
cfg_os_poll! {
mod unix;
#[allow(unused_imports)]
pub use self::unix::*;
pub use unix::*;
}

#[cfg(windows)]
cfg_os_poll! {
mod windows;
pub use self::windows::*;
pub use windows::*;
}

#[cfg(target_os = "wasi")]
cfg_os_poll! {
mod wasi;
pub(crate) use self::wasi::*;
pub(crate) use wasi::*;
}

cfg_not_os_poll! {
mod shell;
pub(crate) use self::shell::*;
pub(crate) use shell::*;

#[cfg(unix)]
cfg_any_os_ext! {
mod unix;
#[cfg(feature = "os-ext")]
pub use self::unix::SourceFd;
pub use unix::SourceFd;
}

#[cfg(unix)]
cfg_net! {
pub use self::unix::SocketAddr;
pub use unix::SocketAddr;
}
}
4 changes: 2 additions & 2 deletions src/sys/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ macro_rules! os_required {
}

mod selector;
pub(crate) use self::selector::{event, Event, Events, Selector};
pub(crate) use selector::{event, Event, Events, Selector};

#[cfg(not(target_os = "wasi"))]
mod waker;
#[cfg(not(target_os = "wasi"))]
pub(crate) use self::waker::Waker;
pub(crate) use waker::Waker;

cfg_net! {
pub(crate) mod tcp;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/shell/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ impl AsRawFd for Selector {

#[allow(clippy::trivially_copy_pass_by_ref)]
pub mod event {
use std::fmt;

use crate::sys::Event;
use crate::Token;
use std::fmt;

pub fn token(_: &Event) -> Token {
os_required!();
Expand Down
9 changes: 6 additions & 3 deletions src/sys/shell/uds.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
pub(crate) mod datagram {
use crate::net::SocketAddr;
use std::io;
use std::os::unix::net;
use std::path::Path;

use crate::net::SocketAddr;

pub(crate) fn bind(_: &Path) -> io::Result<net::UnixDatagram> {
os_required!()
}
Expand Down Expand Up @@ -33,11 +34,12 @@ pub(crate) mod datagram {
}

pub(crate) mod listener {
use crate::net::{SocketAddr, UnixStream};
use std::io;
use std::os::unix::net;
use std::path::Path;

use crate::net::{SocketAddr, UnixStream};

pub(crate) fn bind(_: &Path) -> io::Result<net::UnixListener> {
os_required!()
}
Expand All @@ -56,11 +58,12 @@ pub(crate) mod listener {
}

pub(crate) mod stream {
use crate::net::SocketAddr;
use std::io;
use std::os::unix::net;
use std::path::Path;

use crate::net::SocketAddr;

pub(crate) fn connect(_: &Path) -> io::Result<net::UnixStream> {
os_required!()
}
Expand Down
3 changes: 2 additions & 1 deletion src/sys/shell/waker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::io;

use crate::sys::Selector;
use crate::Token;
use std::io;

#[derive(Debug)]
pub struct Waker {}
Expand Down
17 changes: 9 additions & 8 deletions src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ macro_rules! syscall {

cfg_os_poll! {
mod selector;
pub(crate) use self::selector::{event, Event, Events, Selector};
pub(crate) use selector::{event, Event, Events, Selector};

mod sourcefd;
#[cfg(feature = "os-ext")]
pub use self::sourcefd::SourceFd;
pub use sourcefd::SourceFd;

mod waker;
pub(crate) use self::waker::Waker;
pub(crate) use waker::Waker;

cfg_net! {
mod net;

pub(crate) mod tcp;
pub(crate) mod udp;
pub(crate) mod uds;
pub use self::uds::SocketAddr;
pub use uds::SocketAddr;
}

cfg_io_source! {
Expand All @@ -40,6 +40,7 @@ cfg_os_poll! {
mod stateless_io_source {
use std::io;
use std::os::fd::RawFd;

use crate::Registry;
use crate::Token;
use crate::Interest;
Expand Down Expand Up @@ -90,10 +91,10 @@ cfg_os_poll! {
}

#[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "solaris",target_os = "vita")))]
pub(crate) use self::stateless_io_source::IoSourceState;
pub(crate) use stateless_io_source::IoSourceState;

#[cfg(any(mio_unsupported_force_poll_poll, target_os = "solaris", target_os = "vita"))]
pub(crate) use self::selector::IoSourceState;
pub(crate) use selector::IoSourceState;
}

#[cfg(any(
Expand All @@ -116,12 +117,12 @@ cfg_os_poll! {
cfg_not_os_poll! {
cfg_net! {
mod uds;
pub use self::uds::SocketAddr;
pub use uds::SocketAddr;
}

cfg_any_os_ext! {
mod sourcefd;
#[cfg(feature = "os-ext")]
pub use self::sourcefd::SourceFd;
pub use sourcefd::SourceFd;
}
}
6 changes: 3 additions & 3 deletions src/sys/unix/selector/kqueue.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::{Interest, Token};
use std::mem::{self, MaybeUninit};
use std::ops::{Deref, DerefMut};
use std::os::fd::{AsRawFd, FromRawFd, OwnedFd, RawFd};
Expand All @@ -7,6 +6,8 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;
use std::{cmp, io, ptr, slice};

use crate::{Interest, Token};

/// Unique id for use as `SelectorId`.
#[cfg(debug_assertions)]
static NEXT_ID: AtomicUsize = AtomicUsize::new(1);
Expand Down Expand Up @@ -353,11 +354,10 @@ unsafe impl Sync for Events {}
pub mod event {
use std::fmt;

use super::{Filter, Flags};
use crate::sys::Event;
use crate::Token;

use super::{Filter, Flags};

pub fn token(event: &Event) -> Token {
Token(event.udata as usize)
}
Expand Down
8 changes: 4 additions & 4 deletions src/sys/unix/selector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod epoll;
target_os = "redox",
)
))]
pub(crate) use self::epoll::{event, Event, Events, Selector};
pub(crate) use epoll::{event, Event, Events, Selector};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably have kept the self:: markers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're not needed any more since rust edition 2018/2021, so I the code I write now I never use it any more.


#[cfg(any(
mio_unsupported_force_poll_poll,
Expand All @@ -32,11 +32,11 @@ mod poll;
target_os = "solaris",
target_os = "vita"
))]
pub(crate) use self::poll::{event, Event, Events, Selector};
pub(crate) use poll::{event, Event, Events, Selector};

cfg_io_source! {
#[cfg(any(mio_unsupported_force_poll_poll, target_os = "solaris", target_os = "vita"))]
pub(crate) use self::poll::IoSourceState;
pub(crate) use poll::IoSourceState;
}

#[cfg(all(
Expand Down Expand Up @@ -67,4 +67,4 @@ mod kqueue;
target_os = "watchos",
),
))]
pub(crate) use self::kqueue::{event, Event, Events, Selector};
pub(crate) use kqueue::{event, Event, Events, Selector};
11 changes: 6 additions & 5 deletions src/sys/unix/selector/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
// Permission to use this code has been granted by original author:
// https://github.com/tokio-rs/mio/pull/1602#issuecomment-1218441031

use crate::sys::unix::waker::WakerInternal;
use crate::{Interest, Token};
use std::collections::HashMap;
use std::fmt::{Debug, Formatter};
use std::os::fd::{AsRawFd, RawFd};
use std::sync::atomic::AtomicBool;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::{Arc, Condvar, Mutex};
use std::time::Duration;
use std::{cmp, fmt, io};

use crate::sys::unix::waker::WakerInternal;
use crate::{Interest, Token};

/// Unique id for use as `SelectorId`.
#[cfg(debug_assertions)]
static NEXT_ID: AtomicUsize = AtomicUsize::new(1);
Expand Down Expand Up @@ -540,10 +540,11 @@ pub struct Event {
pub type Events = Vec<Event>;

pub mod event {
use std::fmt;

use crate::sys::unix::selector::poll::POLLRDHUP;
use crate::sys::Event;
use crate::Token;
use std::fmt;

pub fn token(event: &Event) -> Token {
event.token
Expand Down
Loading