I would like to use the &str slice_shift_char , but it is marked as unstable in the documentation:
Unstable: waiting for offset and slice conventions and may not be warranted by the presence of characters and / or char_indices iterators
What would be a good way to implement this method using Rust current std library? So far, I:
fn slice_shift_char(s: &str) -> Option<(char, &str)> { let mut ixs = s.char_indices(); let next = ixs.next(); match next { Some((next_pos, ch)) => { let rest = unsafe { s.slice_unchecked(next_pos, s.len()) }; Some((ch, rest)) }, None => None } }
I would like to avoid calling slice_unchecked . I am using Rust 1.1.
source share