-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add doc aliases for memory allocations #79233
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -433,6 +433,7 @@ impl<T> Vec<T> { | |
/// assert!(vec.capacity() >= 11); | ||
/// ``` | ||
#[inline] | ||
#[doc(alias = "malloc")] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub fn with_capacity(capacity: usize) -> Self { | ||
Self::with_capacity_in(capacity, Global) | ||
|
@@ -766,6 +767,7 @@ impl<T, A: Allocator> Vec<T, A> { | |
/// vec.reserve(10); | ||
/// assert!(vec.capacity() >= 11); | ||
/// ``` | ||
#[doc(alias = "realloc")] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub fn reserve(&mut self, additional: usize) { | ||
self.buf.reserve(self.len, additional); | ||
|
@@ -791,6 +793,7 @@ impl<T, A: Allocator> Vec<T, A> { | |
/// vec.reserve_exact(10); | ||
/// assert!(vec.capacity() >= 11); | ||
/// ``` | ||
#[doc(alias = "realloc")] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub fn reserve_exact(&mut self, additional: usize) { | ||
self.buf.reserve_exact(self.len, additional); | ||
|
@@ -828,6 +831,7 @@ impl<T, A: Allocator> Vec<T, A> { | |
/// } | ||
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?"); | ||
/// ``` | ||
#[doc(alias = "realloc")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rust has no canonical "realloc" function; instead it's split up between various different methods which perform specific kinds of reallocations. Someone searching for "realloc" may not be aware of this, and sharing the various ways in which vectors can be reallocated may be helpful. Conversely an experienced Rust programmer may not recall the exact name of a specific reallocation they're trying to perform (or may want to validate whether a vec method indeed reallocates) and searching for "realloc" may provide them with an answer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine by me, let's give it a try like this then! |
||
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")] | ||
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> { | ||
self.buf.try_reserve(self.len, additional) | ||
|
@@ -869,6 +873,7 @@ impl<T, A: Allocator> Vec<T, A> { | |
/// } | ||
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?"); | ||
/// ``` | ||
#[doc(alias = "realloc")] | ||
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")] | ||
pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> { | ||
self.buf.try_reserve_exact(self.len, additional) | ||
|
@@ -888,6 +893,7 @@ impl<T, A: Allocator> Vec<T, A> { | |
/// vec.shrink_to_fit(); | ||
/// assert!(vec.capacity() >= 3); | ||
/// ``` | ||
#[doc(alias = "realloc")] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub fn shrink_to_fit(&mut self) { | ||
// The capacity is never less than the length, and there's nothing to do when | ||
|
@@ -920,6 +926,7 @@ impl<T, A: Allocator> Vec<T, A> { | |
/// vec.shrink_to(0); | ||
/// assert!(vec.capacity() >= 3); | ||
/// ``` | ||
#[doc(alias = "realloc")] | ||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")] | ||
pub fn shrink_to(&mut self, min_capacity: usize) { | ||
self.buf.shrink_to_fit(cmp::max(self.len, min_capacity)); | ||
|
Uh oh!
There was an error while loading. Please reload this page.