Skip to content

Commit fc44e75

Browse files
tormolThomas Bahn
authored andcommitted
Extend AsAsciiStr to easily convert sub-slices
* Add methods slice_ascii(), and get_ascii() to AsAsciiStr * Add methods slice_ascii_mut() to AsMutasciiStr The main use case is avoiding accidentally panicking by slicing a str in the middle of a codepoint with AsciiStr::from_ascii(str[a..=b]) or AsciiChar::from(str[n]). I had hoped to finally use RangeArgument, but almost nothing in std takes it because they instead went for their own unstable and sealed trait (SliceIndex). Converting between them is also impossible without going through trait objects. SliceIndex is actually workable though, albeit with one wart (associated type). Working with mutable slices is hairy as usual.
1 parent e047318 commit fc44e75

File tree

1 file changed

+236
-44
lines changed

1 file changed

+236
-44
lines changed

0 commit comments

Comments
 (0)