concept main() in category rust

appears as: main()
Rust in Action

This is an excerpt from Manning's book Rust in Action.

Attempting to compile Listing 1.7, “Example of a data race prevented by Rust (ch1/ch1-race/src/main.rs)” results in a large stampede of error messages. Rust will not allow multiple places of an application to have write access to data. Listing 1.7, “Example of a data race prevented by Rust (ch1/ch1-race/src/main.rs)” attempts to allow this in three places: once within the main thread running main() and once in each child thread created by thread::spawn().

  • Make sure that file includes a main() function
  • Listing 10. 15. The main() function of render-hex (ch10/ch10-render-hex/src/main.rs). It parses command-line arguments and manages the SVG generation pipeline.
    fn main() {
        let args = env::args().collect::<Vec<String>>();          #1
        let input = args.get(1).unwrap();                         #1
        let default_filename = format!("{}.svg", input);          #1
        let save_to = args.get(2).unwrap_or(&default_filename);   #1
    
        let operations = parse(input);                            #2
        let path_data = convert(&operations);                     #2
        let document = generate_svg(path_data);                   #2
        svg::save(save_to, &document).unwrap();                   #2
    }