Skip to content

Add item predicate traits to slices, following CharEq for str #14612

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

Closed
aturon opened this issue Jun 2, 2014 · 2 comments
Closed

Add item predicate traits to slices, following CharEq for str #14612

aturon opened this issue Jun 2, 2014 · 2 comments

Comments

@aturon
Copy link
Member

aturon commented Jun 2, 2014

Several methods on the str type take a generic "predicate" on characters:

  • split and friends
  • trim_chars and friends
  • find and friends

The CharEq trait makes character predicates convenient by providing instances for char, various char -> bool function types, and slices of characters.

Vector slices should provide a similar interface. Right now, some of the relevant slice methods operate on individual items, while others take bool-producing functions.

Unfortunately, this is blocked on trait reform (#5527).

@huonw
Copy link
Member

huonw commented Mar 2, 2015

It's unclear to me if this is possible to implement to get exactly the same sort of API as str, since there element type is very generic, and so impls overlap, e.g.:

impl<T: Eq> ElemEq for T { ... }
impl<F: FnMut(&T) -> bool> ElemEq for F { ... }

@aturon
Copy link
Member Author

aturon commented Mar 10, 2015

Yes, this is a pretty old issue and filed before the final overlapping rules became clear. (I think it might have been workable before unboxed closures, and could perhaps be made to work with negative bounds, but @Kimundi's approach is nicer in any case).

@aturon aturon closed this as completed Mar 10, 2015
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
Fix need-mut large span in closures and a false positive

fix rust-lang#14612
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

No branches or pull requests

2 participants