Rust+Programming+for+Beginners+Simplified+Version True
Rust+Programming+for+Beginners+Simplified+Version True
Ascendance.dev ©
“Special Forces for Science and Knowledge”
-Arthur L.
Rust Programming for Beginners Simpli-
fied Version ©
Index
14 Rust Compilation
16 Rust Installation
20 Cargo
22 Data Types
26 Scalar Types
27 Bit Concept
28 Integer Types
30 Large Integers
32 Floating-point numbers
34 Numeric Operations
36 Hexadecimals
38 Octal Numbers
40 Variables and Mutability
42 The ‘let’ keyword
44 The ‘const’ keyword
10 Ascendance.dev
Index
11
Symbols used in this book
12
Symbols used in this book
Mind Map
Concept
Theory
Code
Question
13
Rust Compilation
• Rust is a systems programming language that aims for safety, performance, and
concurrency. To make a simple Rust project, you have to write the Rust code,
compile it, and then run the compiled binary. We’ll use the basic “Hello, World”
program to walk through the compilation process.
Now that the code is compiled, you can execute the binary generated in the previ-
ous step. Run the following command:
```
./main
```
On Windows:
```
main.exe
14 Ascendance.dev
Rust Compilation
You should see the output "Hello, World!" printed in your terminal. Con-
gratulations! You have successfully written, compiled, and executed a
Rust program.
15
Rust Installation
16 Ascendance.dev
Rust Installation
Mac
Run the command on terminal (get a C compiler):
$ xcode-select --install
Windows
You’ll need Visual Studio 2022
• “Desktop Development with C++”
• The Windows 10 or 11 SDK
• The English language pack component
Troubleshoot
Get Rust installed version on terminal:
$ rustc --version
Update
$ rustup update
Uninstall
$ rustup self uninstall
17
Rust installation
• The rustup tool is used for installing and manag-
ing Rust.
Cargo is the default package manager and build tool for the
Rust programming language. It helps developers manage
their project’s dependencies, compile source code, run tests,
and distribute their compiled applications easily. Essentially,
Cargo streamlines the entire development process in Rust,
allowing programmers to focus more on coding.
20 Ascendance.dev
Cargo
2. `cargo run`: This command not only builds the project but also
immediately runs the compiled binary. It is particularly useful
during development because it simplifies the process of testing
your code.
21
Data Types
Scalar Types:
• Integers (whole numbers)
• Floating-point numbers (decimals)
• Booleans (true/false)
• Characters (individual letters/symbols)
24 Ascendance.dev
Data Types
25
Scalar Types
26 Ascendance.dev
Bit Concept
27
Integer Types
28 Ascendance.dev
Integer Types
File name: main.rs
$ cargo run
Output:
29
Large integers
30 Ascendance.dev
Large integers
For example, Rust has a type called `i64`, which uses 64 bits,
and it can store positive and negative whole numbers. The larg-
est number it can store is 2^63-1, which is a huge number but
not as huge as 99e100 (which is a 1 followed by 100 zeroes).
Similarly, Rust has other types like `i128` for even larger whole
numbers, and `u128` for even larger non-negative whole num-
bers. However, none of these can store numbers as large as
99e100.
If you need to work with really big numbers, you’ll need to use
some special types that can grow as needed. These types are
not included by default in Rust and you’ll either need to cre-
ate them yourself, or use a package that someone else already
made, like the `num` crate.
31
Floating-point numbers
32 Ascendance.dev
Floating-point numbers
File name: main.rs
$ cargo run
33
Numeric Operations
34 Ascendance.dev
Numeric Operations
File name: main.rs
$ cargo run
35
Hexadecimals
36 Ascendance.dev
Hexadecimals
File name: main.rs
$ cargo run
37
Octal numbers
38 Ascendance.dev
Octal numbers
File name: main.rs
$ cargo run
39
Variables and Mutability
The `let` keyword
The `const` keyword
The `mut` keyword
The `let
` let`` keyword
42 Ascendance.dev
The `let
` let`` keyword
File name: main.rs
$ cargo run
43
The `const
` const`` keyword
44 Ascendance.dev
The `const
` const`` keyword
File name: main.rs
$ cargo run
45
The `mut
` mut`` keyword
46 Ascendance.dev
The `mut
` mut`` keyword
File name: main.rs
$ cargo run
47
Shadowing
48 Ascendance.dev
Shadowing
File name: main.rs
$ cargo run
49
Booleans
50 Ascendance.dev
Booleans
File name: main.rs
$ cargo run
51
Characters
52 Ascendance.dev
Characters
File name: main.rs
$ cargo run
53
Tuple Type
54 Ascendance.dev
Tuple Type
File name: main.rs
$ cargo run
55
Tuple Type
56 Ascendance.dev
Tuple Type
File name: main.rs
$ cargo run
57
Arrays
58 Ascendance.dev
Arrays
File name: main.rs
$ cargo run
59
Functions
60 Ascendance.dev
Functions
File name: main.rs
$ cargo run
61
Cargo
Cargo is the default package manager and build tool for the
Rust programming language. It helps developers manage
their project’s dependencies, compile source code, run tests,
and distribute their compiled applications easily. Essentially,
Cargo streamlines the entire development process in Rust,
allowing programmers to focus more on coding.
62 Ascendance.dev
Cargo
2. `cargo run`: This command not only builds the project but also
immediately runs the compiled binary. It is particularly useful
during development because it simplifies the process of testing
your code.
63
Comments
Example:
```rust
let x = 5; // assigns value 5 to variable x
```
64 Ascendance.dev
Comments
File name: main.rs
$ cargo run
65
Control Flow
66 Ascendance.dev
Control Flow
• if/else if expressions
• while loops
• and for loops.
• for loops
67
If-else if expressions
68 Ascendance.dev
If-else if expressions
File name: main.rs
$ cargo run
69
While loop
70 Ascendance.dev
While loop
File name: main.rs
$ cargo run
71
For loop
72 Ascendance.dev
For loop
File name: main.rs
$ cargo run
73
This is the end of this journey there are advanced Rust concepts
and this book only is an intro, hope you find this useful, we focus a
lot on the learning experience.
Concepts like: borrowing, packages, crates, modules, tests, mod-
ules, lists, vectors, Strings, Error Handling, Generic Types, Traits,
Tests, Reading Files, I/O, and much more willbe covered on our
next book: “Intermediate Rust Programming”.
We are working hard to create advanced books in Rust!
Thanks for reading!
Protect Nature.
Rust Programming for Beginners Simpli-
fied Version ©