Hacker News new | past | comments | ask | show | jobs | submit login
Using Rust Generics to Write Flexible and Reusable Code (earthly.dev)
4 points by amalinovic on Aug 4, 2023 | hide | past | favorite | 1 comment



Rust's generics are quite strict (types are verified abstractly at the point of definition, not against concrete types at the point of use). This means they sometimes need verbose trait bounds, and are very sensitive to wrong/imprecise lifetime annotations.

Especially for numeric code I'd suggest using macros instead. Generic monomorphisation duplicates code anyway, so macros aren't as terrible as they may seem. Rust's macros are a bit closer to C++ templates than generics are.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: