|
|
|
|
|
by alkonaut
1327 days ago
|
|
Most things don’t need to be written in Rust. But C/C++ exist for a reason, and Rust for effectively the same reasons. Rust looks complicated but it’s a complicated problem that’s why the solution is complicated. If you want zero cost (e.g no GC!) abstractions and some compile time guarantees about concurrency and memory safety well then you have a complex problem requiring a complex solution. &str is a “slice” of a string, it doesn’t own any characters it just points to someone else’s characters. String is a heap allocated string so it has its own characters. The ‘ indicates a lifetime and “static” just means “lives forever”. In the end, lifetimes and multiple string types is the price we pay for performance and safety. There is no world where Rust just had ergonomic strings like Java and safety/performance unaffected. |
|