SlideShare una empresa de Scribd logo
1 de 105
Descargar para leer sin conexión
The Rust Programming Language
Pramode C.E
March 2, 2017
A language that doesn’t affect the way you think about
programming, is not worth knowing.
Alan Perlis.
Figure 1: rustpoem
Why is Rust so exciting?
Safe low-level systems programming
Memory safety without garbage collection
High-level abstractions (influenced by statically typed functional
programming languages like ML) without run-time overhead
Concurrency without data races
Why not just use C/C++?
The second big thing each student should learn is: How
can I avoid being burned by C’s numerous and severe
shortcomings? This is a development environment where
only the paranoid can survive.
http://blog.regehr.org/archives/1393
Why not just use C/C++?
Figure 2: Cloudbleed
A bit of Rust history
Started by Graydon Hoare as a personal project in 2006
Mozilla foundation started sponsoring Rust in 2010
Rust 1.0 released in May, 2015
Regular six week release cycles
Core language features
Memory safety without garbage collection
Ownership
Move Semantics
Borrowing and lifetimes
Static Typing with Type Inference
Algebraic Data Types (Sum and Product types)
Exhaustive Pattern Matching
Trait-based generics
Iterators
Zero Cost Abstractions
Concurrency without data races
Efficient C bindings, minimal runtime
Structure of this workshop
Understanding the problems with C/C++
Understanding Ownership, Borrow, Move semantics and
Lifetimes
Other features (depending on availability of time)
The Stack
// a0.c
int main()
{
int a = 1, b = 2;
return 0;
}
The Stack
Figure 3: The C stack
Buffer overflow
// a1.c
int main()
{
int i=1;
int a[4];
int j=2;
a[4] = 5; // bug
a[5] = 6; // bug
a[10000] = 7; // bug
}
Buffer overflow
Figure 4: Buffer overflow diagram
Pointers in C
// a2.c
int main()
{
int a = 10;
int *b;
b = &a;
*b = 20;
}
Pointers in C
Figure 5: How pointer variables are stored in memory
Stack Frames - deallocations and allocations
// a3.c
void fun2() { int e=5, f=6; }
void fun1() { int c=3, d=4; }
int main()
{
int a=1, b=2;
fun1(); fun2();
return 0;
}
Stack Frames - allocations and deallocations
Figure 6: Multiple stack frames
Stack Frames - allocations and deallocations
Figure 7: Multiple stack frames
Dangling Pointers
// a4.c
void fun2() { int m = 1; int n = 2; }
int* fun1() {
int *p; int q = 0;
p = &q; return p; // bug
}
int main() {
int *a, b; a = fun1();
*a = 10; fun2();
b = *a;
}
Dangling pointers
Figure 8: Dangling pointer
Null pointer dereferencing
// a6.c
#include <strings.h>
#include <stdio.h>
int main()
{
char s[100] = "hello";
char *p;
p = index(s, ’f’);
*p = ’a’; // bug!
return 0;
}
Heap allocation - malloc and free
// a7.c
#include <stdlib.h>
void fun()
{
char *c;
c = malloc(10*sizeof(char));
/* do some stuff here */
free(c);
}
int main()
{
fun();
}
Heap allocation - malloc and free
Figure 9: A stack location pointing to a heap location
Memory leaks
// a8.c
#include <stdlib.h>
void fun()
{
char *c;
c = malloc(10*sizeof(char));
/* do some stuff here */
}
int main()
{
fun(); // bug! memory leak.
}
Use-after-free
// a9.c
#include <stdlib.h>
void fun(char *t) {
/* do some stuff here */
free(t);
}
int main() {
char *c;
c = malloc(10 * sizeof(char));
fun(c);
c[0] = ’A’; //bug! user-after-free
}
Double free
// a10.c
#include <stdlib.h>
void fun(char *t) {
/* do some stuff here */
free(t);
}
int main() {
char *c;
c = malloc(10 * sizeof(char));
fun(c);
free(c); //bug! double free
}
Undefined behaviours and optimization
// a11.c
#include <limits.h>
#include <stdio.h>
// compile the code with optimization (-O3) and without
int main() {
int c = INT_MAX;
if (c+1 < c)
printf("hellon");
printf("%dn", c+1);
}
Undefined behaviours
Figure 10:
https://www.explainxkcd.com/wiki/images/c/cc/cant_sleep.png
Undefined behaviours
When tools like the bounds checking GCC, Purify,
Valgrind, etc. first showed up, it was interesting to run a
random UNIX utility under them. The output of the
checker showed that these utility programs, despite
working perfectly well, executed a ton of memory safety
errors such as use of uninitialized data, accesses beyond
the ends of arrays, etc. Just running grep or whatever
would cause tens or hundreds of these errors to happen.
From: http://blog.regehr.org/archives/226
Undefined behaviours
More and more, I’m starting to wonder how safety-critical
code can continue being written in C.
A comment on: http://blog.regehr.org/archives/232
Hello, world!
// a12.rs
fn main() {
println!("hello, world!");
}
Compile: rustc a12.rs
Run: ./a12
Static Typing and Type inference
// a12-1.rs
fn sqr(x: i32) -> i32 {
let y = x * x; // type inferred
y
}
fn main() {
let t1 = sqr(10); // type inferred
let t2:i32 = sqr(20);
println!("sqr 10 = {}, sqr 20 ={}", t1, t2);
}
Static Typing and Type Inference
The Rust type system is considerably more advanced than that of
“mainstream” languages like Java,C.
https://github.com/jaheba/stuff/blob/master/communicating_intent.
http://ferrisellis.com/posts/rust-implementing-units-for-
types/
https://fsharpforfunandprofit.com/series/designing-with-
types.html (you can do most of these in
Rust)
Immutability
// a12-2.rs
fn main() {
let x = 0; // x is immutable
let mut y = 1;
x = x + 1; // does not work
y = y + 1;
}
Scope
// a12-3.rs
fn main() {
let x = 10;
{
let y = 20;
}
println!("x={}, y={}", x, y);
}
Ownership
// a13.rs
fn main() {
let v = vec![10, 20, 30];
println!("{:?}", v);
}
// how is v deallocated?
Ownership
Figure 11: Memory representation of a vector
Ownership
// a14.rs
fn fun1() {
let v = vec![10 ,20 ,30];
} // how is v deallocated?
fn main() {
fun1();
}
Ownership
// a15.rs
fn main() {
let v1 = vec![10 ,20 ,30];
let v2 = v1;
println!("{:?}", v2);
}
// do we have a double free here?
Ownership
Figure 12: Two pointers
Ownership
// a15-1.rs
fn fun(v2: Vec<i32>) {
println!("{:?}", v2);
}
fn main() {
let v1 = vec![10, 20, 30];
fun(v1);
}
// do we have a double free here?
Ownership
// a16.rs
fn main() {
let v1 = vec![10, 20, 30];
let mut v2 = v1;
v2.truncate(2);
println!("{:?}", v2);
}
// what happens if we try to acces the
// vector through v1?
Move semantics
// a17.rs
fn main() {
let v1 = vec![1,2,3];
let mut v2 = v1;
v2.truncate(2);
println!("{:?}", v1);
}
Move semantics
// a15-2.rs
fn fun(v2: Vec<i32>) {
println!("{:?}", v2);
}
fn main() {
let v1 = vec![10, 20, 30];
fun(v1);
println!("{:?}", v1);
}
Move semantics
// a18.rs
fn main() {
let a = (1, 2.3);
let b = a;
println!("{:?}", a);
}
Move semantics
// a19.rs
fn main() {
let a = (1, 2.3, vec![10,20]);
let b = a;
println!("{:?}", a);
}
Memory safety without garbage collection
Languages like Python, Java etc achieve memory safety at run
time through garbage collection.
Rust achieves memory safety at compile time by static type
analysis.
Ownership + move semantics has some interesting properties
which makes them suitable for general resource management
(not just memory).
Garbage Collection
# a20.py
a = [10, 20, 30]
a.append(40)
print a
Garbage Collection
# a21.py
a = [10, 20, 30]
b = a
b.append(40)
print a # what does this print?
Garbage Collection
Figure 13: References in Python
Garbage Collection
Figure 14: Reference Counting
Garbage Collection
# a22.py
a = [10, 20, 30]
b = a # refcount is 2
a = "hello" # refcount is 1
b = "world" # refcount drops to zero, deallocate
Resource management
# a23.py
def read_a_line():
f = open("/etc/passwd")
s = f.readline()
f.close() # close the file, release OS resources
return s
while True:
print read_a_line()
Resource Leaks in managed languages
# a24.py
def read_a_line():
f = open("/etc/passwd")
s = f.readline()
# No explicit "close"
return s
while True:
print read_a_line()
Rust means never having to close a file!
// a25.rs
use std::fs::File;
use std::io::Read;
fn read_whole_file() -> String {
let mut s = String::new();
let mut f = File::open("/etc/passwd").unwrap();
f.read_to_string(&mut s).unwrap();
s // return the string
}
fn main() {
println!("{}", read_whole_file());
}
Read:
http://blog.skylight.io/rust-means-never-having-to-close-a-socket/
Ownership / Move: Limitations
// a26.rs
fn vector_sum(v: Vec<i32>) -> i32 {
//assume v is always a 3 elemnt vector
v[0] + v[1] + v[2]
}
fn main() {
let v = vec![1,2,3];
let s = vector_sum(v);
println!("{}",s);
}
Ownership / Move: Limitations
// a27.rs
fn vector_sum(v: Vec<i32>) -> i32 {
v[0] + v[1] + v[2]
}
fn vector_product(v: Vec<i32>) -> i32 {
v[0] * v[1] * v[2]
}
fn main() {
let v = vec![1,2,3];
let s = vector_sum(v);
let p = vector_product(v);
println!("{}",p);
}
// does this code compile?
Immutable Borrow
// a28.rs
fn vector_sum(v: &Vec<i32>) -> i32 {
v[0] + v[1] + v[2]
}
fn vector_product(v: &Vec<i32>) -> i32 {
v[0] * v[1] * v[2]
}
fn main() {
let v = vec![1,2,3];
let s = vector_sum(&v);
let p = vector_product(&v);
println!("v={:?}, s={}, p={}", v, s, p);
}
Immutable Borrow
// a29.rs
fn main() {
let v = vec![1,2,3];
let t1 = &v;
let t2 = &v;
println!("{}, {}, {}", t1[0], t2[0], v[0]);
}
// any number of immutable borrows are ok!
Immutable Borrow
// a30.rs
fn change(t1: &Vec<i32>) {
t1[0] = 10;
}
fn main() {
let mut v = vec![1,2,3];
change(&v);
}
// Does the program compile?
Mutable Borrow
// a31.rs
fn change(t1: &mut Vec<i32>) {
t1[0] = 10;
}
fn main() {
let mut v = vec![1,2,3];
change(&mut v);
println!("{:?}", v);
}
A use-after-free bug
// a32.c
#include <stdlib.h>
int main()
{
char *p = malloc(10 * sizeof(char));
char *q;
q = p + 2;
free(p);
*q = ’A’; // bug!
return 0;
}
Vector allocation in Rust
// a33.rs
fn main() {
let mut a = vec![];
a.push(1); a.push(2);
a.push(3); a.push(4);
a.push(5);
println!("{:?}", a);
}
Vector allocation in Rust/C++
Figure 15: Growing a vector
A use-after-free bug in C++
// a33-1.cpp
#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<int> v;
int *p;
v.push_back(1);
p = &v[0];
v.push_back(2);
*p = 100; // bug!
cout << v[0] << endl;
}
A use-after-free bug in Rust?
// a34.rs
fn main() {
let mut v = vec![10, 20, 30, 40];
let p1 = &v[1];
v.push(50);
// bug if we try to use p1
// does this code compile?
}
Borrowing Rules
Any number of immutable borrows can co-exist.
A mutable borrow can not co-exist with other mutable or
immutable borrows.
The “borrow checker” checks violations of these rules at
compile time.
Borrow checker limitations
The borrow checker gives you safety by rejecting ALL unsafe
programs.
But it is not perfect in the sense it rejects safe programs also;
“fighting the borrow checker” is a common sporting activity
among Rust programmers :)
There are plans to improve the situation:
http://smallcultfollowing.com/babysteps/blog/2017/03/01/nested-
method-calls-via-two-phase-borrowing/
Borrow checker limitations - an example
// a35.rs
fn main() {
let mut v = vec![10,20,30];
v.push(v.len());
}
// this will not compile
Borrow checker limitations - an example
// a36.rs
// Same as a35.rs
fn main() {
let mut v = vec![10,20,30];
let tmp0 = &v;
let tmp1 = &mut v;
let tmp2 = Vec::len(tmp0); //v.len()
Vec::push(tmp1, tmp2);// v.push(tmp2)
}
Lifetimes
// a37.rs
fn main() {
let ref1: &Vec<i32>;
{
let v = vec![1, 2, 3];
ref1 = &v;
}
// v gets deallocated as it goes out of
// the scope. What about ref1? Do we have
// a "dangling pointer" here?
}
Lifetimes
// a38.rs
fn foo() -> Vec<i32> {
let v = vec![1, 2, 3];
v // transfer ownership to caller
}
fn main() {
let p = foo();
println!("{:?}", p);
}
Lifetimes
// a39.rs
fn foo() -> &Vec<i32> {
let v = vec![1, 2, 3];
&v // Will this compile?
}
fn main() {
let p = foo();
}
Explicit Lifetime Annotations
// a40.rs
fn foo(v1: &Vec<i32>, v2: &Vec<i32>) -> &i32 {
&v1[0]
}
fn main() {
let v1 = vec![1, 2, 3];
let p:&i32;
{
let v2 = vec![4, 5, 6];
p = foo(&v1, &v2);
// How does the compiler know, just by looking at
// the signature of "foo", that the reference
// returned by "foo" will live as long as "p"?
}
}
Explicit Lifetime Annotations
// a41.rs
fn foo<’a, ’b>(v1: &’a Vec<i32>,
v2: &’b Vec<i32>) -> &’a i32 {
&v1[0]
}
fn main() {
let v1 = vec![1, 2, 3];
let p:&i32;
{
let v2 = vec![4, 5, 6];
p = foo(&v1, &v2);
}
}
Explicit Lifetime Annotations
// a42.rs
fn foo<’a, ’b>(v1: &’a Vec<i32>,
v2: &’b Vec<i32>) -> &’b i32 {
&v2[0]
}
fn main() {
let v1 = vec![1, 2, 3];
let p:&i32;
{
let v2 = vec![4, 5, 6];
p = foo(&v1, &v2);
}
}
Unsafe
// a43.rs
fn main() {
// a is a "raw" pointer intialized to 0
let a: *mut u32 = 0 as *mut u32;
*a = 0;
}
Unsafe
// a44.rs
fn main() {
let a: *mut u32 = 0 as *mut u32;
unsafe {
*a = 0;
}
}
Rust on microcontrollers
Figure 16: Stellaris Launchpad
Rust on microcontrollers
// part of blinky.rs
loop {
gpio::port_write(gpio::GPIO_PORTF_BASE,
gpio::GPIO_PIN_1,
gpio::GPIO_PIN_1);
delay(500000);
gpio::port_write(gpio::GPIO_PORTF_BASE,
gpio::GPIO_PIN_1,
0);
delay(500000);
}
Rust on microcontrollers
http://pramode.in/2016/12/17/rust-on-tiva-launchpad/
https://japaric.github.io/discovery/
A complete web app in Rust (using rocket.rs)
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
#[get("/<name>")]
fn index(name: &str) -> String {
format!("nHello, {}!, hope you are enjoying 
the Rust workshop!n", name)
}
fn main() {
rocket::ignite()
.mount("/", routes![index])
.launch();
}
Test run the web app!
wget -q -O - http://128.199.100.27:8000/Mohan
curl -s http://128.199.100.27:8000/Mohan
End of Part 1
What we have seen so far is the “core” of Rust, these are the
ideas which make Rust unique!
Most of the other “interesting” ideas are borrowed from
statically typed functional programming languages (like ML).
(The first Rust compiler was written in Ocaml).
End of Part 1
Figure 17: rustpoem
Zero Cost Abstractions
// a45.rs
const N: u64 = 1000000000;
fn main() {
let r = (0..N)
.map(|x| x + 1)
.fold(0, |sum, i| sum+i);
println!("{}", r);
}
// Compile with optimizations enabled:
// rustc -O a45.rs
Zero cost abstractions
(0 .. N) => (0, 1, 2, 3, .... N-1) # an "iterator"
(0 .. N).map(|x| x+1) => (1, 2, 3, 4 .... N)
(1, 2, 3, ... N).fold(0, |sum, i| sum + i)
=> ((((0 + 1) + 2) + 3) + 4) + ....
Zero cost abstractions
Here is part of the assembly language code produced by the
compiler for a45.rs:
.Ltmp0:
.cfi_def_cfa_offset 80
movabsq $500000000500000000, %rax
movq %rax, (%rsp)
leaq (%rsp), %rax
movq %rax, 8(%rsp)
Looks like the expression has been evaluated fully at compile time
itself!
Here is the commandline used to produce the above output:
rustc -O a45.rs --emit=asm
Zero cost abstractions
You can write confidently using all the high-level abstractions
the language has to offer.
Your code will almost always be as fast as hand-coded low level
C!
Sum Types and Pattern Matching
// a46.rs
enum Color {
Red,
Green,
Blue,
}
use Color::*;
fn main() {
let c = Red;
match c {
Red => println!("color is Red!"),
Green => println!("color is Green!"),
Blue => println!("color is Blue!")
}
}
Sum Types and Pattern Matching
// a47.rs
#[derive(Debug)]
enum Shape {
Circle(u32),
Square (u32),
Rectangle {ht: u32, wid: u32},
}
use Shape::*;
fn main() {
let s1 = Circle(10);
let s2 = Square(5);
let s3 = Rectangle {ht: 10, wid: 2};
println!("{:?}", s3);
}
Pattern matching is exhaustive
// a48.rs
#[derive(Debug)]
enum Shape {
Circle(f64),
Square (f64),
Rectangle {ht: f64, wid: f64},
}
use Shape::*;
fn area(s: Shape) -> f64 {
match s {
Circle(x) => 3.14 * x * x,
Rectangle {ht: x, wid: y} => x * y,
} // bug!
}
fn main() {
let s1 = Circle(10.0);
println!("{}", area(s1));
}
The Option type
// a49.rs
fn main() {
let mut a = vec![10];
let b = a.pop();
let c = a.pop();
let d = b + 1; // does it compile?
}
The Option type
// a50.rs
fn main() {
let mut a = vec![10];
let b = a.pop();
let c = a.pop();
println!("b = {:?}, c = {:?}", b, c);
}
The Option type
// a51.rs
fn main() {
let mut a = vec![10];
let b = a.pop();
match b {
Some(x) => println!("pop: {}", x),
None => println!("empty stack"),
}
}
The Option type
// a52.rs
fn main() {
let mut a = vec![10];
let b = a.pop();
println!("{}", b.unwrap());
let c = a.pop();
println!("{}", c.unwrap());
}
Generic Enums - an implementation of Option
// a53.rs
// A "generic" enum similar to Option
enum Maybe <T> {
Just(T),
Nothing,
}
use Maybe::*;
fn main() {
let c:Maybe<i32> = Just(10);
let d:Maybe<&str> = Just("hello");
let e = Just(20);
let f = Just("world");
}
Generic functions
// a54.rs
fn identity <T> (x: T) -> T {
x
}
fn main() {
let a = identity(10);
let b = identity(’A’);
let c = identity("hello");
println!("{}, {}, {}", a, b, c);
}
Rust creates specialized versions of the “identity” function for each
argument type. This is called “monomorphization”.
Product Types: Structures
// a55.rs
struct Rectangle {
h: f64,
w: f64,
}
impl Rectangle {
fn area(&self) -> f64 {
self.h * self. w
}
}
fn main() {
let r = Rectangle { h: 2.0, w: 3.0 };
println!("area = {}", r.area());
}
Traits
// a56.rs
struct Rectangle {
h: f64,
w: f64,
}
struct Circle {
r: f64,
}
// is "a" bigger than "b" in area?
// should work for any shape
fn is_bigger <T1, T2> (a: T1, b: T2) -> bool {
a.area() > b.area()
}
fn main() {
let r = Rectangle { h: 3.0, w: 2.0 };
let c = Circle { r: 5.0 };
println!("{}", is_bigger(r, c));
}
Traits
// part of a57.rs
trait HasArea {
fn area(&self) -> f64;
}
impl HasArea for Rectangle {
fn area(&self) -> f64 {
self.h * self.w
}
}
impl HasArea for Circle {
fn area(&self) -> f64 {
3.14 * self.r * self.r
}
}
fn is_bigger <T1:HasArea, T2:HasArea>
(a: T1, b: T2) -> bool {
a.area() > b.area()
}
Tools
Cargo, the package manager (crates.io holds packages)
rustfmt, formatting Rust code according to style guidelines
clippy, a “lint” tool for Rust
rustup (https://www.rustup.rs/), the Rust toolchain
installer/manager
Interesting projects using Rust
Servo, from Mozilla. The next-gen browser engine.
Redox OS (https://www.redox-os.org/), an Operating System
being written from scratch in Rust.
ripgrep (https://github.com/BurntSushi/ripgrep), a fast text
search tool.
rocket.rs - a powerful web framework.
More: https://github.com/kud1ing/awesome-rust
Companies using Rust
Friends of Rust: https://www.rust-lang.org/vi-VN/friends.html
Documentation
Official Rust book (http://rust-lang.github.io/book/). The
second edition is far better, even though it is incomplete.
Upcoming O’Reilly book:
http://shop.oreilly.com/product/0636920040385.do
http://intorust.com/ (screencasts for learning Rust)

Más contenido relacionado

La actualidad más candente

AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
Letswift Swift 3.0
Letswift Swift 3.0Letswift Swift 3.0
Letswift Swift 3.0Sehyun Park
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokusHamletDRC
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
Objective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchObjective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchMatteo Battaglio
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahNick Plante
 
Groovy presentation
Groovy presentationGroovy presentation
Groovy presentationManav Prasad
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)HamletDRC
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Heiko Behrens
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoMuhammad Abdullah
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedSusan Potter
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2José Paumard
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnMoriyoshi Koizumi
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersBartosz Kosarzycki
 
Alfresco the clojure way
Alfresco the clojure wayAlfresco the clojure way
Alfresco the clojure wayCarlo Sciolla
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better JavaGarth Gilmour
 

La actualidad más candente (20)

Modern C++
Modern C++Modern C++
Modern C++
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Letswift Swift 3.0
Letswift Swift 3.0Letswift Swift 3.0
Letswift Swift 3.0
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Objective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchObjective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central Dispatch
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 
Groovy presentation
Groovy presentationGroovy presentation
Groovy presentation
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demo
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
Alfresco the clojure way
Alfresco the clojure wayAlfresco the clojure way
Alfresco the clojure way
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better Java
 

Destacado

Rust Programming Language
Rust Programming LanguageRust Programming Language
Rust Programming LanguageJaeju Kim
 
Servo: The parallel web engine
Servo: The parallel web engineServo: The parallel web engine
Servo: The parallel web engineBruno Abinader
 
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOMERuby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOMEJulien Fitzpatrick
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011Patrick Walton
 
Introduction to Rust Programming Language
Introduction to Rust Programming LanguageIntroduction to Rust Programming Language
Introduction to Rust Programming LanguageRobert 'Bob' Reyes
 
Rust: Systems Programming for Everyone
Rust: Systems Programming for EveryoneRust: Systems Programming for Everyone
Rust: Systems Programming for EveryoneC4Media
 
Performance Comparison of Mutex, RWLock and Atomic types in Rust
Performance Comparison of Mutex, RWLock and  Atomic types in RustPerformance Comparison of Mutex, RWLock and  Atomic types in Rust
Performance Comparison of Mutex, RWLock and Atomic types in RustMitsunori Komatsu
 
Type-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzzType-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzzFranklin Chen
 
RUSTing -- Partially Ordered Rust Programming Ruminations
RUSTing -- Partially Ordered Rust Programming RuminationsRUSTing -- Partially Ordered Rust Programming Ruminations
RUSTing -- Partially Ordered Rust Programming RuminationsAngelo Corsaro
 
Rust: Unlocking Systems Programming
Rust: Unlocking Systems ProgrammingRust: Unlocking Systems Programming
Rust: Unlocking Systems ProgrammingC4Media
 
She Sells C Shells (by the Rust Shore)
She Sells C Shells (by the Rust Shore)She Sells C Shells (by the Rust Shore)
She Sells C Shells (by the Rust Shore)David Evans
 
What the &~#@&lt;!? (Memory Management in Rust)
What the &~#@&lt;!? (Memory Management in Rust)What the &~#@&lt;!? (Memory Management in Rust)
What the &~#@&lt;!? (Memory Management in Rust)David Evans
 
Rust: история языка и контекст применения
Rust: история языка и контекст примененияRust: история языка и контекст применения
Rust: история языка и контекст примененияNikita Baksalyar
 
Introduction to rust: a low-level language with high-level abstractions
Introduction to rust: a low-level language with high-level abstractionsIntroduction to rust: a low-level language with high-level abstractions
Introduction to rust: a low-level language with high-level abstractionsyann_s
 
Почему Rust стоит вашего внимания
Почему Rust стоит вашего вниманияПочему Rust стоит вашего внимания
Почему Rust стоит вашего вниманияMichael Pankov
 
Embedded Rust on IoT devices
Embedded Rust on IoT devicesEmbedded Rust on IoT devices
Embedded Rust on IoT devicesLars Gregori
 
Embedded Rust – Rust on IoT devices
Embedded Rust – Rust on IoT devicesEmbedded Rust – Rust on IoT devices
Embedded Rust – Rust on IoT devicesLars Gregori
 

Destacado (20)

Rust Programming Language
Rust Programming LanguageRust Programming Language
Rust Programming Language
 
Servo: The parallel web engine
Servo: The parallel web engineServo: The parallel web engine
Servo: The parallel web engine
 
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOMERuby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
 
Fpga
FpgaFpga
Fpga
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011
 
Introduction to Rust Programming Language
Introduction to Rust Programming LanguageIntroduction to Rust Programming Language
Introduction to Rust Programming Language
 
Rust: Systems Programming for Everyone
Rust: Systems Programming for EveryoneRust: Systems Programming for Everyone
Rust: Systems Programming for Everyone
 
Performance Comparison of Mutex, RWLock and Atomic types in Rust
Performance Comparison of Mutex, RWLock and  Atomic types in RustPerformance Comparison of Mutex, RWLock and  Atomic types in Rust
Performance Comparison of Mutex, RWLock and Atomic types in Rust
 
Type-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzzType-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzz
 
RUSTing -- Partially Ordered Rust Programming Ruminations
RUSTing -- Partially Ordered Rust Programming RuminationsRUSTing -- Partially Ordered Rust Programming Ruminations
RUSTing -- Partially Ordered Rust Programming Ruminations
 
Rust: Unlocking Systems Programming
Rust: Unlocking Systems ProgrammingRust: Unlocking Systems Programming
Rust: Unlocking Systems Programming
 
She Sells C Shells (by the Rust Shore)
She Sells C Shells (by the Rust Shore)She Sells C Shells (by the Rust Shore)
She Sells C Shells (by the Rust Shore)
 
What the &~#@&lt;!? (Memory Management in Rust)
What the &~#@&lt;!? (Memory Management in Rust)What the &~#@&lt;!? (Memory Management in Rust)
What the &~#@&lt;!? (Memory Management in Rust)
 
Erlang
ErlangErlang
Erlang
 
Rust: история языка и контекст применения
Rust: история языка и контекст примененияRust: история языка и контекст применения
Rust: история языка и контекст применения
 
OOP in Rust
OOP in RustOOP in Rust
OOP in Rust
 
Introduction to rust: a low-level language with high-level abstractions
Introduction to rust: a low-level language with high-level abstractionsIntroduction to rust: a low-level language with high-level abstractions
Introduction to rust: a low-level language with high-level abstractions
 
Почему Rust стоит вашего внимания
Почему Rust стоит вашего вниманияПочему Rust стоит вашего внимания
Почему Rust стоит вашего внимания
 
Embedded Rust on IoT devices
Embedded Rust on IoT devicesEmbedded Rust on IoT devices
Embedded Rust on IoT devices
 
Embedded Rust – Rust on IoT devices
Embedded Rust – Rust on IoT devicesEmbedded Rust – Rust on IoT devices
Embedded Rust – Rust on IoT devices
 

Similar a Rust Workshop - NITC FOSSMEET 2017

Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Yandex
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовYandex
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Troy Miles
 
GDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptxGDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptxGDSCVJTI
 
Clean & Typechecked JS
Clean & Typechecked JSClean & Typechecked JS
Clean & Typechecked JSArthur Puthin
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeMicrosoft Tech Community
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeMicrosoft Tech Community
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Vincenzo Iozzo
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part iiJonah Marrs
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedPascal-Louis Perez
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
Flashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas MacFlashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas MacESET Latinoamérica
 

Similar a Rust Workshop - NITC FOSSMEET 2017 (20)

Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
 
Le langage rust
Le langage rustLe langage rust
Le langage rust
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Rustlabs Quick Start
Rustlabs Quick StartRustlabs Quick Start
Rustlabs Quick Start
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
GDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptxGDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptx
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
Clean & Typechecked JS
Clean & Typechecked JSClean & Typechecked JS
Clean & Typechecked JS
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
 
Introduction to Rust
Introduction to RustIntroduction to Rust
Introduction to Rust
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part ii
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing Speed
 
Rust
RustRust
Rust
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Flashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas MacFlashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas Mac
 

Último

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 

Último (20)

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 

Rust Workshop - NITC FOSSMEET 2017

  • 1. The Rust Programming Language Pramode C.E March 2, 2017
  • 2. A language that doesn’t affect the way you think about programming, is not worth knowing. Alan Perlis.
  • 4. Why is Rust so exciting? Safe low-level systems programming Memory safety without garbage collection High-level abstractions (influenced by statically typed functional programming languages like ML) without run-time overhead Concurrency without data races
  • 5. Why not just use C/C++? The second big thing each student should learn is: How can I avoid being burned by C’s numerous and severe shortcomings? This is a development environment where only the paranoid can survive. http://blog.regehr.org/archives/1393
  • 6. Why not just use C/C++? Figure 2: Cloudbleed
  • 7. A bit of Rust history Started by Graydon Hoare as a personal project in 2006 Mozilla foundation started sponsoring Rust in 2010 Rust 1.0 released in May, 2015 Regular six week release cycles
  • 8. Core language features Memory safety without garbage collection Ownership Move Semantics Borrowing and lifetimes Static Typing with Type Inference Algebraic Data Types (Sum and Product types) Exhaustive Pattern Matching Trait-based generics Iterators Zero Cost Abstractions Concurrency without data races Efficient C bindings, minimal runtime
  • 9. Structure of this workshop Understanding the problems with C/C++ Understanding Ownership, Borrow, Move semantics and Lifetimes Other features (depending on availability of time)
  • 10. The Stack // a0.c int main() { int a = 1, b = 2; return 0; }
  • 11. The Stack Figure 3: The C stack
  • 12. Buffer overflow // a1.c int main() { int i=1; int a[4]; int j=2; a[4] = 5; // bug a[5] = 6; // bug a[10000] = 7; // bug }
  • 13. Buffer overflow Figure 4: Buffer overflow diagram
  • 14. Pointers in C // a2.c int main() { int a = 10; int *b; b = &a; *b = 20; }
  • 15. Pointers in C Figure 5: How pointer variables are stored in memory
  • 16. Stack Frames - deallocations and allocations // a3.c void fun2() { int e=5, f=6; } void fun1() { int c=3, d=4; } int main() { int a=1, b=2; fun1(); fun2(); return 0; }
  • 17. Stack Frames - allocations and deallocations Figure 6: Multiple stack frames
  • 18. Stack Frames - allocations and deallocations Figure 7: Multiple stack frames
  • 19. Dangling Pointers // a4.c void fun2() { int m = 1; int n = 2; } int* fun1() { int *p; int q = 0; p = &q; return p; // bug } int main() { int *a, b; a = fun1(); *a = 10; fun2(); b = *a; }
  • 20. Dangling pointers Figure 8: Dangling pointer
  • 21. Null pointer dereferencing // a6.c #include <strings.h> #include <stdio.h> int main() { char s[100] = "hello"; char *p; p = index(s, ’f’); *p = ’a’; // bug! return 0; }
  • 22. Heap allocation - malloc and free // a7.c #include <stdlib.h> void fun() { char *c; c = malloc(10*sizeof(char)); /* do some stuff here */ free(c); } int main() { fun(); }
  • 23. Heap allocation - malloc and free Figure 9: A stack location pointing to a heap location
  • 24. Memory leaks // a8.c #include <stdlib.h> void fun() { char *c; c = malloc(10*sizeof(char)); /* do some stuff here */ } int main() { fun(); // bug! memory leak. }
  • 25. Use-after-free // a9.c #include <stdlib.h> void fun(char *t) { /* do some stuff here */ free(t); } int main() { char *c; c = malloc(10 * sizeof(char)); fun(c); c[0] = ’A’; //bug! user-after-free }
  • 26. Double free // a10.c #include <stdlib.h> void fun(char *t) { /* do some stuff here */ free(t); } int main() { char *c; c = malloc(10 * sizeof(char)); fun(c); free(c); //bug! double free }
  • 27. Undefined behaviours and optimization // a11.c #include <limits.h> #include <stdio.h> // compile the code with optimization (-O3) and without int main() { int c = INT_MAX; if (c+1 < c) printf("hellon"); printf("%dn", c+1); }
  • 29. Undefined behaviours When tools like the bounds checking GCC, Purify, Valgrind, etc. first showed up, it was interesting to run a random UNIX utility under them. The output of the checker showed that these utility programs, despite working perfectly well, executed a ton of memory safety errors such as use of uninitialized data, accesses beyond the ends of arrays, etc. Just running grep or whatever would cause tens or hundreds of these errors to happen. From: http://blog.regehr.org/archives/226
  • 30. Undefined behaviours More and more, I’m starting to wonder how safety-critical code can continue being written in C. A comment on: http://blog.regehr.org/archives/232
  • 31. Hello, world! // a12.rs fn main() { println!("hello, world!"); } Compile: rustc a12.rs Run: ./a12
  • 32. Static Typing and Type inference // a12-1.rs fn sqr(x: i32) -> i32 { let y = x * x; // type inferred y } fn main() { let t1 = sqr(10); // type inferred let t2:i32 = sqr(20); println!("sqr 10 = {}, sqr 20 ={}", t1, t2); }
  • 33. Static Typing and Type Inference The Rust type system is considerably more advanced than that of “mainstream” languages like Java,C. https://github.com/jaheba/stuff/blob/master/communicating_intent. http://ferrisellis.com/posts/rust-implementing-units-for- types/ https://fsharpforfunandprofit.com/series/designing-with- types.html (you can do most of these in Rust)
  • 34. Immutability // a12-2.rs fn main() { let x = 0; // x is immutable let mut y = 1; x = x + 1; // does not work y = y + 1; }
  • 35. Scope // a12-3.rs fn main() { let x = 10; { let y = 20; } println!("x={}, y={}", x, y); }
  • 36. Ownership // a13.rs fn main() { let v = vec![10, 20, 30]; println!("{:?}", v); } // how is v deallocated?
  • 37. Ownership Figure 11: Memory representation of a vector
  • 38. Ownership // a14.rs fn fun1() { let v = vec![10 ,20 ,30]; } // how is v deallocated? fn main() { fun1(); }
  • 39. Ownership // a15.rs fn main() { let v1 = vec![10 ,20 ,30]; let v2 = v1; println!("{:?}", v2); } // do we have a double free here?
  • 41. Ownership // a15-1.rs fn fun(v2: Vec<i32>) { println!("{:?}", v2); } fn main() { let v1 = vec![10, 20, 30]; fun(v1); } // do we have a double free here?
  • 42. Ownership // a16.rs fn main() { let v1 = vec![10, 20, 30]; let mut v2 = v1; v2.truncate(2); println!("{:?}", v2); } // what happens if we try to acces the // vector through v1?
  • 43. Move semantics // a17.rs fn main() { let v1 = vec![1,2,3]; let mut v2 = v1; v2.truncate(2); println!("{:?}", v1); }
  • 44. Move semantics // a15-2.rs fn fun(v2: Vec<i32>) { println!("{:?}", v2); } fn main() { let v1 = vec![10, 20, 30]; fun(v1); println!("{:?}", v1); }
  • 45. Move semantics // a18.rs fn main() { let a = (1, 2.3); let b = a; println!("{:?}", a); }
  • 46. Move semantics // a19.rs fn main() { let a = (1, 2.3, vec![10,20]); let b = a; println!("{:?}", a); }
  • 47. Memory safety without garbage collection Languages like Python, Java etc achieve memory safety at run time through garbage collection. Rust achieves memory safety at compile time by static type analysis. Ownership + move semantics has some interesting properties which makes them suitable for general resource management (not just memory).
  • 48. Garbage Collection # a20.py a = [10, 20, 30] a.append(40) print a
  • 49. Garbage Collection # a21.py a = [10, 20, 30] b = a b.append(40) print a # what does this print?
  • 50. Garbage Collection Figure 13: References in Python
  • 51. Garbage Collection Figure 14: Reference Counting
  • 52. Garbage Collection # a22.py a = [10, 20, 30] b = a # refcount is 2 a = "hello" # refcount is 1 b = "world" # refcount drops to zero, deallocate
  • 53. Resource management # a23.py def read_a_line(): f = open("/etc/passwd") s = f.readline() f.close() # close the file, release OS resources return s while True: print read_a_line()
  • 54. Resource Leaks in managed languages # a24.py def read_a_line(): f = open("/etc/passwd") s = f.readline() # No explicit "close" return s while True: print read_a_line()
  • 55. Rust means never having to close a file! // a25.rs use std::fs::File; use std::io::Read; fn read_whole_file() -> String { let mut s = String::new(); let mut f = File::open("/etc/passwd").unwrap(); f.read_to_string(&mut s).unwrap(); s // return the string } fn main() { println!("{}", read_whole_file()); } Read: http://blog.skylight.io/rust-means-never-having-to-close-a-socket/
  • 56. Ownership / Move: Limitations // a26.rs fn vector_sum(v: Vec<i32>) -> i32 { //assume v is always a 3 elemnt vector v[0] + v[1] + v[2] } fn main() { let v = vec![1,2,3]; let s = vector_sum(v); println!("{}",s); }
  • 57. Ownership / Move: Limitations // a27.rs fn vector_sum(v: Vec<i32>) -> i32 { v[0] + v[1] + v[2] } fn vector_product(v: Vec<i32>) -> i32 { v[0] * v[1] * v[2] } fn main() { let v = vec![1,2,3]; let s = vector_sum(v); let p = vector_product(v); println!("{}",p); } // does this code compile?
  • 58. Immutable Borrow // a28.rs fn vector_sum(v: &Vec<i32>) -> i32 { v[0] + v[1] + v[2] } fn vector_product(v: &Vec<i32>) -> i32 { v[0] * v[1] * v[2] } fn main() { let v = vec![1,2,3]; let s = vector_sum(&v); let p = vector_product(&v); println!("v={:?}, s={}, p={}", v, s, p); }
  • 59. Immutable Borrow // a29.rs fn main() { let v = vec![1,2,3]; let t1 = &v; let t2 = &v; println!("{}, {}, {}", t1[0], t2[0], v[0]); } // any number of immutable borrows are ok!
  • 60. Immutable Borrow // a30.rs fn change(t1: &Vec<i32>) { t1[0] = 10; } fn main() { let mut v = vec![1,2,3]; change(&v); } // Does the program compile?
  • 61. Mutable Borrow // a31.rs fn change(t1: &mut Vec<i32>) { t1[0] = 10; } fn main() { let mut v = vec![1,2,3]; change(&mut v); println!("{:?}", v); }
  • 62. A use-after-free bug // a32.c #include <stdlib.h> int main() { char *p = malloc(10 * sizeof(char)); char *q; q = p + 2; free(p); *q = ’A’; // bug! return 0; }
  • 63. Vector allocation in Rust // a33.rs fn main() { let mut a = vec![]; a.push(1); a.push(2); a.push(3); a.push(4); a.push(5); println!("{:?}", a); }
  • 64. Vector allocation in Rust/C++ Figure 15: Growing a vector
  • 65. A use-after-free bug in C++ // a33-1.cpp #include <vector> #include <iostream> using namespace std; int main() { vector<int> v; int *p; v.push_back(1); p = &v[0]; v.push_back(2); *p = 100; // bug! cout << v[0] << endl; }
  • 66. A use-after-free bug in Rust? // a34.rs fn main() { let mut v = vec![10, 20, 30, 40]; let p1 = &v[1]; v.push(50); // bug if we try to use p1 // does this code compile? }
  • 67. Borrowing Rules Any number of immutable borrows can co-exist. A mutable borrow can not co-exist with other mutable or immutable borrows. The “borrow checker” checks violations of these rules at compile time.
  • 68. Borrow checker limitations The borrow checker gives you safety by rejecting ALL unsafe programs. But it is not perfect in the sense it rejects safe programs also; “fighting the borrow checker” is a common sporting activity among Rust programmers :) There are plans to improve the situation: http://smallcultfollowing.com/babysteps/blog/2017/03/01/nested- method-calls-via-two-phase-borrowing/
  • 69. Borrow checker limitations - an example // a35.rs fn main() { let mut v = vec![10,20,30]; v.push(v.len()); } // this will not compile
  • 70. Borrow checker limitations - an example // a36.rs // Same as a35.rs fn main() { let mut v = vec![10,20,30]; let tmp0 = &v; let tmp1 = &mut v; let tmp2 = Vec::len(tmp0); //v.len() Vec::push(tmp1, tmp2);// v.push(tmp2) }
  • 71. Lifetimes // a37.rs fn main() { let ref1: &Vec<i32>; { let v = vec![1, 2, 3]; ref1 = &v; } // v gets deallocated as it goes out of // the scope. What about ref1? Do we have // a "dangling pointer" here? }
  • 72. Lifetimes // a38.rs fn foo() -> Vec<i32> { let v = vec![1, 2, 3]; v // transfer ownership to caller } fn main() { let p = foo(); println!("{:?}", p); }
  • 73. Lifetimes // a39.rs fn foo() -> &Vec<i32> { let v = vec![1, 2, 3]; &v // Will this compile? } fn main() { let p = foo(); }
  • 74. Explicit Lifetime Annotations // a40.rs fn foo(v1: &Vec<i32>, v2: &Vec<i32>) -> &i32 { &v1[0] } fn main() { let v1 = vec![1, 2, 3]; let p:&i32; { let v2 = vec![4, 5, 6]; p = foo(&v1, &v2); // How does the compiler know, just by looking at // the signature of "foo", that the reference // returned by "foo" will live as long as "p"? } }
  • 75. Explicit Lifetime Annotations // a41.rs fn foo<’a, ’b>(v1: &’a Vec<i32>, v2: &’b Vec<i32>) -> &’a i32 { &v1[0] } fn main() { let v1 = vec![1, 2, 3]; let p:&i32; { let v2 = vec![4, 5, 6]; p = foo(&v1, &v2); } }
  • 76. Explicit Lifetime Annotations // a42.rs fn foo<’a, ’b>(v1: &’a Vec<i32>, v2: &’b Vec<i32>) -> &’b i32 { &v2[0] } fn main() { let v1 = vec![1, 2, 3]; let p:&i32; { let v2 = vec![4, 5, 6]; p = foo(&v1, &v2); } }
  • 77. Unsafe // a43.rs fn main() { // a is a "raw" pointer intialized to 0 let a: *mut u32 = 0 as *mut u32; *a = 0; }
  • 78. Unsafe // a44.rs fn main() { let a: *mut u32 = 0 as *mut u32; unsafe { *a = 0; } }
  • 79. Rust on microcontrollers Figure 16: Stellaris Launchpad
  • 80. Rust on microcontrollers // part of blinky.rs loop { gpio::port_write(gpio::GPIO_PORTF_BASE, gpio::GPIO_PIN_1, gpio::GPIO_PIN_1); delay(500000); gpio::port_write(gpio::GPIO_PORTF_BASE, gpio::GPIO_PIN_1, 0); delay(500000); }
  • 82. A complete web app in Rust (using rocket.rs) #![feature(plugin)] #![plugin(rocket_codegen)] extern crate rocket; #[get("/<name>")] fn index(name: &str) -> String { format!("nHello, {}!, hope you are enjoying the Rust workshop!n", name) } fn main() { rocket::ignite() .mount("/", routes![index]) .launch(); }
  • 83. Test run the web app! wget -q -O - http://128.199.100.27:8000/Mohan curl -s http://128.199.100.27:8000/Mohan
  • 84. End of Part 1 What we have seen so far is the “core” of Rust, these are the ideas which make Rust unique! Most of the other “interesting” ideas are borrowed from statically typed functional programming languages (like ML). (The first Rust compiler was written in Ocaml).
  • 85. End of Part 1 Figure 17: rustpoem
  • 86. Zero Cost Abstractions // a45.rs const N: u64 = 1000000000; fn main() { let r = (0..N) .map(|x| x + 1) .fold(0, |sum, i| sum+i); println!("{}", r); } // Compile with optimizations enabled: // rustc -O a45.rs
  • 87. Zero cost abstractions (0 .. N) => (0, 1, 2, 3, .... N-1) # an "iterator" (0 .. N).map(|x| x+1) => (1, 2, 3, 4 .... N) (1, 2, 3, ... N).fold(0, |sum, i| sum + i) => ((((0 + 1) + 2) + 3) + 4) + ....
  • 88. Zero cost abstractions Here is part of the assembly language code produced by the compiler for a45.rs: .Ltmp0: .cfi_def_cfa_offset 80 movabsq $500000000500000000, %rax movq %rax, (%rsp) leaq (%rsp), %rax movq %rax, 8(%rsp) Looks like the expression has been evaluated fully at compile time itself! Here is the commandline used to produce the above output: rustc -O a45.rs --emit=asm
  • 89. Zero cost abstractions You can write confidently using all the high-level abstractions the language has to offer. Your code will almost always be as fast as hand-coded low level C!
  • 90. Sum Types and Pattern Matching // a46.rs enum Color { Red, Green, Blue, } use Color::*; fn main() { let c = Red; match c { Red => println!("color is Red!"), Green => println!("color is Green!"), Blue => println!("color is Blue!") } }
  • 91. Sum Types and Pattern Matching // a47.rs #[derive(Debug)] enum Shape { Circle(u32), Square (u32), Rectangle {ht: u32, wid: u32}, } use Shape::*; fn main() { let s1 = Circle(10); let s2 = Square(5); let s3 = Rectangle {ht: 10, wid: 2}; println!("{:?}", s3); }
  • 92. Pattern matching is exhaustive // a48.rs #[derive(Debug)] enum Shape { Circle(f64), Square (f64), Rectangle {ht: f64, wid: f64}, } use Shape::*; fn area(s: Shape) -> f64 { match s { Circle(x) => 3.14 * x * x, Rectangle {ht: x, wid: y} => x * y, } // bug! } fn main() { let s1 = Circle(10.0); println!("{}", area(s1)); }
  • 93. The Option type // a49.rs fn main() { let mut a = vec![10]; let b = a.pop(); let c = a.pop(); let d = b + 1; // does it compile? }
  • 94. The Option type // a50.rs fn main() { let mut a = vec![10]; let b = a.pop(); let c = a.pop(); println!("b = {:?}, c = {:?}", b, c); }
  • 95. The Option type // a51.rs fn main() { let mut a = vec![10]; let b = a.pop(); match b { Some(x) => println!("pop: {}", x), None => println!("empty stack"), } }
  • 96. The Option type // a52.rs fn main() { let mut a = vec![10]; let b = a.pop(); println!("{}", b.unwrap()); let c = a.pop(); println!("{}", c.unwrap()); }
  • 97. Generic Enums - an implementation of Option // a53.rs // A "generic" enum similar to Option enum Maybe <T> { Just(T), Nothing, } use Maybe::*; fn main() { let c:Maybe<i32> = Just(10); let d:Maybe<&str> = Just("hello"); let e = Just(20); let f = Just("world"); }
  • 98. Generic functions // a54.rs fn identity <T> (x: T) -> T { x } fn main() { let a = identity(10); let b = identity(’A’); let c = identity("hello"); println!("{}, {}, {}", a, b, c); } Rust creates specialized versions of the “identity” function for each argument type. This is called “monomorphization”.
  • 99. Product Types: Structures // a55.rs struct Rectangle { h: f64, w: f64, } impl Rectangle { fn area(&self) -> f64 { self.h * self. w } } fn main() { let r = Rectangle { h: 2.0, w: 3.0 }; println!("area = {}", r.area()); }
  • 100. Traits // a56.rs struct Rectangle { h: f64, w: f64, } struct Circle { r: f64, } // is "a" bigger than "b" in area? // should work for any shape fn is_bigger <T1, T2> (a: T1, b: T2) -> bool { a.area() > b.area() } fn main() { let r = Rectangle { h: 3.0, w: 2.0 }; let c = Circle { r: 5.0 }; println!("{}", is_bigger(r, c)); }
  • 101. Traits // part of a57.rs trait HasArea { fn area(&self) -> f64; } impl HasArea for Rectangle { fn area(&self) -> f64 { self.h * self.w } } impl HasArea for Circle { fn area(&self) -> f64 { 3.14 * self.r * self.r } } fn is_bigger <T1:HasArea, T2:HasArea> (a: T1, b: T2) -> bool { a.area() > b.area() }
  • 102. Tools Cargo, the package manager (crates.io holds packages) rustfmt, formatting Rust code according to style guidelines clippy, a “lint” tool for Rust rustup (https://www.rustup.rs/), the Rust toolchain installer/manager
  • 103. Interesting projects using Rust Servo, from Mozilla. The next-gen browser engine. Redox OS (https://www.redox-os.org/), an Operating System being written from scratch in Rust. ripgrep (https://github.com/BurntSushi/ripgrep), a fast text search tool. rocket.rs - a powerful web framework. More: https://github.com/kud1ing/awesome-rust
  • 104. Companies using Rust Friends of Rust: https://www.rust-lang.org/vi-VN/friends.html
  • 105. Documentation Official Rust book (http://rust-lang.github.io/book/). The second edition is far better, even though it is incomplete. Upcoming O’Reilly book: http://shop.oreilly.com/product/0636920040385.do http://intorust.com/ (screencasts for learning Rust)