Rust is a memory-safe programming language designed for safe concurrency. It started in 2006 as a personal project of Graydon Hoare before his employer, Mozilla, started sponsoring it in 2009. Mozilla officially introduced it to the world in 2010.
That is enough for an introduction! You may already read the same information about Rust somewhere. So, let us cut to the chase and head straight to learning Rust and enjoy it!
This tutorial is for those who have experience but are new to Rust. We assume the readers have some programming experience in other programming languages and know some basic computer science concepts.
Rust Environment Setup
This tutorial uses Rust 1.53.0.
There are two ways to install Rust on Windows 10 – through rustup-init.exe and curl within the Windows Subsystem for Linux. This post uses that .exe file.
IDEs for Rust Language
There are 2 IDEs available for Rust – Intellij IDE (using the Rust plugin) and Visual Studio Code.
Rust Language Basics
How To Declare And Use Variables In Rust
Variables in Rust are similar to variables in other high-level programming languages, and how we declare and use them are pretty straight-forward. There are several types of variables, and their declaration may differ from each other.
A data type simply refers to the kind of data. A numeric value 1 is a type of data, and a string “1” is another type of data. Rust has a predefined list of core data types that we can build upon to create our custom data types.
- Rust – How to create Two Dimensional Array Example
- Rust Array Size Limit To 32 No More In 1.47.0 Release
Custom Data Types
- This is still a work-in-progress.
- This is still a work-in-progress.
Cargo.toml dev-dependencies and dependencies
In any codebase, some codes are not for the end-users. Meaning, they do not become part of the final application – be it for QA or the production environment. They are codes for testing (e.g., unit tests) and building the app (or library). If there are codes that do not finally go to the end-users, there are also libraries. Read More.
Rust Immutable And Mutable Variables
The E0384 error is one of the common errors programmers new to Rust will face. By default, variables are immutable in Rust. Having immutable variables helps up write concurrent codes and avoid common problems that come along with concurrency. Read More.
Rust Switch Statements Examples Using Match
Rust does not have a switch keyword but it has the match construct that works like a switch statement in our languages. Generally, the match can run codes or return a single value. It cannot do both at the same time. Let us go through some examples that use the Rust match construct. Read More.
Async Fn and Await Example in Rust That Will Open Your Mind
This post shows code examples that use async, async fn, and await for asynchronous processing. For demonstration purposes, our codes use the futures crate just to block the main function until the asynchronous function completes execution. Read More.
How to get Keys and Values from HashMap
In Rust, we can store key and value pairs using HashMap. This post shows how to store and extract the keys and values from a HashMap using the functions iter(), keys(), values(), get(), and unwrap(). Read More.
Check if a key exists in HashMap Examples
This post shows how to check if a key exists in a HashMap in Rust. As we know, Rust has the HashMap struct, which is part of its Collections library that we can use to store key-value pairs. Read More.
Rust And XML
Write XML Tags using Closure in Rust – No Need to Write Element End Tags
Did you miss writing out an XML element end tag in your Rust codes? Even when you have the best tools, this kind of mistake is not hard to make, and working with XML files is always ugly. We can improve the way we code, though. There is a convenient way to avoid these errors in Rust using Closure. Read More.
Rust And Actix-Web
REST API with Rust, Actix-web, and PostgreSQL – Part 1, 2, and 3
This is a three-part post that demonstrates a simple example of a REST API with Rust, Actix-web, and PostgreSQL – Part 1, Part 2, Part 3.
Return JSON Responses from Actix-web
This post briefly demonstrates how to return JSON responses from a web application written using Actix-web. Read More.
Rust And Rocket Web Framework
Rocket Web Framework Goes Stable
Rust framework Rocket goes stable starting with version 0.5 and Rust 1.45.0. No doubt, it is one of the best frameworks out there. However, it requires Rust Nightly. When I started learning Rust, I needed to choose between Actix-Web and Rocket. Finally, I chose Actix-Web because I had Rust Stable installed. Read More.
Rust Stable And Rocket 0.5 Latest Development Codes
As posted in Rust Framework Rocket Goes Stable, Rocket will be compatible with Rust Stable, starting with version 0.5. It is almost September, and any time soon, we will have the new release. For those who cannot wait because of excitement, we can already use the latest Rocket codes from the master branch for non-production codes. Read More.
Rust Find Duplicate Files With The Same Digests
This post shows how to find duplicate files in Rust with the same digests. The codes display list of duplicate files under the same digest. Read More.