aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • Programming
  • Tools

Learn Rust In 2022

  • Aelia Vita
  • January 19, 2022
  • 4 minute read

If you’re going to explore Rust this year, download our free Rust cheat sheet, so you have a quick reference for the basics.

Rust is a relatively new programming language, and it’s already a popular one winning over programmers from all industries. Still, it’s also a language that builds on everything that’s come before. Rust wasn’t made in a day, after all, so even though there are concepts in Rust that seem wildly different from what you might have learned from Python, Java, C++, and so on, they all have a foundation in the same CPU and NUMA architecture you’ve always been (whether you know it or not) interacting with, and so some of what’s new in Rust feels somehow familiar.


Partner with aster.cloud
for your next big idea.
Let us know here.



From our partners:

CITI.IO :: Business. Institutions. Society. Global Political Economy.
CYBERPOGO.COM :: For the Arts, Sciences, and Technology.
DADAHACKS.COM :: Parenting For The Rest Of Us.
ZEDISTA.COM :: Entertainment. Sports. Culture. Escape.
TAKUMAKU.COM :: For The Hearth And Home.
ASTER.CLOUD :: From The Cloud And Beyond.
LIWAIWAI.COM :: Intelligence, Inside and Outside.
GLOBALCLOUDPLATFORMS.COM :: For The World's Computing Needs.
FIREGULAMAN.COM :: For The Fire In The Belly Of The Coder.
ASTERCASTER.COM :: Supra Astra. Beyond The Stars.
BARTDAY.COM :: Prosperity For Everyone.

Now, I’m not a programmer by trade. I’m impatient yet obsessive. If a language doesn’t help me get the results I want relatively quickly, I rarely find myself inspired to use it when I need to get something done. Rust tries to bring into balance two conflicting things: The modern computer’s need for secure and structured code, and the modern programmer’s desire to do less work while attaining more success.

Install Rust

The rust-lang.org website has great documentation on installing Rust, but usually, it’s as simple as downloading the sh.rustup.rs script and running it.

$ curl –proto ‘=https’ –tlsv1.2 -sSf https://sh.rustup.rs

$ less sh.rustup.sh

$ sh ./sh.rustup.rs

No classes

Rust doesn’t have classes and does not use the class keyword. Rust does have the struct data type, however, its purpose is to serve as a kind of template for a collection of data. So instead of creating a class to represent a virtual object, you can use a struct:

struct Penguin {
genus: String,
species: String,
extinct: bool,
classified: u64,
}

You can use this similar to how a class is used. For instance, once a Penguin struct is defined, you can create instances of it, and interact with that instance:

struct Penguin {
genus: String,
species: String,
extinct: bool,
classified: u64,
}fn main() {
let p = Penguin { genus: “Pygoscelis”.to_owned(),
species: “R adeliæ”.to_owned(),
extinct: false,
classified: 1841 };println!(“Species: {}”, p.species);
println!(“Genus: {}”, p.genus);
println!(“Classified in {}”, p.classified);
if p.extinct == true {
println!(“Sadly this penguin has been made extinct.”);
}

Read More  3 New Ways To Authorize Users To Your Private Workloads On Cloud Run

}

Using the impl data type in conjunction with the struct data type, you can implement a struct containing functions, and you can add inheritance and other class-like features.

Functions

Functions in Rust are a lot like functions in other languages. Each one represents a discreet set of tasks that you can call upon when needed. The primary function must be called main.

Functions are declared using the fn keyword, followed by the function’s name and any parameters the function accepts.

fn foo() {
let n = 8;
println!(“Eight is written as {}”, n);
}

Passing information from one function to another gets done with parameters. For instance, I’ve already created a Penguin class, and I’ve got an instance of a penguin as p, so passing the attributes of p from one function to another requires me to specify p as an accepted Penguin type for its destination function.

fn main() {
let p = Penguin { genus: “Pygoscelis”.to_owned(),
species: “R adeliæ”.to_owned(),
extinct: false, classified: 1841 };
printer(p);
}fn printer(p: Penguin) {
println!(“Species: {}”, p.species);
println!(“Genus: {}”, p.genus);
println!(“Classified in {}”, p.classified);
if p.extinct == true {
println!(“Sadly this penguin has been made extinct.”);
}
}

Variables 

Rust creates immutable variables by default. That means that a variable you create cannot be changed later. This code, humble though it may be, cannot be compiled:

