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

Hacker’s guide to Rust Programming - ACCU 2018

Hacker’s guide to Rust Programming - ACCU 2018

Venture deep into the belly of the Rust programming language design and concepts to uncover the secret incantations to create safe and fast applications

General Description

Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety. It won the first place for "most loved programming language" in the Stack Overflow Developer Survey in 2016 and 2017.

But what makes Rust so fast & safe? Starting from the basics, this workshop will walk you through the core design & concepts of Rust Language which includes:

Syntax and keywords in Rust

Concept of ownership and borrowing to understand memory safety & management

Polymorphism using Traits

Error handling in Rust

Package management using Cargo tool

Famous Rust tools like clippy, Rustfmt, Rustup etc

Live demos of web development, FFI to understand different applications

Discover this and more tips to build creating highly concurrent and highly safe systems using Rust.

vigneshwer dhinakaran

April 14, 2018
Tweet

More Decks by vigneshwer dhinakaran

Other Decks in Programming

Transcript

  1. Zen of Rust Memory Safety without Garbage Collection No runtime

    needed Rich Typesystem High level iterators Freedom from data race Welcoming Community
  2. Tokio MiniHTTP The library is a proof-of-concept implementation of a

    simple HTTP/1.1 server using Tokio. http://aturon.github.io/blog/2016/08/11/futures/
  3. 2016 -18 For the third year in a row, Rust

    is stackoverflow's most loved language https://insights.stackoverflow.com/survey/2018/
  4. 13

  5. Ownership • Rust moves ownership by default • The owner

    has the right to destroy the thing it owns • The memory is freed as soon as the owned variable goes out of it's scope • Hence vehicle may already be destroyed at the point when it's passed to repair_service • Rust catches these errors at compile time
  6. Borrowing • A reference is passed without transferring ownership •

    One can borrow immutable (&) or mutable (&mut) but not both at the same time • Shared ownership can be achieved through special pointers with runtime checks
  7. Mutability Rules • All variables are immutable by default •

    Only one mutable reference at a time ( But as many immutable &’s as you want ) • Mutable references block all other access (The &mut must go out of scope before using other &’s )
  8. Struct • Structs are like lightweight classes • They can

    have fields • They can be instantiated
  9. Struct Every Option is either Some and contains a value,

    or None, and does not. Which makes it explicit (No NullPointerExceptions!)
  10. Struct Every Option is either Some and contains a value,

    or None, and does not. Which makes it explicit (No NullPointerExceptions!)
  11. Traits • Traits are Rust’s sole notion of interface •

    Traits can be statically dispatched • Traits can be dynamically dispatched • Traits solve a variety of additional problems beyond simple abstraction
  12. Generics Can pass any reference to anything that implements the

    Talk trait It has to be looked up in a vtable at run time ~ DYNAMIC DISPATCH
  13. Error Handling Types can be generic In fact the std

    library uses a lot of generic enums
  14. Other Salient features • Custom Middleware • JSON Support •

    Mounting • Error Handling • Encrypted Cookies • Session Support
  15. Tools • rustup: the Rust toolchain installer • rustfmt :

    the Rust code formatting tool • rust-clippy : Rust code linter • Cargo : package manager • ...
  16. 78

  17. When should you use Rust? • Rewrite modules of your

    code that are computationally heavy (Complex math optimizations etc) • For accessing the hardware(ex :- IOT applications, device drivers, GPU’s etc) • Implementing advance concurrency paradigms • Rust FFI calls are non-trivial, so be wise!
  18. What does Rust have to offer? • Modern C/C++ replacement

    • Memory Safety without Garbage Collection • No runtime needed • Rich Typesystem • Strong Functional Programming influence