This directory contains all the materials one need know to get started with Rust programming.
The main objective of this workshop are:
- Get an hands on programming experience with Rust Lang
- Learn in details about the Rust Library, community and tools ecosystem
- Syntax and keywords in Rust
- Concept of ownership and borrowing to understand memory safety & management
- Developing Macros
- Error handling in Rust
- Concurrency & parallelism
- Package management using Cargo tool
- Famous Rust tools like clippy, Rustfmt, Rustup etc
- Live demos of web development, FFI to understand different applications
Follow the instruction below
- Open the terminal (Ctrl + Alt + T)
- Make sure you have internet connection
- Type or copy paste the following command
curl https://sh.rustup.rs -sSf | sh
- Press 1 which is the default installation
- To check if rust is installed properly or not type the following command rustc --version
- Try also cargo --version
- Go to https://win.rustup.rs/ This will download rustup-init.exe
- Double click and start the installation
- Follow from step 4 of the installation instruction of Debian distribution instruction set
If you have git installed in your system, fire your terminal and clone the repo with this following command:
git clone https://github.com/vigneshwerd/DevfestYangon.git
else you can download the zip version of the project
- rustup features:
rustup update stable
rustup self update
rustup install nightly
rustup run nightly rustc --version
rustup default nightly
rustup update
- rustfmy installation:
rustup install nightly
cargo new --bin sample_rust_project
cd sample_rust_project
cargo install rustfmt-nightly
// Magic
cargo fmt
- rust-clippy tool
rustup default nightly
// changes in cargo.toml
[dependencies]
clippy = {version = "*", optional = true}
[features]
default = []
cargo install clippy
// main.rs or code
#![feature(plugin)]
#![plugin(clippy)]
#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]
To run standalone rust scripts:
rustc -A warnings code_script_name.rs
To run Cargo projects:
cd /path_to_repo/cargo_projects/
cargo run
- Why are macros useful?
- Macro is a useful way to avoid repeating code.
- Macros allow you to define special syntax for a specific purpose.
- What's this some(T)?
None and Some are the variants of the enum, that is, a value with type Option can either be a None, or it can be a Some containing a value of type T.
- What's the difference between &str and &'static str?
String is the dynamic heap string type, like Vec: use it when you need to own or modify your string data.
str is an immutable1 sequence of UTF-8 bytes of dynamic length somewhere in memory.
A &str is made up of two components: a pointer to some bytes, and a length, this reference is normally called a 'string slice'
Making a string literal which has type: &'static str, where 'static lifetime is the longest possible lifetime, and lasts for the lifetime of the running program.
- What is varible shadowing?
when the first variable is shadowed by the second, which means that the second variable’s value is what we’ll see when we use the variable.
- How is a closure different from a function?
You can create the closure in one place, and then call the closure to evaluate it in a different context. Unlike functions, closures are able to capture values from the scope in which they are called.
- Difference between static & const?
They’re similar to constants, but static items aren’t inlined upon use. This means that there is only one instance for each value, and it’s at a fixed location in memory.
- What is a hashmap?
In computing, a hash table (hash map) is a data structure which implements an associative array abstract data type, a structure that can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.
- Inheritance in Rust?
Rust does not have multiple inheritance, or even inheritance. However, it does have traits. If the people who implemented structs A and B were considerate enough to describe their interfaces with traits TraitA and TraitB, then you can describe the isomorphism each way with impl TraitA for B and impl TraitB for A, then any variable of type A or type B can be treated as implementing both TraitA and TraitB.
- Rust by example
- FAQ's
- Rust official book
- Online Rust playground
- Awesome crates for different verticals
- Constructor in Rust
Raise an issue if you faced any issues setting up this project.