Skip to content

Implement resize for Vec #20044

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

Merged
merged 1 commit into from
Dec 22, 2014
Merged

Implement resize for Vec #20044

merged 1 commit into from
Dec 22, 2014

Conversation

csouth3
Copy link
Contributor

@csouth3 csouth3 commented Dec 19, 2014

This PR adds resize() to Vec in accordance with RFC 509.

@rust-highfive
Copy link
Contributor

r? @huonw

(rust_highfive has picked a reviewer for you, use r? to override)

@csouth3
Copy link
Contributor Author

csouth3 commented Dec 19, 2014

r? @gankro

@rust-highfive rust-highfive assigned Gankra and unassigned huonw Dec 19, 2014
let len = self.len();

if new_len > len {
self.grow(new_len - len, value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is about to be deprecated, this should be changed to an extend using repeat.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my brain is apparently just turned completely off right now...doesn't repeat yield the same value endlessly? How would you limit extend to only add the proper number of elements?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full expression is self.extend(repeat(value).take(new_len - len))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and there is the missing piece. How I forgot that take was a thing is beyond me -_-
I guess when in doubt, just check IteratorExt :P

This commit adds `resize` to `Vec` in accordance with RFC 509.
@csouth3
Copy link
Contributor Author

csouth3 commented Dec 19, 2014

@gankro Updated.

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Dec 21, 2014
This PR adds `resize()` to `Vec` in accordance with RFC 509.
@bors bors merged commit d61db0c into rust-lang:master Dec 22, 2014
@csouth3 csouth3 deleted the vec-resize branch December 22, 2014 03:03
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.

5 participants