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

Oh. I wonder if the Display trait implementation can be enforced to have no side effects (beside allocation).


When implementing Display you only get access to an immutable reference to self, so the only possibly side effects are writes to global variables.


That depends on what Self contains. Using the Cell types and some of the other inner mutating types, it is possible to change the interior state of self even behind a shared reference.

Additionally, with unsafe it’s also possible. This is in response to “the only possible” statement.

Of course, doing so is not advisable.




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: