class: center, middle # What is Rust? ## and why should you use it? --- # Elevator Pitch - Blazingly fast - Prevents segfaults - Guarantees thread safety - Functional aspects - No language runtime - No garbage collector ??? - Rust runs blazingly fast - very close to the performance of C - You have memory safety, meaning you won't have segmentation faults or other memory related errors during runtime - Guarantees thread safety, totally eliminating race conditions we are used to from C - Multiple functional aspects, which you will see later, such as type inference, pattern matching, algebraic datatypes, and functions such as map, reduce, filter and fold - The language has a very minimal runtime, more similar to the way C has a runtime, but we talk about like it has no runtime, as opposed to Java with its JVM, Python with its Python Interpreter and other managed languages. - Because we really don't have a runtime, Rust is not a managed language, and we do not have garbage collection. The language handles memory management for you automatically and makes sure it is memory safe at compile-time. --- # Mandatory Hello World! ```rust fn main() { println!("Hello TD Talks!"); } ``` ??? - As C, Rust code starts with the main function - Functions in rust are defined by `fn function_name(arguments) -> return_type {` - Println is a macro, which like other macros end in a bang(!) --- # Functional Aspects ```rust enum Maybe { Thing(u64), Nothing, } fn square(num: Maybe) -> Maybe { match num { Maybe::Thing(num) => Maybe::Thing(num * num), Maybe::Nothing => Maybe::Nothing, } } fn main() { // Import the variants of Maybe into scope use Maybe::{Thing, Nothing}; // Type inference decides these are Maybe let num = Thing(1337); // Match is like a switch-case, but on steroids match square(num) { Thing(num_sq) => println!("We have: {}", num_sq), Nothing => println!("We have no value"), } } ``` ??? - Enum is a type which can be one of the different types - Match lets you match types and patterns, and not only values --- # Tooling - Cargo - Crates.io - Rust Language Server - Clippy ??? - For creating a new project, compiling, running, tests, and installing binaries - NPM for Rust - Crates.io is our package repository currently has 22.129 libraries and almost 750M downloads - Rust Language Server uses the Language Server protocol and we have plugins for the most popular editors - Yes, we have our own clippy which helps us write idiomatic code --- # Where is Rust used? - Components of the Dropbox core file-storage system - Realtime A/B-testing system used by Yelp - New firefox CSS engine - Cloudflare's Serverless Platform for WASM ??? - In general, Rust can be used most places - But is mainly used in systems where performance, resource usage and security and safety is important --- # Trying it out - Rust Playground - Rustup ??? - You can try it out directly in a web browser without installing it - If your package manager does not ship it, you can always use rustup from rustup.rs to manage rust, and multiple versions of it --- class: center, middle Rust enables you to write fast code that works ??? - The key take-away is that rust enables you to write code that is performant and you can trust to do what you want it to do - It has a great community, a ton of libraries and a great tools to make programming more pleasant --- class: center, middle # Questions?