SlideShare a Scribd company logo
Here is where your workshop begins!
Sangam Biradar
Blogger :- engineItops.com
Founder :- KubeDaily
- Docker Community Leader , B’lore
- Traefik Ambassador
- Okteto Community Lead , India
- Course Author:- “Lightweight Kubernetes – K3s”
Packt Publication UK
@BiradarSangam | @KubeDaily
Programming language Rust
● Safe and efficient system programming
● Characteristics
○ Procedural language, abstract data type, closures
○ Static typing, strong type inference
○ Safe pointer operations
○ Parallel programming with message passing / shared memory
● Set up
● Online compiler: http://play.rust-lang.org/
● Install Rust compiler to your own environment, if
you want to do it offline.
Setup Rust
● curl -sSf https://static.rust-lang.org/rustup.sh | sh
● Mac / Linux: Install with rustup as above
● Windows: Installer is also available
Compiler installation
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Installed tools
Name Description
rustc Rust Compiler
cargo Package Manager
•We will use cargo to build and run our projects
% cargo new --bin hello_world
% cd hello_world
% cargo build
% cargo run
"Hello, world!" with Cargo
• new command populate project folders
• build command will build binary files
• run command will build project and run it
fn main() {
println! ("Hello, world!");
}
Hello, world
Rust Playground
Cheers! 1st Rust Program Executed Successful !
fn main() {
println!("Hello, world!");
}
main function: entry point
• Rust programs (not libraries) require main function as
their entry point
• fn is a statement to define functions
fn main() {
println!("Hello, world!");
}
println!
- A macro to output literals into consoles
- We can embed expressions
fn main() {
let name = ”Sangam";
println!("Hello, {}", name);
}
Variables
- We can use variables only if we declare them
- let: a statement to declare variables
Rust Playground
fn main() {
let name = ”sangam";
println!("Hello, {}", name);
}
Variable bindings
Rust Playground
fn main() {
let name = "sangam";
println!("Hello, {}", name);
name = "biradar";
println!("Hello, {}", name);
}
Immutable values
•Build error occurs when we build the this code
•We can not change the bound value
fn main() {
let name = "Sangam";
println!("Hello, {}", name);
let name = "Biradar";
println!("Hello, {}", name);
}
Make another variable binding
• In this case, we will not face a build error
• We make another variable binding with a second let
statement
fn main() {
let mut name = "Sangam";
println!("Hello, {}", name);
name = "Rust";
println!("Hello, {}", name);
}
mut: mutable variables declaration
Rust Playground
We can change binded values when their variables declared with mut keyword
fn add(a: i32, b: i32) -> i32 {
a + b
}
fn main() {
println!("1 + 1 = {}", add(1, 1));
println!("13 + 23 = {}", add(13, 23));
}
Function declarations
We need to put type annotations to arguments and
return values
fn add(a: i32, b: i32) -> i32 {
let answer: i32;
answer = a + b;
answer
}
fn main() {
println!("1 + 1 = {}", add(1, 1));
println!("13 + 23 = {}", add(13, 23));
}
Type annotation to variables
• variable_name:type
• We can omit type annotations when compiler can infer
types
fn add(a: i32, b: i32) -> i32 {
a + b
}
fn sub(a: i32, b: i32) -> i32 {
return a - b;
}
fn main() {
println!("1 + 1 = {}", add(1, 1));
println!("13 + 23 = {}", add(13, 23));
println!("23 - 13 = {}", sub(23, 13));
}
Return values
• Functions return the evaluated values of their last
expression
• We can also describe return values with return
statement explicitely
• The return values are annotated as -> type
Primitive types
Type Description
bool Boolean values
char Unicode characters
i8, i16, i32, u8, u16,
u32, u64, isize, usize
Integers
f32, f64 Floating point values
'static str, str, String String values
let a = [1, 2, 3]; // a: [i32; 3]
let mut m = [1, 2, 3]; // m: [i32; 3]
Access to each item with its index
• Fixed length, every item belong to same type
• Annotated as [type; size]
• We need to declare a mutable object when we want to
change its items
Arrays
fn main() {
let a = [1, 2, 3];
println!("0th element {}", a[0]);
println!("1th element : {}", a[1]);
println!("2th element: {}", a[2]);
}
fn main() {
let a = [1, 2, 3];
println!("# of items in a: {}", a.len());
}
len() to refer # of items
We can refer to the arrays length by calling its len method
fn main() {
let a = [0, 1, 2, 3, 4, 5];
let middle = &a[1..4];
println!("a.len() = {}", a.len());
println!("middle.len() = {}", middle.len());
}
Slice: reference to another structure
Create an slice as &array_name[start_index..end_index]
let x = (1, "hello"); // x: (i32, &str)
let mut p1 = (1, 2); // p1: (i32, i32)
let p2 = (3, 4); // p2: (i32, i32)
p1 = p2;
Tuple: fixed size ordered list
•We can create a fixed size ordered list as tuple
•Paris, triples, etc can be represented as tuples
•A tuple can be annotated as (type of first element, type
of second element, ...)
let p = (1, 2, 3);
let (x, y, z) = p;
let x = p.0;
let y = p.1;
let z = p.2;
Access to tuple elements
•We can access each field by destructuring
•Also each items can also be accessed with their
indexes
Control flow
Control flow Statement
Conditional branch if, match
Loop for, loop, while
fn main(){
let x = 5;
if x > 10 {
println!("x > 10")
}else if x > 0{
println!("x < x <= 10")
}else{
println!("x < 0")
};
}
Conditional branch
We need not to write condition within parenthesis
fn main(){
let x = 5;
let y = if x > 0{
1
}else{
0
};
println!("y = {}", y);
}
if expression
if is a expression, not statement in Rust So, it has an
evaluation value
fn main() {
let mut i = 0;
loop{
i = i +1;
println!("{} sangam biradar ", i);
if i > 9{
break;
}
}
}
loop statement: infinite loop
fn main() {
let mut x = 5; // mut x: i32
let mut done = false; // mut done: bool
while !done {
x += x - 3;
println!("{}", x);
if x % 5 == 0 {
done = true;
}
}
}
while statement
We do not need parenthesize
loop conditions as well
fn main() {
for x in 0..10 {
println!("{}", x); // x: i32
}
}
for statement: scan items over iterators
0..10: an object literal, which represents a list consisting
of integers within the specified range
for (index, value) in (0..10).enumerate() {
println!("index = {}, value = {}", index, value);
}
enumerate method
• We can refer to the index value of each iteration by calling enumerate method
fn main() {
let v = vec![1, 2, 3, 4, 5];
let zeroes = vec![0; 10];
for i in 0..v.len() {
println!("v[{}] = {}", i, v[i]);
}
for i in 0..zeroes.len() {
println!("zeroes[{}] = {}", i, zeroes[i]);
}
}
Vector: variable length list
Vec more Details:
https://doc.rust-lang.org/stable/std/vec/
Created with vec! macro
fn main() {
let v = vec![1, 2, 3, 4, 5];
for (index, value) in v.iter().enumerate() {
println!("v[{}] = {}", index, value);
}
}
Scaning a vector
Create an iterator by calling vector's iter method
fn main() {
let v = vec![1, 2, 3, 4, 5];
let result = v.iter().filter(|&n| n % 2 != 0).map(|n| n + 1);
for (index, value) in result.enumerate() {
println!("result[{}]:{}", index, value);
}
}
filter / map
An iterator has several methods to create other iterators such as filter and map
fn main() {
let v = vec![1, 2, 3];
println!("v[1] = {}", v[1]);
let v2 = v;
println!("v2[1] = {}", v2[1]);
println!("v[1] = {}", v[1]);
}
Ownership and move semantics
This code cannot be compiled
Because ownership against vec![1, 2, 3] is moved
from v to v2 Variable binding means "binded value
is a possesion of the biding variable"
fn main(){
let x = 10;
println!("x = {}", x);
let y = x;
println!("y = {}", y);
println!("x = {}", x);
}
Copy trait
Some values (e.g. i32) copy themselves when new
variable bindings are created
• x and y do not bind the same object
• but, they bind different and equivalent objects
Their type implements Copy trait
fn sum_vec(memo:Vec<i32>)->i32{
let mut sum = 0;
for i in memo.iter(){
sum = sum + i;
}
sum
}
fn main() {
let v = vec![1, 2, 3];
println!("sum = {}",sum_vec(v));
println!("sum = {}",sum_vec(v));
}
Owenership transfer via function calls
Causes build error
Ownership of vec![1, 2, 3] has been moved to the first
argument of sum_vec, when its first call
fn sum_vec(memo:Vec<i32>)->(i32, Vec<i32>){
let mut sum = 0;
for i in memo.iter(){
sum = sum + i;
}
(sum, memo)
}
fn main() {
let v = vec![1, 2, 3];
let (sum, v) = sum_vec(v);
println!("sum = {}", sum);
let (sum, _) = sum_vec(v);
println!("sum = {}", sum);
}
Return arguments' ownership with tuples
fn sum_vec(memo: &Vec<i32>) -> i32 {}
fn main() {
let v = vec![1, 2, 3];
println!("sum = {}", sum_vec(&v));
println!("sum = {}", sum_vec(&v));
}
Reference
• We can get a reference to a value by specifying &
before its name
• References are annoted as &Typename
• Functions borrow values' ownership when their
reference are passed
• The ownership automatically returns when borrwing
function returns
fn foo(v: &Vec<i32>){
v.push(5);
}
fn main(){
let v = vec![];
foo(&v);
}
Borrowed values are immutable
fn foo(v: &mut Vec<i32>){
v.push(5);
}
fn main(){
let mut v = vec![];
println!("v.len() = {}", v.len());
foo(&mut v);
println!("v.len() = {}", v.len());
}
Mutable borrowed values
• We can get mutable references with &mut
• Only if the values are mutable
● We can create one ore more read only references (&)
● The # of mutable reference is limited to 1 at most(&mut)
○ Only 1 thread can be change the state
○ This limitation is set to avoid race conditions
Rules of borrowing
fn main() {
let x = 5;
let label = match x {
1 => "sangam",
2 => "rustlab",
3 => "labs",
_ => "kubedaily",
};
println!("{} : {}", x, label);
}
_ matches the uncovered cases
fn main(){
let x = 5;
let label = match x {
1 => ”sangam",
2 => "2",
3 => "San",
4 | 5 | 6 | 7 | 8 | 9 => "single digit",
_ => "Other",
};
println!("{} :{}", x, label);
}
| : union of patterns
•| matches multiple patterns at once
fn main(){
let x = (1, 5);
let label = match x {
(0, 0) => "zero",
(1, 0) | (0, 1) => "unit",
(1, _) => "x is 1",
(_, 1) => "y is 1",
_ => "Other"
};
println!("{}", label);
}
Destructuring
let car = “red “
let red = &car[0..5];
str: how to create a slice from a static text
We Will Contd Next topics in future Session
https://discord.gg/aU3yAmFJoin RustLabs Community:-
https://rustlabs.kubedaily.com/
THANKS!Do you have any questions?
@KubeDaily
Sangam Biradar
@Biradar Sangam
Rustlabs.kubedaily.com

More Related Content

What's hot

Rust-lang
Rust-langRust-lang
​"Delegates, Delegates everywhere" Владимир Миронов
​"Delegates, Delegates everywhere" Владимир Миронов​"Delegates, Delegates everywhere" Владимир Миронов
​"Delegates, Delegates everywhere" Владимир Миронов
AvitoTech
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le
 
GPars (Groovy Parallel Systems)
GPars (Groovy Parallel Systems)GPars (Groovy Parallel Systems)
GPars (Groovy Parallel Systems)
Gagan Agrawal
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demo
Muhammad Abdullah
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GPars
Paul King
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programming
Rodolfo Finochietti
 
ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
Domenic Denicola
 
Rust言語紹介
Rust言語紹介Rust言語紹介
Rust言語紹介
Paweł Rusin
 
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, GettLean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
DroidConTLV
 
Sneaking inside Kotlin features
Sneaking inside Kotlin featuresSneaking inside Kotlin features
Sneaking inside Kotlin features
Chandra Sekhar Nayak
 
Clojure 1.1 And Beyond
Clojure 1.1 And BeyondClojure 1.1 And Beyond
Clojure 1.1 And Beyond
Mike Fogus
 
Current State of Coroutines
Current State of CoroutinesCurrent State of Coroutines
Current State of Coroutines
Guido Pio Mariotti
 
Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)
tarcieri
 
"Kotlin и rx в android" Дмитрий Воронин (Avito)
"Kotlin и rx в android" Дмитрий Воронин  (Avito)"Kotlin и rx в android" Дмитрий Воронин  (Avito)
"Kotlin и rx в android" Дмитрий Воронин (Avito)
AvitoTech
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
Nitay Neeman
 
Qt Memory Management & Signal and Slots
Qt Memory Management & Signal and SlotsQt Memory Management & Signal and Slots
Qt Memory Management & Signal and SlotsJussi Pohjolainen
 
Rust Intro
Rust IntroRust Intro
Rust Intro
Arthur Gavkaluk
 
The Ring programming language version 1.9 book - Part 48 of 210
The Ring programming language version 1.9 book - Part 48 of 210The Ring programming language version 1.9 book - Part 48 of 210
The Ring programming language version 1.9 book - Part 48 of 210
Mahmoud Samir Fayed
 
Letswift Swift 3.0
Letswift Swift 3.0Letswift Swift 3.0
Letswift Swift 3.0
Sehyun Park
 

What's hot (20)

Rust-lang
Rust-langRust-lang
Rust-lang
 
​"Delegates, Delegates everywhere" Владимир Миронов
​"Delegates, Delegates everywhere" Владимир Миронов​"Delegates, Delegates everywhere" Владимир Миронов
​"Delegates, Delegates everywhere" Владимир Миронов
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
GPars (Groovy Parallel Systems)
GPars (Groovy Parallel Systems)GPars (Groovy Parallel Systems)
GPars (Groovy Parallel Systems)
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demo
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GPars
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programming
 
ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
 
Rust言語紹介
Rust言語紹介Rust言語紹介
Rust言語紹介
 
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, GettLean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
 
Sneaking inside Kotlin features
Sneaking inside Kotlin featuresSneaking inside Kotlin features
Sneaking inside Kotlin features
 
Clojure 1.1 And Beyond
Clojure 1.1 And BeyondClojure 1.1 And Beyond
Clojure 1.1 And Beyond
 
Current State of Coroutines
Current State of CoroutinesCurrent State of Coroutines
Current State of Coroutines
 
Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)
 
"Kotlin и rx в android" Дмитрий Воронин (Avito)
"Kotlin и rx в android" Дмитрий Воронин  (Avito)"Kotlin и rx в android" Дмитрий Воронин  (Avito)
"Kotlin и rx в android" Дмитрий Воронин (Avito)
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
 
Qt Memory Management & Signal and Slots
Qt Memory Management & Signal and SlotsQt Memory Management & Signal and Slots
Qt Memory Management & Signal and Slots
 
Rust Intro
Rust IntroRust Intro
Rust Intro
 
The Ring programming language version 1.9 book - Part 48 of 210
The Ring programming language version 1.9 book - Part 48 of 210The Ring programming language version 1.9 book - Part 48 of 210
The Ring programming language version 1.9 book - Part 48 of 210
 
Letswift Swift 3.0
Letswift Swift 3.0Letswift Swift 3.0
Letswift Swift 3.0
 

Similar to Rustlabs Quick Start

GDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptxGDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptx
GDSCVJTI
 
Ownership System in Rust
Ownership System in RustOwnership System in Rust
Ownership System in Rust
Chih-Hsuan Kuo
 
Rust
RustRust
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
pramode_ce
 
Explorando el Diseño de la Memoria en Rust
Explorando el Diseño de la Memoria en RustExplorando el Diseño de la Memoria en Rust
Explorando el Diseño de la Memoria en Rust
Germán Küber
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust language
Gines Espada
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
Yandex
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Yandex
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
FITC
 
Javascript
JavascriptJavascript
Javascript
Vlad Ifrim
 
Beyond javascript using the features of tomorrow
Beyond javascript   using the features of tomorrowBeyond javascript   using the features of tomorrow
Beyond javascript using the features of tomorrow
Alexander Varwijk
 
Python and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihunPython and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihun
JIHUN KIM
 
Briefly Rust
Briefly RustBriefly Rust
Briefly Rust
Daniele Esposti
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
Matt Stine
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
Eduard Tomàs
 
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Codemotion
 
Einführung in TypeScript
Einführung in TypeScriptEinführung in TypeScript
Einführung in TypeScript
Demian Holderegger
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
André Faria Gomes
 

Similar to Rustlabs Quick Start (20)

GDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptxGDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptx
 
Ownership System in Rust
Ownership System in RustOwnership System in Rust
Ownership System in Rust
 
Rust
RustRust
Rust
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
 
Explorando el Diseño de la Memoria en Rust
Explorando el Diseño de la Memoria en RustExplorando el Diseño de la Memoria en Rust
Explorando el Diseño de la Memoria en Rust
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust language
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
Javascript
JavascriptJavascript
Javascript
 
Beyond javascript using the features of tomorrow
Beyond javascript   using the features of tomorrowBeyond javascript   using the features of tomorrow
Beyond javascript using the features of tomorrow
 
Python and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihunPython and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihun
 
Briefly Rust
Briefly RustBriefly Rust
Briefly Rust
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
 
Einführung in TypeScript
Einführung in TypeScriptEinführung in TypeScript
Einführung in TypeScript
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Dartprogramming
DartprogrammingDartprogramming
Dartprogramming
 

More from sangam biradar

Terrascan - Cloud Native Security Tool
Terrascan - Cloud Native Security Tool Terrascan - Cloud Native Security Tool
Terrascan - Cloud Native Security Tool
sangam biradar
 
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
sangam biradar
 
XCloudLabs- AWS Overview
XCloudLabs- AWS Overview XCloudLabs- AWS Overview
XCloudLabs- AWS Overview
sangam biradar
 
Okteto For Kubernetes Developer :- Container Camp 2020
Okteto For Kubernetes Developer :- Container Camp 2020 Okteto For Kubernetes Developer :- Container Camp 2020
Okteto For Kubernetes Developer :- Container Camp 2020
sangam biradar
 
Happy Helming With Okteto
Happy Helming With OktetoHappy Helming With Okteto
Happy Helming With Okteto
sangam biradar
 
5 cool ways to get started with Cloud Native Development ( with Okteto)
5 cool ways to get started with Cloud Native Development ( with Okteto)5 cool ways to get started with Cloud Native Development ( with Okteto)
5 cool ways to get started with Cloud Native Development ( with Okteto)
sangam biradar
 
Docker + Tenserflow + GOlang - Golang singapore Meetup
Docker + Tenserflow + GOlang - Golang singapore MeetupDocker + Tenserflow + GOlang - Golang singapore Meetup
Docker + Tenserflow + GOlang - Golang singapore Meetup
sangam biradar
 
kikstart journey of Golang with Hello world - Gopherlabs
kikstart journey of Golang with Hello world - Gopherlabs kikstart journey of Golang with Hello world - Gopherlabs
kikstart journey of Golang with Hello world - Gopherlabs
sangam biradar
 
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
sangam biradar
 
Decision making - for loop , nested loop ,if-else statements , switch in goph...
Decision making - for loop , nested loop ,if-else statements , switch in goph...Decision making - for loop , nested loop ,if-else statements , switch in goph...
Decision making - for loop , nested loop ,if-else statements , switch in goph...
sangam biradar
 
Types - slice, map, new, make, struct - Gopherlabs
Types - slice, map, new, make, struct - Gopherlabs Types - slice, map, new, make, struct - Gopherlabs
Types - slice, map, new, make, struct - Gopherlabs
sangam biradar
 
Cloud Native Okteto Cloud
Cloud Native Okteto Cloud Cloud Native Okteto Cloud
Cloud Native Okteto Cloud
sangam biradar
 
Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...
Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...
Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...
sangam biradar
 
welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?
sangam biradar
 
Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...
Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...
Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...
sangam biradar
 
TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...
TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...
TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...
sangam biradar
 
Introducing Pico - A Deep Learning Platform using Docker & IoT - Sangam Biradar
Introducing Pico - A Deep Learning Platform using Docker & IoT - Sangam BiradarIntroducing Pico - A Deep Learning Platform using Docker & IoT - Sangam Biradar
Introducing Pico - A Deep Learning Platform using Docker & IoT - Sangam Biradar
sangam biradar
 
