1. Installing Rust
2. The Basics
1. About This Section
3. Hello, World!
cargo new hello
fn main() {
println!("Hello, world!");
}
4. More about Visual Studio Code
5. Variables and Mutability
cargo new variables
cargo build
cargo run
fn main() {
let mut x = 5;
println!("the value of x is {}", x);
x = 6;
println!("the value of x is {}", x);
const SECONDS: i8 = 60;
println!("the value of SECONDS is {}", SECONDS);
}
6. Scalar Data Types
cargo new data_types
fn main() {
let x: i8 = 10;
println!("{}", x);
let _y: u8 = 10;
let decimal = 02_55;
let hex = 0xff;
let octal = 0o377;
let binary = 0b1111_1111;
print!("{},{},{},{}", decimal, hex, octal, binary);
let byte = b'A';
println!("{}", byte);
let x = 2.0;
let y: f32 = 1.0;
let t = true;
let f: bool = false;
let c = 'c';
println!("{}", c);
let a = 10;
let b = 4;
let remainder = a % b;
println!("{}", remainder);
}
7. Tuples