Skip to content

Commit

Permalink
Apply rust 2018 idioms
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed May 22, 2020
1 parent 29d5678 commit 4acfd0b
Show file tree
Hide file tree
Showing 99 changed files with 438 additions and 681 deletions.
6 changes: 0 additions & 6 deletions README.md
Expand Up @@ -90,12 +90,6 @@ Add this to your `Cargo.toml`:
crossbeam = "0.7"
```

Next, add this to your crate:

```rust
extern crate crossbeam;
```

## Compatibility

Crossbeam supports stable Rust releases going back at least six months,
Expand Down
7 changes: 0 additions & 7 deletions crossbeam-channel/README.md
Expand Up @@ -44,13 +44,6 @@ Add this to your `Cargo.toml`:
crossbeam-channel = "0.4"
```

Next, add this to your crate:

```rust
#[macro_use]
extern crate crossbeam_channel;
```

## Compatibility

Crossbeam Channel supports stable Rust releases going back at least six months,
Expand Down
3 changes: 0 additions & 3 deletions crossbeam-channel/benchmarks/crossbeam-channel.rs
@@ -1,6 +1,3 @@
extern crate crossbeam;
extern crate crossbeam_channel;

use crossbeam_channel::{bounded, unbounded, Receiver, Select, Sender};

mod message;
Expand Down
5 changes: 1 addition & 4 deletions crossbeam-channel/benchmarks/crossbeam-deque.rs
@@ -1,7 +1,4 @@
extern crate crossbeam;
extern crate crossbeam_deque as deque;

use crate::deque::{Steal, Worker};
use crossbeam_deque::{Steal, Worker};
use std::thread;

mod message;
Expand Down
2 changes: 0 additions & 2 deletions crossbeam-channel/benchmarks/flume.rs
@@ -1,5 +1,3 @@
extern crate crossbeam;

mod message;

const MESSAGES: usize = 5_000_000;
Expand Down
3 changes: 0 additions & 3 deletions crossbeam-channel/benchmarks/futures-channel.rs
@@ -1,6 +1,3 @@
extern crate crossbeam;
extern crate futures;

use futures::channel::mpsc;
use futures::executor::ThreadPool;
use futures::prelude::*;
Expand Down
3 changes: 0 additions & 3 deletions crossbeam-channel/benchmarks/lockfree.rs
@@ -1,6 +1,3 @@
extern crate crossbeam;
extern crate lockfree;

use lockfree::channel;

mod message;
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-channel/benchmarks/message.rs
Expand Up @@ -6,7 +6,7 @@ const LEN: usize = 1;
pub struct Message(pub [usize; LEN]);

impl fmt::Debug for Message {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("Message")
}
}
Expand Down
3 changes: 0 additions & 3 deletions crossbeam-channel/benchmarks/mpmc.rs
@@ -1,6 +1,3 @@
extern crate crossbeam;
extern crate mpmc;

use std::thread;

mod message;
Expand Down
2 changes: 0 additions & 2 deletions crossbeam-channel/benchmarks/mpsc.rs
@@ -1,5 +1,3 @@
extern crate crossbeam;

use std::sync::mpsc;

mod message;
Expand Down
2 changes: 0 additions & 2 deletions crossbeam-channel/benchmarks/segqueue.rs
@@ -1,5 +1,3 @@
extern crate crossbeam;

use crossbeam::queue::SegQueue;
use std::thread;

Expand Down
2 changes: 0 additions & 2 deletions crossbeam-channel/examples/fibonacci.rs
@@ -1,7 +1,5 @@
//! An asynchronous fibonacci sequence generator.

extern crate crossbeam_channel;

use std::thread;

use crossbeam_channel::{bounded, Sender};
Expand Down
6 changes: 1 addition & 5 deletions crossbeam-channel/examples/matching.rs
Expand Up @@ -42,11 +42,7 @@
//! }
//! ```

#[macro_use]
extern crate crossbeam_channel;
extern crate crossbeam_utils;

use crossbeam_channel::bounded;
use crossbeam_channel::{bounded, select};
use crossbeam_utils::thread;

fn main() {
Expand Down
6 changes: 1 addition & 5 deletions crossbeam-channel/examples/stopwatch.rs
@@ -1,14 +1,10 @@
//! Prints the elapsed time every 1 second and quits on Ctrl+C.

#[macro_use]
extern crate crossbeam_channel;
extern crate signal_hook;

use std::io;
use std::thread;
use std::time::{Duration, Instant};

use crossbeam_channel::{bounded, tick, Receiver};
use crossbeam_channel::{bounded, select, tick, Receiver};
use signal_hook::iterator::Signals;
use signal_hook::SIGINT;

Expand Down
40 changes: 19 additions & 21 deletions crossbeam-channel/src/channel.rs
Expand Up @@ -9,7 +9,9 @@ use std::time::{Duration, Instant};

use crate::context::Context;
use crate::counter;
use crate::err::{RecvError, RecvTimeoutError, SendError, SendTimeoutError, TryRecvError, TrySendError};
use crate::err::{
RecvError, RecvTimeoutError, SendError, SendTimeoutError, TryRecvError, TrySendError,
};
use crate::flavors;
use crate::select::{Operation, SelectHandle, Token};

Expand Down Expand Up @@ -134,11 +136,9 @@ pub fn bounded<T>(cap: usize) -> (Sender<T>, Receiver<T>) {
/// Using an `after` channel for timeouts:
///
/// ```
/// # #[macro_use]
/// # extern crate crossbeam_channel;
/// # fn main() {
/// use std::time::Duration;
/// use crossbeam_channel::{after, unbounded};
/// use crossbeam_channel::{after, select, unbounded};
///
/// let (s, r) = unbounded::<i32>();
/// let timeout = Duration::from_millis(100);
Expand Down Expand Up @@ -187,12 +187,10 @@ pub fn after(duration: Duration) -> Receiver<Instant> {
/// Using a `never` channel to optionally add a timeout to [`select!`]:
///
/// ```
/// # #[macro_use]
/// # extern crate crossbeam_channel;
/// # fn main() {
/// use std::thread;
/// use std::time::{Duration, Instant};
/// use crossbeam_channel::{after, never, unbounded};
/// use crossbeam_channel::{after, select, never, unbounded};
///
/// let (s, r) = unbounded();
///
Expand Down Expand Up @@ -582,7 +580,7 @@ impl<T> Clone for Sender<T> {
}

impl<T> fmt::Debug for Sender<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("Sender { .. }")
}
}
Expand Down Expand Up @@ -941,7 +939,7 @@ impl<T> Receiver<T> {
///
/// assert_eq!(v, [1, 2, 3]);
/// ```
pub fn iter(&self) -> Iter<T> {
pub fn iter(&self) -> Iter<'_, T> {
Iter { receiver: self }
}

Expand Down Expand Up @@ -977,7 +975,7 @@ impl<T> Receiver<T> {
///
/// assert_eq!(v, [1, 2]);
/// ```
pub fn try_iter(&self) -> TryIter<T> {
pub fn try_iter(&self) -> TryIter<'_, T> {
TryIter { receiver: self }
}

Expand Down Expand Up @@ -1040,7 +1038,7 @@ impl<T> Clone for Receiver<T> {
}

impl<T> fmt::Debug for Receiver<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("Receiver { .. }")
}
}
Expand Down Expand Up @@ -1092,22 +1090,22 @@ impl<T> IntoIterator for Receiver<T> {
///
/// assert_eq!(v, [1, 2, 3]);
/// ```
pub struct Iter<'a, T: 'a> {
pub struct Iter<'a, T> {
receiver: &'a Receiver<T>,
}

impl<'a, T> FusedIterator for Iter<'a, T> {}
impl<T> FusedIterator for Iter<'_, T> {}

impl<'a, T> Iterator for Iter<'a, T> {
impl<T> Iterator for Iter<'_, T> {
type Item = T;

fn next(&mut self) -> Option<Self::Item> {
self.receiver.recv().ok()
}
}

impl<'a, T> fmt::Debug for Iter<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl<T> fmt::Debug for Iter<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("Iter { .. }")
}
}
Expand Down Expand Up @@ -1144,20 +1142,20 @@ impl<'a, T> fmt::Debug for Iter<'a, T> {
///
/// assert_eq!(v, [1, 2]);
/// ```
pub struct TryIter<'a, T: 'a> {
pub struct TryIter<'a, T> {
receiver: &'a Receiver<T>,
}

impl<'a, T> Iterator for TryIter<'a, T> {
impl<T> Iterator for TryIter<'_, T> {
type Item = T;

fn next(&mut self) -> Option<Self::Item> {
self.receiver.try_recv().ok()
}
}

impl<'a, T> fmt::Debug for TryIter<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl<T> fmt::Debug for TryIter<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("TryIter { .. }")
}
}
Expand Down Expand Up @@ -1206,7 +1204,7 @@ impl<T> Iterator for IntoIter<T> {
}

impl<T> fmt::Debug for IntoIter<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("IntoIter { .. }")
}
}
Expand Down
22 changes: 11 additions & 11 deletions crossbeam-channel/src/err.rs
Expand Up @@ -116,13 +116,13 @@ pub struct TryReadyError;
pub struct ReadyTimeoutError;

impl<T> fmt::Debug for SendError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"SendError(..)".fmt(f)
}
}

impl<T> fmt::Display for SendError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"sending on a disconnected channel".fmt(f)
}
}
Expand Down Expand Up @@ -150,7 +150,7 @@ impl<T> SendError<T> {
}

impl<T> fmt::Debug for TrySendError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
TrySendError::Full(..) => "Full(..)".fmt(f),
TrySendError::Disconnected(..) => "Disconnected(..)".fmt(f),
Expand All @@ -159,7 +159,7 @@ impl<T> fmt::Debug for TrySendError<T> {
}

impl<T> fmt::Display for TrySendError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
TrySendError::Full(..) => "sending on a full channel".fmt(f),
TrySendError::Disconnected(..) => "sending on a disconnected channel".fmt(f),
Expand Down Expand Up @@ -216,13 +216,13 @@ impl<T> TrySendError<T> {
}

impl<T> fmt::Debug for SendTimeoutError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"SendTimeoutError(..)".fmt(f)
}
}

impl<T> fmt::Display for SendTimeoutError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
SendTimeoutError::Timeout(..) => "timed out waiting on send operation".fmt(f),
SendTimeoutError::Disconnected(..) => "sending on a disconnected channel".fmt(f),
Expand Down Expand Up @@ -280,15 +280,15 @@ impl<T> SendTimeoutError<T> {
}

impl fmt::Display for RecvError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"receiving on an empty and disconnected channel".fmt(f)
}
}

impl error::Error for RecvError {}

impl fmt::Display for TryRecvError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
TryRecvError::Empty => "receiving on an empty channel".fmt(f),
TryRecvError::Disconnected => "receiving on an empty and disconnected channel".fmt(f),
Expand Down Expand Up @@ -325,7 +325,7 @@ impl TryRecvError {
}

impl fmt::Display for RecvTimeoutError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
RecvTimeoutError::Timeout => "timed out waiting on receive operation".fmt(f),
RecvTimeoutError::Disconnected => "channel is empty and disconnected".fmt(f),
Expand Down Expand Up @@ -362,15 +362,15 @@ impl RecvTimeoutError {
}

impl fmt::Display for TrySelectError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"all operations in select would block".fmt(f)
}
}

impl error::Error for TrySelectError {}

impl fmt::Display for SelectTimeoutError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"timed out waiting on select".fmt(f)
}
}
Expand Down
12 changes: 6 additions & 6 deletions crossbeam-channel/src/flavors/array.rs
Expand Up @@ -143,12 +143,12 @@ impl<T> Channel<T> {
}

/// Returns a receiver handle to the channel.
pub fn receiver(&self) -> Receiver<T> {
pub fn receiver(&self) -> Receiver<'_, T> {
Receiver(self)
}

/// Returns a sender handle to the channel.
pub fn sender(&self) -> Sender<T> {
pub fn sender(&self) -> Sender<'_, T> {
Sender(self)
}

Expand Down Expand Up @@ -559,12 +559,12 @@ impl<T> Drop for Channel<T> {
}

/// Receiver handle to a channel.
pub struct Receiver<'a, T: 'a>(&'a Channel<T>);
pub struct Receiver<'a, T>(&'a Channel<T>);

/// Sender handle to a channel.
pub struct Sender<'a, T: 'a>(&'a Channel<T>);
pub struct Sender<'a, T>(&'a Channel<T>);

impl<'a, T> SelectHandle for Receiver<'a, T> {
impl<T> SelectHandle for Receiver<'_, T> {
fn try_select(&self, token: &mut Token) -> bool {
self.0.start_recv(token)
}
Expand Down Expand Up @@ -600,7 +600,7 @@ impl<'a, T> SelectHandle for Receiver<'a, T> {
}
}

impl<'a, T> SelectHandle for Sender<'a, T> {
impl<T> SelectHandle for Sender<'_, T> {
fn try_select(&self, token: &mut Token) -> bool {
self.0.start_send(token)
}
Expand Down

0 comments on commit 4acfd0b

Please sign in to comment.