Back to Top

How To learn Rust Programming language In 10 Minutes

learn rust programming language

Today I am going to explain about a new programming language which is sponsored by Mozilla Research.

These are the topics and agenda of this article. You will get enough knowledge to write code in this programming language reading this article. As I always do, I am also sharing some basic code to get the idea of programming language.

  1. What is Rust?
  2. Why should I use Rust?
  3. Install Rust with rustup
  4. Cargo – Rust’s awesome package manager
  5. rustfmt – the Rust source code formatting tool
  6. Play with Rust: A short demo
  7. Datatype in Rust
  8. OwnerShip and Borrowing in Rust

What is Rust?

Rust is a new systems programming language designed for safety, concurrency, and speed. It was originally conceived by Graydon Hoare and is now developed by a team in Mozilla Research and the community.

Rust is blazingly fast and prevents almost all crashes. Rust is a Multi-paradigm, Functional, imperative, object-oriented programming language. It has Low-level and targets the same problem-space as C and C++ languages. Also, it is safe and pointer lifetimes guard against a lot of errors.

Rust provides memory safety and prevents segment fault and that is the same thing java provides. So what’s the difference? One thing which makes Rust programming language different from Java is ownership and borrowing concept. This programming language writes the particular value whatever you assign to the variable. It owns by that value only. You can’t use that. Once it is out of the box, is automatically destroyed.

I should probably call this language is “Ownership Oriented Language”. This is my own definition which is I actually observed in this language.

Why do we need a new system programming language?

Rust is open source System Programming language.A programmer doesn’t jump to another programming language if there are no advantages to use. Following points explain you that very well.

  • State or art programming language.
  • Solves a lot of common system programming bugs.
  • Cargo : Rust Package manager
  • Improving your toolkit
  • Self learning

Why should use Rust

Rust is a good choice when you’d choose C++. You can also say, “Rust is a systems programming language that pursuing the trifecta: safe, concurrent, and fast.” I would say, Rust is an ownership-oriented programming language.

Every language has some pro and cons and people choosing a language based on the requirement so every time before you choose any language, you need reasons for choosing the specific one. Here, the reason that I’ve looked into Rust at first.

  • Rust is new enough that you can write useful stuff that would have already existed in other languages. You can see Rust has a shorter learning curve. Rust doesn’t require any prior programming language. If you are newbie, you can easily digest Rust.
  • It gives a relatively familiar tool to the modern C++ developers, but in the much more consistent and reliable ways.
  • It is low-level enough that you take account of most resources.
  • It’s more like C++ and Go programming language, less like Node and Ruby
  • cargo is awesome. Managing crates just works as intended, which makes a whole lot of troubles you may have in other languages just vanish with a satisfying poof.
  • System programming language
  • Has great control like C/C++
  • Safety and expressive like python.

Every programming language has some unique features so first understand those feature once before you chose for your development. After you know these much about language, this is a time to set up the language.

How to install Rust?

There are three ways to setup Rust Programming language.

  1. Prebuilt binaries are available at
  2. Source code is available from GitHub
  3. Kits and resources are available from Rust India GitHub

It source code is available because it is open source programming language.

How to Install Rust with Rustup

If you want to develop an application, set up the programming language is the first step to go. First of all, go to and this is automatically recognize your operating system and suggest steps as per that.

Ubuntu / MacOS

Open your terminal (Ctrl + Alt +T). Enter the following command

curl -sSf | sh

If you get any error while installing Rust, you can ask your queries on Rust channel #rust-beginners which you can find out on that link Rust team will definitely reply over there to fix your error.

After installing Rust, check the version.Here is the command:

rustc --version

This is about Linux or Mac Installation. Let’s see Windows installation

Windows Installation

If you are using windows system and want to install Rust in windows, here is the step:

Go to

Once you open the URL, it will directly recognize the operating system you are using and give the option to install package.

This will download the rustup-init.exe file. Once file downloaded, Double click and start the installation. That’s very easy!!

Best things about Rust

  1. Strong type system and reduces a lot of common bugs in system programming langyage
  2. Borrowing and Ownership which provides Memory safety and Freedom from data races
  3. Zero Cost abstraction

What is Cargo and how it works?

One of the best thing about Rust is Cargo. Cargo is the Rust Package Manager(RPM). Nowadays, you can see every language provides package manager using which you can configure and manage packages. It is a tool that allows Rust projects to declare their various dependencies and ensure that you’ll always get a repeatable build.

To accomplish this goal, Cargo does four things:

  • Introduces two metadata files with various bits of project information.
  • Fetches and builds your project’s dependencies.
  • Invokes rustc or another build tool with the correct parameters to build your project.
  • Introduces conventions to make working with Rust projects easier.

If you want to submit your code to Rust community and other uses your package for that you can submit it to cargo.

How to create a new project?

Open the URL

create project in rust


A tool for formatting Rust code according to style guidelines

How to write a code in Rust with example?

A web interface for running Rust code. The interface can also be accessed in most Rust-related channels on To use Playbot in a public channel, address your message to it.

 playbot: println!("Hello, World"); 
-playbot:#rust-offtopic- Hello, World 
-playbot:#rust-offtopic- () playbot: 1+2+3 
-playbot:#rust-offtopic- 6

You can also private message Playbot your code to have it evaluated. In a private message, don’t preface the code with playbot’s nickname:

 /msg playbot println!("Hello, World");