fn main() {
let n = 6;
let n = 5;
}

However, you can declare a mutable variable with the keyword mut, so this code compiles successfully:

fn main() {
let mut n = 6;
println!(“Value is {}”, n);
n = 5;
println!(“Value is {}”, n);
}

Compiler 

The Rust compiler, at least in terms of its error messages, is one of the nicest compilers available. When you get something wrong in Rust, the compiler makes a sincere effort to tell you what you did wrong. I’ve actually learned many nuances of Rust (insofar as I understand any nuance of Rust) just by learning from compiler error messages. Even when an error message is too obscure to learn from directly, it’s almost always enough for an internet search to explain.

Read More  EiriniX Latest Project Contributed To Cloud Foundry Foundation

The easiest way to start a Rust program is to use cargo, the Rust package management and build system.

$ mkdir myproject
$ cd myproject
$ cargo init

This creates the basic infrastructure for a project, most notably a main.rs file in the src subdirectory. Open this file and paste in the example code I’ve generated for this article:

struct Penguin {
genus: String,
species: String,
extinct: bool,
classified: u64,
}fn main() {
let p = Penguin { genus: “Pygoscelis”.to_owned(), species: “R adeliæ”.to_owned(), extinct: false, classified: 1841 };
printer(p);
foo();
}fn printer(p: Penguin) {
println!(“Species: {}”, p.species);
println!(“Genus: {}”, p.genus);
println!(“Classified in {}”, p.classified);
if p.extinct == true {
println!(“Sadly this penguin has been made extinct.”);
}
}

fn foo() {
let mut n = 6;
println!(“Value is {}”, n);
n = 8;
println!(“Eight is written as {}”, n);
}

To compile, use the cargo build command:

<span class="co4">$ </span>cargo build

To run your project, execute the binary in the target subdirectory, or else just use cargo run:

$ cargo run
Species: R adeliæ
Genus: Pygoscelis
Classified in 1841
Value is 6
Eight is written as 8

Crates

Much of the convenience of any language comes from its libraries or modules. In Rust, libraries get distributed and tracked as “crates”. The crates.io website is a good registry of community crates.

To add a crate to your Rust project, list them in the Cargo.toml file. For instance, to install a random number function, I use the rand crate, with * serving as a wildcard to ensure that I get the latest version at compile time:

[package]
name = “myproject”
version = “0.1.0”
authors = [“Seth <[email protected]>”]
edition = “2022”[dependencies]
rand = “*”

Using it in Rust code requires a use statement at the top:

<span class="kw1">use</span> rand<span class="sy0">::</span><span class="me1">Rng</span><span class="sy0">;</span>

Some sample code that creates a random seed and then a random range:

fn foo() {
let mut rng = rand::thread_rng();
let mut n = rng.gen_range(1..99);println!(“Value is {}”, n);
n = rng.gen_range(1..99);
println!(“Value is {}”, n);
}

You can use cargo run to run it, which detects the code change and triggers a new build. The build process downloads the rand crate and all the crates that it, in turn, depends upon, compiles the code, and then runs it:

$ cargo run
Updating crates.io index
Downloaded ppv–lite86 v0.2.16
Downloaded 1 crate (22.2 KB) in 1.40s
Compiling libc v0.2.112
Compiling cfg–if v1.0.0
Compiling ppv–lite86 v0.2.16
Compiling getrandom v0.2.3
Compiling rand_core v0.6.3
Compiling rand_chacha v0.3.1
Compiling rand v0.8.4
Compiling rustpenguin v0.1.0 (/home/sek/Demo/rustpenguin)
Finished dev [unoptimized + debuginfo] target(s) in 13.97s
Running `target/debug/rustpenguin`Species: R adeliæ
Genus: Pygoscelis
Classified in 1841
Value is 70
Value is 35

Rust cheat sheet

Rust is a supremely pleasant language. Thanks to its integration with online registries, its helpful compiler, and its almost intuitive syntax, it feels appropriately modern.

Read More  PyCon 2019 | Take Back the Web with GraphQL

Make no mistake, though, it’s also a complex language, with strict data types, strongly scoped variables, and many built-in methods. Rust is worth looking at, and if you’re going to explore Rust, then you should download our free Rust cheat sheet, so you have a quick reference for the basics. The sooner you get started, the sooner you’ll know Rust. And, of course, you should practice often to avoid getting rusty.

