-
Notifications
You must be signed in to change notification settings - Fork 39
Add Iterable to support streaming #38
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
Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
This code was contributed as part of Gemini <https://github.com/mmaker/gemini>.
Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
src/iterable/mod.rs
Outdated
/// The type of the iterator being generated. | ||
type Iter: Iterator<Item = Self::Item>; | ||
|
||
/// Returns the iterator associated to the current instance. |
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.
/// Returns the iterator associated to the current instance. | |
/// Returns the iterator associated to the current instance. |
/// | ||
/// An Iterable is pretty much like an [`IntoIterator`] that can be copied over | ||
/// and over, and has an hint of the length. | ||
/// In other words, these two functions are pretty much equivalent. |
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.
This sounds like the entire Iterable trait is not necessary, and it is the duty for Gemini to not use Iterable but instead to use the standard library one.
What is the main difference that Iterable provides but not by IntoIterator
?
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.
Fair point: the main difference is that we need to iter over the same stream multiple times, by design.
This means that already we require IntoIterator + Copy
or IntoIterator + Clone
if we want to go down that avenue.
From there, it's pretty much the same, except that now to get the length of a stream it becomes a bit more verbose, and the length function might disagree with the actual length (this is needed for instance when streaming a matrix).
Here's a bit of an overview of how the code might differ: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c7d9d2fca7d1d308601bd5b32d770409
To be fair, on the one hand, the downside is that Iterable::iter
will have to copy all relevant data from the initial structure (until https://github.com/rust-lang/rfcs/blob/master/text/1598-generic_associated_types.md hits the streets). On the other hand, for the long-term vision we have a trait that can be extended with other functions on the top of normal iterables, and that we skip having to type things like vec.into_iter().len()
.
Co-authored-by: Weikeng Chen <w.k@berkeley.edu>
Co-authored-by: Weikeng Chen <w.k@berkeley.edu>
Co-authored-by: Weikeng Chen <w.k@berkeley.edu>
Co-authored-by: Weikeng Chen <w.k@berkeley.edu>
Co-authored-by: Weikeng Chen <w.k@berkeley.edu>
Description
Add streaming utilities as Iterable into the std library.
The struct supports future developments for streaming.
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
Pending
section inCHANGELOG.md
Files changed
in the Github PR explorer