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.

1c88d7906e3ffa450aedff2f5f1d1299?s=128

Florian Gilcher

April 11, 2018
Tweet

Transcript

  1. None
  2. $ cat ~/.profile GIT_AUTHOR_NAME=Florian Gilcher GIT_AUTHOR_EMAIL=florian.gilcher@asquera.de TWITTER_HANDLE=argorak GITHUB_HANDLE=skade BLOG=skade.me YAKS=yakshav.es

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

    Programmer since 2003 • Rust Programmer since 2013 • CEO asquera GmbH / rust- experts.com
  4. • RustFest • Part of the global Rust community team

    • Leadership events team
  5. As a hobby, I shoot arrows at stuff

  6. I’m in management of a programming language.

  7. Whatever that means.

  8. Three Years of Rust

  9. What is Rust?

  10. • 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
  11. Providing an alternative to C/C++, but also higher-level languages.

  12. • Safe • Concurrent • Fast

  13. It’s generally perceived that safety, especially memory-safety comes at a

    runtime cost.
  14. • Safe • Concurrent • Fast

  15. Pick Three

  16. Core features

  17. • Static type system with local type inference • Explicit

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

    memory manage- ment • No garbage collection
  19. 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! }
  20. Base concept: Mutability

  21. 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` }
  22. struct InnerData { val: i32 } struct Data { inner:

    InnerData } fn main() { let mut d = Data { inner: InnerData { val: 41 }}; d.inner.val = 42; }
  23. Base concept: Ownership & Borrowing

  24. • Every piece of data is uniquely owned • Ownership

    can be passed • When owned data reaches the end of a scope, it is destructed
  25. 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!"); }
  26. • Access can be borrowed (mutable and immutable) • You

    can borrow mutably once • Or multiple times immutably • Exclusive: mutable or immutable, never both
  27. 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!"); }
  28. Shared mutable state is an issue even single-threaded applications!

  29. fn main() { let mut vector = vec![1,2,3]; let elem

    = &vector[1]; vector[2] = 4; }
  30. 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
  31. Rust checks validity of all references at compile-time.

  32. struct Data<’a> { inner: &’a i32 } fn return_reference<’a>() ->

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

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

    also mutability, ownership and interconnections between input and output types.
  35. 100, 1000, 10.000 lines of called code, Rust keeps these

    properties!
  36. Abstractions Rust provides higher-level abstractions through Generics and Traits, similar

    to C++ Templates or Java Generics.
  37. Concurrency without fear

  38. let counter = Counter { count: 0 }; for _

    in 1..3 { std::thread::spawn(move || { increment(&mut counter); // capture of moved value: `counter` }); }
  39. 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); }); }
  40. 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); }); }
  41. 2015: Finally done!

  42. Before Release

  43. Removal of a lot of features: • All Runtime •

    stdlib trimming • Garbage collector • Error handling
  44. Coming up with ergonomics and tooling around everything.

  45. RFC process Rust has an RFC process under rust-lang/rfcs on

    GitHub. All language changes have to go through that.
  46. Release: May 15th

  47. The package

  48. rustc The compiler, based on the LLVM.

  49. Cargo A build and dependency management tool, along with a

    registry.
  50. rustup A toolchain manager, covering the ability to run things

    side by side.
  51. rustdoc A documentation tool, complete with API search and doc

    testing.
  52. A book The Rust programming language, first edition.

  53. Compatibility tooling • rust-gdb • vim plugin • VSCode Plugin

  54. Interesting aspect The whole toolchain is cross-compile aware. This is

    hard to retrofit.
  55. Release cycle • Nightly releases • All 6 weeks, nightly

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

    stable interface. CLI interfaces are considered interface.
  57. 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
  58. Teams Rust grows teams on need.

  59. Initial teams Core, Infra, Language, Library, Compiler, Documentation, Community, Moderation

  60. This raises awareness of peoples work and makes them addressable.

  61. Low-friction community interaction • A meetup calendar • This week

    in Rust Newsletter • community@rust-lang.org • Forums/IRC channels
  62. Low-friction contribution People want to contribute! But most projects have

    no tasks for people that just have 5 minutes at a time!
  63. Avoid lingering tasks!

  64. Conversational tone Friendly and focused, not very bikesheddy, non-insulting.

  65. Stating issues is great, just be realistic about the fixes.

  66. Being grumpy or in general stern is completely fine!

  67. Usability Rust was a usable contenter in the systems programming

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

    environ- ment is work • Non-programming work is a sub- stantial amount • Credit it!
  69. 2016: Finding Adoption

  70. Gathering Data

  71. 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
  72. Demographics Rustaceans are coming in equal parts from: • Dynamic

    languages • Classic systems programming • Functional programming
  73. Demographics Rusts community is based in Europe! Other huge groups

    include China, Russia and India.
  74. Production user survey We conducted a production users survey. Feedback

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

    write shared libraries in • For heavily concurrent code, such as servers
  76. Projects are rarely fully Rust, but important parts are!

  77. Production user problems • Library maturity • Tooling maturity

  78. People having problems with what’s not there is better then

    problems with things that are there!
  79. Especially businesses are very aware of context!

  80. Production user liaison Production users get support on compiler-related things.

  81. The friends page https://www.rust-lang.org/friends.html

  82. Users • Mozilla • Dropbox • Chucklefish • Chef •

    NPM • Schauspiel Dortmund
  83. and over 100 other companies

  84. How do we compare to others? We don’t know.

  85. Integrating people • Our default meetup type is "Hack and

    Learn" • Quick review times for patches • Helping out where we can
  86. Integrate people into the project quickly.

  87. Conferences • RustFest (Europe, every half year) • RustConf (US,

    every year) • Rust Belt Rust (US, every year)
  88. Community-run, community sponsored.

  89. 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
  90. 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
  91. 2017: Growing pains

  92. Survey 5500 Respondents.

  93. Stability • Over 90 percent never had upgrade problems •

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

    the community • 75 percent see the community favourably
  95. Are those numbers good? We don’t know. There’s no comparisons.

  96. We don’t know Rust Producing a language doesn’t mean you

    won’t discover things yourself.
  97. • New API practices are beginning to form. • How

    do include Rust into other projects becomes a main question!
  98. New patterns coming up

  99. 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
  100. Realisations Ownership is a vastly more important feature then borrowing

    in Rust.
  101. The book The book needed to be rewritten. Welcome second

    edition!
  102. Direction Which areas should we focus on? Are we even

    solving useful problems?
  103. Hobbyist problems aren’t production user problems!

  104. 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.
  105. 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
  106. 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
  107. Usage in Firefox Rust finally got adopted into Firefox on

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

    languages are ex- tremely complex, even to the pro- ducers • Identify issues early
  110. 2018: The Future is unwritten

  111. Rust2018 campaign A blogging campaign over January. People were encouraged

    write down their wishes for next year.
  112. Results 100 blog posts or essays. readrust.net

  113. StackOverflow most loved language Third time in a row. Why?

  114. We generate and manage Buzz Buzz is a great thing

    if you can back it with actual technology.
  115. People follow the Buzz and find something!

  116. Teams 17 teams, over 100 people.

  117. Community team split • RustBridge • Events team • Content

    team • Switchboard team More then 20 people!
  118. Teaching Rust Teaching programming remains a problem. There’s not much

    hard data!
  119. Goals for this year • Stable story for bare metal

    embed- ded • Promoting our rock-solid network- ing story • WASM
  120. • 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!
  121. Conclusions • Rework your organisation regularly • Change your approaches

    along with it! • See what it unlocks
  122. Large, quality projects without a benevolent dictator are there and

    work. They just don’t make much noise!
  123. Thanks The LLVM project, the Ruby, Python, Mozilla and JavaScript

    communities. We apply your work.