3 ms·
Feedback welcome! I'm sure I'm missing loads of Rust patterns and idioms...
by cstein2 7y ago
Feedback welcome! I'm sure I'm missing loads of Rust patterns and idioms...
- ShorsHammer 7y agoSome comments: Async/await syntax is poorly documented across the ecosystem but has landed now and is useful, without it codebases will look outdated soon enough, hyper itself has some of the best docs Lazystatic is popular way to use globals like that yet don't really bother with it anymore. The paradigms are a bit different for a language, you are discouraged from such things for a reason, there's certainly ways around using globals. You don't need extern crate with 2018 edition and macros are automatically imported
- roblabla 7y agoInstead of lazy static, use once_cell’s Lazy type[0]! It is a replacement that does away with the macro-based approach, possible thanks to improvements in const fn. This leads to improved IDE experience. [0] https://docs.rs/once_cell/1.3.1/once_cell/ https://docs.rs/once_cell/1.3.1/once_cell/
- cstein2 7y agoThanks! What would you suggest instead of a global/lazy static in this situation though? I recall struggling to pass some dynamically allocated structure into the hyper service instantiation.