Skip to content
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

Tracking issue for Vec::resize #27790

Closed
alexcrichton opened this issue Aug 13, 2015 · 17 comments · Fixed by #29254
Closed

Tracking issue for Vec::resize #27790

alexcrichton opened this issue Aug 13, 2015 · 17 comments · Fixed by #29254
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Milestone

Comments

@alexcrichton
Copy link
Member

This is a tracking issue for the unstable vec_resize feature in the standard library. To the best of my knowledge there's no blocker for this beyond "we should decide to have it or not".

cc @gankro

@alexcrichton alexcrichton added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. B-unstable Blocker: Implemented in the nightly compiler and unstable. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Aug 13, 2015
@aturon
Copy link
Member

aturon commented Sep 23, 2015

Nominating for 1.5 FCP discussion.

@alexcrichton
Copy link
Member Author

This issue is now entering its cycle-long FCP for stabilization in 1.5

@alexcrichton alexcrichton added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed I-nominated labels Sep 24, 2015
@bluss
Copy link
Member

bluss commented Sep 24, 2015

The growing part is a "critical" component where we need to grow & zerofill a vector.

@steveklabnik steveklabnik added this to the 1.5 milestone Oct 1, 2015
@dhardy
Copy link
Contributor

dhardy commented Oct 2, 2015

As bluss said, I'd like either resize or fn ensure_size_is_at_least(&mut self, len: usize, fill: T).

The alternative is cumbersome:

let by = newlen - v.len();
v.extend(iter::repeat(0).take(by));

A constructor to create a zeroed out buffer of predefined length would also be useful (Vec::with_capacity(x) doesn't work with std::io::Read::read()).

@Manishearth Manishearth removed the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Oct 2, 2015
@FranklinChen
Copy link
Contributor

I'd like a one-stop way to do what I have to do now:

let mut a = Vec::with_capacity(k);
a.resize(k, x);

@huonw
Copy link
Member

huonw commented Oct 21, 2015

vec![x; k] should work for that.

@FranklinChen
Copy link
Contributor

@huonw D'oh, thanks! I honestly spent a long time looking for how to do that and couldn't find it. I just found it at https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html

I'm very concerned that I've been having a lot of trouble finding out this kind of information (another problem was finding slice syntax information), because it's embedded in text rather than displayed as a "method". Perhaps there should be bulleted documentation for all syntax and macros in its own section? Is it my fault I don't necessarily read whole paragraphs of text that are classified as "examples"?

@bluss
Copy link
Member

bluss commented Oct 21, 2015

@dhardy The alternative is cumbersome and for now, much less efficient, I'll point out.

@dhardy
Copy link
Contributor

dhardy commented Oct 21, 2015

@bluss thanks. I didn't realise I could create a vec with vec![x; k] but would still like resize.

@bluss
Copy link
Member

bluss commented Oct 21, 2015

I'm a bit worried by all the people that don't find vec![x; N].

@petrochenkov
Copy link
Contributor

@bluss
Can you reopen #26723 ?
It's still a problem and the motivation for closing it was unconvincing, but I forgot about it at the time.

@steveklabnik
Copy link
Member

Yeah, discovery is hard :/

@alexcrichton
Copy link
Member Author

The libs team discussed this today and the decision was to stabilize.

@bluss
Copy link
Member

bluss commented Oct 22, 2015

No comment on the dual role of growing and shrinking? Why have both? Only the grow part seems useful (and only the grow part is unique to this method).

@Gankra
Copy link
Contributor

Gankra commented Oct 22, 2015

@bluss the dual role was frequently requested. I was personally happy when we just had truncate and whatever the growing version was. shrug

@bluss
Copy link
Member

bluss commented Oct 22, 2015

I see.

@Gankra
Copy link
Contributor

Gankra commented Oct 23, 2015

fwiw this was accepted in collections reform part 2.

See e.g. rust-lang/rfcs#509 (comment) for discussion

alexcrichton added a commit to alexcrichton/rust that referenced this issue Oct 25, 2015
This commit stabilizes and deprecates library APIs whose FCP has closed in the
last cycle, specifically:

Stabilized APIs:

* `fs::canonicalize`
* `Path::{metadata, symlink_metadata, canonicalize, read_link, read_dir, exists,
   is_file, is_dir}` - all moved to inherent methods from the `PathExt` trait.
* `Formatter::fill`
* `Formatter::width`
* `Formatter::precision`
* `Formatter::sign_plus`
* `Formatter::sign_minus`
* `Formatter::alternate`
* `Formatter::sign_aware_zero_pad`
* `string::ParseError`
* `Utf8Error::valid_up_to`
* `Iterator::{cmp, partial_cmp, eq, ne, lt, le, gt, ge}`
* `<[T]>::split_{first,last}{,_mut}`
* `Condvar::wait_timeout` - note that `wait_timeout_ms` is not yet deprecated
  but will be once 1.5 is released.
* `str::{R,}MatchIndices`
* `str::{r,}match_indices`
* `char::from_u32_unchecked`
* `VecDeque::insert`
* `VecDeque::shrink_to_fit`
* `VecDeque::as_slices`
* `VecDeque::as_mut_slices`
* `VecDeque::swap_remove_front` - (renamed from `swap_front_remove`)
* `VecDeque::swap_remove_back` - (renamed from `swap_back_remove`)
* `Vec::resize`
* `str::slice_mut_unchecked`
* `FileTypeExt`
* `FileTypeExt::{is_block_device, is_char_device, is_fifo, is_socket}`
* `BinaryHeap::from` - `from_vec` deprecated in favor of this
* `BinaryHeap::into_vec` - plus a `Into` impl
* `BinaryHeap::into_sorted_vec`

Deprecated APIs

* `slice::ref_slice`
* `slice::mut_ref_slice`
* `iter::{range_inclusive, RangeInclusive}`
* `std::dynamic_lib`

Closes rust-lang#27706
Closes rust-lang#27725
cc rust-lang#27726 (align not stabilized yet)
Closes rust-lang#27734
Closes rust-lang#27737
Closes rust-lang#27742
Closes rust-lang#27743
Closes rust-lang#27772
Closes rust-lang#27774
Closes rust-lang#27777
Closes rust-lang#27781
cc rust-lang#27788 (a few remaining methods though)
Closes rust-lang#27790
Closes rust-lang#27793
Closes rust-lang#27796
Closes rust-lang#27810
cc rust-lang#28147 (not all parts stabilized)
bors added a commit that referenced this issue Oct 25, 2015
This commit stabilizes and deprecates library APIs whose FCP has closed in the
last cycle, specifically:

Stabilized APIs:

* `fs::canonicalize`
* `Path::{metadata, symlink_metadata, canonicalize, read_link, read_dir, exists,
   is_file, is_dir}` - all moved to inherent methods from the `PathExt` trait.
* `Formatter::fill`
* `Formatter::width`
* `Formatter::precision`
* `Formatter::sign_plus`
* `Formatter::sign_minus`
* `Formatter::alternate`
* `Formatter::sign_aware_zero_pad`
* `string::ParseError`
* `Utf8Error::valid_up_to`
* `Iterator::{cmp, partial_cmp, eq, ne, lt, le, gt, ge}`
* `<[T]>::split_{first,last}{,_mut}`
* `Condvar::wait_timeout` - note that `wait_timeout_ms` is not yet deprecated
  but will be once 1.5 is released.
* `str::{R,}MatchIndices`
* `str::{r,}match_indices`
* `char::from_u32_unchecked`
* `VecDeque::insert`
* `VecDeque::shrink_to_fit`
* `VecDeque::as_slices`
* `VecDeque::as_mut_slices`
* `VecDeque::swap_remove_front` - (renamed from `swap_front_remove`)
* `VecDeque::swap_remove_back` - (renamed from `swap_back_remove`)
* `Vec::resize`
* `str::slice_mut_unchecked`
* `FileTypeExt`
* `FileTypeExt::{is_block_device, is_char_device, is_fifo, is_socket}`
* `BinaryHeap::from` - `from_vec` deprecated in favor of this
* `BinaryHeap::into_vec` - plus a `Into` impl
* `BinaryHeap::into_sorted_vec`

Deprecated APIs

* `slice::ref_slice`
* `slice::mut_ref_slice`
* `iter::{range_inclusive, RangeInclusive}`
* `std::dynamic_lib`

Closes #27706
Closes #27725
cc #27726 (align not stabilized yet)
Closes #27734
Closes #27737
Closes #27742
Closes #27743
Closes #27772
Closes #27774
Closes #27777
Closes #27781
cc #27788 (a few remaining methods though)
Closes #27790
Closes #27793
Closes #27796
Closes #27810
cc #28147 (not all parts stabilized)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants