Skip to content

Commit

Permalink
Introduce prelude and change docs/code to use it
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Feb 23, 2016
1 parent 8b0bedb commit 4bea07e
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ example, to compute the sum of the squares of a sequence of integers,
one might write:

```rust
use rayon::par_iter::*;
use rayon::prelude::*;
fn sum_of_squares(input: &[i32]) -> i32 {
input.par_iter()
.map(|&i| i * i)
Expand All @@ -47,15 +47,15 @@ fn sum_of_squares(input: &[i32]) -> i32 {
Or, to increment all the integers in a slice, you could write:

```rust
use rayon::par_iter::*;
use rayon::prelude::*;
fn increment_all(input: &mut [i32]) {
input.par_iter_mut()
.for_each(|p| *p += 1);
}
```

To use parallel iterators, first import the traits by adding something
like `use rayon::par_iter::*` to your module. You can then call
like `use rayon::prelude::*` to your module. You can then call
`par_iter` and `par_iter_mut` to get a parallel iterator. Like a
[regular iterator][], parallel iterators work by first constructing a
computation and then executing it. See the
Expand Down
2 changes: 1 addition & 1 deletion benches/factorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate rayon;
extern crate test;

use num::{One, BigUint};
use rayon::par_iter::*;
use rayon::prelude::*;
use rayon::Configuration;
use std::ops::Mul;

Expand Down
2 changes: 1 addition & 1 deletion benches/pythagoras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate rayon;
extern crate test;

use num::Integer;
use rayon::par_iter::*;
use rayon::prelude::*;
use rayon::Configuration;
use std::f64::INFINITY;
use std::ops::Add;
Expand Down
2 changes: 1 addition & 1 deletion demo/nbody/src/nbody.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// [1]: https://github.com/IntelLabs/RiverTrail/blob/master/examples/nbody-webgl/NBody.js

use cgmath::{EuclideanVector, Point3, Vector, Vector3};
use rayon::par_iter::*;
use rayon::prelude::*;
use rand::{Rand, Rng};
use std::f64::consts::PI;

Expand Down
2 changes: 1 addition & 1 deletion neg-tests-compile/cannot_collect_filtermap_data.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate rayon;

use rayon::par_iter::*;
use rayon::prelude::*;

// zip requires data of exact size, but filter yields only bounded
// size, so check that we cannot apply it.
Expand Down
2 changes: 1 addition & 1 deletion neg-tests-compile/cannot_zip_filtered_data.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate rayon;

use rayon::par_iter::*;
use rayon::prelude::*;

// zip requires data of exact size, but filter yields only bounded
// size, so check that we cannot apply it.
Expand Down
2 changes: 1 addition & 1 deletion neg-tests-run/iter_panic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate rayon;

use rayon::*;
use rayon::par_iter::*;
use rayon::prelude::*;

// error-pattern:boom

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod api;
mod latch;
mod job;
pub mod par_iter;
pub mod prelude;
#[cfg(test)] mod test;
mod thread_pool;
mod util;
Expand Down
2 changes: 1 addition & 1 deletion src/par_iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! The `ParallelIterator` module makes it easy to write parallel
//! programs using an iterator-style interface. To get access to all
//! the methods you want, the easiest is to write `use
//! rayon::par_iter::*;` at the top of your module, which will import
//! rayon::prelude::*;` at the top of your module, which will import
//! the various traits and methods you need.
//!
//! The submodules of this module mostly just contain implementaton
Expand Down
11 changes: 11 additions & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! The rayon prelude imports the various `ParallelIterator` traits.
//! The intention is that one can include `use rayon::prelude::*` and
//! have easy access to the various traits and methods you will need.

pub use par_iter::IntoParallelIterator;
pub use par_iter::IntoParallelRefIterator;
pub use par_iter::IntoParallelRefMutIterator;
pub use par_iter::ParallelIterator;
pub use par_iter::BoundedParallelIterator;
pub use par_iter::ExactParallelIterator;
pub use par_iter::IndexedParallelIterator;

0 comments on commit 4bea07e

Please sign in to comment.