-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
With try_reserve(_exact) stabilized, the following pattern is going to start cropping up (it already does in our internal code base):
let mut buf = Vec::new();
buf.try_reserve_exact(cap)?;Would adding one or two extra methods per container; try_with_capacity(capacity: usize) -> Result<.., TryReserveError> and try_with_capacity_in(capacity: usize, alloc: A) -> Result<.., TryReserveError> be appropriate ?
Note that the two-liner above works perfectly to the best of my knowledge, it is just a question of conciseness. I also find it makes intent clearer from the start, but other may have diverging opinions on this.
Affected types would be:
try_with_capacity_in(capacity: usize, alloc: A) -> Result<.., TryReserveError>(see all types):std::collections::VecDequestd::vec::Vec
try_with_capacity(capacity: usize) -> Result<.., TryReserveError>(see all types):std::collections::BinaryHeapstd::collections::VecDequestd::collections::hash_map::HashMapstd::collections::hash_set::HashSetstd::ffi::OsStringstd::io::BufReaderstd::io::BufWriterstd::io::LineWriterstd::path::PathBufstd::string::Stringstd::vec::Vec
@rustbot label T-libs C-feature-request T-libs-api
Aside: I'm not sure if this falls under A-allocators
paolobarbolini, Patrick-Poitras, bobbbay, Xuanwo, kornelski and 5 moremo271
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.