Rust provides an online playground to run rust code. If you don’t want to setup Rust on your local system. You can test or write your code here

rust online editor

Here, I am going to show basic Hello World code in Rust. This is very simple!

fn main() {
 let greet = "world";
  println!("Hello {}!", greet);


rust hello world application

Complex Example:

Here I am going to show some arithmetic calculation. Let’s find out the average in Rust. You always needed the main function otherwise it will generate an error. Call your another function from the main.

fn avg(numbers: &[i32]) -> f32 {
    numbers.iter().sum::() as f32 / numbers.len() as f32
fn main() {
    let numbers = [1, 3, 5, 10, 33];
    println!("AVERAGE: {}", avg(&numbers));


rust average operation example

Primitive Types in Rust

Let’s see some primitives available in Rust and how to use them


bool data types return the true or false value.

fn main() {
    let bool_val: bool = true; 
    println!("Bool value is {}", bool_val);

bool primitive datatype in rust


char datatype is used for characters or nonnumeric values.

fn main() {
   let x_char: char = 'a';
   println!("x char is {}", x_char);

char primitive datatype in rust


fn main() {
    let num = 10;
    println!("Num is {}", num);
    let age: i32 = 40;
    println!("Age is {}", age);
    println!("Max i32 {}", ::max_value());
    println!("Max i32 {}", ::min_value());

i8 i16 i32 i64 isize primitive datatype in rust

4. Array

fn main() {
    let rand_array = [1, 2, 3]; // Defining an array
    println!("random array {:?}", rand_array);
    println!("random array 1st element {}", rand_array[0]); // indexing starts with 0
    println!("random array length {}", rand_array.len());
    println!("random array {:?}", &rand_array[1..3]); // last two elements

Complex Data Structure Example:

I am going to explain how to implement class and struct in Rust programming language. Here is the Example:

struct Circle {
    radius: f64,

impl Circle {
    fn area(&self) -> f64 {
        std::f64::consts::PI * (self.radius * self.radius)

fn main() {
    let c = Circle { radius: 2.0 };
    println!("Area {}", c.area());

struct in rust

Traits in Rust

A trait in Rust is a programming language feature that tells the Rust compiler about functionality a type must provide. Recall the impl keyword, used to call a function with method syntax:

  • Interfaces
  • Operator overloading
  • Indicators of behaviour
  • Bounds for generic
  • Dynamic dispatch

Example of Traits:

struct Circle {
    radius: f64,

impl Circle {
    fn area(&self) -> f64 {
        std::f64::consts::PI * (self.radius * self.radius)
} // create a functionality for the datatypes
trait HasArea {
    fn area(&self) -> f64;
// implement area for circle
impl HasArea for Circle {
    fn area(&self) -> f64 {
        std::f64::consts::PI * (self.radius * self.radius)

fn main() {
    let c = Circle { radius: 2.0 };
    println!("Area {}", c.area());

trait in rust

OwnerShip and Borrowing in Rust

Every value in Rust has an ownership scope and returning value has the transferring ownership to a new scope. Before we deep dive into ownership, let’s check out how other programming deal with memory management. Programming language uses stack or heap memory for storing data. The stack is faster than heap because CPU never has to search a place to put new data and the place to get the data from because that place is always on top of the stack.

In Rust, all of the literals like boolean, integers and strings are stored on the stack and for more complicated data, rust has heap memory. Heap is just a pile of memory. Heap is a little bit slower than the stack.

Ownership is a concept where each variable has a value and variable itself is called the owner. Each data has only one owner at a time and when the owner goes out of the scope, the value will be automatically dropped.

Here is some example code which explains scope in Rust

fn main() {
    let a = 1;
        let b = 2; // scope is different from main

Once you create a bracket and define a variable in the bracket, variable scope is limited to this bracket only so you can define multiple brackets to define multiple scopes.

This is not exactly your code in Rust but the basic way to show you ownership.

Let’s look at another Example:

fn main(){
    let v = 1;
    let x = v;
    println!("{:?}",v); // ERROR : use of moved value: “v”

Here, I have defined variable v which actually owns an integer value. Now, I want to bind v to x so x = v. Now, I am trying to print out v.

Here, you will get an error that because v is moved to x. Here, I am moving the reference from v to x and after that actual reference of v disappears entirely from the scope. Only one reference can own a data at a time so that’s what exactly happening here.

To fix this, you have to use the borrowing. To assign the reference to v, to borrow v for a moment for x.

Types of Borrowing

There is two type of borrowing in Rust:

  • Shared Borrowing (&T)
  • Mutable Borrow (&mut T)

I have explained shared borrowing in this article. I am going to end this article here. You just try out Rust programming language by yourself and come to me if you find any difficulties in that.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to use SSL in WordPress

Posted on 6 years ago


How to Install WAMP Server on Windows 8

Posted on 6 years ago


Welcome to Creative Dev

Posted on 7 years ago


How to Setup WordPress Multisite Network?

Posted on 5 years ago


Hello world

Updated 1 month ago

Nick Carter

In depth Understanding of Laravel Core

Updated 3 months ago


ECMAScript 6 New Features – 2

Updated 1 year ago


The Reader’s Poll – June 2015

Posted on 4 years ago


The Reader’s Poll – August 2014

Posted on 5 years ago


The Reader’s Poll – June 2014

Posted on 5 years ago


The Readers’ Poll – May 2014

Posted on 5 years ago


The Readers’ Poll – August 2013

Posted on 6 years ago