3 ms·
> Rust's splitting iterators over `&str` return references to the same data as their own `&str`s, which is a huge performance win. Seems similar to Swift's Sub
by Razengan 8y ago
> Rust's splitting iterators over `&str` return references to the same data as their own `&str`s, which is a huge performance win.
Seems similar to Swift's Substrings (and other collection "slices"):
https://developer.apple.com/documentation/swift/substring https://developer.apple.com/documentation/swift/substring
- iamed2 8y agoSimilar, except for this key difference: > A substring holds a reference to the entire storage of the string it comes from, not just to the portion it presents, even when there is no other reference to the original string. Rust's `&str` doesn't do that, since the borrow checker will ensure at compile time that the `&str` reference doesn't live longer than the data it points to. At runtime there is no structural difference between an "original" `&str` and a `&str` pointing to a substring of the original.