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

Introduction to Rust

July 14, 2021

Introduction to Rust

Apresentação realizada no evento Colóquios de Ciência da Computação da galera da Universidade do Estado de Santa Catarina.


July 14, 2021

More Decks by AF

Other Decks in Programming


  1. Introduction to Rust own your garbage, so others don't have

    to collect it for you Colóquios Ciência da Computação 14/07/2021
  2. Por que você deveria aprender Rust? • Não existe um

    grande mercado 😭 • Comunidade legal • Muito material disponível • Oportunidade de trabalhar com memory management, borrow checker, lifetimes, tipos expressivos • Aprender boas práticas de desenvolvimento com mensagens de erro • Not Haskell, but functional Programming and types • Not List, but Macros
  3. Why Rust? • Desempenho like C/C++ • System Programming Language

    • Guaranteed memory safe, no memory leak • Threads without data races • No runtime, no Garbage Collection • No undefined behaviour • Zero-cost abstractions • Ergonômica, developer happyness • Expressive data structures • Pattern matching • Type inference
  4. Are we * yet? • Firefox (Servo) • Linux •

    Railcae (container engine Oracle) • Embedded devices: ARM, Intel, Microsoft Azure IoT Edge • Web: OpenDNS, Discord, Facebook ... • Tor • WebAssembly wasm web standard • Command-line apps • Network services
  5. Comparada ao C, Rust é • Menos verbosa • Não

    é baseada em gambiarra • Fácil de escrever testes automatizados • Fácil de gerir dependências • Fácil de gerir projetos • De modo geral, Integração Contínua é muito mais fácil
  6. Tools • rustup: the rust toolchain installer • rustc: the

    rust compiler • cargo: the package and project manager • rustdoc: the documentation builder
  7. $ cargo run Finished dev [unoptimized + debuginfo] target(s) in

    0.0 secs Running `target/debug/hello_cargo` Hello, world!
  8. Release flow • RFCs: https://github.com/rust-lang/rfcs • Nightly: include unstable features

    • Beta: upcoming stable releases • Stable: new features with docs every 6 weeks
  9. Ecossistema • crates.io: registry for libs and applications • docs.rs:

    documentation for published libs • https://users.rust-lang.org • https://discordapp.com/invite/rust-lang • https://www.rust-lang.org/community
  10. Statements and Expressions • Rust is an expression-based language, this

    is an important distinction to understand • Statements are instructions that perform some action and do not return a value ◦ Creating a variable and assigning a value to it with the let keyword ◦ Function definitions ◦ C and Ruby assignment returns the value of the assignment • Expressions evaluate to a resulting value ◦ the 6 in the statement let y = 6 ◦ Calling a function ◦ Calling a macro ◦ The block that we use to create new scopes, {} • Function bodies are made up of a series of statements optionally ending in an expression
  11. Ownership is Rust’s most unique feature, and it enables Rust

    to make memory safety guarantees without needing a garbage collector
  12. Ownership • Heap: Memory set aside for dynamic allocation •

    Stack: Memory set aside for a thread • Ownership rules: ◦ Each value in Rust has a variable that's called its owner ◦ There can only be one owner at a time ◦ When the owner goes out of scope, the value will be dropped
  13. Mutable References Pode mudar se indicarmos que a referência é

    mutável. Mas só podemos ter uma referência mutável!
  14. Ficou de fora • Slices • Associated Functions • Enums

    • Modules • Errors with unwrap and expect and ? • Lifetime (não entendi ainda) • Smart Pointers • Object Oriented Programming Features • Concorrência