diff --git a/src/coroutine_impl.rs b/src/coroutine_impl.rs index a7117b26..abcd924d 100644 --- a/src/coroutine_impl.rs +++ b/src/coroutine_impl.rs @@ -13,9 +13,9 @@ use crate::scheduler::get_scheduler; use crate::sync::AtomicOption; use generator::{Generator, Gn}; -/// ///////////////////////////////////////////////////////////////////////////// -/// Coroutine framework types -/// ///////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Coroutine framework types +//////////////////////////////////////////////////////////////////////////////// pub type EventResult = io::Error; @@ -48,9 +48,9 @@ pub trait EventSource { } } -/// ///////////////////////////////////////////////////////////////////////////// -/// Coroutine destruction -/// ///////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Coroutine destruction +//////////////////////////////////////////////////////////////////////////////// pub struct Done; @@ -95,9 +95,9 @@ fn get_co_local(co: &CoroutineImpl) -> *mut CoroutineLocal { co.get_local_data() as *mut CoroutineLocal } -/// ///////////////////////////////////////////////////////////////////////////// -/// Coroutine -/// ///////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Coroutine +//////////////////////////////////////////////////////////////////////////////// /// The internal representation of a `Coroutine` handle struct Inner { diff --git a/src/cqueue.rs b/src/cqueue.rs index 3c11668d..636af838 100644 --- a/src/cqueue.rs +++ b/src/cqueue.rs @@ -94,9 +94,9 @@ pub struct EventSender<'a> { cqueue: &'a Cqueue, } -unsafe impl<'a> Send for EventSender<'a> {} +unsafe impl Send for EventSender<'_> {} -impl<'a> EventSender<'a> { +impl EventSender<'_> { /// get the token pub fn get_token(&self) -> usize { self.token @@ -111,7 +111,7 @@ impl<'a> EventSender<'a> { } } -impl<'a> EventSource for EventSender<'a> { +impl EventSource for EventSender<'_> { fn subscribe(&mut self, co: CoroutineImpl) { self.cqueue.ev_queue.push(Event { id: self.id, @@ -130,7 +130,7 @@ impl<'a> EventSource for EventSender<'a> { } } -impl<'a> Drop for EventSender<'a> { +impl Drop for EventSender<'_> { // when the select coroutine finished will trigger this drop fn drop(&mut self) { self.cqueue.ev_queue.push(Event { diff --git a/src/io/sys/windows/miow.rs b/src/io/sys/windows/miow.rs index 8127254e..8a67e46b 100644 --- a/src/io/sys/windows/miow.rs +++ b/src/io/sys/windows/miow.rs @@ -682,7 +682,7 @@ pub struct AcceptAddrs<'a> { _data: &'a AcceptAddrsBuf, } -impl<'a> AcceptAddrs<'a> { +impl AcceptAddrs<'_> { /// Returns the local socket address contained in this buffer. #[allow(dead_code)] pub fn local(&self) -> Option { diff --git a/src/io/sys/windows/net/socket_peek.rs b/src/io/sys/windows/net/socket_peek.rs index 73755134..d04f0605 100644 --- a/src/io/sys/windows/net/socket_peek.rs +++ b/src/io/sys/windows/net/socket_peek.rs @@ -48,7 +48,7 @@ impl<'a> SocketPeek<'a> { } } -impl<'a> EventSource for SocketPeek<'a> { +impl EventSource for SocketPeek<'_> { fn subscribe(&mut self, co: CoroutineImpl) { let s = get_scheduler(); #[cfg(feature = "io_cancel")] diff --git a/src/io/sys/windows/net/socket_read.rs b/src/io/sys/windows/net/socket_read.rs index 3a3d83bd..a9581586 100644 --- a/src/io/sys/windows/net/socket_read.rs +++ b/src/io/sys/windows/net/socket_read.rs @@ -47,7 +47,7 @@ impl<'a> SocketRead<'a> { } } -impl<'a> EventSource for SocketRead<'a> { +impl EventSource for SocketRead<'_> { fn subscribe(&mut self, co: CoroutineImpl) { let s = get_scheduler(); #[cfg(feature = "io_cancel")] diff --git a/src/io/sys/windows/net/socket_write.rs b/src/io/sys/windows/net/socket_write.rs index 62ba2323..172c257e 100644 --- a/src/io/sys/windows/net/socket_write.rs +++ b/src/io/sys/windows/net/socket_write.rs @@ -40,7 +40,7 @@ impl<'a> SocketWrite<'a> { } } -impl<'a> EventSource for SocketWrite<'a> { +impl EventSource for SocketWrite<'_> { #[allow(clippy::needless_return)] fn subscribe(&mut self, co: CoroutineImpl) { let s = get_scheduler(); diff --git a/src/io/sys/windows/net/tcp_listener_accept.rs b/src/io/sys/windows/net/tcp_listener_accept.rs index e79cf9ba..f931b8ee 100644 --- a/src/io/sys/windows/net/tcp_listener_accept.rs +++ b/src/io/sys/windows/net/tcp_listener_accept.rs @@ -64,7 +64,7 @@ impl<'a> TcpListenerAccept<'a> { } } -impl<'a> EventSource for TcpListenerAccept<'a> { +impl EventSource for TcpListenerAccept<'_> { fn subscribe(&mut self, co: CoroutineImpl) { let _g = self.can_drop.delay_drop(); let s = get_scheduler(); diff --git a/src/io/sys/windows/net/udp_recv_from.rs b/src/io/sys/windows/net/udp_recv_from.rs index e028814b..256223b4 100644 --- a/src/io/sys/windows/net/udp_recv_from.rs +++ b/src/io/sys/windows/net/udp_recv_from.rs @@ -50,7 +50,7 @@ impl<'a> UdpRecvFrom<'a> { } } -impl<'a> EventSource for UdpRecvFrom<'a> { +impl EventSource for UdpRecvFrom<'_> { fn subscribe(&mut self, co: CoroutineImpl) { let _g = self.can_drop.delay_drop(); let s = get_scheduler(); diff --git a/src/io/sys/windows/net/udp_send_to.rs b/src/io/sys/windows/net/udp_send_to.rs index 65b3fdcf..aceb7170 100644 --- a/src/io/sys/windows/net/udp_send_to.rs +++ b/src/io/sys/windows/net/udp_send_to.rs @@ -46,7 +46,7 @@ impl<'a> UdpSendTo<'a> { } } -impl<'a> EventSource for UdpSendTo<'a> { +impl EventSource for UdpSendTo<'_> { #[allow(clippy::needless_return)] fn subscribe(&mut self, co: CoroutineImpl) { let s = get_scheduler(); diff --git a/src/io/sys/windows/pipe/pipe_read.rs b/src/io/sys/windows/pipe/pipe_read.rs index 01fd3576..4c6aae8a 100644 --- a/src/io/sys/windows/pipe/pipe_read.rs +++ b/src/io/sys/windows/pipe/pipe_read.rs @@ -51,7 +51,7 @@ impl<'a> PipeRead<'a> { } } -impl<'a> EventSource for PipeRead<'a> { +impl EventSource for PipeRead<'_> { fn subscribe(&mut self, co: CoroutineImpl) { let s = get_scheduler(); #[cfg(feature = "io_cancel")] diff --git a/src/io/sys/windows/pipe/pipe_write.rs b/src/io/sys/windows/pipe/pipe_write.rs index 0151589c..ed039a76 100644 --- a/src/io/sys/windows/pipe/pipe_write.rs +++ b/src/io/sys/windows/pipe/pipe_write.rs @@ -39,7 +39,7 @@ impl<'a> PipeWrite<'a> { } } -impl<'a> EventSource for PipeWrite<'a> { +impl EventSource for PipeWrite<'_> { #[allow(clippy::needless_return)] fn subscribe(&mut self, co: CoroutineImpl) { let s = get_scheduler(); diff --git a/src/net/tcp.rs b/src/net/tcp.rs index e0dacd5b..46518348 100644 --- a/src/net/tcp.rs +++ b/src/net/tcp.rs @@ -459,7 +459,7 @@ pub struct Incoming<'a> { listener: &'a TcpListener, } -impl<'a> Iterator for Incoming<'a> { +impl Iterator for Incoming<'_> { type Item = io::Result; fn next(&mut self) -> Option> { Some(self.listener.accept().map(|p| p.0)) diff --git a/src/park.rs b/src/park.rs index 844b55bd..1916a3a7 100644 --- a/src/park.rs +++ b/src/park.rs @@ -178,7 +178,7 @@ impl Park { } } -impl<'a> Drop for DropGuard<'a> { +impl Drop for DropGuard<'_> { fn drop(&mut self) { self.0.wait_kernel.store(false, Ordering::Release); } diff --git a/src/scoped.rs b/src/scoped.rs index d84964b1..788c3a50 100644 --- a/src/scoped.rs +++ b/src/scoped.rs @@ -81,7 +81,7 @@ where ret } -impl<'a> fmt::Debug for Scope<'a> { +impl fmt::Debug for Scope<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Scope {{ ... }}") } @@ -208,7 +208,7 @@ impl ScopedJoinHandle { } } -impl<'a> Drop for Scope<'a> { +impl Drop for Scope<'_> { fn drop(&mut self) { self.drop_all() } diff --git a/src/sync/atomic_dur.rs b/src/sync/atomic_dur.rs index f9e39fe5..0a2c661e 100644 --- a/src/sync/atomic_dur.rs +++ b/src/sync/atomic_dur.rs @@ -44,10 +44,5 @@ impl AtomicDuration { } fn dur_to_ms(dur: Duration) -> u64 { - // Note that a duration is a (u64, u32) (seconds, nanoseconds) pair - const MS_PER_SEC: u64 = 1_000; - const NANOS_PER_MILLI: u64 = 1_000_000; - let ns = u64::from(dur.subsec_nanos()); - let ms = (ns + NANOS_PER_MILLI - 1) / NANOS_PER_MILLI; - dur.as_secs().saturating_mul(MS_PER_SEC).saturating_add(ms) + dur.as_millis() as u64 } diff --git a/src/sync/delay_drop.rs b/src/sync/delay_drop.rs index 635c6ecd..21bb1b2e 100644 --- a/src/sync/delay_drop.rs +++ b/src/sync/delay_drop.rs @@ -32,7 +32,7 @@ impl DelayDrop { } } -impl<'a> Drop for DropGuard<'a> { +impl Drop for DropGuard<'_> { fn drop(&mut self) { // kernel would set it to true self.0.can_drop.fetch_and(1, Ordering::Release); diff --git a/src/sync/mpmc.rs b/src/sync/mpmc.rs index 4feef06e..e1c339f4 100644 --- a/src/sync/mpmc.rs +++ b/src/sync/mpmc.rs @@ -162,9 +162,9 @@ pub fn channel() -> (Sender, Receiver) { (Sender::new(a.clone()), Receiver::new(a)) } -/// ///////////////////////////////////////////////////////////////////////////// -/// Sender -/// ///////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Sender +//////////////////////////////////////////////////////////////////////////////// impl Sender { fn new(inner: Arc>) -> Sender { @@ -200,9 +200,9 @@ impl fmt::Debug for Sender { } } -/// ///////////////////////////////////////////////////////////////////////////// -/// Receiver -/// ///////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Receiver +//////////////////////////////////////////////////////////////////////////////// impl Receiver { fn new(inner: Arc>) -> Receiver { @@ -233,7 +233,7 @@ impl Receiver { } } -impl<'a, T> Iterator for Iter<'a, T> { +impl Iterator for Iter<'_, T> { type Item = T; fn next(&mut self) -> Option { @@ -241,7 +241,7 @@ impl<'a, T> Iterator for Iter<'a, T> { } } -impl<'a, T> Iterator for TryIter<'a, T> { +impl Iterator for TryIter<'_, T> { type Item = T; fn next(&mut self) -> Option { diff --git a/src/sync/mpsc.rs b/src/sync/mpsc.rs index edb5a405..7abe6295 100644 --- a/src/sync/mpsc.rs +++ b/src/sync/mpsc.rs @@ -146,9 +146,9 @@ pub fn channel() -> (Sender, Receiver) { (Sender::new(a.clone()), Receiver::new(a)) } -/// ///////////////////////////////////////////////////////////////////////////// -/// Sender -/// ///////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Sender +//////////////////////////////////////////////////////////////////////////////// impl Sender { fn new(inner: Arc>) -> Sender { @@ -179,9 +179,9 @@ impl fmt::Debug for Sender { } } -/// ///////////////////////////////////////////////////////////////////////////// -/// Receiver -/// ///////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Receiver +//////////////////////////////////////////////////////////////////////////////// impl Receiver { fn new(inner: Arc>) -> Receiver { @@ -237,7 +237,7 @@ impl Receiver { } } -impl<'a, T> Iterator for Iter<'a, T> { +impl Iterator for Iter<'_, T> { type Item = T; fn next(&mut self) -> Option { @@ -245,7 +245,7 @@ impl<'a, T> Iterator for Iter<'a, T> { } } -impl<'a, T> Iterator for TryIter<'a, T> { +impl Iterator for TryIter<'_, T> { type Item = T; fn next(&mut self) -> Option { diff --git a/src/sync/mutex.rs b/src/sync/mutex.rs index 57f0ae6a..6d69cbda 100644 --- a/src/sync/mutex.rs +++ b/src/sync/mutex.rs @@ -190,7 +190,7 @@ impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> { } } -impl<'mutex, T: ?Sized> Deref for MutexGuard<'mutex, T> { +impl Deref for MutexGuard<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -198,13 +198,13 @@ impl<'mutex, T: ?Sized> Deref for MutexGuard<'mutex, T> { } } -impl<'mutex, T: ?Sized> DerefMut for MutexGuard<'mutex, T> { +impl DerefMut for MutexGuard<'_, T> { fn deref_mut(&mut self) -> &mut T { unsafe { &mut *self.__lock.data.get() } } } -impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> { +impl Drop for MutexGuard<'_, T> { #[inline] fn drop(&mut self) { self.__lock.poison.done(&self.__poison); @@ -214,7 +214,7 @@ impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> { } } -impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'a, T> { +impl fmt::Debug for MutexGuard<'_, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("MutexGuard") .field("lock", &self.__lock) diff --git a/src/sync/rwlock.rs b/src/sync/rwlock.rs index b2bc9c2f..6eae3aa3 100644 --- a/src/sync/rwlock.rs +++ b/src/sync/rwlock.rs @@ -265,7 +265,7 @@ impl<'rwlock, T: ?Sized> RwLockWriteGuard<'rwlock, T> { } } -impl<'a, T: fmt::Debug> fmt::Debug for RwLockReadGuard<'a, T> { +impl fmt::Debug for RwLockReadGuard<'_, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("RwLockReadGuard") .field("lock", &self.__lock) @@ -273,7 +273,7 @@ impl<'a, T: fmt::Debug> fmt::Debug for RwLockReadGuard<'a, T> { } } -impl<'a, T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'a, T> { +impl fmt::Debug for RwLockWriteGuard<'_, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("RwLockWriteGuard") .field("lock", &self.__lock) @@ -281,7 +281,7 @@ impl<'a, T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'a, T> { } } -impl<'rwlock, T: ?Sized> Deref for RwLockReadGuard<'rwlock, T> { +impl Deref for RwLockReadGuard<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -289,7 +289,7 @@ impl<'rwlock, T: ?Sized> Deref for RwLockReadGuard<'rwlock, T> { } } -impl<'rwlock, T: ?Sized> Deref for RwLockWriteGuard<'rwlock, T> { +impl Deref for RwLockWriteGuard<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -297,19 +297,19 @@ impl<'rwlock, T: ?Sized> Deref for RwLockWriteGuard<'rwlock, T> { } } -impl<'rwlock, T: ?Sized> DerefMut for RwLockWriteGuard<'rwlock, T> { +impl DerefMut for RwLockWriteGuard<'_, T> { fn deref_mut(&mut self) -> &mut T { unsafe { &mut *self.__lock.data.get() } } } -impl<'a, T: ?Sized> Drop for RwLockReadGuard<'a, T> { +impl Drop for RwLockReadGuard<'_, T> { fn drop(&mut self) { self.__lock.read_unlock(); } } -impl<'a, T: ?Sized> Drop for RwLockWriteGuard<'a, T> { +impl Drop for RwLockWriteGuard<'_, T> { fn drop(&mut self) { self.__lock.poison.done(&self.__poison); self.__lock.write_unlock(); diff --git a/src/sync/spsc.rs b/src/sync/spsc.rs index 698a90c9..9043c3e0 100644 --- a/src/sync/spsc.rs +++ b/src/sync/spsc.rs @@ -34,7 +34,7 @@ impl<'a, T> Park<'a, T> { } } -impl<'a, T> Drop for Park<'a, T> { +impl Drop for Park<'_, T> { fn drop(&mut self) { // wait the kernel finish while self.wait_kernel.load(Ordering::Relaxed) { @@ -45,13 +45,13 @@ impl<'a, T> Drop for Park<'a, T> { pub struct DropGuard<'a, 'b, T>(&'b Park<'a, T>); -impl<'a, 'b, T> Drop for DropGuard<'a, 'b, T> { +impl Drop for DropGuard<'_, '_, T> { fn drop(&mut self) { self.0.wait_kernel.store(false, Ordering::Relaxed); } } -impl<'a, T> EventSource for Park<'a, T> { +impl EventSource for Park<'_, T> { // register the coroutine to the park fn subscribe(&mut self, co: CoroutineImpl) { // the queue could dropped if unpark by other thread @@ -249,9 +249,9 @@ pub fn channel() -> (Sender, Receiver) { (Sender::new(a.clone()), Receiver::new(a)) } -/// ///////////////////////////////////////////////////////////////////////////// -/// Sender -/// ///////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Sender +//////////////////////////////////////////////////////////////////////////////// impl Sender { fn new(inner: Arc>) -> Sender { @@ -275,9 +275,9 @@ impl fmt::Debug for Sender { } } -/// ///////////////////////////////////////////////////////////////////////////// -/// Receiver -/// ///////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Receiver +//////////////////////////////////////////////////////////////////////////////// impl Receiver { fn new(inner: Arc>) -> Receiver { @@ -306,7 +306,7 @@ impl Receiver { } } -impl<'a, T> Iterator for Iter<'a, T> { +impl Iterator for Iter<'_, T> { type Item = T; fn next(&mut self) -> Option { @@ -314,7 +314,7 @@ impl<'a, T> Iterator for Iter<'a, T> { } } -impl<'a, T> Iterator for TryIter<'a, T> { +impl Iterator for TryIter<'_, T> { type Item = T; fn next(&mut self) -> Option { diff --git a/src/timeout_list.rs b/src/timeout_list.rs index ada2978e..66e79f55 100644 --- a/src/timeout_list.rs +++ b/src/timeout_list.rs @@ -34,7 +34,7 @@ pub const fn ns_to_dur(ns: u64) -> Duration { #[allow(dead_code)] #[inline] pub const fn ns_to_ms(ns: u64) -> u64 { - (ns + NANOS_PER_MILLI - 1) / NANOS_PER_MILLI + ns.div_ceil(NANOS_PER_MILLI) } #[inline]