Intro
Extension is .rs
Use cargo to create projects in rust .... it is simpler and much faster.
For a new project :
cargo new Project1
cargo build compiles the code and then sets up the dependencies.
cargo run compiles and runs the code in src/main.rs
cargo check checks for errors.
cd src
rustfmt main.rs
The above formats code ..
It is important to have a main.rs file in the src folder which then should have the main function.
Variables in rust
There are two explicit and implicit variables.
!! Name shadowing ?
For constants, write the name of the constant in uppercase, separated by underscores and also you are supposed to specify the type of the constant.
Data Types
Primitive data types.
There are two : Scalar and compound data types.
Scalar Types
Floating point(f32)
integer(u32).
Booleans(bool)
Simply a true(1) or false(0) value.
Characters / char type(char)
Stores a single character, any character and is supposed to be surrounded by single quotations.
// char type
let letter : char = 'a';
Compound Types.
They are tuple and array
Tuples
Symbolized by ().
Are immutable , a sequence
Also a sub topic is accessing elements in a tuple and printing them out, accessed by their index.
Example :
fn main() {
// Getting element at first(0) index.
let tup: (i32, bool, char) = (1, true, 's');
println!("{}", tup.0);
}
Arrays
Symbolized by [].
They should have the same element inside them.
User Input
Prelude - preloaded basic functionality.
A crate is a package or a library in Rust.