Hacker News new | past | comments | ask | show | jobs | submit login

The difference between a heap allocated string (String), a static string literal embedded in the binary (&str), and a stack allocated string ([char], but this is more common in C than Rust) is the simplest introduction to manually managed memory.

The complications have nothing to do with Rust but with how computers manage and allocate memory. You might as well also skip C, C++, Zig, and every other language which gives you fine-tuned access to the stack and heap, because you'll run into the same concept.




Nit: A &str doesn't mean it has to be static, a &'static str does (which are a subset of &str). A &str can easily point to a dynamic String's heap storage too.


str doesn’t have to be embedded in the binary. It can be that, or it can be on the heap, or it can be on the stack.




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

Search: