-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Allow an Iterator to update a &mut [T], add IterReader #14568
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
Conversation
|
} | ||
} | ||
idx | ||
} |
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.
Would something like this suffice?
fn update<I: Iterator<T>>(self, iter: I) -> uint {
let mut i = 0;
for (slot, element) in self.mut_iter().zip(iter) {
*slot = element;
i += 1;
}
return i;
}
If the unsafe
blocks stays, could you add a comment explaining why it is unsafe, what the benefits are, and why it is necessary to not rely on safe code?
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.
You're right, that could work. I'll remove that patch from the PR.
The first patch does seem to deviate a bit from the compositionality of iterators. This would add an |
This PR adds two features to make it possible to transform an `Iterator<u8>` into a `Reader`. The first patch adds a method to mutable slices that allows it to be updated with an `Iterator<T>` without paying for the bounds cost. The second adds a Iterator adaptor, `IterReader`, to provide that `Reader` interface. I had two questions. First, are these named the right things? Second, should `IterReader` instead wrap an `Iterator<Result<u8, E>>`? This would allow you to `IterReader::new(rdr.bytes())`, which could be useful if you want to apply some iterator transformations on a reader while still exporting the Reader interface, but I'd expect there'd be a lot of overhead annotating each byte with an error result.
…st-lang#14568) Fixes rust-lang/rust-clippy#14449, introduced in rust-lang#14314 changelog: [`map_entry`]: fix a false positive where the lint would trigger without any insert calls present
…st-lang#14568) Fixes rust-lang/rust-clippy#14449, introduced in rust-lang#14314 changelog: [`map_entry`]: fix a false positive where the lint would trigger without any insert calls present
…st-lang#14568) Fixes rust-lang/rust-clippy#14449, introduced in rust-lang#14314 changelog: [`map_entry`]: fix a false positive where the lint would trigger without any insert calls present
This PR adds two features to make it possible to transform an
Iterator<u8>
into aReader
. The first patch adds a method to mutable slices that allows it to be updated with anIterator<T>
without paying for the bounds cost. The second adds a Iterator adaptor,IterReader
, to provide thatReader
interface.I had two questions. First, are these named the right things? Second, should
IterReader
instead wrap anIterator<Result<u8, E>>
? This would allow you toIterReader::new(rdr.bytes())
, which could be useful if you want to apply some iterator transformations on a reader while still exporting the Reader interface, but I'd expect there'd be a lot of overhead annotating each byte with an error result.