Re:A half-hour to learn Rust
by throwaway894345 on Saturday January 02, 2021 @04:04PM
(#25616515)
It’s not just performance, but you now have to go back and update every instance of that struct to reflect the change in ownership of that member if you can even change the member in the first place (e.g., you can’t change the type of a member of the struct itself is defined in a third-party package). Moreover, some instances of your struct might be in a tight loop and others might not, but now you’re committing to poorer performance in all cases. Maybe you can box it (although IIRC I’ve run into other issues when I tried this) but in any case this isn’t the “elegance” I was promised. Which is fine, because Rust is a living, rapidly-improving language, but let’s not pretend that there is an elegant solution today.
[ Parent
| on HN ]
Re:A half-hour to learn Rust
by fasterthanlime on Saturday January 02, 2021 @08:29PM
(#25618479)
Libraries can be (and some actually are) designed with that in mind, with COW (copy on write( types that can be either borrowed or owned. Speaking of performance, kstring (of liquid) goes one step further with inline variants for short strings.
I want to say that seems like a valid concern but in practice I've seen it come up only rarely.