Add doc aliases for memory allocations
- Vec::with_capacity / Box::new -> alloc + malloc - Box::new_zeroed -> calloc - Vec::{reserve,reserve_exact,try_reserve_exact,shrink_to_fit,shrink_to} -> realloc
This commit is contained in:
parent
bbc01bb624
commit
7d102383f9
@ -178,8 +178,10 @@ impl<T> Box<T> {
|
||||
/// ```
|
||||
/// let five = Box::new(5);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline(always)]
|
||||
#[doc(alias = "alloc")]
|
||||
#[doc(alias = "malloc")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn new(x: T) -> Self {
|
||||
box x
|
||||
}
|
||||
@ -226,8 +228,9 @@ pub fn new_uninit() -> Box<mem::MaybeUninit<T>> {
|
||||
/// ```
|
||||
///
|
||||
/// [zeroed]: mem::MaybeUninit::zeroed
|
||||
#[unstable(feature = "new_uninit", issue = "63291")]
|
||||
#[inline]
|
||||
#[doc(alias = "calloc")]
|
||||
#[unstable(feature = "new_uninit", issue = "63291")]
|
||||
pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {
|
||||
Self::new_zeroed_in(Global)
|
||||
}
|
||||
|
@ -35,6 +35,8 @@
|
||||
///
|
||||
/// [`Vec`]: crate::vec::Vec
|
||||
#[cfg(not(test))]
|
||||
#[doc(alias = "alloc")]
|
||||
#[doc(alias = "malloc")]
|
||||
#[macro_export]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow_internal_unstable(box_syntax, liballoc_internals)]
|
||||
|
@ -403,6 +403,8 @@ pub const fn new() -> String {
|
||||
/// s.push('a');
|
||||
/// ```
|
||||
#[inline]
|
||||
#[doc(alias = "alloc")]
|
||||
#[doc(alias = "malloc")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn with_capacity(capacity: usize) -> String {
|
||||
String { vec: Vec::with_capacity(capacity) }
|
||||
|
@ -433,6 +433,7 @@ pub const fn new() -> Self {
|
||||
/// 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 @@ pub fn capacity(&self) -> usize {
|
||||
/// 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 @@ pub fn reserve(&mut self, additional: usize) {
|
||||
/// 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 @@ pub fn reserve_exact(&mut self, additional: usize) {
|
||||
/// }
|
||||
/// # 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(&mut self, additional: usize) -> Result<(), TryReserveError> {
|
||||
self.buf.try_reserve(self.len, additional)
|
||||
@ -869,6 +873,7 @@ pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
|
||||
/// }
|
||||
/// # 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 @@ pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveE
|
||||
/// 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 @@ pub fn shrink_to_fit(&mut self) {
|
||||
/// 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));
|
||||
|
Loading…
Reference in New Issue
Block a user