Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
Rust
a low-level language with high-level abstractions
Hello, world!
$ cargo new --bin helloworld && cd helloworld
$ cargo run
Compiling helloworld v0.1.0
Running `target/debug/...
$ cargo build --release
Compiling helloworld v0.1.0rust/helloworld
$ ./target/release/helloworld
Hello, world!
Low level
• C-like performances
• no VM
• no garbage collector
High level
fn is_odd(n: u32) -> bool {

n % 2 == 1

}



fn main() {

println!("Find the sum of all the squared odd number...
High level
• types
• type inference
• no manual memory management
• no null -> Option<T>
• no exception -> Result<T>
High level
• pattern matching
• closure
• immutable by default
• functional
Abstraction without
overhead
let mut acc = 0;

// Iterate: 0, 1, 2, ... to infinity

for n in 0.. {

let n_squared = n * n...
Not OO but Struct with impl
struct Person {

name: String,

}



impl Person {

pub fn say_hello(&self) {

println!("{} sa...
Typeclasses
#[derive(Debug)]

struct Age {

age: i32,

}



fn main() {

let age1 = Age { age: 12 };

let age2 = Age { age...
Typeclassesuse std::ops::Add;



#[derive(Debug)]

struct Age {

age: i32,

}



impl Add for Age {

type Output = Age;


...
Program structure
• Cargo.toml
• unit tests next to implementation
• integration tests in /tests
Ecosystem
• cargo and crates.io
• dependency management
• build / cross-compilation
• https://play.rust-lang.org/
• very w...
Documentation
• https://doc.rust-lang.org/book/ 

http://rustbyexample.com/
• https://this-week-in-rust.org/
Projects using Rust
• Servo
• Redox
• Firefox mp4
• Dropbox
But Go’s “memory footprint” was too
high for the massive stora...
Web
• http://www.arewewebyet.org/
• Ex: https://tech.zalando.de/blog/getting-started-
with-rust/
Rust
• young language: 1.0 in May 2015
• very interesting
• first steps can be challenging
• compared to JVM: no GC / no JIT
Prochain SlideShare
Chargement dans…5
×

sur

Introduction to rust: a low-level language with high-level abstractions Slide 1 Introduction to rust: a low-level language with high-level abstractions Slide 2 Introduction to rust: a low-level language with high-level abstractions Slide 3 Introduction to rust: a low-level language with high-level abstractions Slide 4 Introduction to rust: a low-level language with high-level abstractions Slide 5 Introduction to rust: a low-level language with high-level abstractions Slide 6 Introduction to rust: a low-level language with high-level abstractions Slide 7 Introduction to rust: a low-level language with high-level abstractions Slide 8 Introduction to rust: a low-level language with high-level abstractions Slide 9 Introduction to rust: a low-level language with high-level abstractions Slide 10 Introduction to rust: a low-level language with high-level abstractions Slide 11 Introduction to rust: a low-level language with high-level abstractions Slide 12 Introduction to rust: a low-level language with high-level abstractions Slide 13 Introduction to rust: a low-level language with high-level abstractions Slide 14 Introduction to rust: a low-level language with high-level abstractions Slide 15 Introduction to rust: a low-level language with high-level abstractions Slide 16 Introduction to rust: a low-level language with high-level abstractions Slide 17
Prochain SlideShare
Introduction to Rust Programming Language
Suivant
Télécharger pour lire hors ligne et voir en mode plein écran

2 j’aime

Partager

Télécharger pour lire hors ligne

Introduction to rust: a low-level language with high-level abstractions

Télécharger pour lire hors ligne

Introduction to rust: a low-level language with high-level abstractions

Introduction to rust: a low-level language with high-level abstractions

  1. 1. Rust a low-level language with high-level abstractions
  2. 2. Hello, world! $ cargo new --bin helloworld && cd helloworld $ cargo run Compiling helloworld v0.1.0 Running `target/debug/helloworld` Hello, world!
  3. 3. $ cargo build --release Compiling helloworld v0.1.0rust/helloworld $ ./target/release/helloworld Hello, world!
  4. 4. Low level • C-like performances • no VM • no garbage collector
  5. 5. High level fn is_odd(n: u32) -> bool {
 n % 2 == 1
 }
 
 fn main() {
 println!("Find the sum of all the squared odd numbers under 1000");
 let upper = 1000;
 let sum_of_squared_odd_numbers: u32 =
 (0..).map(|n| n * n) // All natural numbers squared
 .take_while(|&n| n < upper) // Below upper limit
 .filter(|n| is_odd(*n)) // That are odd
 .fold(0, |sum, i| sum + i); // Sum them
 println!("result: {}", sum_of_squared_odd_numbers);
 } Gist
  6. 6. High level • types • type inference • no manual memory management • no null -> Option<T> • no exception -> Result<T>
  7. 7. High level • pattern matching • closure • immutable by default • functional
  8. 8. Abstraction without overhead let mut acc = 0;
 // Iterate: 0, 1, 2, ... to infinity
 for n in 0.. {
 let n_squared = n * n;
 
 if n_squared >= upper {
 // Break loop if exceeded the upper limit
 break;
 } else if is_odd(n_squared) {
 acc += n_squared;
 }
 }
 acc let sum_of_squared_odd_numbers: u32 =
 (0..).map(|n| n * n)
 .take_while(|&n| n < upper)
 .filter(|n| is_odd(*n))
 .fold(0, |sum, i| sum + i); Same perf! (functional version even faster)
  9. 9. Not OO but Struct with impl struct Person {
 name: String,
 }
 
 impl Person {
 pub fn say_hello(&self) {
 println!("{} says hello!", self.name);
 }
 }
 
 fn main() {
 let p = Person { name: "Bibi".to_string() };
 p.say_hello();
 } Gist
  10. 10. Typeclasses #[derive(Debug)]
 struct Age {
 age: i32,
 }
 
 fn main() {
 let age1 = Age { age: 12 };
 let age2 = Age { age: 24 };
 let sum = age1 + age2;
 println!("age1 + age2 = {:?}", sum);
 } <anon>:9:15: 9:19 error: binary operation `+` cannot be applied to type `Age` [E0369] <anon>:9 let sum = age1 + age2; ^~~~
  11. 11. Typeclassesuse std::ops::Add;
 
 #[derive(Debug)]
 struct Age {
 age: i32,
 }
 
 impl Add for Age {
 type Output = Age;
 
 fn add(self, other: Age) -> Age {
 println!("Adding!");
 Age { age: self.age + other.age }
 }
 }
 
 fn main() {
 let age1 = Age { age: 12 };
 let age2 = Age { age: 24 };
 let sum = age1 + age2;
 println!("age1 + age2 = {:?}", sum);
 } Gist
  12. 12. Program structure • Cargo.toml • unit tests next to implementation • integration tests in /tests
  13. 13. Ecosystem • cargo and crates.io • dependency management • build / cross-compilation • https://play.rust-lang.org/ • very welcoming community • https://github.com/kud1ing/awesome-rust
  14. 14. Documentation • https://doc.rust-lang.org/book/ 
 http://rustbyexample.com/ • https://this-week-in-rust.org/
  15. 15. Projects using Rust • Servo • Redox • Firefox mp4 • Dropbox But Go’s “memory footprint” was too high for the massive storage systems the company was trying to build. Dropbox needed a language that would take up less space in memory, because so much memory would be filled with all those files streaming onto the machine. So, in the middle of this two-and-half-year project, they switched to Rust on the Diskotech machines. And that’s what Dropbox is now pushing into its data centers.
  16. 16. Web • http://www.arewewebyet.org/ • Ex: https://tech.zalando.de/blog/getting-started- with-rust/
  17. 17. Rust • young language: 1.0 in May 2015 • very interesting • first steps can be challenging • compared to JVM: no GC / no JIT
  • iplevrakis

    Jan. 16, 2019
  • MatthiasErche1

    Oct. 7, 2016

Introduction to rust: a low-level language with high-level abstractions

Vues

Nombre de vues

2 114

Sur Slideshare

0

À partir des intégrations

0

Nombre d'intégrations

19

Actions

Téléchargements

14

Partages

0

Commentaires

0

Mentions J'aime

2

×