# Why Rust? ## 2022 Edition <!-- .element: class="fragment" --> --- # Performance * Native binary <!-- .element: class="fragment" --> * No garbage collector <!-- .element: class="fragment" --> * Zero-cost abstractions as first focus <!-- .element: class="fragment" --> * Const by default - easier to optimize <!-- .element: class="fragment" --> * Move by default <!-- .element: class="fragment" --> --- ## Lazy iterators ```cpp [2|4-8] int main() { std::vector<int> input { 1, 2, 3, 4, 5 }; auto it = std::remove_if( input.begin(), input.end(), [](int i) { return i % 2 = 1; } ); input.erase(it, input.end()); // ... } ``` --- ## Lazy Iterators ```cpp [6-12] int main() { std::vector<int> input { 1, 2, 3, 4, 5 }; // ... std::vector<int> mapped; std::transform( std::make_move_iterator(input.begin()), std::make_move_iterator(input.end()), std::inserter(mapped, mapped.end()), [](int i) { return i * i; } ); } ``` --- ## Lazy iterators ```rust [2|5|6|4,7] fn main() { let input = 1..=5; let mapped: Vec<_> = input .filter(|i| i % 2 == 0) .map(|i| i * i) .collect(); } ``` --- ## Lazy iterators - C++21 ```cpp [2|5|6|8-12] int main() { auto const input = view::iota(1, 6); auto const output_view = views::filter([](int i) { return i % 2 == 0 }) | views::transform([](int i) { return i * i}); std::vector<int> output; std::copy( output_view.begin(), output_view.end(), std::inserter(output, output.end()) ); } ``` --- # Reliability * Borrow checker preventing exploitable bugs <!-- .element: class="fragment" --> * Structure-behavior separation <!-- .element: class="fragment" --> * Generics understanding traits <!-- .element: class="fragment" --> * Explicit error handling <!-- .element: class="fragment" --> --- # Productivity * Great toolset including dependency management <!-- .element: class="fragment" --> * Easy cross-compilation <!-- .element: class="fragment" --> * Typesystem improving productivity <!-- .element: class="fragment" --> * Great community and learning resources <!-- .element: class="fragment" --> --- # Toolset * Rustup + Cargo <!-- .element: class="fragment" --> * Clippy <!-- .element: class="fragment" --> * Doc comments <!-- .element: class="fragment" --> * Rust analyzer <!-- .element: class="fragment" --> --- # Cross-compilation * Embeded programming <!-- .element: class="fragment" --> * Browser-side execution with Wasm <!-- .element: class="fragment" --> * Smart contracts with Wasm <!-- .element: class="fragment" --> * Plugins with Wasm <!-- .element: class="fragment" --> --- ## Learning resources - books * The Rust Language <!-- .element: class="fragment" --> * Rust by example <!-- .element: class="fragment" --> * The Embeded Rust Book <!-- .element: class="fragment" --> * Rust and WebAssembly <!-- .element: class="fragment" --> * CosmWasm book <!-- .element: class="fragment" --> * And more books <!-- .element: class="fragment" --> --- # Thank you
{"metaMigratedAt":"2023-06-17T05:13:29.578Z","metaMigratedFrom":"Content","title":"Why Rust?","breaks":true,"contributors":"[{\"id\":\"a29aa4a5-328c-4980-852a-0e957f26f569\",\"add\":3922,\"del\":876}]"}
    221 views