Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Three Years of Rust

Three Years of Rust

A look back at three years of Rust.

Florian Gilcher

April 11, 2018
Tweet

More Decks by Florian Gilcher

Other Decks in Programming

Transcript

  1. • Rust and Elasticsearch Trainer • Event organiser • Ruby

    Programmer since 2003 • Rust Programmer since 2013 • CEO asquera GmbH / rust- experts.com
  2. • new systems programming language • powers and was developed

    in along with Servo, a new browser engine • by Mozilla and the Community • First stable release May 15th, 2015
  3. • Static type system with local type inference • Explicit

    mutability • Zero-cost abstractions • Runtime-independent concurrency safety
  4. • Errors are values • No null • Static automatic

    memory manage- ment • No garbage collection
  5. extern crate tempdir; use tempdir::*; use std::fs::File; fn main() {

    let tempdir = TempDir::new("accu"); let mut tempfile = match tempdir { Ok(dir) => { File::create( dir.path().join("tmpfile") ) } Err(_) => { panic!("Couldn’t open tempdir") } } do_something(&mut tempfile); // look, no close necessary! }
  6. struct InnerData { val: i32 } struct Data { inner:

    InnerData } fn main() { let d = Data { inner: InnerData { val: 41 }}; d.inner.val = 42; // error: cannot assign to immutable field `d.inner.val` }
  7. struct InnerData { val: i32 } struct Data { inner:

    InnerData } fn main() { let mut d = Data { inner: InnerData { val: 41 }}; d.inner.val = 42; }
  8. • Every piece of data is uniquely owned • Ownership

    can be passed • When owned data reaches the end of a scope, it is destructed
  9. use std::fs::File; use std::io::Write; fn main() { let file =

    File::open("test") .expect("Unable to open file, bailing!"); take_and_write_to_file(file); // take_and_write_to_file(file); // ^^ Illegal } fn take_and_write_to_file(mut file: File) { writeln!(file, "{}", "Hello #accuconf!"); }
  10. • Access can be borrowed (mutable and immutable) • You

    can borrow mutably once • Or multiple times immutably • Exclusive: mutable or immutable, never both
  11. use std::fs::File; use std::io::Write; fn main() { let mut file

    = File::open("test") .expect("Unable to open file, bailing!"); write_to_file(&mut file); write_to_file(&mut file); } fn write_to_file(file: &mut File) { writeln!(file, "{}", "Hello #gotober!"); }
  12. error[E0502]: cannot borrow `vector` as mutable –> src/main.rs:4:5 | 3

    | let elem = &vector[1]; | —— immutable borrow occurs h 4 | vector[2] = 4; | ^^^^^^ mutable borrow occurs here 5 | } | - immutable borrow ends here
  13. struct Data<’a> { inner: &’a i32 } fn return_reference<’a>() ->

    Data<’a> { let number = 4; Data { inner: &number } }
  14. –> src/main.rs:8:20 | 8 | Data { inner: &number }

    | ^^^^^^ does not live long 9 | } | - borrowed value only lives until here |
  15. All Rust function signatures not only signal data types, but

    also mutability, ownership and interconnections between input and output types.
  16. let counter = Counter { count: 0 }; for _

    in 1..3 { std::thread::spawn(move || { increment(&mut counter); // capture of moved value: `counter` }); }
  17. use std::rc::Rc; let rc = Rc::new(Counter { count: 0 });

    for _ in 1..3 { let handle = rc.clone(); std::thread::spawn(move || { // `std::rc::Rc<Counter>` cannot be sent between threads safely increment(&mut handle); }); }
  18. use std::sync::{Arc,Mutex}; let rc = Arc::new(Mutex::new(Counter { count: 0 }));

    for _ in 1..3 { let handle = rc.clone(); std::thread::spawn(move || { increment(&mut handle); }); }
  19. Removal of a lot of features: • All Runtime •

    stdlib trimming • Garbage collector • Error handling
  20. RFC process Rust has an RFC process under rust-lang/rfcs on

    GitHub. All language changes have to go through that.
  21. Release cycle • Nightly releases • All 6 weeks, nightly

    is promoted to beta • After 6 weeks, beta is promoted to stable
  22. Stability Rust is backwards-compatibile, the stable compiler only exposes the

    stable interface. CLI interfaces are considered interface.
  23. Project management • Anti-Benevolent Dictator For Life • Core is

    a tie-breaker, not much more • Most contributions are from non- Mozillians (75/100) • Rust had close to 1000 contributors in 2015
  24. Low-friction contribution People want to contribute! But most projects have

    no tasks for people that just have 5 minutes at a time!
  25. Usability Rust was a usable contenter in the systems programming

    space back then, but a lot of things were missing, notably: libraries.
  26. Conclusions • Good tooling early helps • Establishing a productive

    environ- ment is work • Non-programming work is a sub- stantial amount • Credit it!
  27. Survey We ran a users survey with 3000 respondents. •

    20 percent of all users were using Rust at work • Half of them in projects over 10k LoC
  28. Demographics Rustaceans are coming in equal parts from: • Dynamic

    languages • Classic systems programming • Functional programming
  29. Production user survey We conducted a production users survey. Feedback

    was good, especially for reliability. Pain points were as expected.
  30. Production uses • Alternative to plain C • Language to

    write shared libraries in • For heavily concurrent code, such as servers
  31. Integrating people • Our default meetup type is "Hack and

    Learn" • Quick review times for patches • Helping out where we can
  32. Conferences • RustFest (Europe, every half year) • RustConf (US,

    every year) • Rust Belt Rust (US, every year)
  33. Support people online • We’re on youtube: /c/rustvideos • Twitter:

    twitter.com/rustlang • We tried running a global Hackfest • The Rust community loves to write
  34. Conclusions • Social media isn’t a bad word • Actively

    speaking is better then waiting • Your bugtracker is only half of the story • A solid base is better then a lot of half-solutions
  35. Stability • Over 90 percent never had upgrade problems •

    Almost everyone uses our tooling • People rate the tooling favourably
  36. Community • 99 percent of people have no issue with

    the community • 75 percent see the community favourably
  37. • New API practices are beginning to form. • How

    do include Rust into other projects becomes a main question!
  38. Ownership is useful beyond pure memory safety: • Used to

    model statemachines • Used to model device driver mem- ory • Extremely useful in concurrency • "Who’s owning that" is a common programming problem
  39. Release cycle review The release cycle worked well. We only

    botched one release (1.14), hit no larger issues. It’s a benefit to users, changes are consumable.
  40. Rust is becoming a practices leader • Other languages adopt

    the commu- nity interaction model (NodeJS) • Other products and languages adopt our RFC process (Ember, Swift) • Our management model is taken interest in
  41. RFC process problems Volume brings issues! • People with too

    much time swamp the process • People with no time can’t follow along and feel excluded • Non-english speakers have issues to follow
  42. Usage in Firefox Rust finally got adopted into Firefox on

    large scale, the CSS styling engine is now powered by Rust!
  43. Conclusions • Have a sense of accomplishment sometimes • Programming

    languages are ex- tremely complex, even to the pro- ducers • Identify issues early
  44. We generate and manage Buzz Buzz is a great thing

    if you can back it with actual technology.
  45. Community team split • RustBridge • Events team • Content

    team • Switchboard team More then 20 people!
  46. Goals for this year • Stable story for bare metal

    embed- ded • Promoting our rock-solid network- ing story • WASM
  47. • Shipping language ergonomics around async/await and boilerplate ("Rust 2018")

    • Have a conference on every conti- nent by 2019 • Make people aware that we are adopted!