Skip to content

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

Closed
wants to merge 8 commits into from

Conversation

erickt
Copy link
Contributor

@erickt erickt commented Dec 15, 2013

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 is Seq, 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 only vec implements MutableSeq.

It also includes some minor cleanup, like standardizing some comment doc styles, and adding a .clone_iter() to vecs so we can change vec.push_all into taking an iterator.

@liigo
Copy link
Contributor

liigo commented Dec 16, 2013

Good work

@erickt
Copy link
Contributor Author

erickt commented Dec 17, 2013

@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 MutableSeq trait. I could make it even simpler if we had a NewContainer trait that allowed us to generically construct a container.

@erickt
Copy link
Contributor Author

erickt commented Dec 17, 2013

@alexcrichton: .extend() would work, so maybe MutableSeq should inherit from that trait and get rid of .push_all. There is also the open question of what should we should be naming these methods anyway (see #10852).

@alexcrichton
Copy link
Member

Interesting! I wonder if it would make more sense to define this NewContainer trait in the serialization library instead of the standard library though? Just a thought, certainly a cool application!

bors added a commit that referenced this pull request Dec 28, 2013
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.
@alexcrichton
Copy link
Member

Closing due to inactivity, but feel free to reopen with a rebase!

bors pushed a commit to rust-lang-ci/rust that referenced this pull request Jun 5, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 5, 2023
… 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
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 30, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants