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

Use an `enum` like Cow[1] that allows passing around static strings along with dynamic strings, as well as interior pointers: the compiler can check that things don't get invalidated and the enum makes it trivial to deallocate things correctly (in fact, it's all done automatically by the compiler), so a more aggressive design can be used, no need to defensively copy the strings.

[1]: https://doc.rust-lang.org/std/borrow/enum.Cow.html



Oh, wow, thanks. I finally understand what the purpose of Cow is!




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: