- // We clone the counter for the first thread, which increments it by 2 every 15ms.
- let counter1 = counter.clone();
- let handle1 = thread::spawn(move || {
- for _ in 0..10 {
- thread::sleep_ms(15);
- counter1.increment(2);
- }
- });
-
- // The second thread increments the counter by 3 every 20ms.
- let counter2 = counter.clone();
- let handle2 = thread::spawn(move || {
- for _ in 0..10 {
- thread::sleep_ms(20);
- counter2.increment(3);
+// Now, we can sort, e.g., an vector of numbers.
+fn sort_nums(data: &mut Vec<i32>) {
+ sort(&mut data[..]);
+}
+
+// ## Arrays
+fn sort_array() {
+ let mut array_of_data: [f64; 5] = [1.0, 3.4, 12.7, -9.12, 0.1];
+ sort(&mut array_of_data);
+}
+
+// ## External Dependencies
+
+
+// I disabled the following module (using a rather bad hack), because it only compiles if `docopt` is linked.
+// Remove the attribute of the `rgrep` module to enable compilation.
+#[cfg(feature = "disabled")]
+pub mod rgrep {
+ // Now that `docopt` is linked, we can first add it to the namespace with `extern crate` and then import shorter names with `use`.
+ // We also import some other pieces that we will need.
+ extern crate docopt;
+ use self::docopt::Docopt;
+ use part13::{run, Options, OutputMode};
+ use std::process;
+
+ // The `USAGE` string documents how the program is to be called. It's written in a format that `docopt` can parse.
+ static USAGE: &'static str = "
+Usage: rgrep [-c] [-s] <pattern> <file>...
+
+Options:
+ -c, --count Count number of matching lines (rather than printing them).
+ -s, --sort Sort the lines before printing.
+";
+
+ // This function extracts the rgrep options from the command-line arguments.
+ fn get_options() -> Options {
+ // This parses `argv` and exit the program with an error message if it fails. The code is taken from the [`docopt` documentation](http://burntsushi.net/rustdoc/docopt/). <br/>
+ let args = Docopt::new(USAGE).and_then(|d| d.parse()).unwrap_or_else(|e| e.exit());
+ // Now we can get all the values out.
+ let count = args.get_bool("-c");
+ let sort = args.get_bool("-s");
+ let pattern = args.get_str("<pattern>");
+ let files = args.get_vec("<file>");
+ if count && sort {
+ println!("Setting both '-c' and '-s' at the same time does not make any sense.");
+ process::exit(1);