mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-06 10:05:45 -08:00
Rust implementation of 91_Train
This commit is contained in:
41
91_Train/rust/src/main.rs
Normal file
41
91_Train/rust/src/main.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use std::process;//allows for some better error handling
|
||||
|
||||
mod lib; //allows access to lib.rs
|
||||
use lib::Config;
|
||||
|
||||
/// main function
|
||||
/// responsibilities:
|
||||
/// - Calling the command line logic with the argument values
|
||||
/// - Setting up any other configuration
|
||||
/// - Calling a run function in lib.rs
|
||||
/// - Handling the error if run returns an error
|
||||
fn main() {
|
||||
//greet user
|
||||
welcome();
|
||||
|
||||
// set up other configuration
|
||||
let mut config = Config::new().unwrap_or_else(|err| {
|
||||
eprintln!("Problem configuring program: {}", err);
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
// run the program
|
||||
if let Err(e) = lib::run(&mut config) {
|
||||
eprintln!("Application Error: {}", e); //use the eprintln! macro to output to standard error
|
||||
process::exit(1); //exit the program with an error code
|
||||
}
|
||||
|
||||
//end of program
|
||||
println!("THANKS FOR PLAYING!");
|
||||
}
|
||||
|
||||
/// print the welcome message
|
||||
fn welcome() {
|
||||
println!("
|
||||
Train
|
||||
CREATIVE COMPUTING MORRISTOWN, NEW JERSEY
|
||||
|
||||
|
||||
TIME - SPEED DISTANCE EXERCISE
|
||||
");
|
||||
}
|
||||
Reference in New Issue
Block a user