-
Notifications
You must be signed in to change notification settings - Fork 633
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
Implement FuturesUnordered::iter_mut #618
Implement FuturesUnordered::iter_mut #618
Conversation
d022efb
to
f21c2a1
Compare
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.
The impl looks correct to me. I added some naming related comments.
src/stream/futures_unordered.rs
Outdated
@@ -427,6 +436,37 @@ impl<T> Drop for FuturesUnordered<T> { | |||
} | |||
} | |||
|
|||
#[derive(Debug)] | |||
/// Mutable iterator over all futures in the unordered set. | |||
pub struct FuturesUnorderedIterMut<'a, F: 'a> { |
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.
I would probably just name this IterMut
as it already is in the futures_unordered
module.
src/stream/mod.rs
Outdated
@@ -112,7 +112,7 @@ if_std! { | |||
pub use self::collect::Collect; | |||
pub use self::wait::Wait; | |||
pub use self::split::{SplitStream, SplitSink}; | |||
pub use self::futures_unordered::{futures_unordered, FuturesUnordered}; | |||
pub use self::futures_unordered::{futures_unordered, FuturesUnordered, FuturesUnorderedIterMut}; |
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.
I probably wouldn't re-export this type. Instead, maybe make the futures_unordered
module pub (and ensure no priv types are accidentally exported).
f21c2a1
to
1f8339f
Compare
@carllerche Thanks for the review, addressed all feedback! |
Inside this module there's a public |
src/stream/futures_unordered.rs
Outdated
pub struct IterMut<'a, F: 'a> { | ||
node: *const Node<F>, | ||
len: usize, | ||
_marker: PhantomData<&'a F> |
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.
I think this may best be &'a mut FuturesUnordered<F>
perhaps?
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.
Apologies -- can you go into more details why that would be better?
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.
Long long ago in Rust there were subtle distinctions between how &mut T
and &T
worked, and I forget if any of them are still true today. Basically because this is a mutable iterator it's "better" to have a phantom data of &mut ...
instead of &...
to ensure this information is conveyed to the compiler.
Additionally I figure it's best to store FuturesUnordered<F>
as that's effectively what's happening here (vs just F
). This can also cause subtle differences but probably not as important as &mut
vs not
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.
Thanks for explaining that, changed it!
Which release of rust included |
Unsure, but the function can also just be moved |
@carllerche According to this, @alexcrichton the |
@srijs right yeah but as is this would also export |
1f8339f
to
cce3c07
Compare
@alexcrichton Implemented your feedback. Now that we have |
cce3c07
to
8c7a70b
Compare
src/stream/mod.rs
Outdated
@@ -103,7 +103,7 @@ if_std! { | |||
mod wait; | |||
mod channel; | |||
mod split; | |||
mod futures_unordered; | |||
mod futures_unordered_impl; |
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.
Oh I was thinking that we'd still want a futures_unordered
module which contained the FuturesUnordered
type, for example. I think we'll just want to move the definition of the constructor, futures_unordered
, from the module to this stream
module
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.
No problem, changed!
Ah yeah so for now I personally like the free function for symmetry with the rest of the crate, but eventual deprecation is of course possible! |
8c7a70b
to
16ee1d3
Compare
@alexcrichton Feedback addressed, let me know if you'd like me to change anything else! |
16ee1d3
to
d59b8a3
Compare
Awesome, thanks! |
Implementing
FuturesUnordered::iter_mut
as suggested in #605. Generally it should be said that I don't have a lot of experience with unsafe rust yet, so I would appreciate a thorough review!I did not go for the other suggested ones (
into_iter
/drain
), since I lack the insight into how to implement this safely without leaking memory.