5 ms·
Couldn't syntax like `a_string[..3]` be made to result in compilation errors in Rust? Since that'd almost always be a bug? (right?) And in the rare cases, when
by KajMagnus 8y ago
Couldn't syntax like `a_string[..3]` be made to result in compilation errors in Rust? Since that'd almost always be a bug? (right?)
And in the rare cases, when it's not a bug, then one can just use `as_bytes` which would be good to do in any case, to indicate to other humans that this is not a bug.
B.t.w. I love the error message `[..3]` generates: "thread 'main' panicked at 'byte index 3 is not a char boundary; it is inside '早' (bytes 2..5) of `ab早`'" — I've never seen such easy to understand error messages in any language (except for in a few cases in Scala).
- steveklabnik 8y agoWe could have never implemented Index for String, sure. We have though, so removing it would be a breaking change.
- KajMagnus 8y agoOk (Maybe a compile time warning? that doesn't break the build)
- steveklabnik 8y agoThat could be done, if it was agreed that this is a mis-feature. I don't think there's agreement on that, though.