This feature was originally appeared in opensource.com


For enquiries, product placements, sponsorships, and collaborations, connect with us at [email protected]. We'd love to hear from you!

Our humans need coffee too! Your support is highly appreciated, thank you!

Aelia Vita

Related Topics
  • Open Source
  • Programming Language
  • Rust programming
You May Also Like
View Post
  • Technology
  • Tools

IBM Launches Enterprise Advantage Service to Help Businesses Scale Agentic AI

  • January 19, 2026
aster-cloud-sms-pexels-tim-samuel-6697306
View Post
  • Programming
  • Software

Send SMS texts with Amazon’s SNS simple notification service

  • July 1, 2025
aster-cloud-website-pexels-goumbik-574069
View Post
  • Programming
  • Software

Host a static website on AWS with Amazon S3 and Route 53

  • June 27, 2025
notta-ai-header
View Post
  • Featured
  • Tools

Notta vs Fireflies: Which AI Transcription Tool Deserves Your Attention in 2025?

  • May 16, 2025
zedreviews-Apple-iPhone-16-Pro-finish-lineup-240909
View Post
  • Featured
  • Gears
  • Tech
  • Technology
  • Tools

Apple debuts iPhone 16 Pro and iPhone 16 Pro Max

  • September 10, 2024
zedreviews-Apple-AirPods-Active-Noise-Cancellation-240909
View Post
  • Featured
  • Gears
  • Tech
  • Technology
  • Tools

Apple introduces AirPods 4 and the world’s first all-in-one hearing health experience with AirPods Pro 2

  • September 10, 2024
Automation
View Post
  • Automation
  • Platforms
  • Tools

Automate Your Data Warehouse Migration To BigQuery With New Data Migration Tool

  • August 24, 2023
Developers | Software | Program | Engineering
View Post
  • Software Engineering
  • Technology
  • Tools

Top IDEs And Compilers For C++.

  • July 4, 2023

Stay Connected!
LATEST
  • digital-nomad-freelancer-worker-2151205464 1
    One paperwork problem – Get your Digital Nomad Visa employment documents fast from UK, EU or Singapore
    • June 16, 2026
  • 2
    Samsung Art Store Brings Art Basel to Homes Worldwide With New Curated Collection
    • June 15, 2026
  • 3
    You Do Not Need to Invest in the IPO of SpaceX, Anthropic, and OpenAI
    • June 10, 2026
  • 4
    The consequences of relying on AI for accurate news
    • June 10, 2026
  • 5
    Connecting AI agents with unstructured data using Google Cloud Storage MCP Servers
    • June 10, 2026
  • 6
    WWDC26: Apple unveils next generation of Apple Intelligence, Siri AI, powerful parental controls, and an expansive set of software improvements
    • June 8, 2026
  • 7
    IBM and Google Cloud Announce Strategic Partnership to Scale AI with Human Expertise and AI‑Powered Delivery
    • June 4, 2026
  • Data center 8
    Data Sovereignty in Spain. It’s Not Just About the Law, It’s About Efficiency
    • June 3, 2026
  • 9
    Ink vs Pixels. What you miss versus what you are actually missing.
    • June 1, 2026
  • 10
    Banks race to patch new cyber vulnerabilities, and other cybersecurity news
    • May 25, 2026
about
Hello World!

We are aster.cloud. We’re created by programmers for programmers.

Our site aims to provide guides, programming tips, reviews, and interesting materials for tech people and those who want to learn in general.

We would like to hear from you.

If you have any feedback, enquiries, or sponsorship request, kindly reach out to us at:

[email protected]
Most Popular
  • pope-leo-xiv-cq5dam-1500.844 1
    Pope Leo XIV to Publish First Encyclical on Artificial Intelligence and Human Dignity on 25 May
    • May 22, 2026
  • 2
    Portfolio to Clients, and is Strengthened by Ongoing Project Glasswing Work
    • May 20, 2026
  • reMarkable Paper Pure 3
    Everything The reMarkable Paper Pure Actually Does
    • May 14, 2026
  • 4
    Scaling cloud and AI: Microsoft Azure’s commitment to Europe’s digital future
    • May 11, 2026
  • Anthropic Institute 5
    Introducing The Anthropic Institute
    • March 11, 2026
  • /
  • Technology
  • Tools
  • About
  • Contact Us

Input your search keywords and press Enter.