4 ms·
>Rust gets memory safety without a hit in performance Interesting. How does rust statically verify that array accesses are in bounds?
by acconsta 11y ago
>Rust gets memory safety without a hit in performance
Interesting. How does rust statically verify that array accesses are in bounds?
- bjz_ 11y agoRust defaults to run-time bounds-checked array accesses, but iterators mean that the bounds only need to be checked once.
- acconsta 11y ago>iterators mean that the bounds only need to be checked once. How is that possible with random access or mutable containers?
- masklinn 11y agoA Rust object can be owned (T), mutably referenced (&mut T) or immutably referenced (&T). To a given owned object you can create either a single mutable reference or any number of immutable references (concurrently, sequentially is fine). When you create an iterator from a container, the iterator contains an immutable reference to the container. As long as the iterator is alive, it's not possible to take a mutable reference to the container, and thus not possible to modify it. Because a reference can't outlive its source, this also ensures the iterator can't outlive the collection.
- heinrich5991 11y agoArray accesses are checked at runtime.