Getting Rusty

Krishna Kant
Coinmonks
4 min readAug 8, 2022

--

So, welcome to yet another blog, after getting introduced to Solidity, it is time to take a shower in another famous and probably the best blockchain network of the future -Solana’s supported language RUST.
We will understand more about Rust in two articles, the other one will be the continuation of the article with this one.

Rust is already sharing a parallel space with Ethereum and it is expected that in future, Rust will be adapted more than any other Blockchain network because its parent network Solana is comparatively better in terms of safety, speed and concurrency.

History of RUST

Rust grew out of a personal project begun in 2006 by Mozilla employee Graydon Hoare. Mozilla began sponsoring the project in 2009 and officially announced the project in 2010. During the same year, work had shifted from the initial compiler written in OCaml to a self-hosting compiler based on LLVM written in Rust. The new Rust compiler, named rustc, successfully compiled itself in 2011. The first numbered pre-alpha version of the compiler, Rust 0.1, was released in January 2012.
Rust’s type system, changed considerably between versions 0.2, 0.3, and 0.4 of Rust. Version 0.2 introduced classes for the first time, and version 0.3 added destructors and polymorphism through the use of interfaces. In Rust 0.4, traits were added as a means to provide inheritance; interfaces were unified with traits and removed as a separate feature. Classes were also removed and replaced by a combination of implementations and structured types. Along with conventional static typing, before version 0.4, Rust also supported typestate analysis through contracts. It was removed in release 0.4, though the same functionality can be achieved by leveraging Rust’s type system.

In January 2014, the editor-in-chief of Dr. Dobb’s Journal, Andrew Binstock, commented on Rust’s chances of becoming a competitor to C++ in addition to the languages D, Go, and Nim (then Nimrod). According to Binstock, while Rust was “widely viewed as a remarkably elegant language”, adoption slowed because it repeatedly changed between versions. The first stable release, Rust 1.0, was announced on May 15, 2015

Understanding RUST Program vitals

Declaring Variables-
In Rust, creating a variable is also known as declaring the variable.
let num = 1;
here, let keyword is the initializer, num is the variable name and 1 is the value, ‘=’ sign is the assignment operator. We can also say that 1 is the value whose owner is num.

Print statements-

fn main(){
println!(“hello”);
}
now, to understand the components, it should be noted that whatever task we want to perform in Rust, everything must be wrapped in the compiler’s recognisable main function. It can be understood as the global scope of the Rust language.
In order to print anything, we need to write “println!”. This is the command which triggers the compiler to print the values given inside the argument.

Now, to print any variable-
fn main(){
let num=1;
println!(“{}”, num);
}
Here, we have given a placeholder {} which will act as a pre-reserved empty space to be filled by the latest variable encountered by the compiler.
also, if we have to print more variables along with string values then-
println!(“num1 is {} and num2 is {}”, num1,num2);
here, the first placeholder will be filled by the num1 variable value and the second placeholder by the num2 value, every filling will be in order only.

Naming convention in Rust-

A variable name can be defined with the following rules-

  • Composed of letters, digits, underscore,
  • Must begin either with a letter or underscore,
  • Upper and lower case letters are distinct because Rust is case-sensitive,
  • Must not be any pre-reserved keyword.

Common naming conventions-
- Camel case(eg. someVariable)
- Snake case(eg. some_variable)

Keywords in Rust-
Keywords are predefined and reserved words which are used in programming that have special meanings in the compiler.
Keywords are the part of the syntax and they cannot be used as an identifier.

Data types in Rust-
There are two types of data types in Rust.
- Scalar types
- Compound types
Scaler type- It represents a single value.
There are total 4 primary scaler data types-

  • Integers,
  • Floating Point,
  • Boolean,
  • Character
    example- let num:bool = true;

Integer
size signed unsigned
8 bit i8 u8
16 bit i16 u16
32 bit i132 u32
64 bit i64 u64
128 bit i128 u128
also, there is one more size declaration- isSize: isSize responds with the size of the processor of a particular system. If it is i64 processor then isSize=64 bytes.
Since every byte has 8 bits so, i8 can store 64 bits of value and so on.

the range of values can be- -(2^n — 1) to +(2^n — 1) -1 for unsigned,
and 0 to +(2^n — 1) -1 for signed.

Floating Points-
It is used to store decimal values.
there are two types of decimal storage types declarations-
f32 and f64.
It should be noted that when the trailing decimal values are lesser, we use f32 and when these are more, we use f64. For storing 5.6 we will use f32 and for 3.56 we will use f64.

Boolean
let bool_true : bool = true;
let bool_false : bool = false;

Char
We can store everything including alphabets, numbers, characters and underscore, and space in Char.
let var_char:char = ‘2ab_ &7c’ ;

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also, Read

--

--