-
Setting Up the Environment
- Installing Rust using
rustup
. - Using
cargo
(Rust’s package manager) for creating and managing projects. - Basic commands:
cargo new
,cargo build
,cargo run
,cargo test
.
- Installing Rust using
-
Variables and Mutability
- Declaring variables with
let
. - Understanding immutability by default (
let x = 5
). - Using
mut
for mutable variables (let mut x = 5
).
- Declaring variables with
-
Basic Data Types
- Scalar types:
i32
,f64
,bool
,char
. - Compound types:
tuples
andarrays
. - String types:
String
and&str
.
- Scalar types:
-
Functions
- Defining functions (
fn
keyword). - Function parameters and return types.
- Expressions vs. statements in functions.
- Defining functions (
-
Control Flow
- Conditional statements:
if
,else
,else if
. - Loops:
loop
,while
, andfor
. - Using
break
andcontinue
in loops.
- Conditional statements:
-
Ownership
- Understanding the concept of ownership.
- The stack vs. the heap.
- Move semantics (values vs. references).
- Memory safety without a garbage collector.
-
Borrowing and References
- Immutable references (
&T
). - Mutable references (
&mut T
). - Rules of borrowing (one mutable or many immutable references).
- Immutable references (
-
Slices
- Slicing arrays and strings with
[start..end]
. - Understanding slice types (
&[T]
,&str
).
- Slicing arrays and strings with
-
Enums and Pattern Matching
- Defining enums.
- Using
match
expressions to handle different enum variants. - Using
if let
for simple matches.
-
Structs
- Defining and using structs.
- Tuple structs and unit-like structs.
- Implementing methods for structs using
impl
.
-
Error Handling
- Using
Result<T, E>
andOption<T>
. - Pattern matching on
Result
andOption
. - Propagating errors using
?
.
- Using
-
Traits
- Defining traits (similar to interfaces in other languages).
- Implementing traits for structs and enums.
- Common traits:
Debug
,Clone
,PartialEq
,Default
.
-
Modules and Crates
- Organizing code using modules (
mod
keyword). - Using external crates with
Cargo.toml
.
- Organizing code using modules (
-
The Standard Library
- Common collections:
Vec
,HashMap
,Option
,Result
. - String handling and conversions.
- File I/O basics (
std::fs
,std::io
).
- Common collections:
-
Notifications
You must be signed in to change notification settings - Fork 0
vixhnuchandran/rust
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Basics of rust.