Rust in the 6.2 kernel
Rust in the 6.2 kernel
Posted Nov 17, 2022 17:32 UTC (Thu) by khim (subscriber, #9252)In reply to: Rust in the 6.2 kernel by atnot
Parent article: Rust in the 6.2 kernel
The difference between &str, String and Box<str> (which also) shows why Rust is a step forward while C++… not so much.
In C, of course, both “owned” and “borrowed” strings are represented as char *. C++ offers std::string and std::string_view, but… it's still responsibility of the developer to keep track of std::string_view's validity!
This makes C++ complication over C somewhat… unsatisfying: yes, we encoded difference in intents, but it's still our responsibility to keep track of everything… why do we need that complication?
But &str comes with additional assurances from the compiler: it's borrowed string, but it's compiler job to ensure that it's correctly borrowed! And String and Box<str> are owned, but it's compiler job to ensure they are correctly owned (initialized before use, etc).
That's why people say that Rust is attempting to raise the abstraction in the programming language: you genuinely can offload some of your knowledge into the machine and hope that it would verify that everything is done correctly.
It's similar to Sparse in some sense.
