-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
&str should have split_first #48731
Comments
This function was called fn slice_shift_char(a: &str) -> Option<(char, &str)> {
let mut chars = a.chars();
chars.next().map(|c| (c, chars.as_str()))
}
fn main() {
assert_eq!(slice_shift_char("hello"), Some(('h', "ello")));
assert_eq!(slice_shift_char("ĺḿńóṕ"), Some(('ĺ', "ḿńóṕ")));
assert_eq!(slice_shift_char(""), None);
} |
We don't keep bugs open for small feature requests for libraries like this; big things need an RFC, small things can be PR'd. Thanks! |
I don't feel it's a good reason. The same reasoning could be say about slice. Also, this is far from obvious. |
There isn't a |
@kennytm One could say the same for slice fn slice_shift_slice(a: &[u8]) -> Option<(u8, &[u8])> {
let mut iter = a.iter();
iter.next().map(|&n| (n, iter.as_slice()))
} |
fn split_first<T>(a: &[T]) -> Option<(&T, &[T])> {
match a {
[head, tail @ ..] => Some((head, tail)),
[] => None,
}
} Meanwhile I was just explaining the decision made
|
I know all that, I just explain your argument could work the same for have refused |
string slices should have a split_first, just like array slices.
returns -> (char, &str)
The text was updated successfully, but these errors were encountered: