CharIndices should have a way to access the current offset from the beginning

The CharIndices iterator has a field internally called front_offset, that I think would be very useful to have access to.

You can already do something like '|(offset, _)| offset)', but that is wordy, in addition to not handling the case where the iterator has ended, where you'd want the offset to be equal to the length.

I think it would be an easy and quite handy addition to add a method to CharIndices, maybe called 'offset' or something, that just gives back the starting offset of the next character.

1 Like

You can also add c.len_utf8() to the previously returned index. You don't need to call next.

This seems like a reasonable request. You could submit a pull request to add this as an unstable method to the standard library.