-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add container::{NewContainer, Seq, MutableSeq} and other cleanup #10989
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
Whereas FromIterator is a pull construction of a container, the combination of NewContainer and Mutable{Set,Map,etc} allows for a push construction of a container.
Good work |
@alexcrichton: My reason for wanting this was from my experimental new serialization/deserialization library rust-serde. Since I'm creating actual sequences, maps, and sets, it'd be really handy to generically write just one "build a sequence", instead of having to cut and paste the same code to parse a vec/DList/RingBuf/HashMap/TreeMap/etc. Check out this line for an example of how life is simpler with a |
@alexcrichton: |
Interesting! I wonder if it would make more sense to define this |
This patch changes `result::collect` (and adds a new `option::collect`) from creating a `~[T]` to take an `Iterator`. This makes the function much more flexible, and may replace the need for #10989. This patch is a little more complicated than it needs to be because of #11084. Once that is fixed we can replace the `CollectIterator` with a `Scan` iterator. It also fixes a test warning.
Closing due to inactivity, but feel free to reopen with a rebase! |
… r=HKalbasi Add regression test for rust-lang#10989 rust-lang#10989 seems to have been fixed. This patch merely adds a regression test. Closes rust-lang#10989
…on, r=Manishearth Use placeref abstraction rust-lang#80647 suggests refactoring certain patterns with MIR places to use higher-level abstractions provided by the [`Place`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/mir/struct.Place.html)/[`PlaceRef`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/mir/struct.PlaceRef.html). While working on that issue, I found a couple candidates for such refactoring in clippy. *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: none
I expect this will need some discussion before it lands. This PR starts fleshing out
std::container
with three new traits. The first,NewContainer
allows someone to generically create of a certain size. The second isSeq
, which is a placeholder for generic immutable sequence methods, but it's currently empty. The third,MutableSeq
, is where mutable functions like.push()
/.pop()
and etc can be placed. For the moment onlyvec
implements MutableSeq.It also includes some minor cleanup, like standardizing some comment doc styles, and adding a
.clone_iter()
to vecs so we can changevec.push_all
into taking an iterator.