This repository is dedicated to contain code written with Cargo while self-learning coding in Rust.
All executable projects are prefixed with learn_, followed by topic number [0-9]_[0-9]_ incrementally and topic covered in the project. Please use code responsibly.
To run all project in this repository, make sure you already installed cargo by running the cargo --version in the terminal.
# check the version of cargo
$ cargo --version
# navigate to a specific project folder
$ cd .\learn_1_1_hello_world\
# compile
$ cargo build
# execute
$ cargo runProf. Hussam AI-Hertani
Teacher in Electronics and Information Technology program
Heritage College, Gatineau, Quebec, Canada
The Rust Programming Language: https://doc.rust-lang.org/book/title-page.html
Rust by Example: https://doc.rust-lang.org/rust-by-example/
The Cargo Book: https://doc.rust-lang.org/cargo/index.html
fn main() {
// Display the message "Hello, world!"
todo!("Display the message by using the todo!() macro");
}fn main() {
// Our main function does one task: show a message
// println! displays the input "Hello, world!" to the screen
println!("Hello, world!");
}// Specify the data type "char"
let character_1: char = 'S';
let character_2: char = 'f';
// Compiler interprets a single item in quotations as the "char" data type
let smiley_face = '😃';
// Compiler interprets a series of items in quotations as a "str" data type and creates a "&str" reference
let string_1 = "miley ";
// Specify the data type "str" with the reference syntax "&str"
let string_2: &str = "ace";
println!("{} is a {}{}{}{}.", smiley_face, character_1, string_1, character_2, string_2);# update rustup
$ rustup self update
# set nightly version to default for academic purpose
$ rustup default nightly
# Install Rust Language Server (RSL)
$ rustup component add rls --toolchain nightly
$ rustup component add rust-analysis --toolchain nightly
$ rustup component add rust-src --toolchain nightly
# see the basics of rustc compiler
$ rustc -h
# see the basics of cargo (package management tool)
$ cargo -h- Rust manages code based on
crateandmod; Think ofcrateas projects, eachcrateis a complete unit for compiling, delivering an.exeor.libfile.
Inside eachcrate,modis placed as namespaces. - By default, the
rustccompiler introduces dependance to thestdlib; In addition to that, the compiler automatically adds anusestatement for eachcratedeveloped by the user:use std::prelude::*;for commonly usedtype,trait,functionandmacro.
The source code of thepreludemodule is placed in/src/libstd/prelude/directory. - The line I type the most is
#![allow(unused)]
