diff options
| author | a14m <[email protected]> | 2021-04-03 02:15:09 +0200 |
|---|---|---|
| committer | a14m <[email protected]> | 2021-04-03 02:15:09 +0200 |
| commit | d690299c83b28fc380c5eb37f4e978e6a6411758 (patch) | |
| tree | d4bdf8d404fc1db6735fccd5d84179e095908be0 | |
| parent | c6271541765b06c8437491e012de19da08b0ab3e (diff) | |
Add missing docs
| -rw-r--r-- | CLI/rust/src/game_of_life.rs | 2 | ||||
| -rw-r--r-- | CLI/rust/src/game_of_life/opts.rs | 12 | ||||
| -rw-r--r-- | CLI/rust/src/main.rs | 1 |
3 files changed, 15 insertions, 0 deletions
diff --git a/CLI/rust/src/game_of_life.rs b/CLI/rust/src/game_of_life.rs index 2534bd0..18cb1ab 100644 --- a/CLI/rust/src/game_of_life.rs +++ b/CLI/rust/src/game_of_life.rs @@ -1,3 +1,5 @@ +//! Game of Life module for generating the CLI app, validating the options +//! and starting the simulation use clap::{crate_authors, crate_version, App, Arg}; /// Options module for validations and Opts struct diff --git a/CLI/rust/src/game_of_life/opts.rs b/CLI/rust/src/game_of_life/opts.rs index f32c4a8..7431b2c 100644 --- a/CLI/rust/src/game_of_life/opts.rs +++ b/CLI/rust/src/game_of_life/opts.rs @@ -8,6 +8,7 @@ use mocktopus::macros::mockable; pub(crate) mod validators; #[derive(Debug, Clone)] +/// Parsed options for generating a Game of Life simulation pub(crate) struct Opts { pub seed: usize, pub input: Option<String>, @@ -20,6 +21,17 @@ pub(crate) struct Opts { #[cfg_attr(test, mockable)] impl Opts { + /// Parse args, set the defaults for the dynamic options (like `seed`, `width`, `height`) + /// and validate the conflicting options (same live/dead cell configured). + /// + /// The dynamic options that can be set are: + /// - `seed` is set to random if it's not provided. + /// - `width` is set to the current terminal screen width when not provided. + /// - `height` is set to the current terminal screen height -2 when not provided. + /// + /// The parsed options are typed into the correct types used (from strings) + /// and validated to make sure that they work together (live/dead cells must be different) + /// and the delay between renders must be a positive integer (milliseconds). pub fn from(args: ArgMatches) -> Result<Opts, Error> { // Set the seed to a random generated number as default if not provided let rnd = thread_rng().gen_range(0..1_000_000); diff --git a/CLI/rust/src/main.rs b/CLI/rust/src/main.rs index a831dd8..d1af26f 100644 --- a/CLI/rust/src/main.rs +++ b/CLI/rust/src/main.rs @@ -1,5 +1,6 @@ mod game_of_life; +/// Create and run a Game of Life simulations fn main() { let opts = game_of_life::opts::Opts::from(game_of_life::app().get_matches()) .unwrap_or_else(|e| e.exit()); |
