-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add std::str::Chars remaining() function #12395
Comments
Not only this is more efficient (no need to count twice), but also safe ( |
@mneumann pull request? 😄 |
@cmr: I think we'd want that for all related Iterators where it makes sense as well, no? |
@mneumann fn main() {
let s = "find α-particles";
let mut start = s.len();
for (i, c) in s.char_indices() {
if c == 'p' {
start = i;
break;
}
}
println!("remaining={}", s.slice_from(start));
} |
@bluss: Thanks. That works of course. Closing for now. |
Fwiw, if this is implemented you could even call it |
fix: f32 and f64 representation during lowering should fix rust-lang#12380
[`let_underscore_untyped`]: fix false positive on async function changelog: [`let_underscore_untyped`]: fix false positive on async function Fix rust-lang#12395
This is quite useful when scanning strings, especially when more flexibility is needed. For example, the following example uses
slice_from
which is not always safe as it uses byte offsets (but using char offsets would be O(n) and I want to avoid it!).Instead when something like
remaining()
would exist, the code could be rewritten as:This comes in very useful and is also more efficient! Iterators are not always enough, so that's why I do not want to pass iterators around and instead work on string slices.
The text was updated successfully, but these errors were encountered: