diff --git a/src/fs/dir_builder.rs b/src/fs/dir_builder.rs index 0de230d..3064f7a 100644 --- a/src/fs/dir_builder.rs +++ b/src/fs/dir_builder.rs @@ -14,7 +14,7 @@ use crate::task::blocking; /// /// [`os::unix::fs::DirBuilderExt`]: ../os/unix/fs/trait.DirBuilderExt.html /// [`std::fs::DirBuilder`]: https://doc.rust-lang.org/std/fs/struct.DirBuilder.html -#[derive(Debug)] +#[derive(Debug, Default)] pub struct DirBuilder { /// Set to `true` if non-existent parent directories should be created. recursive: bool, diff --git a/src/fs/open_options.rs b/src/fs/open_options.rs index c6cc74a..252873c 100644 --- a/src/fs/open_options.rs +++ b/src/fs/open_options.rs @@ -290,6 +290,12 @@ impl OpenOptions { } } +impl Default for OpenOptions { + fn default() -> Self { + Self::new() + } +} + cfg_if! { if #[cfg(feature = "docs")] { use crate::os::unix::fs::OpenOptionsExt; diff --git a/src/io/stderr.rs b/src/io/stderr.rs index 64e0b18..e743e00 100644 --- a/src/io/stderr.rs +++ b/src/io/stderr.rs @@ -117,7 +117,7 @@ impl Write for Stderr { // Start the operation asynchronously. *state = State::Busy(blocking::spawn(async move { - let res = std::io::Write::write(&mut inner.stderr, &mut inner.buf); + let res = std::io::Write::write(&mut inner.stderr, &inner.buf); inner.last_op = Some(Operation::Write(res)); State::Idle(Some(inner)) })); diff --git a/src/io/stdout.rs b/src/io/stdout.rs index b7fee70..faf0c79 100644 --- a/src/io/stdout.rs +++ b/src/io/stdout.rs @@ -117,7 +117,7 @@ impl Write for Stdout { // Start the operation asynchronously. *state = State::Busy(blocking::spawn(async move { - let res = std::io::Write::write(&mut inner.stdout, &mut inner.buf); + let res = std::io::Write::write(&mut inner.stdout, &inner.buf); inner.last_op = Some(Operation::Write(res)); State::Idle(Some(inner)) })); diff --git a/src/net/udp/mod.rs b/src/net/udp/mod.rs index a750899..4588be1 100644 --- a/src/net/udp/mod.rs +++ b/src/net/udp/mod.rs @@ -391,14 +391,14 @@ impl UdpSocket { /// let mdns_addr = Ipv4Addr::new(224, 0, 0, 123); /// /// let socket = UdpSocket::bind("127.0.0.1:0").await?; - /// socket.join_multicast_v4(&mdns_addr, &interface)?; + /// socket.join_multicast_v4(mdns_addr, interface)?; /// # /// # Ok(()) }) } /// ``` - pub fn join_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> { + pub fn join_multicast_v4(&self, multiaddr: Ipv4Addr, interface: Ipv4Addr) -> io::Result<()> { self.watcher .get_ref() - .join_multicast_v4(multiaddr, interface) + .join_multicast_v4(&multiaddr, &interface) } /// Executes an operation of the `IPV6_ADD_MEMBERSHIP` type. @@ -435,10 +435,10 @@ impl UdpSocket { /// For more information about this option, see [`join_multicast_v4`]. /// /// [`join_multicast_v4`]: #method.join_multicast_v4 - pub fn leave_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> { + pub fn leave_multicast_v4(&self, multiaddr: Ipv4Addr, interface: Ipv4Addr) -> io::Result<()> { self.watcher .get_ref() - .leave_multicast_v4(multiaddr, interface) + .leave_multicast_v4(&multiaddr, &interface) } /// Executes an operation of the `IPV6_DROP_MEMBERSHIP` type. diff --git a/src/stream/stream/filter.rs b/src/stream/stream/filter.rs index 3fd5453..8ed282c 100644 --- a/src/stream/stream/filter.rs +++ b/src/stream/stream/filter.rs @@ -36,13 +36,11 @@ where let next = futures_core::ready!(self.as_mut().stream().poll_next(cx)); match next { - Some(v) => match (self.as_mut().predicate())(&v) { - true => Poll::Ready(Some(v)), - false => { - cx.waker().wake_by_ref(); - Poll::Pending - } - }, + Some(v) if (self.as_mut().predicate())(&v) => Poll::Ready(Some(v)), + Some(_) => { + cx.waker().wake_by_ref(); + Poll::Pending + } None => Poll::Ready(None), } } diff --git a/src/stream/stream/find.rs b/src/stream/stream/find.rs index 014c8b7..93624c0 100644 --- a/src/stream/stream/find.rs +++ b/src/stream/stream/find.rs @@ -36,13 +36,11 @@ where let item = futures_core::ready!(Pin::new(&mut *self.stream).poll_next(cx)); match item { - Some(v) => match (&mut self.p)(&v) { - true => Poll::Ready(Some(v)), - false => { - cx.waker().wake_by_ref(); - Poll::Pending - } - }, + Some(v) if (&mut self.p)(&v) => Poll::Ready(Some(v)), + Some(_) => { + cx.waker().wake_by_ref(); + Poll::Pending + } None => Poll::Ready(None), } } diff --git a/src/stream/stream/skip_while.rs b/src/stream/stream/skip_while.rs index a54b051..b1a8d9e 100644 --- a/src/stream/stream/skip_while.rs +++ b/src/stream/stream/skip_while.rs @@ -38,13 +38,12 @@ where match next { Some(v) => match self.as_mut().predicate() { - Some(p) => match p(&v) { - true => (), - false => { + Some(p) => { + if !p(&v) { *self.as_mut().predicate() = None; return Poll::Ready(Some(v)); } - }, + } None => return Poll::Ready(Some(v)), }, None => return Poll::Ready(None), diff --git a/src/sync/mutex.rs b/src/sync/mutex.rs index 8ae51ad..673eb83 100644 --- a/src/sync/mutex.rs +++ b/src/sync/mutex.rs @@ -10,7 +10,7 @@ use crate::future::Future; use crate::task::{Context, Poll, Waker}; /// Set if the mutex is locked. -const LOCK: usize = 1 << 0; +const LOCK: usize = 1; /// Set if there are tasks blocked on the mutex. const BLOCKED: usize = 1 << 1; diff --git a/src/sync/rwlock.rs b/src/sync/rwlock.rs index 36f475b..55a29fc 100644 --- a/src/sync/rwlock.rs +++ b/src/sync/rwlock.rs @@ -10,7 +10,7 @@ use crate::future::Future; use crate::task::{Context, Poll, Waker}; /// Set if a write lock is held. -const WRITE_LOCK: usize = 1 << 0; +const WRITE_LOCK: usize = 1; /// Set if there are read operations blocked on the lock. const BLOCKED_READS: usize = 1 << 1; diff --git a/src/task/block_on.rs b/src/task/block_on.rs index 2d49dca..f585693 100644 --- a/src/task/block_on.rs +++ b/src/task/block_on.rs @@ -69,12 +69,11 @@ where let future = task_local::add_finalizer(future); let future = async move { - let res = future.await; + future.await; trace!("block_on completed", { parent_id: parent_id, child_id: child_id, }); - res }; // Pin the future onto the stack. diff --git a/src/task/blocking.rs b/src/task/blocking.rs index 41177bc..8f4277c 100644 --- a/src/task/blocking.rs +++ b/src/task/blocking.rs @@ -135,7 +135,7 @@ fn random(n: u32) -> u32 { use std::num::Wrapping; thread_local! { - static RNG: Cell> = Cell::new(Wrapping(1406868647)); + static RNG: Cell> = Cell::new(Wrapping(1_406_868_647)); } RNG.with(|rng| { @@ -152,6 +152,6 @@ fn random(n: u32) -> u32 { // // Author: Daniel Lemire // Source: https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/ - ((x.0 as u64).wrapping_mul(n as u64) >> 32) as u32 + ((u64::from(x.0)).wrapping_mul(u64::from(n)) >> 32) as u32 }) } diff --git a/src/task/builder.rs b/src/task/builder.rs index 630876c..a43b42b 100644 --- a/src/task/builder.rs +++ b/src/task/builder.rs @@ -4,7 +4,7 @@ use crate::future::Future; use crate::io; /// Task builder that configures the settings of a new task. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct Builder { pub(crate) name: Option, } diff --git a/src/task/sleepers.rs b/src/task/sleepers.rs index a907175..4e70129 100644 --- a/src/task/sleepers.rs +++ b/src/task/sleepers.rs @@ -30,7 +30,7 @@ impl Sleepers { pub fn wait(&self) { let mut sleep = self.sleep.lock().unwrap(); - if self.notified.swap(false, Ordering::SeqCst) == false { + if !self.notified.swap(false, Ordering::SeqCst) { *sleep += 1; let _ = self.wake.wait(sleep).unwrap(); } @@ -38,7 +38,7 @@ impl Sleepers { /// Notifies one thread. pub fn notify_one(&self) { - if self.notified.load(Ordering::SeqCst) == false { + if !self.notified.load(Ordering::SeqCst) { let mut sleep = self.sleep.lock().unwrap(); if *sleep > 0 { diff --git a/src/task/task.rs b/src/task/task.rs index 8a1adde..ba808aa 100644 --- a/src/task/task.rs +++ b/src/task/task.rs @@ -122,7 +122,7 @@ impl TaskId { unsafe { TaskId(NonZeroU64::new_unchecked(id)) } } - pub(crate) fn as_u64(&self) -> u64 { + pub(crate) fn as_u64(self) -> u64 { self.0.get() } }