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

Rust wants the things that are expensive to be obvious. Going from &str to String allocates, so that requires an upfront conversion before use.

On the other-hand String has a Deref impl to &str, so you can call any method defined on &str directly from a variable of type String. That doesn’t require any cast, and those methods can be called directly on the variable making it very easy.

To me this feels like a good trade off in ergonomics vs. performance.



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

Search: