Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Maybe the correct function signature is this? fn peek<T>(&mut self, callback: impl for<'a> FnOnce(Option<&'a Self::Item>) -> T) -> TThis would mean, for example, that |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| // SAFETY: by type invariant, the `end_or_len` field is always | ||
| // non-null for a non-ZST pointee. (This transmute ensures we | ||
| // get `!nonnull` metadata on the load of the field.) | ||
| if ptr == crate::intrinsics::transmute::<$ptr, NonNull<T>>(end_or_len) { |
There was a problem hiding this comment.
| // SAFETY: by type invariant, the `end_or_len` field is always | |
| // non-null for a non-ZST pointee. (This transmute ensures we | |
| // get `!nonnull` metadata on the load of the field.) | |
| if ptr == crate::intrinsics::transmute::<$ptr, NonNull<T>>(end_or_len) { | |
| if ptr.as_ptr() == end_or_len { |
There was a problem hiding this comment.
Hmm, I was not able to write it this way as Rust determines the types differ in their mutability. In general, this code was based on the next() method generic over both Iter and IterMut
There was a problem hiding this comment.
What exactly was the error? Seems possible to resolve by adding a $as_ptr metavar that is either as_ptr or as_mut_ptr depending on which one is being implemented (like into_ref).
next is a bit magical, others should try to be simpler if possible. cloning and advancing should be fine, it's cheap.
There was a problem hiding this comment.
Cloning actually wouldn't work for IterMut since it doesn't implement it. But that actually brings up a good point; the safety comments need to say why it is sound to hand out a&mut T.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
This doesn't seem to be tested at all. Please make sure that even unstable API gets helpful examples, aside from checking the implementation they serve as a very useful smoke test for whether or not the API makes sense in the first place.
Additionally, the type-specific impls need tests in library/coretests
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@wmstack Are you still open to working on this PR? If not, then I’m willing to take over the work on this. |
|
@bluebear94 Feel free to pick this up as I’m tied up with coursework at the moment. |
|
☔ The latest upstream changes (presumably #147353) made this pull request unmergeable. Please resolve the merge conflicts. |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Improve documentation for `PeekableIterator` to reflect the changes in API Co-authored-by: +merlan #flirora <flirora@flirora.xyz>
Co-authored-by: Tim (Theemathas) Chirananthavat <theemathas@gmail.com>
934253c to
512e44f
Compare
This comment has been minimized.
This comment has been minimized.
|
The job Click to see the possible cause of the failure (guessed by this bot) |
Tracking issue: #132973
Implementation
Todo: Determine which structures need to implement
PeekableIterator:slice::iterstr::Charsvec::IntoIterPeekable<T>Unresolved Issues:
peek()without mutating?