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

Introduction to Rust (December 2015)

Introduction to Rust (December 2015)

Rust is the new kid on the block. It runs on bare metal, is blazingly fast and offers sophisticated compile time checks. It offers memory safety without requiring a Garbage Collector.

Learning Rust will make you a better programmer.

I will give an introductory talk about Rust and show its nicest features. We'll also check out some interesting projects written in Rust.

Matthias Endler

December 15, 2015
Tweet

More Decks by Matthias Endler

Other Decks in Programming

Transcript

  1. Rust - Created by Graydon Hoare - Funded by Mozilla

    - Primary goal: A safer systems language - First version: 2010 - Current version 1.5 - Main project: Servo browser engine
  2. • Provide the right abstractions • Provide awesome tools •

    Allow making mistakes • Build a helpful community Systems Programming can be fun!
  3. Where Rust makes sense • Operating Systems • Encryption •

    Databases • Graphics programming • … (everywhere you need speed and safety)
  4. Where Rust makes sense glium • High-level wrapper around OpenGL

    • Avoids all OpenGL errors diesel • A safe, extensible ORM and Query Builder • Operating System written in pure Rust,
 designed to be modular and secure Redox crossbeam • A collection of lock-less data structures turbine • A high-performance, non-locking, inter-task communication library written in Rust. • Go channels on steroids
  5. What I like about… • PHP: Package manager, Community •

    Python: Syntax, Libraries • Golang: Tooling, Documentation, Concurrency • C: Speed, no overhead
  6. What I like about… • PHP: Package manager, Community •

    Python: Syntax, Libraries • Golang: Tooling, Documentation, Concurrency • C: Speed, no overhead RUST
  7. What sucks about… • PHP: Syntax (a bit), legacy functions

    • Python: Package manager, 2 vs 3 • Golang: Error handling, package manager, no generics, Syntax (a bit) • C: Missing package manager, safety
  8. Popular systems languages Type safety Type expression Type checking Garbage

    Collector C unsafe explicit static No C++ unsafe explicit static No Go safe implicit/explicit static Yes Rust safe implicit/explicit static/dynamic optional
  9. #include <iostream> #include <vector> #include <string> int main() { std::vector<std::string>

    v; v.push_back("foo"); auto const &x = v[0]; v.push_back("bar"); // Undefined behavior! std::cout << x << '\n'; }
  10. There’s multiple mutable references to the same data Ownership Avoid

    There should only be one owner at the same time In Rust this is enforced by the compiler!
  11. Is this really an issue? Search results on StackOverflow.com: segfault

    10.899 results segmentation fault 21.238 results memory leak 55.064 results
  12. fn f(x: Type) {...} fn f(x: &Type) {...} fn f(x:

    &mut Type) {...} Shared borrow Mutable borrow Ownership • one owner • mutable • readable • Share as you like • immutable • readable • one at a time • mutable • readable
  13. What sucks about Rust • Fighting with the Borrow checker

    • Syntax (a bit) • Missing packages (you can help!) • probably more…
  14. Tool list Unit testing: builtin Package manager Syntax highlighting Formatting

    Code completion Debugging Code linter Benchmarking Profiling Code coverage
  15. Unit testing: builtin Package manager: cargo Syntax highlighting Formatting Code

    completion Debugging Code linter Benchmarking Profiling Code coverage Tool list
  16. Unit testing: builtin Package manager: cargo Syntax highlighting: atom-language-rust Formatting

    Code completion Debugging Code linter Benchmarking Profiling Code coverage Tool list
  17. Unit testing: builtin Package manager: cargo Syntax highlighting: atom-language-rust Formatting:

    rustfmt Code completion Debugging Code linter Benchmarking Profiling Code coverage Tool list
  18. Unit testing: builtin Package manager: cargo Syntax highlighting: atom-language-rust Formatting:

    rustfmt Code completion: racer Debugging Code linter Benchmarking Profiling Code coverage Tool list
  19. Unit testing: builtin Package manager: cargo Syntax highlighting: atom-language-rust Formatting:

    rustfmt Code completion: racer Debugging: rust gdb? Code linter Benchmarking Profiling Code coverage Tool list
  20. Unit testing: builtin Package manager: cargo Syntax highlighting: atom-language-rust Formatting:

    rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking Profiling Code coverage Tool list
  21. Unit testing: builtin Package manager: cargo Syntax highlighting: atom-language-rust Formatting:

    rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking: builtin Profiling Code coverage Tool list
  22. Unit testing: builtin Package manager: cargo Syntax highlighting: atom-language-rust Formatting:

    rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking: builtin Profiling: meh… Code coverage Tool list
  23. Unit testing: builtin Package manager: cargo Syntax highlighting: atom-language-rust Formatting:

    rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking: builtin Profiling: meh… torch? Code coverage Tool list
  24. Unit testing: builtin Package manager: cargo Syntax highlighting: atom-language-rust Formatting:

    rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking: builtin Profiling: meh… torch? Code coverage: kcov? Tool list
  25. kcov …is a code coverage tester for compiled programs, Python

    scripts and shell scripts language: rust matrix: fast_finish: true include: - rust: nightly env: FEATURES="--features nightly" sudo: false - rust: nightly env: FEATURES="--features nightly" BENCH=true sudo: false - rust: beta sudo: true after_success: | sudo apt-get install libcurl4-openssl-dev libelf-dev libdw-dev && wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz && tar xzf master.tar.gz && mkdir kcov-master/build && cd kcov-master/build && cmake .. && make && sudo make install && cd ../.. && kcov --coveralls-id=$TRAVIS_JOB_ID --exclude-pattern=/.cargo target/kcov target/debug/hyper-* Put this into your .travis.yml:
  26. We need to focus on those… Unit testing Package manager

    Syntax highlighting Formatting Code completion Debugging Code linter Benchmarking Profiling Code coverage