September 7, 2019 Cloud Native and Containerisation (Joint Meetup with Docke...
September 7, 2019  Cloud Native and Containerisation (Joint Meetup with Docke...September 7, 2019  Cloud Native and Containerisation (Joint Meetup with Docke...
September 7, 2019 Cloud Native and Containerisation (Joint Meetup with Docke...
sangam biradar
 
Implementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam Biradar
Implementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam BiradarImplementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam Biradar
Implementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam Biradar
sangam biradar
 
Docker on IOT - Dockercon19 SFO Recap & Announcements, Bangalore
Docker on IOT - Dockercon19 SFO Recap & Announcements, BangaloreDocker on IOT - Dockercon19 SFO Recap & Announcements, Bangalore
Docker on IOT - Dockercon19 SFO Recap & Announcements, Bangalore
sangam biradar
 

More from sangam biradar (20)

Terrascan - Cloud Native Security Tool
Terrascan - Cloud Native Security Tool Terrascan - Cloud Native Security Tool
Terrascan - Cloud Native Security Tool
 
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
 
XCloudLabs- AWS Overview
XCloudLabs- AWS Overview XCloudLabs- AWS Overview
XCloudLabs- AWS Overview
 
Okteto For Kubernetes Developer :- Container Camp 2020
Okteto For Kubernetes Developer :- Container Camp 2020 Okteto For Kubernetes Developer :- Container Camp 2020
Okteto For Kubernetes Developer :- Container Camp 2020
 
Happy Helming With Okteto
Happy Helming With OktetoHappy Helming With Okteto
Happy Helming With Okteto
 
5 cool ways to get started with Cloud Native Development ( with Okteto)
5 cool ways to get started with Cloud Native Development ( with Okteto)5 cool ways to get started with Cloud Native Development ( with Okteto)
5 cool ways to get started with Cloud Native Development ( with Okteto)
 
Docker + Tenserflow + GOlang - Golang singapore Meetup
Docker + Tenserflow + GOlang - Golang singapore MeetupDocker + Tenserflow + GOlang - Golang singapore Meetup
Docker + Tenserflow + GOlang - Golang singapore Meetup
 
kikstart journey of Golang with Hello world - Gopherlabs
kikstart journey of Golang with Hello world - Gopherlabs kikstart journey of Golang with Hello world - Gopherlabs
kikstart journey of Golang with Hello world - Gopherlabs
 
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
 
Decision making - for loop , nested loop ,if-else statements , switch in goph...
Decision making - for loop , nested loop ,if-else statements , switch in goph...Decision making - for loop , nested loop ,if-else statements , switch in goph...
Decision making - for loop , nested loop ,if-else statements , switch in goph...
 
Types - slice, map, new, make, struct - Gopherlabs
Types - slice, map, new, make, struct - Gopherlabs Types - slice, map, new, make, struct - Gopherlabs
Types - slice, map, new, make, struct - Gopherlabs
 
Cloud Native Okteto Cloud
Cloud Native Okteto Cloud Cloud Native Okteto Cloud
Cloud Native Okteto Cloud
 
Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...
Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...
Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...
 
welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?
 
Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...
Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...
Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...
 
TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...
TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...
TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...
 
Introducing Pico - A Deep Learning Platform using Docker & IoT - Sangam Biradar
Introducing Pico - A Deep Learning Platform using Docker & IoT - Sangam BiradarIntroducing Pico - A Deep Learning Platform using Docker & IoT - Sangam Biradar
Introducing Pico - A Deep Learning Platform using Docker & IoT - Sangam Biradar
 
September 7, 2019 Cloud Native and Containerisation (Joint Meetup with Docke...
September 7, 2019  Cloud Native and Containerisation (Joint Meetup with Docke...September 7, 2019  Cloud Native and Containerisation (Joint Meetup with Docke...
September 7, 2019 Cloud Native and Containerisation (Joint Meetup with Docke...
 
Implementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam Biradar
Implementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam BiradarImplementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam Biradar
Implementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam Biradar
 
Docker on IOT - Dockercon19 SFO Recap & Announcements, Bangalore
Docker on IOT - Dockercon19 SFO Recap & Announcements, BangaloreDocker on IOT - Dockercon19 SFO Recap & Announcements, Bangalore
Docker on IOT - Dockercon19 SFO Recap & Announcements, Bangalore
 

Recently uploaded

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 

Rustlabs Quick Start

  • 1. Here is where your workshop begins!
  • 2. Sangam Biradar Blogger :- engineItops.com Founder :- KubeDaily - Docker Community Leader , B’lore - Traefik Ambassador - Okteto Community Lead , India - Course Author:- “Lightweight Kubernetes – K3s” Packt Publication UK @BiradarSangam | @KubeDaily
  • 3. Programming language Rust ● Safe and efficient system programming ● Characteristics ○ Procedural language, abstract data type, closures ○ Static typing, strong type inference ○ Safe pointer operations ○ Parallel programming with message passing / shared memory
  • 4. ● Set up ● Online compiler: http://play.rust-lang.org/ ● Install Rust compiler to your own environment, if you want to do it offline. Setup Rust
  • 5. ● curl -sSf https://static.rust-lang.org/rustup.sh | sh ● Mac / Linux: Install with rustup as above ● Windows: Installer is also available Compiler installation curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • 6. Installed tools Name Description rustc Rust Compiler cargo Package Manager •We will use cargo to build and run our projects
  • 7. % cargo new --bin hello_world % cd hello_world % cargo build % cargo run "Hello, world!" with Cargo • new command populate project folders • build command will build binary files • run command will build project and run it
  • 8. fn main() { println! ("Hello, world!"); } Hello, world Rust Playground Cheers! 1st Rust Program Executed Successful !
  • 9. fn main() { println!("Hello, world!"); } main function: entry point • Rust programs (not libraries) require main function as their entry point • fn is a statement to define functions
  • 10. fn main() { println!("Hello, world!"); } println! - A macro to output literals into consoles - We can embed expressions
  • 11. fn main() { let name = ”Sangam"; println!("Hello, {}", name); } Variables - We can use variables only if we declare them - let: a statement to declare variables Rust Playground
  • 12. fn main() { let name = ”sangam"; println!("Hello, {}", name); } Variable bindings Rust Playground
  • 13. fn main() { let name = "sangam"; println!("Hello, {}", name); name = "biradar"; println!("Hello, {}", name); } Immutable values •Build error occurs when we build the this code •We can not change the bound value
  • 14. fn main() { let name = "Sangam"; println!("Hello, {}", name); let name = "Biradar"; println!("Hello, {}", name); } Make another variable binding • In this case, we will not face a build error • We make another variable binding with a second let statement
  • 15. fn main() { let mut name = "Sangam"; println!("Hello, {}", name); name = "Rust"; println!("Hello, {}", name); } mut: mutable variables declaration Rust Playground We can change binded values when their variables declared with mut keyword
  • 16. fn add(a: i32, b: i32) -> i32 { a + b } fn main() { println!("1 + 1 = {}", add(1, 1)); println!("13 + 23 = {}", add(13, 23)); } Function declarations We need to put type annotations to arguments and return values
  • 17. fn add(a: i32, b: i32) -> i32 { let answer: i32; answer = a + b; answer } fn main() { println!("1 + 1 = {}", add(1, 1)); println!("13 + 23 = {}", add(13, 23)); } Type annotation to variables • variable_name:type • We can omit type annotations when compiler can infer types
  • 18. fn add(a: i32, b: i32) -> i32 { a + b } fn sub(a: i32, b: i32) -> i32 { return a - b; } fn main() { println!("1 + 1 = {}", add(1, 1)); println!("13 + 23 = {}", add(13, 23)); println!("23 - 13 = {}", sub(23, 13)); } Return values • Functions return the evaluated values of their last expression • We can also describe return values with return statement explicitely • The return values are annotated as -> type
  • 19. Primitive types Type Description bool Boolean values char Unicode characters i8, i16, i32, u8, u16, u32, u64, isize, usize Integers f32, f64 Floating point values 'static str, str, String String values
  • 20. let a = [1, 2, 3]; // a: [i32; 3] let mut m = [1, 2, 3]; // m: [i32; 3] Access to each item with its index • Fixed length, every item belong to same type • Annotated as [type; size] • We need to declare a mutable object when we want to change its items Arrays fn main() { let a = [1, 2, 3]; println!("0th element {}", a[0]); println!("1th element : {}", a[1]); println!("2th element: {}", a[2]); }
  • 21. fn main() { let a = [1, 2, 3]; println!("# of items in a: {}", a.len()); } len() to refer # of items We can refer to the arrays length by calling its len method
  • 22. fn main() { let a = [0, 1, 2, 3, 4, 5]; let middle = &a[1..4]; println!("a.len() = {}", a.len()); println!("middle.len() = {}", middle.len()); } Slice: reference to another structure Create an slice as &array_name[start_index..end_index]
  • 23. let x = (1, "hello"); // x: (i32, &str) let mut p1 = (1, 2); // p1: (i32, i32) let p2 = (3, 4); // p2: (i32, i32) p1 = p2; Tuple: fixed size ordered list •We can create a fixed size ordered list as tuple •Paris, triples, etc can be represented as tuples •A tuple can be annotated as (type of first element, type of second element, ...)
  • 24. let p = (1, 2, 3); let (x, y, z) = p; let x = p.0; let y = p.1; let z = p.2; Access to tuple elements •We can access each field by destructuring •Also each items can also be accessed with their indexes
  • 25. Control flow Control flow Statement Conditional branch if, match Loop for, loop, while
  • 26. fn main(){ let x = 5; if x > 10 { println!("x > 10") }else if x > 0{ println!("x < x <= 10") }else{ println!("x < 0") }; } Conditional branch We need not to write condition within parenthesis
  • 27. fn main(){ let x = 5; let y = if x > 0{ 1 }else{ 0 }; println!("y = {}", y); } if expression if is a expression, not statement in Rust So, it has an evaluation value
  • 28. fn main() { let mut i = 0; loop{ i = i +1; println!("{} sangam biradar ", i); if i > 9{ break; } } } loop statement: infinite loop
  • 29. fn main() { let mut x = 5; // mut x: i32 let mut done = false; // mut done: bool while !done { x += x - 3; println!("{}", x); if x % 5 == 0 { done = true; } } } while statement We do not need parenthesize loop conditions as well
  • 30. fn main() { for x in 0..10 { println!("{}", x); // x: i32 } } for statement: scan items over iterators 0..10: an object literal, which represents a list consisting of integers within the specified range
  • 31. for (index, value) in (0..10).enumerate() { println!("index = {}, value = {}", index, value); } enumerate method • We can refer to the index value of each iteration by calling enumerate method
  • 32. fn main() { let v = vec![1, 2, 3, 4, 5]; let zeroes = vec![0; 10]; for i in 0..v.len() { println!("v[{}] = {}", i, v[i]); } for i in 0..zeroes.len() { println!("zeroes[{}] = {}", i, zeroes[i]); } } Vector: variable length list Vec more Details: https://doc.rust-lang.org/stable/std/vec/ Created with vec! macro
  • 33. fn main() { let v = vec![1, 2, 3, 4, 5]; for (index, value) in v.iter().enumerate() { println!("v[{}] = {}", index, value); } } Scaning a vector Create an iterator by calling vector's iter method
  • 34. fn main() { let v = vec![1, 2, 3, 4, 5]; let result = v.iter().filter(|&n| n % 2 != 0).map(|n| n + 1); for (index, value) in result.enumerate() { println!("result[{}]:{}", index, value); } } filter / map An iterator has several methods to create other iterators such as filter and map
  • 35. fn main() { let v = vec![1, 2, 3]; println!("v[1] = {}", v[1]); let v2 = v; println!("v2[1] = {}", v2[1]); println!("v[1] = {}", v[1]); } Ownership and move semantics This code cannot be compiled Because ownership against vec![1, 2, 3] is moved from v to v2 Variable binding means "binded value is a possesion of the biding variable"
  • 36. fn main(){ let x = 10; println!("x = {}", x); let y = x; println!("y = {}", y); println!("x = {}", x); } Copy trait Some values (e.g. i32) copy themselves when new variable bindings are created • x and y do not bind the same object • but, they bind different and equivalent objects Their type implements Copy trait
  • 37. fn sum_vec(memo:Vec<i32>)->i32{ let mut sum = 0; for i in memo.iter(){ sum = sum + i; } sum } fn main() { let v = vec![1, 2, 3]; println!("sum = {}",sum_vec(v)); println!("sum = {}",sum_vec(v)); } Owenership transfer via function calls Causes build error Ownership of vec![1, 2, 3] has been moved to the first argument of sum_vec, when its first call
  • 38. fn sum_vec(memo:Vec<i32>)->(i32, Vec<i32>){ let mut sum = 0; for i in memo.iter(){ sum = sum + i; } (sum, memo) } fn main() { let v = vec![1, 2, 3]; let (sum, v) = sum_vec(v); println!("sum = {}", sum); let (sum, _) = sum_vec(v); println!("sum = {}", sum); } Return arguments' ownership with tuples
  • 39. fn sum_vec(memo: &Vec<i32>) -> i32 {} fn main() { let v = vec![1, 2, 3]; println!("sum = {}", sum_vec(&v)); println!("sum = {}", sum_vec(&v)); } Reference • We can get a reference to a value by specifying & before its name • References are annoted as &Typename • Functions borrow values' ownership when their reference are passed • The ownership automatically returns when borrwing function returns
  • 40. fn foo(v: &Vec<i32>){ v.push(5); } fn main(){ let v = vec![]; foo(&v); } Borrowed values are immutable
  • 41. fn foo(v: &mut Vec<i32>){ v.push(5); } fn main(){ let mut v = vec![]; println!("v.len() = {}", v.len()); foo(&mut v); println!("v.len() = {}", v.len()); } Mutable borrowed values • We can get mutable references with &mut • Only if the values are mutable
  • 42. ● We can create one ore more read only references (&) ● The # of mutable reference is limited to 1 at most(&mut) ○ Only 1 thread can be change the state ○ This limitation is set to avoid race conditions Rules of borrowing
  • 43. fn main() { let x = 5; let label = match x { 1 => "sangam", 2 => "rustlab", 3 => "labs", _ => "kubedaily", }; println!("{} : {}", x, label); } _ matches the uncovered cases
  • 44. fn main(){ let x = 5; let label = match x { 1 => ”sangam", 2 => "2", 3 => "San", 4 | 5 | 6 | 7 | 8 | 9 => "single digit", _ => "Other", }; println!("{} :{}", x, label); } | : union of patterns •| matches multiple patterns at once
  • 45. fn main(){ let x = (1, 5); let label = match x { (0, 0) => "zero", (1, 0) | (0, 1) => "unit", (1, _) => "x is 1", (_, 1) => "y is 1", _ => "Other" }; println!("{}", label); } Destructuring
  • 46. let car = “red “ let red = &car[0..5]; str: how to create a slice from a static text
  • 47. We Will Contd Next topics in future Session https://discord.gg/aU3yAmFJoin RustLabs Community:- https://rustlabs.kubedaily.com/
  • 48. THANKS!Do you have any questions? @KubeDaily Sangam Biradar @Biradar Sangam Rustlabs.kubedaily.com