3. What is Rust
●
A language for system programming
●
Created by Mozilla (2010~, 2015 v1.0)
●
Multi paradigm, fast, productive and safe
●
“Fearless concurrency”
●
Community Driven and Open Source (MIT lic.)
4. Why we need it?
●
A replacement of C/C++ (mostly C++)
●
A powerfull type system
●
Zero cost of abstraction
●
Safety with the borrow checker
●
Highly memory controll without a GC
●
Rustup, cargo, rustfmt...
5. Where you should use it?
●
System code as alternative of C/C++ or where you
should have bindings with such libs
●
System code as an alternative of Java or Go where you
need more precise control of the memory (no GC)
●
Embedded applications
●
Bar metal
●
WebAssembly and more...
6. The strenghts?
●
Many concurrency bugs are almost impossible!
●
Strong memory handling checks!
●
Enums first class citizens!
●
Explicit error handling!
●
No NULL, null, nil…!
●
Powerfull Pattern Matching!
●
Macro!
7. ...and more features…
●
Dependency handling included (cargo)
●
Documentation included (/// + rustdoc)
●
Linter included
●
Test/Examples/Bench included
●
RLS (rust-analyzer)...
9. Ownership Rules
●
Each value in Rust has a variable that’s called its
owner
●
There can only be one owner at a time
●
When the owner goes out of scope, the value
will be dropped
10. Ownership some examples
let my_var = String::from(“Hello Developer Thursday!”);
require_ownership(my_var); // ← move ownership
println!(“My var {}”, my_var); // ← can’t be done!
…
let another_var = String::from(“Hi Developer Thursday!”);
just_borrow_it(&another_var); // ← notice the &
println!(“Another {}”, another_var); // ← now it’s fine!!
…
let mut mutable_var = String::from(“Hi ”);
requiere_mutable_borrow(&mut mutable_var); // this is possible as Rust guarantee there will
// just 1 reference to mutable_var
println!(“A mutable var {}”, mutable_var);
11. Lifetime
fn just_a_function<’a>(
haystack: &’a str, needle: &’a str
) → Option<&’a str> {
let found = haystack.find(needle)?;
let result = &haystack[found..needle.len()];
Some(reuslt.as_ref())
}
13. Multithreading vs Async
Multithreading → good for parallelization
Async → good for concurrecy
Native OS threads
async / .await
+ runtime
(tokio / async-std)
No Green Thread anymore in the language
14. But how fast it can be?
ripgrep: https://blog.burntsushi.net/ripgrep/
16. Discord Switching From Go to Rust
https://blog.discordapp.com/why-discord-is-switching-from-go-to-rust-a190bbca2b1f
17. Rust for the web
Seed: Rust framework for creating fast and reliable web apps with a structure that follows the Elm
Architecture.
Percy: A modular toolkit for building interactive frontend browser apps with Rust + WebAssembly.
Supports server side rendering.
Yew: Rust / Wasm client web app framework with architecture inspired by Elm and Redux. Yew is
based on stdweb that has a lot of features.
Draco: A Rust library for building client side web applications with WebAssembly modeled after the
Elm architecture and Redux.
Smithy: A front-end framework for writing WebAssembly applications entirely in Rust. Its goal is to
allow you to do so using idiomatic Rust, without giving up any of the compiler's safety guarantees.
squark: Rust frontend framework, for web browser and more with architecture inspired from Elm
and HyperApp.
Dodrio: A fast, bump-allocated virtual DOM library for Rust and WebAssembly.
rust-dominator: Zero cost declarative DOM library using FRP signals for Rust!
18. WASM
It’s a standard from W3C
Run inside the
browsers
Can be written in any
LLVM supported
language
Safe
Open and debuggable
Efficient and fast
It’s not JavaScript
https://webassembly.org/
20. WASI
The WebAssembly System Interface
March 2019: Standardizing WASI: A system interface to run WebAssembly
outside the web
https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webassembly-system-interface/
C / Rust
It’s a standard as a subgroup of the W3C
WebAssembly CG
https://wasi.dev/
22. Wastime
●
A runtime to run WASM + WASI application on the server
●
Written in Rust!
●
Safe as the application is sandboxed as it runs inside a browser
●
Fast as WASM is a compact and efficient format
●
Lightwight as you just need the runtime
●
Portable the format is standard on every architecture, just need the
runtime!
●
Polyglot wastime can be ported to different languages, and so you can
import librearies written in Rust and compiled in WASM and then
loaded as a Python module!
23. Krustlet
●
A kubelet rewritten in Rust, that runs WASM
programs
●
No need of containers images anymore
●
No need of an OS anymore!
●
And Krustlet can run without any OS too!!