Skip to content
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

Provide method find_slice() for &[T] #15853

Closed
nwin opened this issue Jul 21, 2014 · 2 comments
Closed

Provide method find_slice() for &[T] #15853

nwin opened this issue Jul 21, 2014 · 2 comments

Comments

@nwin
Copy link
Contributor

nwin commented Jul 21, 2014

&str has find_str(). It would be handy to have such a method for slices as well. This is for example useful for work with non-utf8 based strings.

A simple implementation for std::slice::ImmutableEqVector could be:

/// Returns the index of the first matching subslice
fn find_slice<T: PartialEq>(&self, needle: &[T]) -> Option<uint> {
    for i in range(0, this.len()) {
        if this.slice_from(i).starts_with(needle) {
            return Some(i)
        }
    }
    None
}

If desired I could file a pull request.

@aochagavia
Copy link
Contributor

I guess the best would be to file a pull request. You will probably get more feedback than here.

@steveklabnik
Copy link
Member

Adding methods to core types now requires an RFC. Please file one if you'd like this still!

bors added a commit to rust-lang-ci/rust that referenced this issue Nov 16, 2023
…mment, r=lnicola

Try to update parser/event doc

`TokenSource` and `TreeSink` has been refactored as part of rust-lang#10765, they no longer exist in code repo. This pr tries to remove them from event module level comment to prevent confusion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants