Post B4gI9dBCcPL7XRDk3c by Aissen@social.treehouse.systems
(DIR) More posts by Aissen@social.treehouse.systems
(DIR) Post #B4gI9MFBaLQP0rxBPE by Aissen@social.treehouse.systems
0 likes, 1 repeats
Rust In Paris started with Waffle @wffl presenting the Little Rust Delights. #RustLang #RustInParis
(DIR) Post #B4gI9VMbg7hzIUUjiq by Aissen@social.treehouse.systems
0 likes, 0 repeats
Waffle usually sees the broken parts of Rust, and wanted to share the nice things about Rust. #RustInParis
(DIR) Post #B4gI9XncceVSqr9L6m by Aissen@social.treehouse.systems
0 likes, 0 repeats
The first thing is the collect trait, which allows collecting into many collections. But also unexpected things like tuples, Option or Result. One can even collect a unit () from an iterator. It allows composition with other Result<(), E> to implement a custom `try_for_each`.#RustInParis
(DIR) Post #B4gI9ZPacyTHqtvAvY by Aissen@social.treehouse.systems
0 likes, 0 repeats
It's possible to include a file with `include_str!` directly into the documentation of item. For example, the full README of the project can be included in a crate doc that way to prevent duplication. #RustInParis
(DIR) Post #B4gI9bNXJa17x6yZ0K by Aissen@social.treehouse.systems
0 likes, 0 repeats
In Rust, a loop is infinite, so its type is ! aka the never type. If the loop {...} has a break, the type changes to the unit type (). And break can even take a value, and its type becomes the type of the loop#RustLang #RustInParis
(DIR) Post #B4gI9dBCcPL7XRDk3c by Aissen@social.treehouse.systems
0 likes, 0 repeats
In addition, loops can have labels, which is useful when nested. And similarly, break takes a label just before its value.#RustInParis
(DIR) Post #B4gI9erQMuhukfyyVU by Aissen@social.treehouse.systems
0 likes, 0 repeats
Patterns are a powerful feature of Rust. They are known to be useful in match. But they can be used everywhere, as long as they are exhaustive: in let assignments, for loops, function arguments...#RustInParis
(DIR) Post #B4gI9gT2OYO9jcaWm0 by Aissen@social.treehouse.systems
0 likes, 0 repeats
In some cases, for example when implementing a trait, it might be desirable to implement a Result, when we know that the error will never happen. The standard library has std::convert::Infallible for that. It's there possible to not use .unwrap() but let Ok(v) = result instead, which gives a stack guarantee. In this case, Infallible is not special, and any uninhabited type can be used for that, even the never type: ! .#RustInParis
(DIR) Post #B4gI9i0Og0fQVNCgPQ by Aissen@social.treehouse.systems
0 likes, 0 repeats
Rust allows let without assignment, so a variable can be assigned only once later (mutation is still disallowed). This can be used to escape blocks, or to make multiple assignements in blocks more readable. Waffle also showed a much cooler trick to prevent using Trait objects, but for that you'll have to watch the video!#RustLang #RustInParis