Rollup merge of #75725 - LeSeulArtichaut:alloc-intra-doc, r=jyn514
Use intra-doc-links in `alloc` I didn't have time to test this, so I will let the CI do it for me. r? @jyn514 cc #75080
This commit is contained in:
commit
ec629800ec
@ -36,8 +36,6 @@ extern "Rust" {
|
||||
///
|
||||
/// Note: while this type is unstable, the functionality it provides can be
|
||||
/// accessed through the [free functions in `alloc`](index.html#functions).
|
||||
///
|
||||
/// [`AllocRef`]: trait.AllocRef.html
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
#[derive(Copy, Clone, Default, Debug)]
|
||||
pub struct Global;
|
||||
@ -55,10 +53,6 @@ pub struct Global;
|
||||
///
|
||||
/// See [`GlobalAlloc::alloc`].
|
||||
///
|
||||
/// [`Global`]: struct.Global.html
|
||||
/// [`AllocRef`]: trait.AllocRef.html
|
||||
/// [`GlobalAlloc::alloc`]: trait.GlobalAlloc.html#tymethod.alloc
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@ -92,10 +86,6 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
|
||||
/// # Safety
|
||||
///
|
||||
/// See [`GlobalAlloc::dealloc`].
|
||||
///
|
||||
/// [`Global`]: struct.Global.html
|
||||
/// [`AllocRef`]: trait.AllocRef.html
|
||||
/// [`GlobalAlloc::dealloc`]: trait.GlobalAlloc.html#tymethod.dealloc
|
||||
#[stable(feature = "global_alloc", since = "1.28.0")]
|
||||
#[inline]
|
||||
pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
|
||||
@ -114,10 +104,6 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
|
||||
/// # Safety
|
||||
///
|
||||
/// See [`GlobalAlloc::realloc`].
|
||||
///
|
||||
/// [`Global`]: struct.Global.html
|
||||
/// [`AllocRef`]: trait.AllocRef.html
|
||||
/// [`GlobalAlloc::realloc`]: trait.GlobalAlloc.html#method.realloc
|
||||
#[stable(feature = "global_alloc", since = "1.28.0")]
|
||||
#[inline]
|
||||
pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
|
||||
@ -137,10 +123,6 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
|
||||
///
|
||||
/// See [`GlobalAlloc::alloc_zeroed`].
|
||||
///
|
||||
/// [`Global`]: struct.Global.html
|
||||
/// [`AllocRef`]: trait.AllocRef.html
|
||||
/// [`GlobalAlloc::alloc_zeroed`]: trait.GlobalAlloc.html#method.alloc_zeroed
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
|
@ -118,14 +118,13 @@
|
||||
//! described in [rust-lang/unsafe-code-guidelines#198][ucg#198].
|
||||
//!
|
||||
//! [ucg#198]: https://github.com/rust-lang/unsafe-code-guidelines/issues/198
|
||||
//! [dereferencing]: ../../std/ops/trait.Deref.html
|
||||
//! [`Box`]: struct.Box.html
|
||||
//! [`Box<T>`]: struct.Box.html
|
||||
//! [`Box::<T>::from_raw(value)`]: struct.Box.html#method.from_raw
|
||||
//! [`Box::<T>::into_raw`]: struct.Box.html#method.into_raw
|
||||
//! [`Global`]: ../alloc/struct.Global.html
|
||||
//! [`Layout`]: ../alloc/struct.Layout.html
|
||||
//! [`Layout::for_value(&*value)`]: ../alloc/struct.Layout.html#method.for_value
|
||||
//! [dereferencing]: core::ops::Deref
|
||||
//! [`Box<T>`]: Box
|
||||
//! [`Box::<T>::from_raw(value)`]: Box::from_raw
|
||||
//! [`Box::<T>::into_raw`]: Box::into_raw
|
||||
//! [`Global`]: crate::alloc::Global
|
||||
//! [`Layout`]: crate::alloc::Layout
|
||||
//! [`Layout::for_value(&*value)`]: crate::alloc::Layout::for_value
|
||||
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
@ -240,7 +239,6 @@ impl<T> Box<T> {
|
||||
/// Converts a `Box<T>` into a `Box<[T]>`
|
||||
///
|
||||
/// This conversion does not allocate on the heap and happens in place.
|
||||
///
|
||||
#[unstable(feature = "box_into_boxed_slice", issue = "71582")]
|
||||
pub fn into_boxed_slice(boxed: Box<T>) -> Box<[T]> {
|
||||
// *mut T and *mut [T; 1] have the same size and alignment
|
||||
@ -386,9 +384,8 @@ impl<T: ?Sized> Box<T> {
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// [memory layout]: index.html#memory-layout
|
||||
/// [`Layout`]: ../alloc/struct.Layout.html
|
||||
/// [`Box::into_raw`]: struct.Box.html#method.into_raw
|
||||
/// [memory layout]: self#memory-layout
|
||||
/// [`Layout`]: crate::Layout
|
||||
#[stable(feature = "box_raw", since = "1.4.0")]
|
||||
#[inline]
|
||||
pub unsafe fn from_raw(raw: *mut T) -> Self {
|
||||
@ -433,8 +430,7 @@ impl<T: ?Sized> Box<T> {
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// [memory layout]: index.html#memory-layout
|
||||
/// [`Box::from_raw`]: struct.Box.html#method.from_raw
|
||||
/// [memory layout]: self#memory-layout
|
||||
#[stable(feature = "box_raw", since = "1.4.0")]
|
||||
#[inline]
|
||||
pub fn into_raw(b: Box<T>) -> *mut T {
|
||||
@ -478,8 +474,6 @@ impl<T: ?Sized> Box<T> {
|
||||
/// to call it as `Box::leak(b)` instead of `b.leak()`. This
|
||||
/// is so that there is no conflict with a method on the inner type.
|
||||
///
|
||||
/// [`Box::from_raw`]: struct.Box.html#method.from_raw
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Simple usage:
|
||||
|
@ -7,8 +7,8 @@
|
||||
//! array-based containers are generally faster,
|
||||
//! more memory efficient, and make better use of CPU cache.
|
||||
//!
|
||||
//! [`Vec`]: ../../vec/struct.Vec.html
|
||||
//! [`VecDeque`]: ../vec_deque/struct.VecDeque.html
|
||||
//! [`Vec`]: crate::vec::Vec
|
||||
//! [`VecDeque`]: super::vec_deque::VecDeque
|
||||
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
@ -50,11 +50,8 @@ struct Node<T> {
|
||||
|
||||
/// An iterator over the elements of a `LinkedList`.
|
||||
///
|
||||
/// This `struct` is created by the [`iter`] method on [`LinkedList`]. See its
|
||||
/// This `struct` is created by [`LinkedList::iter()`]. See its
|
||||
/// documentation for more.
|
||||
///
|
||||
/// [`iter`]: struct.LinkedList.html#method.iter
|
||||
/// [`LinkedList`]: struct.LinkedList.html
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Iter<'a, T: 'a> {
|
||||
head: Option<NonNull<Node<T>>>,
|
||||
@ -80,11 +77,8 @@ impl<T> Clone for Iter<'_, T> {
|
||||
|
||||
/// A mutable iterator over the elements of a `LinkedList`.
|
||||
///
|
||||
/// This `struct` is created by the [`iter_mut`] method on [`LinkedList`]. See its
|
||||
/// This `struct` is created by [`LinkedList::iter_mut()`]. See its
|
||||
/// documentation for more.
|
||||
///
|
||||
/// [`iter_mut`]: struct.LinkedList.html#method.iter_mut
|
||||
/// [`LinkedList`]: struct.LinkedList.html
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct IterMut<'a, T: 'a> {
|
||||
// We do *not* exclusively own the entire list here, references to node's `element`
|
||||
@ -109,7 +103,6 @@ impl<T: fmt::Debug> fmt::Debug for IterMut<'_, T> {
|
||||
/// (provided by the `IntoIterator` trait). See its documentation for more.
|
||||
///
|
||||
/// [`into_iter`]: struct.LinkedList.html#method.into_iter
|
||||
/// [`LinkedList`]: struct.LinkedList.html
|
||||
#[derive(Clone)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct IntoIter<T> {
|
||||
|
@ -501,31 +501,23 @@
|
||||
//! it would internally pass around this structure until it has been determined
|
||||
//! where output should go to.
|
||||
//!
|
||||
//! [`usize`]: ../../std/primitive.usize.html
|
||||
//! [`isize`]: ../../std/primitive.isize.html
|
||||
//! [`i8`]: ../../std/primitive.i8.html
|
||||
//! [`Display`]: trait.Display.html
|
||||
//! [`Binary`]: trait.Binary.html
|
||||
//! [`fmt::Result`]: type.Result.html
|
||||
//! [`Result`]: ../../std/result/enum.Result.html
|
||||
//! [`std::fmt::Error`]: struct.Error.html
|
||||
//! [`Formatter`]: struct.Formatter.html
|
||||
//! [`write!`]: ../../std/macro.write.html
|
||||
//! [`Debug`]: trait.Debug.html
|
||||
//! [`format!`]: ../../std/macro.format.html
|
||||
//! [`to_string`]: ../../std/string/trait.ToString.html
|
||||
//! [`writeln!`]: ../../std/macro.writeln.html
|
||||
//! [`fmt::Result`]: Result
|
||||
//! [`Result`]: core::result::Result
|
||||
//! [`std::fmt::Error`]: Error
|
||||
//! [`write!`]: core::write
|
||||
//! [`write`]: core::write
|
||||
//! [`format!`]: crate::format
|
||||
//! [`to_string`]: crate::string::ToString
|
||||
//! [`writeln!`]: core::writeln
|
||||
//! [`write_fmt`]: ../../std/io/trait.Write.html#method.write_fmt
|
||||
//! [`std::io::Write`]: ../../std/io/trait.Write.html
|
||||
//! [`print!`]: ../../std/macro.print.html
|
||||
//! [`println!`]: ../../std/macro.println.html
|
||||
//! [`eprint!`]: ../../std/macro.eprint.html
|
||||
//! [`eprintln!`]: ../../std/macro.eprintln.html
|
||||
//! [`write!`]: ../../std/macro.write.html
|
||||
//! [`format_args!`]: ../../std/macro.format_args.html
|
||||
//! [`fmt::Arguments`]: struct.Arguments.html
|
||||
//! [`write`]: fn.write.html
|
||||
//! [`format`]: fn.format.html
|
||||
//! [`format_args!`]: core::format_args
|
||||
//! [`fmt::Arguments`]: Arguments
|
||||
//! [`format`]: crate::format
|
||||
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
@ -576,9 +568,8 @@ use crate::string;
|
||||
/// assert_eq!(s, "Hello, world!");
|
||||
/// ```
|
||||
///
|
||||
/// [`Arguments`]: struct.Arguments.html
|
||||
/// [`format_args!`]: ../../std/macro.format_args.html
|
||||
/// [`format!`]: ../../std/macro.format.html
|
||||
/// [`format_args!`]: core::format_args
|
||||
/// [`format!`]: crate::format
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn format(args: Arguments<'_>) -> string::String {
|
||||
let capacity = args.estimated_capacity();
|
||||
|
@ -50,11 +50,11 @@
|
||||
//! The [`alloc`](alloc/index.html) module defines the low-level interface to the
|
||||
//! default global allocator. It is not compatible with the libc allocator API.
|
||||
//!
|
||||
//! [`Arc`]: sync/index.html
|
||||
//! [`Box`]: boxed/index.html
|
||||
//! [`Cell`]: ../core/cell/index.html
|
||||
//! [`Rc`]: rc/index.html
|
||||
//! [`RefCell`]: ../core/cell/index.html
|
||||
//! [`Arc`]: sync
|
||||
//! [`Box`]: boxed
|
||||
//! [`Cell`]: core::cell
|
||||
//! [`Rc`]: rc
|
||||
//! [`RefCell`]: core::cell
|
||||
|
||||
#![allow(unused_attributes)]
|
||||
#![stable(feature = "alloc", since = "1.36.0")]
|
||||
|
@ -29,8 +29,7 @@
|
||||
/// to the same boxed integer value, not five references pointing to independently
|
||||
/// boxed integers.
|
||||
///
|
||||
/// [`Vec`]: ../std/vec/struct.Vec.html
|
||||
/// [`Clone`]: ../std/clone/trait.Clone.html
|
||||
/// [`Vec`]: crate::vec::Vec
|
||||
#[cfg(not(test))]
|
||||
#[macro_export]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -81,11 +80,11 @@ macro_rules! vec {
|
||||
/// To convert a single value to a string, use the [`to_string`] method. This
|
||||
/// will use the [`Display`] formatting trait.
|
||||
///
|
||||
/// [fmt]: ../std/fmt/index.html
|
||||
/// [fmt]: core::fmt
|
||||
/// [`print!`]: ../std/macro.print.html
|
||||
/// [`write!`]: ../std/macro.write.html
|
||||
/// [`to_string`]: ../std/string/trait.ToString.html
|
||||
/// [`Display`]: ../std/fmt/trait.Display.html
|
||||
/// [`write!`]: core::write
|
||||
/// [`to_string`]: crate::string::ToString
|
||||
/// [`Display`]: core::fmt::Display
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
|
@ -214,18 +214,15 @@
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! [`Rc`]: struct.Rc.html
|
||||
//! [`Weak`]: struct.Weak.html
|
||||
//! [clone]: ../../std/clone/trait.Clone.html#tymethod.clone
|
||||
//! [`Cell`]: ../../std/cell/struct.Cell.html
|
||||
//! [`RefCell`]: ../../std/cell/struct.RefCell.html
|
||||
//! [send]: ../../std/marker/trait.Send.html
|
||||
//! [clone]: Clone::clone
|
||||
//! [`Cell`]: core::cell::Cell
|
||||
//! [`RefCell`]: core::cell::RefCell
|
||||
//! [send]: core::marker::Send
|
||||
//! [arc]: ../../std/sync/struct.Arc.html
|
||||
//! [`Deref`]: ../../std/ops/trait.Deref.html
|
||||
//! [downgrade]: struct.Rc.html#method.downgrade
|
||||
//! [upgrade]: struct.Weak.html#method.upgrade
|
||||
//! [`None`]: ../../std/option/enum.Option.html#variant.None
|
||||
//! [mutability]: ../../std/cell/index.html#introducing-mutability-inside-of-something-immutable
|
||||
//! [`Deref`]: core::ops::Deref
|
||||
//! [downgrade]: Rc::downgrade
|
||||
//! [upgrade]: Weak::upgrade
|
||||
//! [mutability]: core::cell#introducing-mutability-inside-of-something-immutable
|
||||
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
@ -396,13 +393,11 @@ impl<T> Rc<T> {
|
||||
|
||||
/// Returns the inner value, if the `Rc` has exactly one strong reference.
|
||||
///
|
||||
/// Otherwise, an [`Err`][result] is returned with the same `Rc` that was
|
||||
/// Otherwise, an [`Err`] is returned with the same `Rc` that was
|
||||
/// passed in.
|
||||
///
|
||||
/// This will succeed even if there are outstanding weak references.
|
||||
///
|
||||
/// [result]: ../../std/result/enum.Result.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@ -553,7 +548,7 @@ impl<T: ?Sized> Rc<T> {
|
||||
/// To avoid a memory leak the pointer must be converted back to an `Rc` using
|
||||
/// [`Rc::from_raw`][from_raw].
|
||||
///
|
||||
/// [from_raw]: struct.Rc.html#method.from_raw
|
||||
/// [from_raw]: Rc::from_raw
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -613,8 +608,8 @@ impl<T: ?Sized> Rc<T> {
|
||||
/// This function is unsafe because improper use may lead to memory unsafety,
|
||||
/// even if the returned `Rc<T>` is never accessed.
|
||||
///
|
||||
/// [into_raw]: struct.Rc.html#method.into_raw
|
||||
/// [transmute]: ../../std/mem/fn.transmute.html
|
||||
/// [into_raw]: Rc::into_raw
|
||||
/// [transmute]: core::mem::transmute
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -645,9 +640,7 @@ impl<T: ?Sized> Rc<T> {
|
||||
unsafe { Self::from_ptr(rc_ptr) }
|
||||
}
|
||||
|
||||
/// Creates a new [`Weak`][weak] pointer to this allocation.
|
||||
///
|
||||
/// [weak]: struct.Weak.html
|
||||
/// Creates a new [`Weak`] pointer to this allocation.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -666,9 +659,7 @@ impl<T: ?Sized> Rc<T> {
|
||||
Weak { ptr: this.ptr }
|
||||
}
|
||||
|
||||
/// Gets the number of [`Weak`][weak] pointers to this allocation.
|
||||
///
|
||||
/// [weak]: struct.Weak.html
|
||||
/// Gets the number of [`Weak`] pointers to this allocation.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -704,17 +695,15 @@ impl<T: ?Sized> Rc<T> {
|
||||
this.strong()
|
||||
}
|
||||
|
||||
/// Returns `true` if there are no other `Rc` or [`Weak`][weak] pointers to
|
||||
/// Returns `true` if there are no other `Rc` or [`Weak`] pointers to
|
||||
/// this allocation.
|
||||
///
|
||||
/// [weak]: struct.Weak.html
|
||||
#[inline]
|
||||
fn is_unique(this: &Self) -> bool {
|
||||
Rc::weak_count(this) == 0 && Rc::strong_count(this) == 1
|
||||
}
|
||||
|
||||
/// Returns a mutable reference into the given `Rc`, if there are
|
||||
/// no other `Rc` or [`Weak`][weak] pointers to the same allocation.
|
||||
/// no other `Rc` or [`Weak`] pointers to the same allocation.
|
||||
///
|
||||
/// Returns [`None`] otherwise, because it is not safe to
|
||||
/// mutate a shared value.
|
||||
@ -722,10 +711,8 @@ impl<T: ?Sized> Rc<T> {
|
||||
/// See also [`make_mut`][make_mut], which will [`clone`][clone]
|
||||
/// the inner value when there are other pointers.
|
||||
///
|
||||
/// [weak]: struct.Weak.html
|
||||
/// [`None`]: ../../std/option/enum.Option.html#variant.None
|
||||
/// [make_mut]: struct.Rc.html#method.make_mut
|
||||
/// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone
|
||||
/// [make_mut]: Rc::make_mut
|
||||
/// [clone]: Clone::clone
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -750,7 +737,7 @@ impl<T: ?Sized> Rc<T> {
|
||||
///
|
||||
/// See also [`get_mut`], which is safe and does appropriate checks.
|
||||
///
|
||||
/// [`get_mut`]: struct.Rc.html#method.get_mut
|
||||
/// [`get_mut`]: Rc::get_mut
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
@ -796,7 +783,7 @@ impl<T: ?Sized> Rc<T> {
|
||||
/// assert!(!Rc::ptr_eq(&five, &other_five));
|
||||
/// ```
|
||||
///
|
||||
/// [`ptr::eq`]: ../../std/ptr/fn.eq.html
|
||||
/// [`ptr::eq`]: core::ptr::eq
|
||||
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
|
||||
this.ptr.as_ptr() == other.ptr.as_ptr()
|
||||
}
|
||||
@ -814,9 +801,8 @@ impl<T: Clone> Rc<T> {
|
||||
///
|
||||
/// See also [`get_mut`], which will fail rather than cloning.
|
||||
///
|
||||
/// [`Weak`]: struct.Weak.html
|
||||
/// [`clone`]: ../../std/clone/trait.Clone.html#tymethod.clone
|
||||
/// [`get_mut`]: struct.Rc.html#method.get_mut
|
||||
/// [`clone`]: Clone::clone
|
||||
/// [`get_mut`]: Rc::get_mut
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -1117,8 +1103,6 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc<T> {
|
||||
/// drop(foo); // Doesn't print anything
|
||||
/// drop(foo2); // Prints "dropped!"
|
||||
/// ```
|
||||
///
|
||||
/// [`Weak`]: ../../std/rc/struct.Weak.html
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
self.dec_strong();
|
||||
@ -1600,11 +1584,7 @@ impl<T, I: iter::TrustedLen<Item = T>> ToRcSlice<T> for I {
|
||||
///
|
||||
/// The typical way to obtain a `Weak` pointer is to call [`Rc::downgrade`].
|
||||
///
|
||||
/// [`Rc`]: struct.Rc.html
|
||||
/// [`Rc::downgrade`]: struct.Rc.html#method.downgrade
|
||||
/// [`upgrade`]: struct.Weak.html#method.upgrade
|
||||
/// [`Option`]: ../../std/option/enum.Option.html
|
||||
/// [`None`]: ../../std/option/enum.Option.html#variant.None
|
||||
/// [`upgrade`]: Weak::upgrade
|
||||
#[stable(feature = "rc_weak", since = "1.4.0")]
|
||||
pub struct Weak<T: ?Sized> {
|
||||
// This is a `NonNull` to allow optimizing the size of this type in enums,
|
||||
@ -1631,8 +1611,7 @@ impl<T> Weak<T> {
|
||||
/// Constructs a new `Weak<T>`, without allocating any memory.
|
||||
/// Calling [`upgrade`] on the return value always gives [`None`].
|
||||
///
|
||||
/// [`upgrade`]: #method.upgrade
|
||||
/// [`None`]: ../../std/option/enum.Option.html
|
||||
/// [`upgrade`]: Weak::upgrade
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -1671,7 +1650,7 @@ impl<T> Weak<T> {
|
||||
/// // assert_eq!("hello", unsafe { &*weak.as_ptr() });
|
||||
/// ```
|
||||
///
|
||||
/// [`null`]: ../../std/ptr/fn.null.html
|
||||
/// [`null`]: core::ptr::null
|
||||
#[stable(feature = "rc_as_ptr", since = "1.45.0")]
|
||||
pub fn as_ptr(&self) -> *const T {
|
||||
let ptr: *mut RcBox<T> = NonNull::as_ptr(self.ptr);
|
||||
@ -1713,8 +1692,8 @@ impl<T> Weak<T> {
|
||||
/// assert_eq!(0, Rc::weak_count(&strong));
|
||||
/// ```
|
||||
///
|
||||
/// [`from_raw`]: struct.Weak.html#method.from_raw
|
||||
/// [`as_ptr`]: struct.Weak.html#method.as_ptr
|
||||
/// [`from_raw`]: Weak::from_raw
|
||||
/// [`as_ptr`]: Weak::as_ptr
|
||||
#[stable(feature = "weak_into_raw", since = "1.45.0")]
|
||||
pub fn into_raw(self) -> *const T {
|
||||
let result = self.as_ptr();
|
||||
@ -1761,12 +1740,9 @@ impl<T> Weak<T> {
|
||||
/// assert!(unsafe { Weak::from_raw(raw_2) }.upgrade().is_none());
|
||||
/// ```
|
||||
///
|
||||
/// [`into_raw`]: struct.Weak.html#method.into_raw
|
||||
/// [`upgrade`]: struct.Weak.html#method.upgrade
|
||||
/// [`Rc`]: struct.Rc.html
|
||||
/// [`Weak`]: struct.Weak.html
|
||||
/// [`new`]: struct.Weak.html#method.new
|
||||
/// [`forget`]: ../../std/mem/fn.forget.html
|
||||
/// [`into_raw`]: Weak::into_raw
|
||||
/// [`upgrade`]: Weak::upgrade
|
||||
/// [`new`]: Weak::new
|
||||
#[stable(feature = "weak_into_raw", since = "1.45.0")]
|
||||
pub unsafe fn from_raw(ptr: *const T) -> Self {
|
||||
if ptr.is_null() {
|
||||
@ -1794,9 +1770,6 @@ impl<T: ?Sized> Weak<T> {
|
||||
///
|
||||
/// Returns [`None`] if the inner value has since been dropped.
|
||||
///
|
||||
/// [`Rc`]: struct.Rc.html
|
||||
/// [`None`]: ../../std/option/enum.Option.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@ -1829,8 +1802,6 @@ impl<T: ?Sized> Weak<T> {
|
||||
/// Gets the number of strong (`Rc`) pointers pointing to this allocation.
|
||||
///
|
||||
/// If `self` was created using [`Weak::new`], this will return 0.
|
||||
///
|
||||
/// [`Weak::new`]: #method.new
|
||||
#[stable(feature = "weak_counts", since = "1.41.0")]
|
||||
pub fn strong_count(&self) -> usize {
|
||||
if let Some(inner) = self.inner() { inner.strong() } else { 0 }
|
||||
@ -1899,7 +1870,7 @@ impl<T: ?Sized> Weak<T> {
|
||||
/// assert!(!first.ptr_eq(&third));
|
||||
/// ```
|
||||
///
|
||||
/// [`ptr::eq`]: ../../std/ptr/fn.eq.html
|
||||
/// [`ptr::eq`]: core::ptr::eq
|
||||
#[inline]
|
||||
#[stable(feature = "weak_ptr_eq", since = "1.39.0")]
|
||||
pub fn ptr_eq(&self, other: &Self) -> bool {
|
||||
@ -1981,8 +1952,8 @@ impl<T> Default for Weak<T> {
|
||||
/// Constructs a new `Weak<T>`, allocating memory for `T` without initializing
|
||||
/// it. Calling [`upgrade`] on the return value always gives [`None`].
|
||||
///
|
||||
/// [`None`]: ../../std/option/enum.Option.html
|
||||
/// [`upgrade`]: ../../std/rc/struct.Weak.html#method.upgrade
|
||||
/// [`None`]: Option
|
||||
/// [`upgrade`]: Weak::upgrade
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -70,11 +70,7 @@
|
||||
//! * Further methods that return iterators are [`.split`], [`.splitn`],
|
||||
//! [`.chunks`], [`.windows`] and more.
|
||||
//!
|
||||
//! [`Clone`]: ../../std/clone/trait.Clone.html
|
||||
//! [`Eq`]: ../../std/cmp/trait.Eq.html
|
||||
//! [`Ord`]: ../../std/cmp/trait.Ord.html
|
||||
//! [`Iter`]: struct.Iter.html
|
||||
//! [`Hash`]: ../../std/hash/trait.Hash.html
|
||||
//! [`Hash`]: core::hash::Hash
|
||||
//! [`.iter`]: ../../std/primitive.slice.html#method.iter
|
||||
//! [`.iter_mut`]: ../../std/primitive.slice.html#method.iter_mut
|
||||
//! [`.split`]: ../../std/primitive.slice.html#method.split
|
||||
@ -560,7 +556,7 @@ impl [u8] {
|
||||
///
|
||||
/// To uppercase the value in-place, use [`make_ascii_uppercase`].
|
||||
///
|
||||
/// [`make_ascii_uppercase`]: #method.make_ascii_uppercase
|
||||
/// [`make_ascii_uppercase`]: u8::make_ascii_uppercase
|
||||
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
|
||||
#[inline]
|
||||
pub fn to_ascii_uppercase(&self) -> Vec<u8> {
|
||||
@ -577,7 +573,7 @@ impl [u8] {
|
||||
///
|
||||
/// To lowercase the value in-place, use [`make_ascii_lowercase`].
|
||||
///
|
||||
/// [`make_ascii_lowercase`]: #method.make_ascii_lowercase
|
||||
/// [`make_ascii_lowercase`]: u8::make_ascii_lowercase
|
||||
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
|
||||
#[inline]
|
||||
pub fn to_ascii_lowercase(&self) -> Vec<u8> {
|
||||
|
@ -2,9 +2,7 @@
|
||||
|
||||
//! Thread-safe reference-counting pointers.
|
||||
//!
|
||||
//! See the [`Arc<T>`][arc] documentation for more details.
|
||||
//!
|
||||
//! [arc]: struct.Arc.html
|
||||
//! See the [`Arc<T>`][Arc] documentation for more details.
|
||||
|
||||
use core::any::Any;
|
||||
use core::borrow;
|
||||
@ -100,21 +98,21 @@ macro_rules! acquire {
|
||||
/// ## Breaking cycles with `Weak`
|
||||
///
|
||||
/// The [`downgrade`][downgrade] method can be used to create a non-owning
|
||||
/// [`Weak`][weak] pointer. A [`Weak`][weak] pointer can be [`upgrade`][upgrade]d
|
||||
/// [`Weak`] pointer. A [`Weak`] pointer can be [`upgrade`][upgrade]d
|
||||
/// to an `Arc`, but this will return [`None`] if the value stored in the allocation has
|
||||
/// already been dropped. In other words, `Weak` pointers do not keep the value
|
||||
/// inside the allocation alive; however, they *do* keep the allocation
|
||||
/// (the backing store for the value) alive.
|
||||
///
|
||||
/// A cycle between `Arc` pointers will never be deallocated. For this reason,
|
||||
/// [`Weak`][weak] is used to break cycles. For example, a tree could have
|
||||
/// strong `Arc` pointers from parent nodes to children, and [`Weak`][weak]
|
||||
/// [`Weak`] is used to break cycles. For example, a tree could have
|
||||
/// strong `Arc` pointers from parent nodes to children, and [`Weak`]
|
||||
/// pointers from children back to their parents.
|
||||
///
|
||||
/// # Cloning references
|
||||
///
|
||||
/// Creating a new reference from an existing reference counted pointer is done using the
|
||||
/// `Clone` trait implemented for [`Arc<T>`][arc] and [`Weak<T>`][weak].
|
||||
/// `Clone` trait implemented for [`Arc<T>`][Arc] and [`Weak<T>`][Weak].
|
||||
///
|
||||
/// ```
|
||||
/// use std::sync::Arc;
|
||||
@ -139,23 +137,20 @@ macro_rules! acquire {
|
||||
/// Arc::downgrade(&my_arc);
|
||||
/// ```
|
||||
///
|
||||
/// [`Weak<T>`][weak] does not auto-dereference to `T`, because the inner value may have
|
||||
/// [`Weak<T>`][Weak] does not auto-dereference to `T`, because the inner value may have
|
||||
/// already been dropped.
|
||||
///
|
||||
/// [arc]: struct.Arc.html
|
||||
/// [weak]: struct.Weak.html
|
||||
/// [`Rc<T>`]: ../../std/rc/struct.Rc.html
|
||||
/// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone
|
||||
/// [`Rc<T>`]: crate::rc::Rc
|
||||
/// [clone]: Clone::clone
|
||||
/// [mutex]: ../../std/sync/struct.Mutex.html
|
||||
/// [rwlock]: ../../std/sync/struct.RwLock.html
|
||||
/// [atomic]: ../../std/sync/atomic/index.html
|
||||
/// [`Send`]: ../../std/marker/trait.Send.html
|
||||
/// [`Sync`]: ../../std/marker/trait.Sync.html
|
||||
/// [deref]: ../../std/ops/trait.Deref.html
|
||||
/// [downgrade]: struct.Arc.html#method.downgrade
|
||||
/// [upgrade]: struct.Weak.html#method.upgrade
|
||||
/// [`None`]: ../../std/option/enum.Option.html#variant.None
|
||||
/// [`RefCell<T>`]: ../../std/cell/struct.RefCell.html
|
||||
/// [atomic]: core::sync::atomic
|
||||
/// [`Send`]: core::marker::Send
|
||||
/// [`Sync`]: core::marker::Sync
|
||||
/// [deref]: core::ops::Deref
|
||||
/// [downgrade]: Arc::downgrade
|
||||
/// [upgrade]: Weak::upgrade
|
||||
/// [`RefCell<T>`]: core::cell::RefCell
|
||||
/// [`std::sync`]: ../../std/sync/index.html
|
||||
/// [`Arc::clone(&from)`]: #method.clone
|
||||
///
|
||||
@ -184,7 +179,7 @@ macro_rules! acquire {
|
||||
///
|
||||
/// Sharing a mutable [`AtomicUsize`]:
|
||||
///
|
||||
/// [`AtomicUsize`]: ../../std/sync/atomic/struct.AtomicUsize.html
|
||||
/// [`AtomicUsize`]: core::sync::atomic::AtomicUsize
|
||||
///
|
||||
/// ```no_run
|
||||
/// use std::sync::Arc;
|
||||
@ -254,11 +249,7 @@ impl<T: ?Sized> Arc<T> {
|
||||
///
|
||||
/// The typical way to obtain a `Weak` pointer is to call [`Arc::downgrade`].
|
||||
///
|
||||
/// [`Arc`]: struct.Arc.html
|
||||
/// [`Arc::downgrade`]: struct.Arc.html#method.downgrade
|
||||
/// [`upgrade`]: struct.Weak.html#method.upgrade
|
||||
/// [`Option`]: ../../std/option/enum.Option.html
|
||||
/// [`None`]: ../../std/option/enum.Option.html#variant.None
|
||||
/// [`upgrade`]: Weak::upgrade
|
||||
#[stable(feature = "arc_weak", since = "1.4.0")]
|
||||
pub struct Weak<T: ?Sized> {
|
||||
// This is a `NonNull` to allow optimizing the size of this type in enums,
|
||||
@ -396,13 +387,11 @@ impl<T> Arc<T> {
|
||||
|
||||
/// Returns the inner value, if the `Arc` has exactly one strong reference.
|
||||
///
|
||||
/// Otherwise, an [`Err`][result] is returned with the same `Arc` that was
|
||||
/// Otherwise, an [`Err`] is returned with the same `Arc` that was
|
||||
/// passed in.
|
||||
///
|
||||
/// This will succeed even if there are outstanding weak references.
|
||||
///
|
||||
/// [result]: ../../std/result/enum.Result.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@ -550,9 +539,7 @@ impl<T: ?Sized> Arc<T> {
|
||||
/// Consumes the `Arc`, returning the wrapped pointer.
|
||||
///
|
||||
/// To avoid a memory leak the pointer must be converted back to an `Arc` using
|
||||
/// [`Arc::from_raw`][from_raw].
|
||||
///
|
||||
/// [from_raw]: struct.Arc.html#method.from_raw
|
||||
/// [`Arc::from_raw`].
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -612,8 +599,8 @@ impl<T: ?Sized> Arc<T> {
|
||||
/// This function is unsafe because improper use may lead to memory unsafety,
|
||||
/// even if the returned `Arc<T>` is never accessed.
|
||||
///
|
||||
/// [into_raw]: struct.Arc.html#method.into_raw
|
||||
/// [transmute]: ../../std/mem/fn.transmute.html
|
||||
/// [into_raw]: Arc::into_raw
|
||||
/// [transmute]: core::mem::transmute
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -646,9 +633,7 @@ impl<T: ?Sized> Arc<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new [`Weak`][weak] pointer to this allocation.
|
||||
///
|
||||
/// [weak]: struct.Weak.html
|
||||
/// Creates a new [`Weak`] pointer to this allocation.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -690,9 +675,7 @@ impl<T: ?Sized> Arc<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the number of [`Weak`][weak] pointers to this allocation.
|
||||
///
|
||||
/// [weak]: struct.Weak.html
|
||||
/// Gets the number of [`Weak`] pointers to this allocation.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
@ -861,7 +844,7 @@ impl<T: ?Sized> Arc<T> {
|
||||
/// assert!(!Arc::ptr_eq(&five, &other_five));
|
||||
/// ```
|
||||
///
|
||||
/// [`ptr::eq`]: ../../std/ptr/fn.eq.html
|
||||
/// [`ptr::eq`]: core::ptr::eq
|
||||
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
|
||||
this.ptr.as_ptr() == other.ptr.as_ptr()
|
||||
}
|
||||
@ -1098,7 +1081,7 @@ impl<T: ?Sized> Receiver for Arc<T> {}
|
||||
impl<T: Clone> Arc<T> {
|
||||
/// Makes a mutable reference into the given `Arc`.
|
||||
///
|
||||
/// If there are other `Arc` or [`Weak`][weak] pointers to the same allocation,
|
||||
/// If there are other `Arc` or [`Weak`] pointers to the same allocation,
|
||||
/// then `make_mut` will create a new allocation and invoke [`clone`][clone] on the inner value
|
||||
/// to ensure unique ownership. This is also referred to as clone-on-write.
|
||||
///
|
||||
@ -1107,10 +1090,9 @@ impl<T: Clone> Arc<T> {
|
||||
///
|
||||
/// See also [`get_mut`][get_mut], which will fail rather than cloning.
|
||||
///
|
||||
/// [weak]: struct.Weak.html
|
||||
/// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone
|
||||
/// [get_mut]: struct.Arc.html#method.get_mut
|
||||
/// [`Rc::make_mut`]: ../rc/struct.Rc.html#method.make_mut
|
||||
/// [clone]: Clone::clone
|
||||
/// [get_mut]: Arc::get_mut
|
||||
/// [`Rc::make_mut`]: super::rc::Rc::make_mut
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -1184,18 +1166,16 @@ impl<T: Clone> Arc<T> {
|
||||
|
||||
impl<T: ?Sized> Arc<T> {
|
||||
/// Returns a mutable reference into the given `Arc`, if there are
|
||||
/// no other `Arc` or [`Weak`][weak] pointers to the same allocation.
|
||||
/// no other `Arc` or [`Weak`] pointers to the same allocation.
|
||||
///
|
||||
/// Returns [`None`][option] otherwise, because it is not safe to
|
||||
/// Returns [`None`] otherwise, because it is not safe to
|
||||
/// mutate a shared value.
|
||||
///
|
||||
/// See also [`make_mut`][make_mut], which will [`clone`][clone]
|
||||
/// the inner value when there are other pointers.
|
||||
///
|
||||
/// [weak]: struct.Weak.html
|
||||
/// [option]: ../../std/option/enum.Option.html
|
||||
/// [make_mut]: struct.Arc.html#method.make_mut
|
||||
/// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone
|
||||
/// [make_mut]: Arc::make_mut
|
||||
/// [clone]: Clone::clone
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -1229,7 +1209,7 @@ impl<T: ?Sized> Arc<T> {
|
||||
///
|
||||
/// See also [`get_mut`], which is safe and does appropriate checks.
|
||||
///
|
||||
/// [`get_mut`]: struct.Arc.html#method.get_mut
|
||||
/// [`get_mut`]: Arc::get_mut
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
@ -1315,8 +1295,6 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
|
||||
/// drop(foo); // Doesn't print anything
|
||||
/// drop(foo2); // Prints "dropped!"
|
||||
/// ```
|
||||
///
|
||||
/// [`Weak`]: ../../std/sync/struct.Weak.html
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
// Because `fetch_sub` is already atomic, we do not need to synchronize
|
||||
@ -1401,8 +1379,7 @@ impl<T> Weak<T> {
|
||||
/// Constructs a new `Weak<T>`, without allocating any memory.
|
||||
/// Calling [`upgrade`] on the return value always gives [`None`].
|
||||
///
|
||||
/// [`upgrade`]: struct.Weak.html#method.upgrade
|
||||
/// [`None`]: ../../std/option/enum.Option.html#variant.None
|
||||
/// [`upgrade`]: Weak::upgrade
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -1441,7 +1418,7 @@ impl<T> Weak<T> {
|
||||
/// // assert_eq!("hello", unsafe { &*weak.as_ptr() });
|
||||
/// ```
|
||||
///
|
||||
/// [`null`]: ../../std/ptr/fn.null.html
|
||||
/// [`null`]: core::ptr::null
|
||||
#[stable(feature = "weak_into_raw", since = "1.45.0")]
|
||||
pub fn as_ptr(&self) -> *const T {
|
||||
let ptr: *mut ArcInner<T> = NonNull::as_ptr(self.ptr);
|
||||
@ -1483,8 +1460,8 @@ impl<T> Weak<T> {
|
||||
/// assert_eq!(0, Arc::weak_count(&strong));
|
||||
/// ```
|
||||
///
|
||||
/// [`from_raw`]: struct.Weak.html#method.from_raw
|
||||
/// [`as_ptr`]: struct.Weak.html#method.as_ptr
|
||||
/// [`from_raw`]: Weak::from_raw
|
||||
/// [`as_ptr`]: Weak::as_ptr
|
||||
#[stable(feature = "weak_into_raw", since = "1.45.0")]
|
||||
pub fn into_raw(self) -> *const T {
|
||||
let result = self.as_ptr();
|
||||
@ -1530,12 +1507,10 @@ impl<T> Weak<T> {
|
||||
/// assert!(unsafe { Weak::from_raw(raw_2) }.upgrade().is_none());
|
||||
/// ```
|
||||
///
|
||||
/// [`new`]: struct.Weak.html#method.new
|
||||
/// [`into_raw`]: struct.Weak.html#method.into_raw
|
||||
/// [`upgrade`]: struct.Weak.html#method.upgrade
|
||||
/// [`Weak`]: struct.Weak.html
|
||||
/// [`Arc`]: struct.Arc.html
|
||||
/// [`forget`]: ../../std/mem/fn.forget.html
|
||||
/// [`new`]: Weak::new
|
||||
/// [`into_raw`]: Weak::into_raw
|
||||
/// [`upgrade`]: Weak::upgrade
|
||||
/// [`forget`]: std::mem::forget
|
||||
#[stable(feature = "weak_into_raw", since = "1.45.0")]
|
||||
pub unsafe fn from_raw(ptr: *const T) -> Self {
|
||||
if ptr.is_null() {
|
||||
@ -1565,9 +1540,6 @@ impl<T: ?Sized> Weak<T> {
|
||||
///
|
||||
/// Returns [`None`] if the inner value has since been dropped.
|
||||
///
|
||||
/// [`Arc`]: struct.Arc.html
|
||||
/// [`None`]: ../../std/option/enum.Option.html#variant.None
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@ -1619,8 +1591,6 @@ impl<T: ?Sized> Weak<T> {
|
||||
/// Gets the number of strong (`Arc`) pointers pointing to this allocation.
|
||||
///
|
||||
/// If `self` was created using [`Weak::new`], this will return 0.
|
||||
///
|
||||
/// [`Weak::new`]: #method.new
|
||||
#[stable(feature = "weak_counts", since = "1.41.0")]
|
||||
pub fn strong_count(&self) -> usize {
|
||||
if let Some(inner) = self.inner() { inner.strong.load(SeqCst) } else { 0 }
|
||||
@ -1637,8 +1607,6 @@ impl<T: ?Sized> Weak<T> {
|
||||
/// Due to implementation details, the returned value can be off by 1 in
|
||||
/// either direction when other threads are manipulating any `Arc`s or
|
||||
/// `Weak`s pointing to the same allocation.
|
||||
///
|
||||
/// [`Weak::new`]: #method.new
|
||||
#[stable(feature = "weak_counts", since = "1.41.0")]
|
||||
pub fn weak_count(&self) -> usize {
|
||||
self.inner()
|
||||
@ -1716,7 +1684,7 @@ impl<T: ?Sized> Weak<T> {
|
||||
/// assert!(!first.ptr_eq(&third));
|
||||
/// ```
|
||||
///
|
||||
/// [`ptr::eq`]: ../../std/ptr/fn.eq.html
|
||||
/// [`ptr::eq`]: core::ptr::eq
|
||||
#[inline]
|
||||
#[stable(feature = "weak_ptr_eq", since = "1.39.0")]
|
||||
pub fn ptr_eq(&self, other: &Self) -> bool {
|
||||
@ -1765,8 +1733,7 @@ impl<T> Default for Weak<T> {
|
||||
/// Calling [`upgrade`] on the return value always
|
||||
/// gives [`None`].
|
||||
///
|
||||
/// [`None`]: ../../std/option/enum.Option.html#variant.None
|
||||
/// [`upgrade`]: ../../std/sync/struct.Weak.html#method.upgrade
|
||||
/// [`upgrade`]: Weak::upgrade
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user