Having studied computer science, I think this is time to learn one language for good. Although I have a lot of experience using Java, I want to pivot to the security side and Rust seems to be the perfect choice (for me). There are a lot of languages but since I want to start from the very beginning, why not choose a language which is fast, efficient and memory-safe.
I have no idea what to expect from Rust but will document the journey.
My main sources for help, reference and documentation will be Rust by Example and Black Hat Rust.
- Installing Rust - rustup
- Hello World
- Formatted Print
- Implementing
fmt::Display
for the first time
- Getting more comfortable with
traits
1.2.2 - Display - Finishing with some cool
formatting
tricks - 1.2.3 Formatting
- Playing with primitives and writing functions -
primitives
2 - Primitives - 2.1 Literals and Operators
- 2.2 Tuples
- Slices are similar to array but... - 2.3 - Arrays and Slices
- Custom types - Starting with structures - 3.1 - Structures
- Completed the activities in
3.1 - Structures
- Learnt about 3.2 Enums
- Did some coding using
use
for enums. 3.2.1 use
- About 3.3 Constants
- Coming back to 3.2.2. C-like enums
- Finished the 1. Getting Started section.
- Useful tips about
cargo
here - 1.3 Hello,Cargo!
Takeaway tips
- We can create a project using
cargo new
. - We can build a project using
cargo build
. - We can build and run a project in one step using
cargo run
. - We can build a project without producing a binary to check for errors using
cargo check
. - Instead of saving the result of the build in the same directory as our code, Cargo stores it in the
target/debug
directory.
- Started the module 3. Common Programming Concepts section.
- Studying 3.1 Variables and Mutability
Takeaway tips
- Variable is immutable by default.
- However we can use
mut
to make a variable mutable. - Constants aren’t just immutable by default—they’re always immutable.
- Constants are valid for the entire time a program runs, within the scope in which they were declared.
- Learnt about
shadowing
. - Completed the 3.1 Variables and Mutability section.
Takeaway tips
- Difference between
mut
andshadowing
is that because we’re effectively creating a new variable when we use thelet
keyword again. - First variable is shadowed by the second, which means that the second variable is what the compiler will see when you use the name of the variable.
- Learning about
Data types
. - Currently on 3.2. Data Types section.
Takeaway tips
- Rust is a statically typed language, which means that it must know the types of all variables at compile time.
- A scalar type represents a single value. Rust has four primary scalar types: integers, floating-point numbers, Booleans, and characters.
- Finished
3.2. Data Types
.
Takeaway tips
- Rust has two primitive compound types: tuples and array.
- A
tuple
is a general way of grouping together a number of values with a variety of types into one compound type. Tuples have a fixed length: once declared, they cannot grow or shrink in size. - Unlike a tuple, every element of an
array
must have the same type. Unlike arrays in some other languages, arrays in Rust have a fixed length.
- Started 3.3. Functions
Takeaway tips
- In function signatures, you must declare the type of each parameter.
- Statements are instructions that perform some action and do not return a value.
- Expressions evaluate to a value.
- Expressions do not include ending semicolons. If you add a semicolon to the end of an expression, you turn it into a statement, and it will then not return a value.
- Finished 3.3. Functions
- Finished 3.4. Comments
- Started 3.5. Control Flow
Takeaway tips
- You must be explicit and always provide
if
with a Boolean as its condition. - In the
if
,else if
andelse
blocks, if the types are mismatched, it will throw an error.
- Continued 3.5. Control Flow
- Tried
if
andwhile
loop
Takeaway tips
- We can use
break your_return_value_here
to break from the loop and return a value. - Nothing else! It is similar to loops in
JAVA
orC++
.