// to complete the job: Which files to work on, which pattern to look for, and how to output. <br/>
// Besides just printing all the matching lines, we will also offer to count them, or alternatively to sort them.
#[derive(Clone,Copy)]
-enum OutputMode {
+pub enum OutputMode {
Print,
SortAndPrint,
Count,
}
use self::OutputMode::*;
-struct Options {
- files: Vec<String>,
- pattern: String,
- output_mode: OutputMode,
+pub struct Options {
+ pub files: Vec<String>,
+ pub pattern: String,
+ pub output_mode: OutputMode,
}
},
SortAndPrint => {
// We are asked to sort the matching lines before printing. So let's collect them all in a local vector...
- let data: Vec<String> = in_channel.iter().collect();
+ let mut data: Vec<String> = in_channel.iter().collect();
// ...and implement the actual sorting later.
unimplemented!()
}
// With the operations of the three threads defined, we can now implement a function that performs grepping according
// to some given options.
-fn run(options: Options) {
+pub fn run(options: Options) {
// We move the `options` into an `Arc`, as that's what the thread workers expect.
let options = Arc::new(options);
handle3.join().unwrap();
}
-// Now we have all the pieces together for testing our `rgrep` with some hard-coded options.
+// Now we have all the pieces together for testing our rgrep with some hard-coded options.
pub fn main() {
let options = Options {
files: vec!["src/part10.rs".to_string(), "src/part11.rs".to_string(), "src/part12.rs".to_string()],
run(options);
}
-// **Exercise 12.1**: Change `rgrep` such that it prints now only the matching lines, but also the name of the file
+// **Exercise 12.1**: Change rgrep such that it prints now only the matching lines, but also the name of the file
// and the number of the line in the file. You will have to change the type of the channels from `String` to something
// that records this extra information.