Course plan.
- Installation
- Introduction to
cargo
- Introduction to Rust Syntax:
- Variables:
let
,mut
- Functions:
fn
String
,str
,format!
,println!
- Arrays:
Vec
,slice
- HashMap (or Dictionary):
HashMap
- Ownership, Borrowing
- Control Flow:
if
,if let
,match
- Loops:
loop
,while
,while let
,for
, iterators
- Variables:
- Write
fn hello(name:&str) -> String
- will return: "Hello -name-!"
- Write
fn make_it_double(num:i32) -> i32
- will return: 4 when given 2
- Write
fn multiply_pi(num:f32) -> f32
- will multiply the num with Pi(π) and return the result.
- Introduction to:
- Enum
- Result
- Option
- Struct
- Traits
- Macro
- Write
fn to_letter_grade(num:u8) -> String
- will return "AA" for 100, "BA" for 89 etc.
- Write
fn log(level:LogLevel, msg:&str) -> String
- LogLevel is an enum. Prints logs with level tag:
[WARN]: This is warning log.
- LogLevel is an enum. Prints logs with level tag:
- Write
Person {name:String, age: u8, gender: Gender}
- Gender is an enum. Also implement
Display
trait forPerson
with format:{name}({age})
ex:Emin(24)
.
- Gender is an enum. Also implement
- Write
display!(Person, "{}({})", name, gender)
- This macro will implement Display trait for Person with format you provide.
- Crates, Tests
- Crates:
use
,mod
,pub mod
, create your own crate - Usage of an example crate: serde
- Writing Tests
- Crates:
- Make
Person { name:String, age:u8, gender:Gender::Male }
struct transformable to JSON string with serde & serde_json crate:- Example:
{"name":"Emin","age":24,"gender":"Male"}
- Example:
- Write 3 test cases for first task.
- Write jsonified output of the
Person
struct toperson.json
file.- Writing to a file examples: https://doc.rust-lang.org/std/fs/struct.File.html
- Closure
- Iterator
filter
map
nth
count
enumerate
- Fibonacci series with Iterator trait
- Generics
- Lifetimes
- Filter even numbers on a list
- Multiply all numbers with 2 on a list
- Implement an iterator which implements this algorithm:
f(n) = f(n-1) * f(n-2)
andn > 0
- Thread, Mutex, Atomic, Channel
- Fearless Concurrency
- thread
- thread w/ mutex
- thread w/ atomic
- thread w/ channel
- Calculate nth prime number with threads.
- Find every given prime number on an array
&[u32]
with spawning a thread for each of it, and send the result withstd::sync::mpsc::Sender
.
- Find every given prime number on an array
- Introduction to asynchronous programming:
async-std
.async
,Future
- Example: async TCP server
- Write tcp chat server with
async-std
- Send each message to other connections.
- Use Arc<Mutex<>> to share "user list" between the tasks.
- Use 22222 port to make us test it easily.