CroftSoft / Library / Tutorials

Rust Project Setup

2023 Jul 24 Mon

David Wallace Croft



In recommended reading order

Project Setup

  1. Install Visual Studio Code (VS Code)
    • You will want to install this before you install git
  2. Install git
    • When it prompts you to select your editor, choose VS Code
  3. Install Rust
    • If you previously installed Rust, you can update it:
    rustup update
  4. Install the following VS Code extensions
  5. Use cargo to make the project directory cargo new project-name
  6. Test your setup cd project-name/ cargo run
  7. Open VS Code code .
  8. Add properties to the package section of your Cargo manifest file Cargo.toml [package] authors = ["First Middle Last <>"] # Use the categories from categories = ["category-name"] description = "project description" edition = "2021" homepage = "" # keywords = ["keyword"] # Remark this line out if your project is not open source license = "MIT" name = "project-name" # Change this value to true when you publish to publish = false readme = "" # Remark this line out if your project is not in a code repository repository = "" version = "0.1.0"
  9. Make a file in your project root directory # Project Name - Project description ## Usage - cd project-name/ - cargo run ## History - Initial release: YYYY-MM-DD
  10. Make a rustfmt.toml in your project root directory # array_width = 1 # condense_wildcard_suffixes = true fn_params_layout = "Vertical" # group_imports = "StdExternalCrate" hard_tabs = false # imports_layout = "HorizontalVertical" match_block_trailing_comma = true # max_width = 80 merge_derives = true newline_style = "Unix" # normalize_comments = true remove_nested_parens = true single_line_if_else_max_width = 0 # single_line_let_else_max_width = 0 struct_lit_width = 0 struct_variant_width = 0 tab_spaces = 2 use_field_init_shorthand = true use_try_shorthand = true # version = "Two" # wrap_comments = true
  11. If your project is open source, make a LICENSE.txt file MIT License Copyright (c) [year] [copyright-holder-name] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  12. Commit your code changes git add . git commit -m "Rust project setup"
  13. Push to your remote code repository git push

© 2022-2023 CroftSoft Inc

- Books
- Code
- Courses
- Links
- Media
- Software
- Tutorials
CroftSoft Web