SlideShare a Scribd company logo
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 1/49
RUSTRUST
Be pinched by a cBe pinched by a cRUSTRUSTacean to prevent programmingacean to prevent programming
errors !errors !
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 2/49
2 words about us2 words about us
$ cat ~/.bash_profile
NAME="René Ribaud"
AGE=43
source ./1998.sh
PROFESSION="Unices system and storage" 
"administrator , since 2003"
HISTORY="Lots (too many) infrastructure" 
"implementation projects" 
"Discover Linux & FLOSS between" 
"1995 / 2000" 
"First step in the cloud around 2011" 
", pre-sales solution architect" 
"2014 (Cloud, DevOps)" 
"I’m an Ops !"
COMPANY="CGI 20th November 2017"
JOB="Information system architect" 
"specialized around DevOps technologies"
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 3/49
2 words about us2 words about us
François BestFrançois Best
Freelance Developer
Embedded/Realtime C/C++
background
Seduced by the Dark Side of the Web
Current interests:
Rust (of course)
Security / Cryptography
Decentralisation
Personal data protection
& de-GAFAMing
Github: |
Web:
@franky47
@47ng
francoisbest.com
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 4/49
What is RUST ?What is RUST ?
New systems programming language
Multi paradigm language (imperative, functional, object
oriented (not fully))
By Mozilla and the Community
Dual license MIT and Apache v2.0
First stable release May 15th, 2015
Rust 2018 (v1.31), a major new edition released
December 6th, 2018
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 5/49
Goal ?Goal ?
Provide an alternative to C/C++ and also higher-levelProvide an alternative to C/C++ and also higher-level
languageslanguages
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 6/49
Why is this Ops guy speaking about aWhy is this Ops guy speaking about a
programming language ?programming language ?
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 7/49
Immune to coder disease 1Immune to coder disease 1
My language is the best !My language is the best !
And my code is also the best !And my code is also the best !
This is part of my job to know languages and especially how to build projects usingThis is part of my job to know languages and especially how to build projects using
themthem
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 8/49
Immune to coder disease 2Immune to coder disease 2
I don't make mistakes, only bad coders are making onesI don't make mistakes, only bad coders are making ones
Really, how do you explain all major projects security issues ?Really, how do you explain all major projects security issues ?
I'm fed up about segfaults and null pointer exceptions !I'm fed up about segfaults and null pointer exceptions !
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 9/49
Why is RUST exciting to me ?Why is RUST exciting to me ?
And probably why should you look at it ?And probably why should you look at it ?
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 10/49
PromisesPromises
Focus on safety -> avoids errors and helps finding them
!
Especially safe concurrency
Fast, really fast !
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 11/49
But alsoBut also
Compiled language, few runtime dependencies
Produces binaries, that could be static with musl
Can interact easily with other languages via ABI and
bindings (Python, C/C++, JS...)
State of mind, hard at compile time, but safe at runtime
Somewhere challenging !
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 12/49
Ripgrep (rg)Ripgrep (rg)
An application written in RustAn application written in Rust
A grep enhanced
Compatible with standard grep
Search speed is really
impressive
Look also at fd, exa, lsd...
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 13/49
And a cute mascot !And a cute mascot !
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 14/49
What it looks likeWhat it looks like
extern crate flate2;
use flate2::read::GzDecoder;
use std::fs::File;
use std::io::Read;
fn run() -> String {
let path = "ascii.txt.gz";
let mut contents = String::new();
let gz = File::open(path).unwrap(); // open and decompress file
let mut uncompress = GzDecoder::new(gz);
uncompress.read_to_string(&mut contents).unwrap();
contents // return implicitly contents
}
fn main() {
println!("Hello, world!");
let result = run(); // call run function
println!("{}", result); // display compress file content
}
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 15/49
Language featuresLanguage features
Static type system with local type
inference
Explicit mutability
Zero-cost abstractions
Runtime-independent concurrency safety
Errors are values
No null
Static automatic memory management
No garbage collection
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 16/49
Safety is achieved by mainly 3 conceptsSafety is achieved by mainly 3 concepts
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 17/49
MutabilityMutability
struct Bike {
speed: u32,
distance: u32,
brand: String,
}
fn main() {
let mybike = Bike {
speed: 25,
distance: 1508,
brand: "Liteville".to_string(),
};
mybike.speed = 30; //Reassign !!!
println!(
"Bike {}: speed={} distance={}",
mybike.brand, mybike.speed, mybike.distance
);
}
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 18/49
Mutability errorMutability error
error[E0594]: cannot assign to field `mybike.speed` of immutable binding
--> src/main.rs:14:5
|
8 | let mybike = Bike {
| ------ help: make this binding mutable: `mut mybike`
...
14 | mybike.speed = 30; //Reassign !!!
| ^^^^^^^^^^^^^^^^^ cannot mutably borrow field of immutable binding
error: aborting due to previous error
For more information about this error, try `rustc --explain E0594`.
error: Could not compile `immutability`.
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 19/49
Ownership & BorrowingOwnership & Borrowing
Every piece of data is uniquely owned
Ownership can be passed
When owned data reaches the end of a scope, it is
destroyed
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 20/49
OwnershipOwnership
fn main() {
let s1 = String::from("Hello, RUST ! 🦀");
let s2 = s1;
println!("{}", s1);
}
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 21/49
Ownership errorOwnership error
--> src/main.rs:3:9
|
3 | let s2 = s1;
|
= note: #[warn(unused_variables)] on by default
error[E0382]: borrow of moved value: `s1`
--> src/main.rs:4:20
|
3 | let s2 = s1;
| -- value moved here
4 | println!("{}", s1);
| ^^ value borrowed here after move
|
= note: move occurs because `s1` has type
`std::string::String`, which does not implement the `Copy` trait
error: aborting due to previous error
For more information about this error, try `rustc --explain E0382`.
error: Could not compile `owned2`.
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 22/49
OwnershipOwnership
fn main() {
let s = String::from("Hello, RUST ! 🦀");
display(s);
display(s); // Already owned !
}
fn display(some_string: String) {
println!("{}", some_string);
}
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 23/49
Ownership errorOwnership error
error[E0382]: use of moved value: `s`
--> src/main.rs:5:13
|
4 | display(s);
| - value moved here
5 | display(s); // Already owned !
| ^ value used here after move
|
= note: move occurs because `s` has type `std::string::String`,
which does not implement the `Copy` trait
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 24/49
Ownership & BorrowingOwnership & Borrowing
Access can be borrowed (mutable and
immutable)
You can borrow mutably once
Or multiple times immutably
Exclusive: mutable or immutable, never both
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 25/49
BorrowingBorrowing
fn main() {
let s = String::from("Hello, RUST ! 🦀");
display(&s);
display(&s);
}
fn display(some_string: &String) {
println!("{}", some_string);
}
Hello, RUST ! 🦀
Hello, RUST ! 🦀
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 26/49
Borrowing mutableBorrowing mutable
fn main() {
let s = String::from("Hello");
change(&s);
println!("{}", s);
}
fn change(some_string: &String) {
some_string.push_str(", RUST ! 🦀");
}
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 27/49
Borrowing mutable errorBorrowing mutable error
error[E0596]: cannot borrow immutable borrowed content `*some_string` as mutable
--> src/main.rs:9:5
|
8 | fn change(some_string: &String) {
| ------- use `&mut String` here to make mutable
9 | some_string.push_str(", RUST ! 🦀");
| ^^^^^^^^^^^ cannot borrow as mutable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`.
error: Could not compile `borrow_mut`.
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 28/49
Borrowing mutable fixedBorrowing mutable fixed
fn main() {
let mut s = String::from("Hello");
change(&mut s);
println!("{}", s);
}
fn change(some_string: &mut String) {
some_string.push_str(", RUST ! 🦀");
}
Hello, RUST ! 🦀
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 29/49
References validity checksReferences validity checks
#[derive(Debug)]
struct Person<'a> {
first_name: &'a str,
last_name: &'a str,
age: &'a i32,
phone: Vec<&'a str>,
}
fn return_reference<'a>() -> Person<'a> {
let age = 25;
Person {
first_name: "John",
last_name: "Doe",
age: &age,
phone: vec!["123-123", "456-456"],
}
}
fn main() {
let person = return_reference();
println!("{:?}", person);
}
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 30/49
References validity checks errorReferences validity checks error
error[E0597]: `age` does not live long enough
--> src/main.rs:15:15
|
15 | age: &age,
| ^^^ borrowed value does not live long enough
...
18 | }
| - borrowed value only lives until here
|
note: borrowed value must be valid for the lifetime 'a as defined on the function
body at 9:1...
--> src/main.rs:9:1
|
9 | fn return_reference<'a>() -> Person<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0597`.
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 31/49
Concurrency without fearConcurrency without fear
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 32/49
Concurrency without fearConcurrency without fear
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 33/49
Concurrency without fear errorConcurrency without fear error
Rust type system allows no data racesRust type system allows no data races
error[E0596]: cannot borrow `words` as mutable, as it is a captured variable
in a `Fn` closure
--> src/main.rs:19:54
|
19 | .for_each(|arg| tally_words(arg.to_string(), &mut words).unwrap());
| ^^^^^^^^^^ cannot borrow
as mutable
|
help: consider changing this to accept closures that implement `FnMut`
--> src/main.rs:19:19
|
19 | .for_each(|arg| tally_words(arg.to_string(), &mut words).unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`.
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 34/49
High level abstractionHigh level abstraction
Generics and TraitsGenerics and Traits
Define shared behavior
Define behavior based on types
Define behavior from various types with trait
bounds
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 35/49
Unsafe RustUnsafe Rust
Allow to disengage some safety features
Use at your own risk !
Crates using unsafe code can be audited with cargo-
geiger
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 36/49
A modern languageA modern language
with builtin code quality standardswith builtin code quality standards
Documentation embedded into code
Unit tests
Integration tests
Great documentation (books and std
lib)
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 37/49
A modern languageA modern language
with tools to be productivewith tools to be productive
Environment setup and update rustup
Package (crates) management cargo + plugin
Code formatting rustfmt
Compiler rustc
Efficient error messages
Potential solution
Linter clippy
Code completion racer
Help transition to 2018 edition rustfix
Editor integration (IntelliJ, Vs code, Vim,
Emacs...)
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 38/49
Opinionated for productivityOpinionated for productivity
Avoiding bikesheddingAvoiding bikeshedding
Crates have a defined filesystem structure
Modules & exports based on file location (like Python)
But with control over public / private exports (like
ES6)
Batteries included, but replaceable
Procedural macros for DSLs (eg: JSON, CSS...)
Custom compile-time extensions with build scripts
Cargo extensions with cargo-foo binary crates
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 39/49
Interesting cratesInteresting crates
That extend the std libThat extend the std lib
Date and time management chrono
Parallel iteration rayon
HTTP client reqwest
Command line parsing clap, docopt,
structopt
Logging log
Serialization serde
Regular expressions regex
...
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 40/49
Area of useArea of use
Command line tools
Web and network
services
Embedded device, IOT
WebAssembly
Games
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 41/49
Who is using Rust ?Who is using Rust ?
Mozilla, servo project
RedHat, stratis
project
Dropbox
Telenor
Chef
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 42/49
Who is using Rust ?Who is using Rust ?
Ready at dawn
Chucklefish that published Stardew Valley and Starbound,
is using Rust in their new projects Wargroove and
Witchbrook to get safe concurrency and portability
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 43/49
Who is using Rust ?Who is using Rust ?
Clevercloud, (Geoffroy Couprie)
nom, parser
Sozu, reverse proxy
Snips
ANSSI: RFC for secure application design in
Rust
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 44/49
Governance and communityGovernance and community
Rust is pragmaticRust is pragmatic
All features are driven by needs of real software
The language is evolved with user feedback
Consciously chooses familiar constructs
Picks good ideas from others
Doesn’t want to be the primary language at all
cost
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 45/49
Governance and communityGovernance and community
Beloved language and communityBeloved language and community
Voted "Most loved language" on Stackoverflow 2018,
2017, 2016
Only 1/100 of survey respondents have issues with the
Rust community
Newcomers from all directions
https://insights.stackoverflow.com/survey/2018/#most-loved-dreaded-and-wantedhttps://insights.stackoverflow.com/survey/2018/#most-loved-dreaded-and-wanted
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 46/49
Governance and communityGovernance and community
growthgrowth
https://8-p.info/visualizing-crates-io/https://8-p.info/visualizing-crates-io/
Crates.ioCrates.io
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 47/49
Governance and communityGovernance and community
Help from the communityHelp from the community
Lots of books
IRC and Discord
channels
User forum
Youtube channel
Meetups
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 48/49
Governance and communityGovernance and community
Beloved language and communityBeloved language and community
Experience from Mozilla to drive open projects
All major decisions, go to an open Request For
Comments process
Release every 6 weeks
3 channels: stable, beta and nightly
Medium time to merged PR for changes: 6 days!
More then 4/5 of contributions to the Rust language come
from outside Mozilla
The compiler has more then 2000 contributors
3/27/2019 Be pinched by a cRUSTacean to prevent programming errors !
localhost:8000/rust/?print-pdf#/ 49/49
THANK YOUTHANK YOU
René Ribaud <rene.ribaud@cgi.com>
François Best
<contact@francoisbest.com>

More Related Content

PDF
Bash is not a second zone citizen programming language
PDF
Bash in theory and in practice - part two
PDF
Bash in theory and in practice - part one
PDF
PDF
Arduino programming of ML-style in ATS
ODP
Writing webapps with Perl Dancer
PDF
Metasepi team meeting #17: Invariant captured by ATS's API
PPT
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
Bash is not a second zone citizen programming language
Bash in theory and in practice - part two
Bash in theory and in practice - part one
Arduino programming of ML-style in ATS
Writing webapps with Perl Dancer
Metasepi team meeting #17: Invariant captured by ATS's API
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)

What's hot (13)

PDF
Perl Dancer for Python programmers
ODP
Perl Moderno
PDF
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
PDF
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
PPT
Happy porting x86 application to android
PPTX
How to build a slack-hubot with js
PDF
Composer the right way - SunshinePHP
PDF
Cross Building the FreeBSD ports tree by Baptiste Daroussin
PDF
To swiftly go where no OS has gone before
PDF
Quick Intro To JRuby
PPTX
Connecting C++ and JavaScript on the Web with Embind
PPT
Rush, a shell that will yield to you
PPTX
Webinar - Windows Application Management with Puppet
Perl Dancer for Python programmers
Perl Moderno
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
Happy porting x86 application to android
How to build a slack-hubot with js
Composer the right way - SunshinePHP
Cross Building the FreeBSD ports tree by Baptiste Daroussin
To swiftly go where no OS has gone before
Quick Intro To JRuby
Connecting C++ and JavaScript on the Web with Embind
Rush, a shell that will yield to you
Webinar - Windows Application Management with Puppet
Ad

Similar to Be pinched by a cRUSTacean to prevent programming errors ! (20)

PDF
Intro to Rust 2019
ODP
Introduction To Rust
PDF
Rust: Reach Further (from QCon Sao Paolo 2018)
PPTX
Introduction to Rust (Presentation).pptx
ODP
Rust Primer
PDF
Rust: Reach Further
PDF
Le langage rust
PDF
Rust: Systems Programming for Everyone
PDF
Rust Intro @ Roma Rust meetup
PDF
Embedded Rust on IoT devices
PPTX
The Rust Programming Language vs The C Programming Language
PDF
The Rust Programming Language
PPT
Rust Programming Language
PDF
Introduction to Rust - Waterford Tech Meetup 2025
PDF
Rust and Eclipse
PPTX
Rust Intro
PDF
Why rust?
PPTX
Rust vs C++
PDF
Rust "Hot or Not" at Sioux
PDF
Introduction to Rust
Intro to Rust 2019
Introduction To Rust
Rust: Reach Further (from QCon Sao Paolo 2018)
Introduction to Rust (Presentation).pptx
Rust Primer
Rust: Reach Further
Le langage rust
Rust: Systems Programming for Everyone
Rust Intro @ Roma Rust meetup
Embedded Rust on IoT devices
The Rust Programming Language vs The C Programming Language
The Rust Programming Language
Rust Programming Language
Introduction to Rust - Waterford Tech Meetup 2025
Rust and Eclipse
Rust Intro
Why rust?
Rust vs C++
Rust "Hot or Not" at Sioux
Introduction to Rust
Ad

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation theory and applications.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Machine learning based COVID-19 study performance prediction
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Electronic commerce courselecture one. Pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPT
Teaching material agriculture food technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
Unlocking AI with Model Context Protocol (MCP)
Encapsulation theory and applications.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine learning based COVID-19 study performance prediction
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Electronic commerce courselecture one. Pdf
20250228 LYD VKU AI Blended-Learning.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Encapsulation_ Review paper, used for researhc scholars
Building Integrated photovoltaic BIPV_UPV.pdf
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
The AUB Centre for AI in Media Proposal.docx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Review of recent advances in non-invasive hemoglobin estimation
“AI and Expert System Decision Support & Business Intelligence Systems”

Be pinched by a cRUSTacean to prevent programming errors !

  • 1. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 1/49 RUSTRUST Be pinched by a cBe pinched by a cRUSTRUSTacean to prevent programmingacean to prevent programming errors !errors !
  • 2. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 2/49 2 words about us2 words about us $ cat ~/.bash_profile NAME="René Ribaud" AGE=43 source ./1998.sh PROFESSION="Unices system and storage" "administrator , since 2003" HISTORY="Lots (too many) infrastructure" "implementation projects" "Discover Linux & FLOSS between" "1995 / 2000" "First step in the cloud around 2011" ", pre-sales solution architect" "2014 (Cloud, DevOps)" "I’m an Ops !" COMPANY="CGI 20th November 2017" JOB="Information system architect" "specialized around DevOps technologies"
  • 3. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 3/49 2 words about us2 words about us François BestFrançois Best Freelance Developer Embedded/Realtime C/C++ background Seduced by the Dark Side of the Web Current interests: Rust (of course) Security / Cryptography Decentralisation Personal data protection & de-GAFAMing Github: | Web: @franky47 @47ng francoisbest.com
  • 4. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 4/49 What is RUST ?What is RUST ? New systems programming language Multi paradigm language (imperative, functional, object oriented (not fully)) By Mozilla and the Community Dual license MIT and Apache v2.0 First stable release May 15th, 2015 Rust 2018 (v1.31), a major new edition released December 6th, 2018
  • 5. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 5/49 Goal ?Goal ? Provide an alternative to C/C++ and also higher-levelProvide an alternative to C/C++ and also higher-level languageslanguages
  • 6. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 6/49 Why is this Ops guy speaking about aWhy is this Ops guy speaking about a programming language ?programming language ?
  • 7. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 7/49 Immune to coder disease 1Immune to coder disease 1 My language is the best !My language is the best ! And my code is also the best !And my code is also the best ! This is part of my job to know languages and especially how to build projects usingThis is part of my job to know languages and especially how to build projects using themthem
  • 8. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 8/49 Immune to coder disease 2Immune to coder disease 2 I don't make mistakes, only bad coders are making onesI don't make mistakes, only bad coders are making ones Really, how do you explain all major projects security issues ?Really, how do you explain all major projects security issues ? I'm fed up about segfaults and null pointer exceptions !I'm fed up about segfaults and null pointer exceptions !
  • 9. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 9/49 Why is RUST exciting to me ?Why is RUST exciting to me ? And probably why should you look at it ?And probably why should you look at it ?
  • 10. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 10/49 PromisesPromises Focus on safety -> avoids errors and helps finding them ! Especially safe concurrency Fast, really fast !
  • 11. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 11/49 But alsoBut also Compiled language, few runtime dependencies Produces binaries, that could be static with musl Can interact easily with other languages via ABI and bindings (Python, C/C++, JS...) State of mind, hard at compile time, but safe at runtime Somewhere challenging !
  • 12. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 12/49 Ripgrep (rg)Ripgrep (rg) An application written in RustAn application written in Rust A grep enhanced Compatible with standard grep Search speed is really impressive Look also at fd, exa, lsd...
  • 13. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 13/49 And a cute mascot !And a cute mascot !
  • 14. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 14/49 What it looks likeWhat it looks like extern crate flate2; use flate2::read::GzDecoder; use std::fs::File; use std::io::Read; fn run() -> String { let path = "ascii.txt.gz"; let mut contents = String::new(); let gz = File::open(path).unwrap(); // open and decompress file let mut uncompress = GzDecoder::new(gz); uncompress.read_to_string(&mut contents).unwrap(); contents // return implicitly contents } fn main() { println!("Hello, world!"); let result = run(); // call run function println!("{}", result); // display compress file content }
  • 15. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 15/49 Language featuresLanguage features Static type system with local type inference Explicit mutability Zero-cost abstractions Runtime-independent concurrency safety Errors are values No null Static automatic memory management No garbage collection
  • 16. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 16/49 Safety is achieved by mainly 3 conceptsSafety is achieved by mainly 3 concepts
  • 17. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 17/49 MutabilityMutability struct Bike { speed: u32, distance: u32, brand: String, } fn main() { let mybike = Bike { speed: 25, distance: 1508, brand: "Liteville".to_string(), }; mybike.speed = 30; //Reassign !!! println!( "Bike {}: speed={} distance={}", mybike.brand, mybike.speed, mybike.distance ); }
  • 18. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 18/49 Mutability errorMutability error error[E0594]: cannot assign to field `mybike.speed` of immutable binding --> src/main.rs:14:5 | 8 | let mybike = Bike { | ------ help: make this binding mutable: `mut mybike` ... 14 | mybike.speed = 30; //Reassign !!! | ^^^^^^^^^^^^^^^^^ cannot mutably borrow field of immutable binding error: aborting due to previous error For more information about this error, try `rustc --explain E0594`. error: Could not compile `immutability`.
  • 19. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 19/49 Ownership & BorrowingOwnership & Borrowing Every piece of data is uniquely owned Ownership can be passed When owned data reaches the end of a scope, it is destroyed
  • 20. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 20/49 OwnershipOwnership fn main() { let s1 = String::from("Hello, RUST ! 🦀"); let s2 = s1; println!("{}", s1); }
  • 21. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 21/49 Ownership errorOwnership error --> src/main.rs:3:9 | 3 | let s2 = s1; | = note: #[warn(unused_variables)] on by default error[E0382]: borrow of moved value: `s1` --> src/main.rs:4:20 | 3 | let s2 = s1; | -- value moved here 4 | println!("{}", s1); | ^^ value borrowed here after move | = note: move occurs because `s1` has type `std::string::String`, which does not implement the `Copy` trait error: aborting due to previous error For more information about this error, try `rustc --explain E0382`. error: Could not compile `owned2`.
  • 22. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 22/49 OwnershipOwnership fn main() { let s = String::from("Hello, RUST ! 🦀"); display(s); display(s); // Already owned ! } fn display(some_string: String) { println!("{}", some_string); }
  • 23. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 23/49 Ownership errorOwnership error error[E0382]: use of moved value: `s` --> src/main.rs:5:13 | 4 | display(s); | - value moved here 5 | display(s); // Already owned ! | ^ value used here after move | = note: move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait
  • 24. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 24/49 Ownership & BorrowingOwnership & Borrowing Access can be borrowed (mutable and immutable) You can borrow mutably once Or multiple times immutably Exclusive: mutable or immutable, never both
  • 25. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 25/49 BorrowingBorrowing fn main() { let s = String::from("Hello, RUST ! 🦀"); display(&s); display(&s); } fn display(some_string: &String) { println!("{}", some_string); } Hello, RUST ! 🦀 Hello, RUST ! 🦀
  • 26. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 26/49 Borrowing mutableBorrowing mutable fn main() { let s = String::from("Hello"); change(&s); println!("{}", s); } fn change(some_string: &String) { some_string.push_str(", RUST ! 🦀"); }
  • 27. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 27/49 Borrowing mutable errorBorrowing mutable error error[E0596]: cannot borrow immutable borrowed content `*some_string` as mutable --> src/main.rs:9:5 | 8 | fn change(some_string: &String) { | ------- use `&mut String` here to make mutable 9 | some_string.push_str(", RUST ! 🦀"); | ^^^^^^^^^^^ cannot borrow as mutable error: aborting due to previous error For more information about this error, try `rustc --explain E0596`. error: Could not compile `borrow_mut`.
  • 28. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 28/49 Borrowing mutable fixedBorrowing mutable fixed fn main() { let mut s = String::from("Hello"); change(&mut s); println!("{}", s); } fn change(some_string: &mut String) { some_string.push_str(", RUST ! 🦀"); } Hello, RUST ! 🦀
  • 29. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 29/49 References validity checksReferences validity checks #[derive(Debug)] struct Person<'a> { first_name: &'a str, last_name: &'a str, age: &'a i32, phone: Vec<&'a str>, } fn return_reference<'a>() -> Person<'a> { let age = 25; Person { first_name: "John", last_name: "Doe", age: &age, phone: vec!["123-123", "456-456"], } } fn main() { let person = return_reference(); println!("{:?}", person); }
  • 30. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 30/49 References validity checks errorReferences validity checks error error[E0597]: `age` does not live long enough --> src/main.rs:15:15 | 15 | age: &age, | ^^^ borrowed value does not live long enough ... 18 | } | - borrowed value only lives until here | note: borrowed value must be valid for the lifetime 'a as defined on the function body at 9:1... --> src/main.rs:9:1 | 9 | fn return_reference<'a>() -> Person<'a> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error For more information about this error, try `rustc --explain E0597`.
  • 31. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 31/49 Concurrency without fearConcurrency without fear
  • 32. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 32/49 Concurrency without fearConcurrency without fear
  • 33. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 33/49 Concurrency without fear errorConcurrency without fear error Rust type system allows no data racesRust type system allows no data races error[E0596]: cannot borrow `words` as mutable, as it is a captured variable in a `Fn` closure --> src/main.rs:19:54 | 19 | .for_each(|arg| tally_words(arg.to_string(), &mut words).unwrap()); | ^^^^^^^^^^ cannot borrow as mutable | help: consider changing this to accept closures that implement `FnMut` --> src/main.rs:19:19 | 19 | .for_each(|arg| tally_words(arg.to_string(), &mut words).unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error For more information about this error, try `rustc --explain E0596`.
  • 34. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 34/49 High level abstractionHigh level abstraction Generics and TraitsGenerics and Traits Define shared behavior Define behavior based on types Define behavior from various types with trait bounds
  • 35. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 35/49 Unsafe RustUnsafe Rust Allow to disengage some safety features Use at your own risk ! Crates using unsafe code can be audited with cargo- geiger
  • 36. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 36/49 A modern languageA modern language with builtin code quality standardswith builtin code quality standards Documentation embedded into code Unit tests Integration tests Great documentation (books and std lib)
  • 37. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 37/49 A modern languageA modern language with tools to be productivewith tools to be productive Environment setup and update rustup Package (crates) management cargo + plugin Code formatting rustfmt Compiler rustc Efficient error messages Potential solution Linter clippy Code completion racer Help transition to 2018 edition rustfix Editor integration (IntelliJ, Vs code, Vim, Emacs...)
  • 38. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 38/49 Opinionated for productivityOpinionated for productivity Avoiding bikesheddingAvoiding bikeshedding Crates have a defined filesystem structure Modules & exports based on file location (like Python) But with control over public / private exports (like ES6) Batteries included, but replaceable Procedural macros for DSLs (eg: JSON, CSS...) Custom compile-time extensions with build scripts Cargo extensions with cargo-foo binary crates
  • 39. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 39/49 Interesting cratesInteresting crates That extend the std libThat extend the std lib Date and time management chrono Parallel iteration rayon HTTP client reqwest Command line parsing clap, docopt, structopt Logging log Serialization serde Regular expressions regex ...
  • 40. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 40/49 Area of useArea of use Command line tools Web and network services Embedded device, IOT WebAssembly Games
  • 41. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 41/49 Who is using Rust ?Who is using Rust ? Mozilla, servo project RedHat, stratis project Dropbox Telenor Chef
  • 42. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 42/49 Who is using Rust ?Who is using Rust ? Ready at dawn Chucklefish that published Stardew Valley and Starbound, is using Rust in their new projects Wargroove and Witchbrook to get safe concurrency and portability
  • 43. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 43/49 Who is using Rust ?Who is using Rust ? Clevercloud, (Geoffroy Couprie) nom, parser Sozu, reverse proxy Snips ANSSI: RFC for secure application design in Rust
  • 44. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 44/49 Governance and communityGovernance and community Rust is pragmaticRust is pragmatic All features are driven by needs of real software The language is evolved with user feedback Consciously chooses familiar constructs Picks good ideas from others Doesn’t want to be the primary language at all cost
  • 45. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 45/49 Governance and communityGovernance and community Beloved language and communityBeloved language and community Voted "Most loved language" on Stackoverflow 2018, 2017, 2016 Only 1/100 of survey respondents have issues with the Rust community Newcomers from all directions https://insights.stackoverflow.com/survey/2018/#most-loved-dreaded-and-wantedhttps://insights.stackoverflow.com/survey/2018/#most-loved-dreaded-and-wanted
  • 46. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 46/49 Governance and communityGovernance and community growthgrowth https://8-p.info/visualizing-crates-io/https://8-p.info/visualizing-crates-io/ Crates.ioCrates.io
  • 47. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 47/49 Governance and communityGovernance and community Help from the communityHelp from the community Lots of books IRC and Discord channels User forum Youtube channel Meetups
  • 48. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 48/49 Governance and communityGovernance and community Beloved language and communityBeloved language and community Experience from Mozilla to drive open projects All major decisions, go to an open Request For Comments process Release every 6 weeks 3 channels: stable, beta and nightly Medium time to merged PR for changes: 6 days! More then 4/5 of contributions to the Rust language come from outside Mozilla The compiler has more then 2000 contributors
  • 49. 3/27/2019 Be pinched by a cRUSTacean to prevent programming errors ! localhost:8000/rust/?print-pdf#/ 49/49 THANK YOUTHANK YOU René Ribaud <rene.ribaud@cgi.com> François Best <contact@francoisbest.com>