powerful abstractions, no null, no segfaults, no leaks, yet C-like performance and control over memory.” "Our preliminary measurements show the Rust component performing beautifully and delivering identical results to the original C++ component it’s replacing—but now implemented in a memory-safe programming language." "Rust has been the perfect tool for this job because it allowed us to offload an expensive operation into a native library without having to use C or C++, which would not be well suited for a task of this complexity. "
None; println!("{}", value.unwrap()); } thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', ../src/libcore/option.rs:326 note: Run with `RUST_BACKTRACE=1` for a backtrace. You know exactly where panic can occur
=> println!("{}", x), None => println!("Nothing"), } value.unwrap_or(5) Pattern matching Use a default value Some(String::from("Barcamp")).map(|s| s.len()); Apply a function
<anon>:4:20 | 3 | let y = x; | - value moved here 4 | println!("{}", x.len()); | ^ value used here after move <std macros>:2:27: 2:58 note: in this expansion of format_args! <std macros>:3:1: 3:54 note: in this expansion of print! (defined in <std macros>) <anon>:4:5: 4:29 note: in this expansion of println! (defined in <std macros>) | = note: move occurs because `x` has type `std::vec::Vec<i32>`, which does not implement the `Copy` trait error: aborting due to previous error
one owner 2. Others can borrow it from the owner but the reference must last no longer than the owner let y; if true { let x = vec![1]; y = &x; } println!("{}", y.len());
--> <anon>:5:14 5 | y = &x; | ^ note: reference must be valid for the block suffix following statement 0 at 2:10... --> <anon>:2:11 2 | let y; | ^ note: ...but borrowed value is only valid for the block suffix following statement 0 at 4:24 --> <anon>:4:25 4 | let x = vec![1]; | ^
one owner 2. Others can borrow it from the owner but the borrow must last no longer than the owner 3. Only one mutable reference let mut x = vec![1]; x.push(5); let y = &x; y.push(6);
one owner 2. Others can borrow it from the owner but the borrow must last no longer than the owner 3. Only one mutable reference let mut x = vec![1]; x.push(5); let y = &mut x; x.push(6);
than once at a time --> <anon>:5:5 | 4 | let y = &mut x; | - first mutable borrow occurs here 5 | x.push(6); | ^ second mutable borrow occurs here 6 | } | - first borrow ends here
free: Rust use RAII plus lifetime check • Dangling pointers: Prevented by lifetime check • Rust also have no socket/file pointer closing function. Socket is closed when it goes out of scope.
but it borrows `x`, which is owned by the current function --> <anon>:5:31 | 5 | let child = thread::spawn(|| *x += 1); | ^^ - `x` is borrowed here | | | may outlive borrowed value `x` | help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword, as shown: | let child = thread::spawn(move || *x += 1);
<anon>:6:5 | 5 | let child = thread::spawn(move || *x += 1); | ------- value moved (into closure) here 6 | *x += 1; | ^^^^^^^ value used here after move | = note: move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
time • Generic can be dispatched statically (like C++ templates) ◦ Rust has zero-cost abstraction as its core value: pay for only what you use • Rust have no garbage collection • Rust allocate all local variable on the stack
next-generation web engine for Firefox users, building on the Gecko engine as a solid foundation. • We're going to ship major improvements in 2017, and we'll iterate from there • https://wiki.mozilla.org/Quantum
the 14 companies that responded is using Rust in their products. • Rust is very much a tool for general-purpose development where performance and safety matters. • Pain points ◦ Library support ◦ C++ FFI ◦ IDE Support ◦ Build time ◦ Learning curve for new developers