Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

FWIW, for most of my Rust use cases I found I can get away with a relatively simple heuristic:

- if you pass it is a parameter, pass a read-only reference.

- if you return a value as a result of a function call, clone as necessary and return as an owned object, try to never return a reference.

- if the above two don’t fit, it’s thinking time; either the structure of the program can still afford for them with some refactor, or it’s genuinely incompatible.

The former avoids excessive copying and limits the bugs due to attempting to modify a cloned object, the latter limits the lifetime managing gymnastics required. The third allows to keep the program logic relatively simple except in the cases where it’s really required.

Hope that this is of some use :-)



- if you pass it is a parameter, pass a read-only reference.

Completely breaks with a lot of async code




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: