diff --git a/examples/word-count-cls/src/lib.rs b/examples/word-count-cls/src/lib.rs index 1ba68ecd..9fde5c25 100644 --- a/examples/word-count-cls/src/lib.rs +++ b/examples/word-count-cls/src/lib.rs @@ -8,11 +8,11 @@ extern crate rayon; use std::fs::File; use std::io::prelude::*; -use rayon::prelude::*; use pyo3::prelude::*; +use rayon::prelude::*; -use pyo3::py::methods as pymethods; use pyo3::py::class as pyclass; +use pyo3::py::methods as pymethods; use pyo3::py::modinit as pymodinit; #[pyclass(dict)] @@ -23,10 +23,9 @@ struct WordCounter { #[pymethods] impl WordCounter { - #[new] fn __new__(obj: &PyRawObject, path: String) -> PyResult<()> { - obj.init(|t| WordCounter {path, token: t}) + obj.init(|t| WordCounter { path, token: t }) } fn search(&self, py: Python, search: String) -> PyResult { @@ -46,12 +45,13 @@ impl WordCounter { } } - fn matches(word: &str, search: &str) -> bool { let mut search = search.chars(); for ch in word.chars().skip_while(|ch| !ch.is_alphabetic()) { match search.next() { - None => { return !ch.is_alphabetic(); } + None => { + return !ch.is_alphabetic(); + } Some(expect) => { if ch.to_lowercase().next() != Some(expect) { return false; @@ -73,15 +73,14 @@ fn wc_line(line: &str, search: &str) -> i32 { } fn wc_sequential(lines: &str, search: &str) -> i32 { - lines.lines() - .map(|line| wc_line(line, search)) - .fold(0, |sum, line| sum + line) + lines + .lines() + .map(|line| wc_line(line, search)) + .fold(0, |sum, line| sum + line) } fn wc_parallel(lines: &str, search: &str) -> i32 { - lines.par_lines() - .map(|line| wc_line(line, search)) - .sum() + lines.par_lines().map(|line| wc_line(line, search)).sum() } #[pymodinit(_word_count)] diff --git a/examples/word-count/src/lib.rs b/examples/word-count/src/lib.rs index 76c7c180..2a936649 100644 --- a/examples/word-count/src/lib.rs +++ b/examples/word-count/src/lib.rs @@ -7,8 +7,8 @@ extern crate rayon; use std::fs::File; use std::io::prelude::*; -use rayon::prelude::*; use pyo3::prelude::*; +use rayon::prelude::*; use pyo3::py::modinit as pymodinit; @@ -16,7 +16,9 @@ fn matches(word: &str, search: &str) -> bool { let mut search = search.chars(); for ch in word.chars().skip_while(|ch| !ch.is_alphabetic()) { match search.next() { - None => { return !ch.is_alphabetic(); } + None => { + return !ch.is_alphabetic(); + } Some(expect) => { if ch.to_lowercase().next() != Some(expect) { return false; @@ -38,20 +40,18 @@ fn wc_line(line: &str, search: &str) -> i32 { } fn wc_sequential(lines: &str, search: &str) -> i32 { - lines.lines() - .map(|line| wc_line(line, search)) - .fold(0, |sum, line| sum + line) + lines + .lines() + .map(|line| wc_line(line, search)) + .fold(0, |sum, line| sum + line) } fn wc_parallel(lines: &str, search: &str) -> i32 { - lines.par_lines() - .map(|line| wc_line(line, search)) - .sum() + lines.par_lines().map(|line| wc_line(line, search)).sum() } #[pymodinit(_word_count)] fn init_mod(py: Python, m: &PyModule) -> PyResult<()> { - #[pyfn(m, "search")] fn search(py: Python, path: String, search: String) -> PyResult { let mut file = File::open(path)?;