Skip to content

Commit

Permalink
Don't use nightly, just use rayon
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Jul 15, 2022
1 parent 64a6046 commit bfa9cdd
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
toolchain: stable
components: clippy
- uses: Swatinem/rust-cache@v1
- name: Install JS dependencies
Expand Down
101 changes: 101 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ regex = "1"
html-escape = "0.2"
toml = "0.5"
lazy_static = "1.4"
rayon = {version = "1.5", default-features = false}

[dev-dependencies]
tempfile = "3"
4 changes: 0 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// TODO: remove this once Rust 1.63 is released
#![feature(scoped_threads)]
#![allow(stable_features)]

use std::{io, process};

use clap::{Parser, Subcommand};
Expand Down
14 changes: 7 additions & 7 deletions src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{
fs,
path::{Path, PathBuf},
process::Command,
thread,
};

use anyhow::{bail, Context, Result};
Expand Down Expand Up @@ -228,15 +227,16 @@ impl Preprocessor for QuizProcessor {
};
processor.copy_js_files()?;

thread::scope(|s| {
fn for_each_mut<'scope, 'a: 'scope, 'b: 'scope, 'c: 'scope>(
s: &'a thread::Scope<'scope, '_>,
processor: &'b QuizProcessorRef,
items: impl IntoIterator<Item = &'c mut BookItem>,
// TODO: use std::thread::Scope once that gets stabilized
rayon::scope(|s| {
fn for_each_mut<'scope, 'proc: 'scope, 'item: 'scope>(
s: &rayon::Scope<'scope>,
processor: &'proc QuizProcessorRef,
items: impl IntoIterator<Item = &'item mut BookItem>,
) {
for item in items {
if let BookItem::Chapter(chapter) = item {
s.spawn(|| {
s.spawn(|_| {
let chapter_path = processor.src_dir.join(chapter.path.as_ref().unwrap());
let chapter_dir = chapter_path.parent().unwrap();
processor
Expand Down

0 comments on commit bfa9cdd

Please sign in to comment.