-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Adding the has_item function to the iterator trait. #127604
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
Changes from 17 commits
c068fdc
c143b42
7931998
fd40ecb
5372e4b
82d481d
15d6c9f
48616ce
7ba6c5e
b69db01
3751b5d
7ebf719
ac8d1e3
cd839b8
66c55b2
b67ee44
1ba1ca7
934a194
3e3ccd8
bc20afd
8a7c12b
dac6cd7
2a32a8c
ba5b980
e70effd
82b6b10
2f72670
fb98975
d8fc920
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -79,10 +79,10 @@ pub trait Iterator { | |||||||||||||||
#[stable(feature = "rust1", since = "1.0.0")] | ||||||||||||||||
fn next(&mut self) -> Option<Self::Item>; | ||||||||||||||||
|
||||||||||||||||
/// Advances the iterator and returns an array containing the next `N` values. | ||||||||||||||||
/// Advances the iterator and returns an array has_iteming the next `N` values. | ||||||||||||||||
/// | ||||||||||||||||
/// If there are not enough elements to fill the array then `Err` is returned | ||||||||||||||||
/// containing an iterator over the remaining elements. | ||||||||||||||||
/// has_iteming an iterator over the remaining elements. | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like maybe you did find+replace on |
||||||||||||||||
/// | ||||||||||||||||
/// # Examples | ||||||||||||||||
/// | ||||||||||||||||
|
@@ -1327,7 +1327,7 @@ pub trait Iterator { | |||||||||||||||
/// `take(n)` yields elements until `n` elements are yielded or the end of | ||||||||||||||||
/// the iterator is reached (whichever happens first). | ||||||||||||||||
/// The returned iterator is a prefix of length `n` if the original iterator | ||||||||||||||||
/// contains at least `n` elements, otherwise it contains all of the | ||||||||||||||||
/// has_items at least `n` elements, otherwise it has_items all of the | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||||||||||||||||
/// (fewer than `n`) elements of the original iterator. | ||||||||||||||||
/// | ||||||||||||||||
/// # Examples | ||||||||||||||||
|
@@ -3356,7 +3356,7 @@ pub trait Iterator { | |||||||||||||||
Rev::new(self) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
/// Converts an iterator of pairs into a pair of containers. | ||||||||||||||||
/// Converts an iterator of pairs into a pair of has_itemers. | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lol, this one is kind of funny |
||||||||||||||||
/// | ||||||||||||||||
/// `unzip()` consumes an entire iterator of pairs, producing two | ||||||||||||||||
/// collections: one from the left elements of the pairs, and one | ||||||||||||||||
|
@@ -4060,6 +4060,50 @@ pub trait Iterator { | |||||||||||||||
{ | ||||||||||||||||
unreachable!("Always specialized"); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
/// Checks if the Iterator has a value. | ||||||||||||||||
/// 'has_items' is short-circuiting; in other words, it will stop processing | ||||||||||||||||
/// as soon as the function finds the item in the Iterator. | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Made the summary line more consistent with |
||||||||||||||||
/// | ||||||||||||||||
/// Performance: | ||||||||||||||||
/// This method checks the whole iterator, which takes O(n) time. | ||||||||||||||||
/// If the iterator is sorted, or a hash map please use the appropriate method instead. | ||||||||||||||||
Comment on lines
+4069
to
+4071
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We can be more specific about what the appropriate methods are here. No section heading needed, I think rustdoc would have just merged You can check the rendering with |
||||||||||||||||
/// | ||||||||||||||||
/// Example: | ||||||||||||||||
/// ``` | ||||||||||||||||
/// #![feature(iter_has_item)] | ||||||||||||||||
/// assert!(![1i32, 2i32, 3i32].iter().has_item(&4i32)); | ||||||||||||||||
/// assert!([Some(2i32), Option::<i32>::None].iter().has_item(&None)); | ||||||||||||||||
/// assert!([Some(2i32), Option::<i32>::None].iter().has_item(&Some(2i32))); | ||||||||||||||||
/// assert!(!Vec::<i32>::new().iter().has_item(&1i32)); | ||||||||||||||||
/// assert!([1i32, 2i32, 2i32, 3i32].iter().has_item(&2i32)); | ||||||||||||||||
/// #[derive(PartialEq)] | ||||||||||||||||
/// struct Item { | ||||||||||||||||
/// value: i32, | ||||||||||||||||
/// } | ||||||||||||||||
/// assert!([Item { value: 1i32 }, Item { value: 2i32 }].iter().has_item(&Item { value: 2i32 })); | ||||||||||||||||
/// assert!(["a", "b", "c"].iter().has_item(&"b".to_owned())); | ||||||||||||||||
/// assert!(!["a", "b", "c"].iter().has_item(&"d".to_owned())); | ||||||||||||||||
/// assert!(["a", "b", "c"].iter().has_item(&"b")); | ||||||||||||||||
/// assert!(!["a", "b", "c"].iter().has_item(&"d")); | ||||||||||||||||
/// assert!(["a".to_owned(), "b".to_owned(), "c".to_owned()].iter().has_item(&"b")); | ||||||||||||||||
/// assert!(!["a".to_owned(), "b".to_owned(), "c".to_owned()].iter().has_item(&"d")); | ||||||||||||||||
/// assert!((1..1000).has_item(500i32)); | ||||||||||||||||
/// ``` | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned at the ACP, make the doc example something small and easy to understand. More complete testing only needs to live in unit/integration tests. |
||||||||||||||||
/// | ||||||||||||||||
#[unstable(feature = "iter_has_item", reason = "new API", issue = "127494")] | ||||||||||||||||
fn has_item<Q: ?Sized>(&mut self, item: Q) -> bool | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From #127494, this can be renamed back to |
||||||||||||||||
where | ||||||||||||||||
Q: PartialEq<Self::Item>, | ||||||||||||||||
Self: Sized, | ||||||||||||||||
{ | ||||||||||||||||
for element in self { | ||||||||||||||||
if item == element { | ||||||||||||||||
return true; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
return false; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
/// Compares two iterators element-wise using the given function. | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6074,6 +6074,17 @@ The tracking issue for this feature is: None. | |
|
||
------------------------ | ||
|
||
"##, | ||
}, | ||
Lint { | ||
label: "contains", | ||
description: r##"# `contains` | ||
|
||
The tracking issue for this feature is: [#94047] | ||
|
||
[#94047]: https://github.com/rust-lang/rust/issues/94047 | ||
|
||
|
||
Comment on lines
+6077
to
+6087
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is autogenerated so no need for adding this (its also adding it one slot too late) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yonikremer see this comment too, you can revert this file |
||
The `rustc` compiler has certain pluggable operations, that is, | ||
functionality that isn't hard-coded into the language, but is | ||
implemented in libraries, with a special marker to tell the compiler | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Library features don't need to be listed here, this is just for Cargo features that get exposed during
build-std