What is the naming convention for functions and methods in Rust?
snake_case
What is the naming convention for local variables in Rust?
snake_case
What is the naming convention for types and traits in rust?
UpperCamelCase
How would you make a new directory for a projects folder with a hello_world folder in that directory with Powershell?
What is proper file naming convention in rust?
Ex: hello_world.rs
How do you write a function in Rust with “Hello, world!” as the output?
fn main() {
println!("Hello, world!");
}What is always the first piece of code that runs in every executable Rust program?
fn main() {
}What is Cargo?
(another name for libraries is dependencies)
How do you check the version of Cargo in rust?
cargo –version
How would you create a new project using cargo?
$ cargo new hello_cargo $ cd hello_cargo
What is the Cargo.toml file in Rust?
How do you build and/or run Rust programs with cargo?
What kind of variables are made by default in Rust?
let apples = 5; // immutable
How do we make a variable immutable in Rust?
let mut bananas = 5; // mutable
How do you define a string in Rust?
String::new() is a function that returns a new instance of a string
* Ex:
let mut guess = String::new();
What is the standard library for input/output in Rust and how do you include it in the program?
use std::io;
What does the following code do?
io::stdin()
.read_line(&mut guess)How do you handle situations where the read_line operation fails?
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
How do you check to see if your program compiles but you do not want to create an executable to run the program?
What is the advantage to using this command over cargo build?
$ cargo check
Break down what each line of this simple program does:
Lets break it down by line:
**Line 1: **Input/output library in Rust that allows us to obtain user input and print the output. io comes from rusts standard library, std
**Lines 4 & 6: ** Simple print statements
**Line 8: ** Creates a mutable variable guess and calls the function String
**Line 1: **
**Line 1: **
**Line 1: **