Apply 16 commits (squashed)

----------

Fix spacing for links inside code blocks, and improve link tooltips in alloc::fmt

----------

Fix spacing for links inside code blocks, and improve link tooltips in alloc::{rc, sync}

----------

Fix spacing for links inside code blocks, and improve link tooltips in alloc::string

----------

Fix spacing for links inside code blocks in alloc::vec

----------

Fix spacing for links inside code blocks in core::option

----------

Fix spacing for links inside code blocks, and improve a few link tooltips in core::result

----------

Fix spacing for links inside code blocks in core::{iter::{self, iterator}, stream::stream, poll}

----------

Fix spacing for links inside code blocks, and improve a few link tooltips in std::{fs, path}

----------

Fix spacing for links inside code blocks in std::{collections, time}

----------

Fix spacing for links inside code blocks in and make formatting of `&str`-like types consistent in std::ffi::{c_str, os_str}

----------

Fix spacing for links inside code blocks, and improve link tooltips in std::ffi

----------

Fix spacing for links inside code blocks, and improve a few link tooltips
in std::{io::{self, buffered::{bufreader, bufwriter}, cursor, util}, net::{self, addr}}

----------

Fix typo in link to `into` for `OsString` docs

----------

Remove tooltips that will probably become redundant in the future

----------

Apply suggestions from code review

Replacing `…std/primitive.reference.html` paths with just `reference`

Co-authored-by: Joshua Nelson <github@jyn.dev>

----------

Also replace `…std/primitive.reference.html` paths with just `reference` in `core::pin`
This commit is contained in:
Frank Steffahn 2021-08-25 11:45:08 +02:00
parent 7b0e554ee2
commit 67065fe933
26 changed files with 225 additions and 234 deletions

View File

@ -348,7 +348,7 @@
//! provides some helper methods. //! provides some helper methods.
//! //!
//! Additionally, the return value of this function is [`fmt::Result`] which is a //! Additionally, the return value of this function is [`fmt::Result`] which is a
//! type alias of [`Result`]`<(), `[`std::fmt::Error`]`>`. Formatting implementations //! type alias of <code>[Result]<(), [std::fmt::Error]></code>. Formatting implementations
//! should ensure that they propagate errors from the [`Formatter`] (e.g., when //! should ensure that they propagate errors from the [`Formatter`] (e.g., when
//! calling [`write!`]). However, they should never return errors spuriously. That //! calling [`write!`]). However, they should never return errors spuriously. That
//! is, a formatting implementation must and may only return an error if the //! is, a formatting implementation must and may only return an error if the
@ -505,23 +505,19 @@
//! it would internally pass around this structure until it has been determined //! it would internally pass around this structure until it has been determined
//! where output should go to. //! where output should go to.
//! //!
//! [`fmt::Result`]: Result //! [`fmt::Result`]: Result "fmt::Result"
//! [`Result`]: core::result::Result //! [Result]: core::result::Result "std::result::Result"
//! [`std::fmt::Error`]: Error //! [std::fmt::Error]: Error "fmt::Error"
//! [`write!`]: core::write //! [`write`]: write() "fmt::write"
//! [`write`]: core::write //! [`to_string`]: crate::string::ToString::to_string "ToString::to_string"
//! [`format!`]: crate::format
//! [`to_string`]: crate::string::ToString
//! [`writeln!`]: core::writeln
//! [`write_fmt`]: ../../std/io/trait.Write.html#method.write_fmt //! [`write_fmt`]: ../../std/io/trait.Write.html#method.write_fmt
//! [`std::io::Write`]: ../../std/io/trait.Write.html //! [`std::io::Write`]: ../../std/io/trait.Write.html
//! [`print!`]: ../../std/macro.print.html //! [`print!`]: ../../std/macro.print.html "print!"
//! [`println!`]: ../../std/macro.println.html //! [`println!`]: ../../std/macro.println.html "println!"
//! [`eprint!`]: ../../std/macro.eprint.html //! [`eprint!`]: ../../std/macro.eprint.html "eprint!"
//! [`eprintln!`]: ../../std/macro.eprintln.html //! [`eprintln!`]: ../../std/macro.eprintln.html "eprintln!"
//! [`format_args!`]: core::format_args //! [`fmt::Arguments`]: Arguments "fmt::Arguments"
//! [`fmt::Arguments`]: Arguments //! [`format`]: format() "fmt::format"
//! [`format`]: crate::format
#![stable(feature = "rust1", since = "1.0.0")] #![stable(feature = "rust1", since = "1.0.0")]

View File

@ -781,9 +781,7 @@ impl<T: ?Sized> Rc<T> {
/// Consumes the `Rc`, returning the wrapped pointer. /// Consumes the `Rc`, returning the wrapped pointer.
/// ///
/// To avoid a memory leak the pointer must be converted back to an `Rc` using /// To avoid a memory leak the pointer must be converted back to an `Rc` using
/// [`Rc::from_raw`][from_raw]. /// [`Rc::from_raw`].
///
/// [from_raw]: Rc::from_raw
/// ///
/// # Examples /// # Examples
/// ///
@ -834,7 +832,7 @@ impl<T: ?Sized> Rc<T> {
/// and alignment as `T`. This is trivially true if `U` is `T`. /// and alignment as `T`. This is trivially true if `U` is `T`.
/// Note that if `U` is not `T` but has the same size and alignment, this is /// Note that if `U` is not `T` but has the same size and alignment, this is
/// basically like transmuting references of different types. See /// basically like transmuting references of different types. See
/// [`mem::transmute`][transmute] for more information on what /// [`mem::transmute`] for more information on what
/// restrictions apply in this case. /// restrictions apply in this case.
/// ///
/// The user of `from_raw` has to make sure a specific value of `T` is only /// The user of `from_raw` has to make sure a specific value of `T` is only
@ -844,7 +842,6 @@ impl<T: ?Sized> Rc<T> {
/// even if the returned `Rc<T>` is never accessed. /// even if the returned `Rc<T>` is never accessed.
/// ///
/// [into_raw]: Rc::into_raw /// [into_raw]: Rc::into_raw
/// [transmute]: core::mem::transmute
/// ///
/// # Examples /// # Examples
/// ///
@ -1086,8 +1083,6 @@ impl<T: ?Sized> Rc<T> {
/// assert!(Rc::ptr_eq(&five, &same_five)); /// assert!(Rc::ptr_eq(&five, &same_five));
/// assert!(!Rc::ptr_eq(&five, &other_five)); /// assert!(!Rc::ptr_eq(&five, &other_five));
/// ``` /// ```
///
/// [`ptr::eq`]: core::ptr::eq
pub fn ptr_eq(this: &Self, other: &Self) -> bool { pub fn ptr_eq(this: &Self, other: &Self) -> bool {
this.ptr.as_ptr() == other.ptr.as_ptr() this.ptr.as_ptr() == other.ptr.as_ptr()
} }
@ -1993,7 +1988,7 @@ impl<T, I: iter::TrustedLen<Item = T>> ToRcSlice<T> for I {
/// `Weak` is a version of [`Rc`] that holds a non-owning reference to the /// `Weak` is a version of [`Rc`] that holds a non-owning reference to the
/// managed allocation. The allocation is accessed by calling [`upgrade`] on the `Weak` /// managed allocation. The allocation is accessed by calling [`upgrade`] on the `Weak`
/// pointer, which returns an [`Option`]`<`[`Rc`]`<T>>`. /// pointer, which returns an <code>[Option]<[Rc]\<T>></code>.
/// ///
/// Since a `Weak` reference does not count towards ownership, it will not /// Since a `Weak` reference does not count towards ownership, it will not
/// prevent the value stored in the allocation from being dropped, and `Weak` itself makes no /// prevent the value stored in the allocation from being dropped, and `Weak` itself makes no
@ -2090,7 +2085,7 @@ impl<T: ?Sized> Weak<T> {
/// // assert_eq!("hello", unsafe { &*weak.as_ptr() }); /// // assert_eq!("hello", unsafe { &*weak.as_ptr() });
/// ``` /// ```
/// ///
/// [`null`]: core::ptr::null /// [`null`]: ptr::null
#[stable(feature = "rc_as_ptr", since = "1.45.0")] #[stable(feature = "rc_as_ptr", since = "1.45.0")]
pub fn as_ptr(&self) -> *const T { pub fn as_ptr(&self) -> *const T {
let ptr: *mut RcBox<T> = NonNull::as_ptr(self.ptr); let ptr: *mut RcBox<T> = NonNull::as_ptr(self.ptr);
@ -2317,8 +2312,6 @@ impl<T: ?Sized> Weak<T> {
/// let third = Rc::downgrade(&third_rc); /// let third = Rc::downgrade(&third_rc);
/// assert!(!first.ptr_eq(&third)); /// assert!(!first.ptr_eq(&third));
/// ``` /// ```
///
/// [`ptr::eq`]: core::ptr::eq
#[inline] #[inline]
#[stable(feature = "weak_ptr_eq", since = "1.39.0")] #[stable(feature = "weak_ptr_eq", since = "1.39.0")]
pub fn ptr_eq(&self, other: &Self) -> bool { pub fn ptr_eq(&self, other: &Self) -> bool {
@ -2400,7 +2393,6 @@ impl<T> Default for Weak<T> {
/// Constructs a new `Weak<T>`, without allocating any memory. /// Constructs a new `Weak<T>`, without allocating any memory.
/// Calling [`upgrade`] on the return value always gives [`None`]. /// Calling [`upgrade`] on the return value always gives [`None`].
/// ///
/// [`None`]: Option
/// [`upgrade`]: Weak::upgrade /// [`upgrade`]: Weak::upgrade
/// ///
/// # Examples /// # Examples

View File

@ -79,7 +79,7 @@ use crate::vec::Vec;
/// ///
/// # Examples /// # Examples
/// ///
/// You can create a `String` from [a literal string][`str`] with [`String::from`]: /// You can create a `String` from [a literal string][`&str`] with [`String::from`]:
/// ///
/// [`String::from`]: From::from /// [`String::from`]: From::from
/// ///
@ -128,7 +128,7 @@ use crate::vec::Vec;
/// println!("The first letter of s is {}", s[0]); // ERROR!!! /// println!("The first letter of s is {}", s[0]); // ERROR!!!
/// ``` /// ```
/// ///
/// [`OsString`]: ../../std/ffi/struct.OsString.html /// [`OsString`]: ../../std/ffi/struct.OsString.html "ffi::OsString"
/// ///
/// Indexing is intended to be a constant-time operation, but UTF-8 encoding /// Indexing is intended to be a constant-time operation, but UTF-8 encoding
/// does not allow us to do this. Furthermore, it's not clear what sort of /// does not allow us to do this. Furthermore, it's not clear what sort of
@ -141,7 +141,7 @@ use crate::vec::Vec;
/// ///
/// # Deref /// # Deref
/// ///
/// `String`s implement [`Deref`]`<Target=str>`, and so inherit all of [`str`]'s /// `String` implements <code>[Deref]<Target = [str]></code>, and so inherits all of [`str`]'s
/// methods. In addition, this means that you can pass a `String` to a /// methods. In addition, this means that you can pass a `String` to a
/// function which takes a [`&str`] by using an ampersand (`&`): /// function which takes a [`&str`] by using an ampersand (`&`):
/// ///
@ -182,7 +182,7 @@ use crate::vec::Vec;
/// to explicitly extract the string slice containing the string. The second /// to explicitly extract the string slice containing the string. The second
/// way changes `example_func(&example_string);` to /// way changes `example_func(&example_string);` to
/// `example_func(&*example_string);`. In this case we are dereferencing a /// `example_func(&*example_string);`. In this case we are dereferencing a
/// `String` to a [`str`][`&str`], then referencing the [`str`][`&str`] back to /// `String` to a [`str`], then referencing the [`str`] back to
/// [`&str`]. The second way is more idiomatic, however both work to do the /// [`&str`]. The second way is more idiomatic, however both work to do the
/// conversion explicitly rather than relying on the implicit conversion. /// conversion explicitly rather than relying on the implicit conversion.
/// ///
@ -282,9 +282,11 @@ use crate::vec::Vec;
/// ///
/// Here, there's no need to allocate more memory inside the loop. /// Here, there's no need to allocate more memory inside the loop.
/// ///
/// [`str`]: prim@str /// [str]: prim@str "str"
/// [`&str`]: prim@str /// [`str`]: prim@str "str"
/// [`Deref`]: core::ops::Deref /// [`&str`]: prim@str "&str"
/// [Deref]: core::ops::Deref "ops::Deref"
/// [`Deref`]: core::ops::Deref "ops::Deref"
/// [`as_str()`]: String::as_str /// [`as_str()`]: String::as_str
#[derive(PartialOrd, Eq, Ord)] #[derive(PartialOrd, Eq, Ord)]
#[cfg_attr(not(test), rustc_diagnostic_item = "string_type")] #[cfg_attr(not(test), rustc_diagnostic_item = "string_type")]
@ -308,10 +310,10 @@ pub struct String {
/// an analogue to `FromUtf8Error`, and you can get one from a `FromUtf8Error` /// an analogue to `FromUtf8Error`, and you can get one from a `FromUtf8Error`
/// through the [`utf8_error`] method. /// through the [`utf8_error`] method.
/// ///
/// [`Utf8Error`]: core::str::Utf8Error /// [`Utf8Error`]: str::Utf8Error "std::str::Utf8Error"
/// [`std::str`]: core::str /// [`std::str`]: core::str "std::str"
/// [`&str`]: prim@str /// [`&str`]: prim@str "&str"
/// [`utf8_error`]: Self::utf8_error /// [`utf8_error`]: FromUtf8Error::utf8_error
/// ///
/// # Examples /// # Examples
/// ///
@ -487,8 +489,8 @@ impl String {
/// with this error. /// with this error.
/// ///
/// [`from_utf8_unchecked`]: String::from_utf8_unchecked /// [`from_utf8_unchecked`]: String::from_utf8_unchecked
/// [`Vec<u8>`]: crate::vec::Vec /// [`Vec<u8>`]: crate::vec::Vec "Vec"
/// [`&str`]: prim@str /// [`&str`]: prim@str "&str"
/// [`into_bytes`]: String::into_bytes /// [`into_bytes`]: String::into_bytes
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@ -524,7 +526,7 @@ impl String {
/// it's already valid UTF-8, we don't need a new allocation. This return /// it's already valid UTF-8, we don't need a new allocation. This return
/// type allows us to handle both cases. /// type allows us to handle both cases.
/// ///
/// [`Cow<'a, str>`]: crate::borrow::Cow /// [`Cow<'a, str>`]: crate::borrow::Cow "borrow::Cow"
/// ///
/// # Examples /// # Examples
/// ///
@ -625,7 +627,7 @@ impl String {
/// conversion requires a memory allocation. /// conversion requires a memory allocation.
/// ///
/// [`from_utf8_lossy`]: String::from_utf8_lossy /// [`from_utf8_lossy`]: String::from_utf8_lossy
/// [`Cow<'a, str>`]: crate::borrow::Cow /// [`Cow<'a, str>`]: crate::borrow::Cow "borrow::Cow"
/// [U+FFFD]: core::char::REPLACEMENT_CHARACTER /// [U+FFFD]: core::char::REPLACEMENT_CHARACTER
/// ///
/// # Examples /// # Examples
@ -1721,11 +1723,11 @@ impl String {
unsafe { self.as_mut_vec() }.splice((start, end), replace_with.bytes()); unsafe { self.as_mut_vec() }.splice((start, end), replace_with.bytes());
} }
/// Converts this `String` into a [`Box`]`<`[`str`]`>`. /// Converts this `String` into a <code>[Box]<[str]></code>.
/// ///
/// This will drop any excess capacity. /// This will drop any excess capacity.
/// ///
/// [`str`]: prim@str /// [str]: prim@str "str"
/// ///
/// # Examples /// # Examples
/// ///
@ -1795,8 +1797,8 @@ impl FromUtf8Error {
/// an analogue to `FromUtf8Error`. See its documentation for more details /// an analogue to `FromUtf8Error`. See its documentation for more details
/// on using it. /// on using it.
/// ///
/// [`std::str`]: core::str /// [`std::str`]: core::str "std::str"
/// [`&str`]: prim@str /// [`&str`]: prim@str "&str"
/// ///
/// # Examples /// # Examples
/// ///
@ -2319,7 +2321,7 @@ impl ops::DerefMut for String {
/// ///
/// This alias exists for backwards compatibility, and may be eventually deprecated. /// This alias exists for backwards compatibility, and may be eventually deprecated.
/// ///
/// [`Infallible`]: core::convert::Infallible /// [`Infallible`]: core::convert::Infallible "convert::Infallible"
#[stable(feature = "str_parse_error", since = "1.5.0")] #[stable(feature = "str_parse_error", since = "1.5.0")]
pub type ParseError = core::convert::Infallible; pub type ParseError = core::convert::Infallible;
@ -2606,7 +2608,7 @@ impl<'a> From<&'a str> for Cow<'a, str> {
/// assert_eq!(Cow::from("eggplant"), Cow::Borrowed("eggplant")); /// assert_eq!(Cow::from("eggplant"), Cow::Borrowed("eggplant"));
/// ``` /// ```
/// ///
/// [`Borrowed`]: crate::borrow::Cow::Borrowed /// [`Borrowed`]: crate::borrow::Cow::Borrowed "borrow::Cow::Borrowed"
#[inline] #[inline]
fn from(s: &'a str) -> Cow<'a, str> { fn from(s: &'a str) -> Cow<'a, str> {
Cow::Borrowed(s) Cow::Borrowed(s)
@ -2629,7 +2631,7 @@ impl<'a> From<String> for Cow<'a, str> {
/// assert_eq!(Cow::from(s), Cow::<'static, str>::Owned(s2)); /// assert_eq!(Cow::from(s), Cow::<'static, str>::Owned(s2));
/// ``` /// ```
/// ///
/// [`Owned`]: crate::borrow::Cow::Owned /// [`Owned`]: crate::borrow::Cow::Owned "borrow::Cow::Owned"
#[inline] #[inline]
fn from(s: String) -> Cow<'a, str> { fn from(s: String) -> Cow<'a, str> {
Cow::Owned(s) Cow::Owned(s)
@ -2651,7 +2653,7 @@ impl<'a> From<&'a String> for Cow<'a, str> {
/// assert_eq!(Cow::from(&s), Cow::Borrowed("eggplant")); /// assert_eq!(Cow::from(&s), Cow::Borrowed("eggplant"));
/// ``` /// ```
/// ///
/// [`Borrowed`]: crate::borrow::Cow::Borrowed /// [`Borrowed`]: crate::borrow::Cow::Borrowed "borrow::Cow::Borrowed"
#[inline] #[inline]
fn from(s: &'a String) -> Cow<'a, str> { fn from(s: &'a String) -> Cow<'a, str> {
Cow::Borrowed(s.as_str()) Cow::Borrowed(s.as_str())

View File

@ -99,8 +99,8 @@ macro_rules! acquire {
/// first: after all, isn't the point of `Arc<T>` thread safety? The key is /// first: after all, isn't the point of `Arc<T>` thread safety? The key is
/// this: `Arc<T>` makes it thread safe to have multiple ownership of the same /// this: `Arc<T>` makes it thread safe to have multiple ownership of the same
/// data, but it doesn't add thread safety to its data. Consider /// data, but it doesn't add thread safety to its data. Consider
/// `Arc<`[`RefCell<T>`]`>`. [`RefCell<T>`] isn't [`Sync`], and if `Arc<T>` was always /// <code>Arc<[RefCell\<T>]></code>. [`RefCell<T>`] isn't [`Sync`], and if `Arc<T>` was always
/// [`Send`], `Arc<`[`RefCell<T>`]`>` would be as well. But then we'd have a problem: /// [`Send`], <code>Arc<[RefCell\<T>]></code> would be as well. But then we'd have a problem:
/// [`RefCell<T>`] is not thread safe; it keeps track of the borrowing count using /// [`RefCell<T>`] is not thread safe; it keeps track of the borrowing count using
/// non-atomic operations. /// non-atomic operations.
/// ///
@ -176,6 +176,7 @@ macro_rules! acquire {
/// [deref]: core::ops::Deref /// [deref]: core::ops::Deref
/// [downgrade]: Arc::downgrade /// [downgrade]: Arc::downgrade
/// [upgrade]: Weak::upgrade /// [upgrade]: Weak::upgrade
/// [RefCell\<T>]: core::cell::RefCell
/// [`RefCell<T>`]: core::cell::RefCell /// [`RefCell<T>`]: core::cell::RefCell
/// [`std::sync`]: ../../std/sync/index.html /// [`std::sync`]: ../../std/sync/index.html
/// [`Arc::clone(&from)`]: Arc::clone /// [`Arc::clone(&from)`]: Arc::clone
@ -206,7 +207,7 @@ macro_rules! acquire {
/// ///
/// Sharing a mutable [`AtomicUsize`]: /// Sharing a mutable [`AtomicUsize`]:
/// ///
/// [`AtomicUsize`]: core::sync::atomic::AtomicUsize /// [`AtomicUsize`]: core::sync::atomic::AtomicUsize "sync::atomic::AtomicUsize"
/// ///
/// ```no_run /// ```no_run
/// use std::sync::Arc; /// use std::sync::Arc;
@ -262,7 +263,7 @@ impl<T: ?Sized> Arc<T> {
/// `Weak` is a version of [`Arc`] that holds a non-owning reference to the /// `Weak` is a version of [`Arc`] that holds a non-owning reference to the
/// managed allocation. The allocation is accessed by calling [`upgrade`] on the `Weak` /// managed allocation. The allocation is accessed by calling [`upgrade`] on the `Weak`
/// pointer, which returns an [`Option`]`<`[`Arc`]`<T>>`. /// pointer, which returns an <code>[Option]<[Arc]\<T>></code>.
/// ///
/// Since a `Weak` reference does not count towards ownership, it will not /// Since a `Weak` reference does not count towards ownership, it will not
/// prevent the value stored in the allocation from being dropped, and `Weak` itself makes no /// prevent the value stored in the allocation from being dropped, and `Weak` itself makes no
@ -476,7 +477,7 @@ impl<T> Arc<T> {
/// assert_eq!(*zero, 0) /// assert_eq!(*zero, 0)
/// ``` /// ```
/// ///
/// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed /// [zeroed]: mem::MaybeUninit::zeroed
#[cfg(not(no_global_oom_handling))] #[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")] #[unstable(feature = "new_uninit", issue = "63291")]
pub fn new_zeroed() -> Arc<mem::MaybeUninit<T>> { pub fn new_zeroed() -> Arc<mem::MaybeUninit<T>> {
@ -684,7 +685,7 @@ impl<T> Arc<[T]> {
/// assert_eq!(*values, [0, 0, 0]) /// assert_eq!(*values, [0, 0, 0])
/// ``` /// ```
/// ///
/// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed /// [zeroed]: mem::MaybeUninit::zeroed
#[cfg(not(no_global_oom_handling))] #[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")] #[unstable(feature = "new_uninit", issue = "63291")]
pub fn new_zeroed_slice(len: usize) -> Arc<[mem::MaybeUninit<T>]> { pub fn new_zeroed_slice(len: usize) -> Arc<[mem::MaybeUninit<T>]> {
@ -712,7 +713,7 @@ impl<T> Arc<mem::MaybeUninit<T>> {
/// Calling this when the content is not yet fully initialized /// Calling this when the content is not yet fully initialized
/// causes immediate undefined behavior. /// causes immediate undefined behavior.
/// ///
/// [`MaybeUninit::assume_init`]: ../../std/mem/union.MaybeUninit.html#method.assume_init /// [`MaybeUninit::assume_init`]: mem::MaybeUninit::assume_init
/// ///
/// # Examples /// # Examples
/// ///
@ -751,7 +752,7 @@ impl<T> Arc<[mem::MaybeUninit<T>]> {
/// Calling this when the content is not yet fully initialized /// Calling this when the content is not yet fully initialized
/// causes immediate undefined behavior. /// causes immediate undefined behavior.
/// ///
/// [`MaybeUninit::assume_init`]: ../../std/mem/union.MaybeUninit.html#method.assume_init /// [`MaybeUninit::assume_init`]: mem::MaybeUninit::assume_init
/// ///
/// # Examples /// # Examples
/// ///
@ -1086,7 +1087,7 @@ impl<T: ?Sized> Arc<T> {
/// assert!(!Arc::ptr_eq(&five, &other_five)); /// assert!(!Arc::ptr_eq(&five, &other_five));
/// ``` /// ```
/// ///
/// [`ptr::eq`]: core::ptr::eq /// [`ptr::eq`]: core::ptr::eq "ptr::eq"
pub fn ptr_eq(this: &Self, other: &Self) -> bool { pub fn ptr_eq(this: &Self, other: &Self) -> bool {
this.ptr.as_ptr() == other.ptr.as_ptr() this.ptr.as_ptr() == other.ptr.as_ptr()
} }
@ -1714,7 +1715,7 @@ impl<T: ?Sized> Weak<T> {
/// // assert_eq!("hello", unsafe { &*weak.as_ptr() }); /// // assert_eq!("hello", unsafe { &*weak.as_ptr() });
/// ``` /// ```
/// ///
/// [`null`]: core::ptr::null /// [`null`]: core::ptr::null "ptr::null"
#[stable(feature = "weak_into_raw", since = "1.45.0")] #[stable(feature = "weak_into_raw", since = "1.45.0")]
pub fn as_ptr(&self) -> *const T { pub fn as_ptr(&self) -> *const T {
let ptr: *mut ArcInner<T> = NonNull::as_ptr(self.ptr); let ptr: *mut ArcInner<T> = NonNull::as_ptr(self.ptr);
@ -1806,7 +1807,6 @@ impl<T: ?Sized> Weak<T> {
/// [`new`]: Weak::new /// [`new`]: Weak::new
/// [`into_raw`]: Weak::into_raw /// [`into_raw`]: Weak::into_raw
/// [`upgrade`]: Weak::upgrade /// [`upgrade`]: Weak::upgrade
/// [`forget`]: std::mem::forget
#[stable(feature = "weak_into_raw", since = "1.45.0")] #[stable(feature = "weak_into_raw", since = "1.45.0")]
pub unsafe fn from_raw(ptr: *const T) -> Self { pub unsafe fn from_raw(ptr: *const T) -> Self {
// See Weak::as_ptr for context on how the input pointer is derived. // See Weak::as_ptr for context on how the input pointer is derived.
@ -1982,7 +1982,7 @@ impl<T: ?Sized> Weak<T> {
/// assert!(!first.ptr_eq(&third)); /// assert!(!first.ptr_eq(&third));
/// ``` /// ```
/// ///
/// [`ptr::eq`]: core::ptr::eq /// [`ptr::eq`]: core::ptr::eq "ptr::eq"
#[inline] #[inline]
#[stable(feature = "weak_ptr_eq", since = "1.39.0")] #[stable(feature = "weak_ptr_eq", since = "1.39.0")]
pub fn ptr_eq(&self, other: &Self) -> bool { pub fn ptr_eq(&self, other: &Self) -> bool {

View File

@ -296,8 +296,8 @@ mod spec_extend;
/// on an empty Vec, it will not allocate memory. Similarly, if you store zero-sized /// on an empty Vec, it will not allocate memory. Similarly, if you store zero-sized
/// types inside a `Vec`, it will not allocate space for them. *Note that in this case /// types inside a `Vec`, it will not allocate space for them. *Note that in this case
/// the `Vec` might not report a [`capacity`] of 0*. `Vec` will allocate if and only /// the `Vec` might not report a [`capacity`] of 0*. `Vec` will allocate if and only
/// if [`mem::size_of::<T>`]`() * capacity() > 0`. In general, `Vec`'s allocation /// if <code>[mem::size_of::\<T>]\() * [capacity]\() > 0</code>. In general, `Vec`'s allocation
/// details are very subtle &mdash; if you intend to allocate memory using a `Vec` /// details are very subtle --- if you intend to allocate memory using a `Vec`
/// and use it for something else (either to pass to unsafe code, or to build your /// and use it for something else (either to pass to unsafe code, or to build your
/// own memory-backed collection), be sure to deallocate this memory by using /// own memory-backed collection), be sure to deallocate this memory by using
/// `from_raw_parts` to recover the `Vec` and then dropping it. /// `from_raw_parts` to recover the `Vec` and then dropping it.
@ -305,8 +305,8 @@ mod spec_extend;
/// If a `Vec` *has* allocated memory, then the memory it points to is on the heap /// If a `Vec` *has* allocated memory, then the memory it points to is on the heap
/// (as defined by the allocator Rust is configured to use by default), and its /// (as defined by the allocator Rust is configured to use by default), and its
/// pointer points to [`len`] initialized, contiguous elements in order (what /// pointer points to [`len`] initialized, contiguous elements in order (what
/// you would see if you coerced it to a slice), followed by [`capacity`]` - /// you would see if you coerced it to a slice), followed by <code>[capacity] - [len]</code>
/// `[`len`] logically uninitialized, contiguous elements. /// logically uninitialized, contiguous elements.
/// ///
/// A vector containing the elements `'a'` and `'b'` with capacity 4 can be /// A vector containing the elements `'a'` and `'b'` with capacity 4 can be
/// visualized as below. The top part is the `Vec` struct, it contains a /// visualized as below. The top part is the `Vec` struct, it contains a
@ -348,7 +348,7 @@ mod spec_extend;
/// ///
/// [`push`] and [`insert`] will never (re)allocate if the reported capacity is /// [`push`] and [`insert`] will never (re)allocate if the reported capacity is
/// sufficient. [`push`] and [`insert`] *will* (re)allocate if /// sufficient. [`push`] and [`insert`] *will* (re)allocate if
/// [`len`]` == `[`capacity`]. That is, the reported capacity is completely /// <code>[len] == [capacity]</code>. That is, the reported capacity is completely
/// accurate, and can be relied on. It can even be used to manually free the memory /// accurate, and can be relied on. It can even be used to manually free the memory
/// allocated by a `Vec` if desired. Bulk insertion methods *may* reallocate, even /// allocated by a `Vec` if desired. Bulk insertion methods *may* reallocate, even
/// when not necessary. /// when not necessary.
@ -360,7 +360,7 @@ mod spec_extend;
/// ///
/// `vec![x; n]`, `vec![a, b, c, d]`, and /// `vec![x; n]`, `vec![a, b, c, d]`, and
/// [`Vec::with_capacity(n)`][`Vec::with_capacity`], will all produce a `Vec` /// [`Vec::with_capacity(n)`][`Vec::with_capacity`], will all produce a `Vec`
/// with exactly the requested capacity. If [`len`]` == `[`capacity`], /// with exactly the requested capacity. If <code>[len] == [capacity]</code>,
/// (as is the case for the [`vec!`] macro), then a `Vec<T>` can be converted to /// (as is the case for the [`vec!`] macro), then a `Vec<T>` can be converted to
/// and from a [`Box<[T]>`][owned slice] without reallocating or moving the elements. /// and from a [`Box<[T]>`][owned slice] without reallocating or moving the elements.
/// ///
@ -384,8 +384,10 @@ mod spec_extend;
/// [`&str`]: type@str /// [`&str`]: type@str
/// [`shrink_to_fit`]: Vec::shrink_to_fit /// [`shrink_to_fit`]: Vec::shrink_to_fit
/// [`shrink_to`]: Vec::shrink_to /// [`shrink_to`]: Vec::shrink_to
/// [capacity]: Vec::capacity
/// [`capacity`]: Vec::capacity /// [`capacity`]: Vec::capacity
/// [`mem::size_of::<T>`]: core::mem::size_of /// [mem::size_of::\<T>]: core::mem::size_of
/// [len]: Vec::len
/// [`len`]: Vec::len /// [`len`]: Vec::len
/// [`push`]: Vec::push /// [`push`]: Vec::push
/// [`insert`]: Vec::insert /// [`insert`]: Vec::insert

View File

@ -39,7 +39,7 @@
//! ``` //! ```
//! //!
//! An iterator has a method, [`next`], which when called, returns an //! An iterator has a method, [`next`], which when called, returns an
//! [`Option`]`<Item>`. [`next`] will return [`Some(Item)`] as long as there //! <code>[Option]\<Item></code>. Calling [`next`] will return [`Some(Item)`] as long as there
//! are elements, and once they've all been exhausted, will return `None` to //! are elements, and once they've all been exhausted, will return `None` to
//! indicate that iteration is finished. Individual iterators may choose to //! indicate that iteration is finished. Individual iterators may choose to
//! resume iteration, and so calling [`next`] again may or may not eventually //! resume iteration, and so calling [`next`] again may or may not eventually

View File

@ -96,7 +96,7 @@ pub trait Iterator {
/// Specifically, `size_hint()` returns a tuple where the first element /// Specifically, `size_hint()` returns a tuple where the first element
/// is the lower bound, and the second element is the upper bound. /// is the lower bound, and the second element is the upper bound.
/// ///
/// The second half of the tuple that is returned is an [`Option`]`<`[`usize`]`>`. /// The second half of the tuple that is returned is an <code>[Option]<[usize]></code>.
/// A [`None`] here means that either there is no known upper bound, or the /// A [`None`] here means that either there is no known upper bound, or the
/// upper bound is larger than [`usize`]. /// upper bound is larger than [`usize`].
/// ///
@ -115,11 +115,9 @@ pub trait Iterator {
/// That said, the implementation should provide a correct estimation, /// That said, the implementation should provide a correct estimation,
/// because otherwise it would be a violation of the trait's protocol. /// because otherwise it would be a violation of the trait's protocol.
/// ///
/// The default implementation returns `(0, `[`None`]`)` which is correct for any /// The default implementation returns <code>(0, [None])</code> which is correct for any
/// iterator. /// iterator.
/// ///
/// [`usize`]: type@usize
///
/// # Examples /// # Examples
/// ///
/// Basic usage: /// Basic usage:
@ -870,7 +868,6 @@ pub trait Iterator {
/// The returned iterator might panic if the to-be-returned index would /// The returned iterator might panic if the to-be-returned index would
/// overflow a [`usize`]. /// overflow a [`usize`].
/// ///
/// [`usize`]: type@usize
/// [`zip`]: Iterator::zip /// [`zip`]: Iterator::zip
/// ///
/// # Examples /// # Examples

View File

@ -47,9 +47,9 @@
//! //!
//! Rust's pointer types must always point to a valid location; there are //! Rust's pointer types must always point to a valid location; there are
//! no "null" references. Instead, Rust has *optional* pointers, like //! no "null" references. Instead, Rust has *optional* pointers, like
//! the optional owned box, [`Option`]`<`[`Box<T>`]`>`. //! the optional owned box, <code>[Option]<[Box\<T>]></code>.
//! //!
//! [`Box<T>`]: ../../std/boxed/struct.Box.html //! [Box\<T>]: ../../std/boxed/struct.Box.html
//! //!
//! The following example uses [`Option`] to create an optional box of //! The following example uses [`Option`] to create an optional box of
//! [`i32`]. Notice that in order to use the inner [`i32`] value, the //! [`i32`]. Notice that in order to use the inner [`i32`] value, the
@ -111,16 +111,20 @@
//! //!
//! ## Adapters for working with references //! ## Adapters for working with references
//! //!
//! * [`as_ref`] converts from `&Option<T>` to `Option<&T>` //! * [`as_ref`] converts from <code>[&][][Option]\<T></code> to <code>[Option]<[&]T></code>
//! * [`as_mut`] converts from `&mut Option<T>` to `Option<&mut T>` //! * [`as_mut`] converts from <code>[&mut] [Option]\<T></code> to <code>[Option]<[&mut] T></code>
//! * [`as_deref`] converts from `&Option<T>` to `Option<&T::Target>` //! * [`as_deref`] converts from <code>[&][][Option]\<T></code> to
//! * [`as_deref_mut`] converts from `&mut Option<T>` to //! <code>[Option]<[&]T::[Target]></code>
//! `Option<&mut T::Target>` //! * [`as_deref_mut`] converts from <code>[&mut] [Option]\<T></code> to
//! * [`as_pin_ref`] converts from [`Pin`]`<&Option<T>>` to //! <code>[Option]<[&mut] T::[Target]></code>
//! `Option<`[`Pin`]`<&T>>` //! * [`as_pin_ref`] converts from <code>[Pin]<[&][][Option]\<T>></code> to
//! * [`as_pin_mut`] converts from [`Pin`]`<&mut Option<T>>` to //! <code>[Option]<[Pin]<[&]T>></code>
//! `Option<`[`Pin`]`<&mut T>>` //! * [`as_pin_mut`] converts from <code>[Pin]<[&mut] [Option]\<T>></code> to
//! <code>[Option]<[Pin]<[&mut] T>></code>
//! //!
//! [&]: reference "shared reference"
//! [&mut]: reference "mutable reference"
//! [Target]: Deref::Target "ops::Deref::Target"
//! [`as_deref`]: Option::as_deref //! [`as_deref`]: Option::as_deref
//! [`as_deref_mut`]: Option::as_deref_mut //! [`as_deref_mut`]: Option::as_deref_mut
//! [`as_mut`]: Option::as_mut //! [`as_mut`]: Option::as_mut
@ -603,13 +607,13 @@ impl<T> Option<T> {
/// ///
/// # Examples /// # Examples
/// ///
/// Converts an `Option<`[`String`]`>` into an `Option<`[`usize`]`>`, preserving the original. /// Converts an <code>Option<[String]></code> into an <code>Option<[usize]></code>, preserving
/// The [`map`] method takes the `self` argument by value, consuming the original, /// the original. The [`map`] method takes the `self` argument by value, consuming the original,
/// so this technique uses `as_ref` to first take an `Option` to a reference /// so this technique uses `as_ref` to first take an `Option` to a reference
/// to the value inside the original. /// to the value inside the original.
/// ///
/// [`map`]: Option::map /// [`map`]: Option::map
/// [`String`]: ../../std/string/struct.String.html /// [String]: ../../std/string/struct.String.html "String"
/// ///
/// ``` /// ```
/// let text: Option<String> = Some("Hello, world!".to_string()); /// let text: Option<String> = Some("Hello, world!".to_string());
@ -649,7 +653,9 @@ impl<T> Option<T> {
} }
} }
/// Converts from [`Pin`]`<&Option<T>>` to `Option<`[`Pin`]`<&T>>`. /// Converts from <code>[Pin]<[&]Option\<T>></code> to <code>Option<[Pin]<[&]T>></code>.
///
/// [&]: reference "shared reference"
#[inline] #[inline]
#[stable(feature = "pin", since = "1.33.0")] #[stable(feature = "pin", since = "1.33.0")]
pub fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> { pub fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
@ -658,7 +664,9 @@ impl<T> Option<T> {
unsafe { Pin::get_ref(self).as_ref().map(|x| Pin::new_unchecked(x)) } unsafe { Pin::get_ref(self).as_ref().map(|x| Pin::new_unchecked(x)) }
} }
/// Converts from [`Pin`]`<&mut Option<T>>` to `Option<`[`Pin`]`<&mut T>>`. /// Converts from <code>[Pin]<[&mut] Option\<T>></code> to <code>Option<[Pin]<[&mut] T>></code>.
///
/// [&mut]: reference "mutable reference"
#[inline] #[inline]
#[stable(feature = "pin", since = "1.33.0")] #[stable(feature = "pin", since = "1.33.0")]
pub fn as_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>> { pub fn as_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>> {
@ -819,9 +827,10 @@ impl<T> Option<T> {
/// ///
/// # Examples /// # Examples
/// ///
/// Converts an `Option<`[`String`]`>` into an `Option<`[`usize`]`>`, consuming the original: /// Converts an <code>Option<[String]></code> into an <code>Option<[usize]></code>, consuming
/// the original:
/// ///
/// [`String`]: ../../std/string/struct.String.html /// [String]: ../../std/string/struct.String.html "String"
/// ``` /// ```
/// let maybe_some_string = Some(String::from("Hello, World!")); /// let maybe_some_string = Some(String::from("Hello, World!"));
/// // `Option::map` takes self *by value*, consuming `maybe_some_string` /// // `Option::map` takes self *by value*, consuming `maybe_some_string`
@ -1584,9 +1593,9 @@ impl<T: DerefMut> Option<T> {
impl<T, E> Option<Result<T, E>> { impl<T, E> Option<Result<T, E>> {
/// Transposes an `Option` of a [`Result`] into a [`Result`] of an `Option`. /// Transposes an `Option` of a [`Result`] into a [`Result`] of an `Option`.
/// ///
/// [`None`] will be mapped to [`Ok`]`(`[`None`]`)`. /// [`None`] will be mapped to <code>[Ok]\([None])</code>.
/// [`Some`]`(`[`Ok`]`(_))` and [`Some`]`(`[`Err`]`(_))` will be mapped to /// <code>[Some]\([Ok]\(\_))</code> and <code>[Some]\([Err]\(\_))</code> will be mapped to
/// [`Ok`]`(`[`Some`]`(_))` and [`Err`]`(_)`. /// <code>[Ok]\([Some]\(\_))</code> and <code>[Err]\(\_)</code>.
/// ///
/// # Examples /// # Examples
/// ///
@ -1724,13 +1733,13 @@ impl<'a, T> From<&'a Option<T>> for Option<&'a T> {
/// ///
/// # Examples /// # Examples
/// ///
/// Converts an `Option<`[`String`]`>` into an `Option<`[`usize`]`>`, preserving the original. /// Converts an <code>[Option]<[String]></code> into an <code>[Option]<[usize]></code>, preserving
/// The [`map`] method takes the `self` argument by value, consuming the original, /// the original. The [`map`] method takes the `self` argument by value, consuming the original,
/// so this technique uses `from` to first take an `Option` to a reference /// so this technique uses `from` to first take an [`Option`] to a reference
/// to the value inside the original. /// to the value inside the original.
/// ///
/// [`map`]: Option::map /// [`map`]: Option::map
/// [`String`]: ../../std/string/struct.String.html /// [String]: ../../std/string/struct.String.html "String"
/// ///
/// ``` /// ```
/// let s: Option<String> = Some(String::from("Hello, Rustaceans!")); /// let s: Option<String> = Some(String::from("Hello, Rustaceans!"));

View File

@ -368,15 +368,15 @@
//! [Vec::push]: ../../std/vec/struct.Vec.html#method.push "Vec::push" //! [Vec::push]: ../../std/vec/struct.Vec.html#method.push "Vec::push"
//! [Rc]: ../../std/rc/struct.Rc.html "rc::Rc" //! [Rc]: ../../std/rc/struct.Rc.html "rc::Rc"
//! [RefCell]: crate::cell::RefCell "cell::RefCell" //! [RefCell]: crate::cell::RefCell "cell::RefCell"
//! [`drop`]: Drop::drop "Drop::drop" //! [`drop`]: Drop::drop
//! [VecDeque]: ../../std/collections/struct.VecDeque.html "collections::VecDeque" //! [VecDeque]: ../../std/collections/struct.VecDeque.html "collections::VecDeque"
//! [`ptr::write`]: crate::ptr::write "ptr::write" //! [`ptr::write`]: crate::ptr::write "ptr::write"
//! [`Future`]: crate::future::Future "future::Future" //! [`Future`]: crate::future::Future "future::Future"
//! [drop-impl]: #drop-implementation //! [drop-impl]: #drop-implementation
//! [drop-guarantee]: #drop-guarantee //! [drop-guarantee]: #drop-guarantee
//! [`poll`]: crate::future::Future::poll "future::Future::poll" //! [`poll`]: crate::future::Future::poll "future::Future::poll"
//! [&]: ../../std/primitive.reference.html "shared reference" //! [&]: reference "shared reference"
//! [&mut]: ../../std/primitive.reference.html "mutable reference" //! [&mut]: reference "mutable reference"
//! [`unsafe`]: ../../std/keyword.unsafe.html "keyword unsafe" //! [`unsafe`]: ../../std/keyword.unsafe.html "keyword unsafe"
#![stable(feature = "pin", since = "1.33.0")] #![stable(feature = "pin", since = "1.33.0")]

View File

@ -88,7 +88,7 @@
//! ``` //! ```
//! //!
//! *Note: The actual definition of [`Write`] uses [`io::Result`], which //! *Note: The actual definition of [`Write`] uses [`io::Result`], which
//! is just a synonym for [`Result`]`<T, `[`io::Error`]`>`.* //! is just a synonym for <code>[Result]<T, [io::Error]></code>.*
//! //!
//! This method doesn't produce a value, but the write may //! This method doesn't produce a value, but the write may
//! fail. It's crucial to handle the error case, and *not* write //! fail. It's crucial to handle the error case, and *not* write
@ -217,13 +217,13 @@
//! early return of [`Err`] that it provides. //! early return of [`Err`] that it provides.
//! //!
//! [`expect`]: Result::expect //! [`expect`]: Result::expect
//! [`Write`]: ../../std/io/trait.Write.html //! [`Write`]: ../../std/io/trait.Write.html "io::Write"
//! [`write_all`]: ../../std/io/trait.Write.html#method.write_all //! [`write_all`]: ../../std/io/trait.Write.html#method.write_all "io::Write::write_all"
//! [`io::Result`]: ../../std/io/type.Result.html //! [`io::Result`]: ../../std/io/type.Result.html "io::Result"
//! [`?`]: crate::ops::Try //! [`?`]: crate::ops::Try
//! [`Ok(T)`]: Ok //! [`Ok(T)`]: Ok
//! [`Err(E)`]: Err //! [`Err(E)`]: Err
//! [`io::Error`]: ../../std/io/struct.Error.html //! [io::Error]: ../../std/io/struct.Error.html "io::Error"
//! //!
//! # Method overview //! # Method overview
//! //!

View File

@ -52,7 +52,7 @@ pub trait Stream {
/// Specifically, `size_hint()` returns a tuple where the first element /// Specifically, `size_hint()` returns a tuple where the first element
/// is the lower bound, and the second element is the upper bound. /// is the lower bound, and the second element is the upper bound.
/// ///
/// The second half of the tuple that is returned is an [`Option`]`<`[`usize`]`>`. /// The second half of the tuple that is returned is an <code>[Option]<[usize]></code>.
/// A [`None`] here means that either there is no known upper bound, or the /// A [`None`] here means that either there is no known upper bound, or the
/// upper bound is larger than [`usize`]. /// upper bound is larger than [`usize`].
/// ///
@ -71,7 +71,7 @@ pub trait Stream {
/// That said, the implementation should provide a correct estimation, /// That said, the implementation should provide a correct estimation,
/// because otherwise it would be a violation of the trait's protocol. /// because otherwise it would be a violation of the trait's protocol.
/// ///
/// The default implementation returns `(0, `[`None`]`)` which is correct for any /// The default implementation returns <code>(0, [None])</code> which is correct for any
/// stream. /// stream.
#[inline] #[inline]
fn size_hint(&self) -> (usize, Option<usize>) { fn size_hint(&self) -> (usize, Option<usize>) {

View File

@ -30,9 +30,10 @@ impl<T> Poll<T> {
/// ///
/// # Examples /// # Examples
/// ///
/// Converts a `Poll<`[`String`]`>` into an `Poll<`[`usize`]`>`, consuming the original: /// Converts a <code>Poll<[String]></code> into a <code>Poll<[usize]></code>, consuming
/// the original:
/// ///
/// [`String`]: ../../std/string/struct.String.html /// [String]: ../../std/string/struct.String.html "String"
/// ``` /// ```
/// # use core::task::Poll; /// # use core::task::Poll;
/// let poll_some_string = Poll::Ready(String::from("Hello, World!")); /// let poll_some_string = Poll::Ready(String::from("Hello, World!"));

View File

@ -217,7 +217,7 @@
//! contents by-value. This is great when the collection itself is no longer //! contents by-value. This is great when the collection itself is no longer
//! needed, and the values are needed elsewhere. Using `extend` with `into_iter` //! needed, and the values are needed elsewhere. Using `extend` with `into_iter`
//! is the main way that contents of one collection are moved into another. //! is the main way that contents of one collection are moved into another.
//! `extend` automatically calls `into_iter`, and takes any `T: `[`IntoIterator`]. //! `extend` automatically calls `into_iter`, and takes any <code>T: [IntoIterator]</code>.
//! Calling `collect` on an iterator itself is also a great way to convert one //! Calling `collect` on an iterator itself is also a great way to convert one
//! collection into another. Both of these methods should internally use the //! collection into another. Both of these methods should internally use the
//! capacity management tools discussed in the previous section to do this as //! capacity management tools discussed in the previous section to do this as
@ -396,7 +396,7 @@
//! assert_eq!(map.keys().next().unwrap().b, "baz"); //! assert_eq!(map.keys().next().unwrap().b, "baz");
//! ``` //! ```
//! //!
//! [`IntoIterator`]: crate::iter::IntoIterator //! [IntoIterator]: crate::iter::IntoIterator "iter::IntoIterator"
#![stable(feature = "rust1", since = "1.0.0")] #![stable(feature = "rust1", since = "1.0.0")]

View File

@ -29,18 +29,18 @@ use crate::sys_common::memchr;
/// type is a static guarantee that the underlying bytes contain no interior 0 /// type is a static guarantee that the underlying bytes contain no interior 0
/// bytes ("nul characters") and that the final byte is 0 ("nul terminator"). /// bytes ("nul characters") and that the final byte is 0 ("nul terminator").
/// ///
/// `CString` is to [`&CStr`] as [`String`] is to [`&str`]: the former /// `CString` is to <code>&[CStr]</code> as [`String`] is to <code>&[str]</code>: the former
/// in each pair are owned strings; the latter are borrowed /// in each pair are owned strings; the latter are borrowed
/// references. /// references.
/// ///
/// # Creating a `CString` /// # Creating a `CString`
/// ///
/// A `CString` is created from either a byte slice or a byte vector, /// A `CString` is created from either a byte slice or a byte vector,
/// or anything that implements [`Into`]`<`[`Vec`]`<`[`u8`]`>>` (for /// or anything that implements <code>[Into]<[Vec]<[u8]>></code> (for
/// example, you can build a `CString` straight out of a [`String`] or /// example, you can build a `CString` straight out of a [`String`] or
/// a [`&str`], since both implement that trait). /// a <code>&[str]</code>, since both implement that trait).
/// ///
/// The [`CString::new`] method will actually check that the provided `&[u8]` /// The [`CString::new`] method will actually check that the provided <code>&[[u8]]</code>
/// does not have 0 bytes in the middle, and return an error if it /// does not have 0 bytes in the middle, and return an error if it
/// finds one. /// finds one.
/// ///
@ -55,7 +55,7 @@ use crate::sys_common::memchr;
/// ///
/// # Extracting a slice of the whole C string /// # Extracting a slice of the whole C string
/// ///
/// Alternatively, you can obtain a `&[`[`u8`]`]` slice from a /// Alternatively, you can obtain a <code>&[[u8]]</code> slice from a
/// `CString` with the [`CString::as_bytes`] method. Slices produced in this /// `CString` with the [`CString::as_bytes`] method. Slices produced in this
/// way do *not* contain the trailing nul terminator. This is useful /// way do *not* contain the trailing nul terminator. This is useful
/// when you will be calling an extern function that takes a `*const /// when you will be calling an extern function that takes a `*const
@ -64,7 +64,7 @@ use crate::sys_common::memchr;
/// You can of course get the slice's length with its /// You can of course get the slice's length with its
/// [`len`][slice::len] method. /// [`len`][slice::len] method.
/// ///
/// If you need a `&[`[`u8`]`]` slice *with* the nul terminator, you /// If you need a <code>&[[u8]]</code> slice *with* the nul terminator, you
/// can use [`CString::as_bytes_with_nul`] instead. /// can use [`CString::as_bytes_with_nul`] instead.
/// ///
/// Once you have the kind of slice you need (with or without a nul /// Once you have the kind of slice you need (with or without a nul
@ -73,9 +73,8 @@ use crate::sys_common::memchr;
/// extern functions. See the documentation for that function for a /// extern functions. See the documentation for that function for a
/// discussion on ensuring the lifetime of the raw pointer. /// discussion on ensuring the lifetime of the raw pointer.
/// ///
/// [`&str`]: prim@str /// [str]: prim@str "str"
/// [`Deref`]: ops::Deref /// [`Deref`]: ops::Deref
/// [`&CStr`]: CStr
/// ///
/// # Examples /// # Examples
/// ///
@ -120,12 +119,12 @@ pub struct CString {
/// Representation of a borrowed C string. /// Representation of a borrowed C string.
/// ///
/// This type represents a borrowed reference to a nul-terminated /// This type represents a borrowed reference to a nul-terminated
/// array of bytes. It can be constructed safely from a `&[`[`u8`]`]` /// array of bytes. It can be constructed safely from a <code>&[[u8]]</code>
/// slice, or unsafely from a raw `*const c_char`. It can then be /// slice, or unsafely from a raw `*const c_char`. It can then be
/// converted to a Rust [`&str`] by performing UTF-8 validation, or /// converted to a Rust <code>&[str]</code> by performing UTF-8 validation, or
/// into an owned [`CString`]. /// into an owned [`CString`].
/// ///
/// `&CStr` is to [`CString`] as [`&str`] is to [`String`]: the former /// `&CStr` is to [`CString`] as <code>&[str]</code> is to [`String`]: the former
/// in each pair are borrowed references; the latter are owned /// in each pair are borrowed references; the latter are owned
/// strings. /// strings.
/// ///
@ -183,7 +182,7 @@ pub struct CString {
/// println!("string: {}", my_string_safe()); /// println!("string: {}", my_string_safe());
/// ``` /// ```
/// ///
/// [`&str`]: prim@str /// [str]: prim@str "str"
#[derive(Hash)] #[derive(Hash)]
#[cfg_attr(not(test), rustc_diagnostic_item = "CStr")] #[cfg_attr(not(test), rustc_diagnostic_item = "CStr")]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@ -682,7 +681,7 @@ impl CString {
unsafe { ptr::read(&this.inner) } unsafe { ptr::read(&this.inner) }
} }
/// Converts a [`Vec`]`<u8>` to a [`CString`] without checking the /// Converts a <code>[Vec]<[u8]></code> to a [`CString`] without checking the
/// invariants on the given [`Vec`]. /// invariants on the given [`Vec`].
/// ///
/// # Safety /// # Safety
@ -705,7 +704,7 @@ impl CString {
Self { inner: v.into_boxed_slice() } Self { inner: v.into_boxed_slice() }
} }
/// Attempts to converts a [`Vec`]`<u8>` to a [`CString`]. /// Attempts to converts a <code>[Vec]<[u8]></code> to a [`CString`].
/// ///
/// Runtime checks are present to ensure there is only one nul byte in the /// Runtime checks are present to ensure there is only one nul byte in the
/// [`Vec`], its last element. /// [`Vec`], its last element.
@ -793,7 +792,7 @@ impl fmt::Debug for CString {
#[stable(feature = "cstring_into", since = "1.7.0")] #[stable(feature = "cstring_into", since = "1.7.0")]
impl From<CString> for Vec<u8> { impl From<CString> for Vec<u8> {
/// Converts a [`CString`] into a [`Vec`]`<u8>`. /// Converts a [`CString`] into a <code>[Vec]<[u8]></code>.
/// ///
/// The conversion consumes the [`CString`], and removes the terminating NUL byte. /// The conversion consumes the [`CString`], and removes the terminating NUL byte.
#[inline] #[inline]
@ -867,7 +866,7 @@ impl From<Cow<'_, CStr>> for Box<CStr> {
#[stable(feature = "c_string_from_box", since = "1.18.0")] #[stable(feature = "c_string_from_box", since = "1.18.0")]
impl From<Box<CStr>> for CString { impl From<Box<CStr>> for CString {
/// Converts a [`Box`]`<CStr>` into a [`CString`] without copying or allocating. /// Converts a <code>[Box]<[CStr]></code> into a [`CString`] without copying or allocating.
#[inline] #[inline]
fn from(s: Box<CStr>) -> CString { fn from(s: Box<CStr>) -> CString {
s.into_c_string() s.into_c_string()
@ -876,7 +875,7 @@ impl From<Box<CStr>> for CString {
#[stable(feature = "cstring_from_vec_of_nonzerou8", since = "1.43.0")] #[stable(feature = "cstring_from_vec_of_nonzerou8", since = "1.43.0")]
impl From<Vec<NonZeroU8>> for CString { impl From<Vec<NonZeroU8>> for CString {
/// Converts a [`Vec`]`<`[`NonZeroU8`]`>` into a [`CString`] without /// Converts a <code>[Vec]<[NonZeroU8]></code> into a [`CString`] without
/// copying nor checking for inner null bytes. /// copying nor checking for inner null bytes.
#[inline] #[inline]
fn from(v: Vec<NonZeroU8>) -> CString { fn from(v: Vec<NonZeroU8>) -> CString {
@ -906,7 +905,7 @@ impl Clone for Box<CStr> {
#[stable(feature = "box_from_c_string", since = "1.20.0")] #[stable(feature = "box_from_c_string", since = "1.20.0")]
impl From<CString> for Box<CStr> { impl From<CString> for Box<CStr> {
/// Converts a [`CString`] into a [`Box`]`<CStr>` without copying or allocating. /// Converts a [`CString`] into a <code>[Box]<[CStr]></code> without copying or allocating.
#[inline] #[inline]
fn from(s: CString) -> Box<CStr> { fn from(s: CString) -> Box<CStr> {
s.into_boxed_c_str() s.into_boxed_c_str()
@ -939,7 +938,7 @@ impl<'a> From<&'a CString> for Cow<'a, CStr> {
#[stable(feature = "shared_from_slice2", since = "1.24.0")] #[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl From<CString> for Arc<CStr> { impl From<CString> for Arc<CStr> {
/// Converts a [`CString`] into an [`Arc`]`<CStr>` without copying or allocating. /// Converts a [`CString`] into an <code>[Arc]<[CStr]></code> without copying or allocating.
#[inline] #[inline]
fn from(s: CString) -> Arc<CStr> { fn from(s: CString) -> Arc<CStr> {
let arc: Arc<[u8]> = Arc::from(s.into_inner()); let arc: Arc<[u8]> = Arc::from(s.into_inner());
@ -958,7 +957,7 @@ impl From<&CStr> for Arc<CStr> {
#[stable(feature = "shared_from_slice2", since = "1.24.0")] #[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl From<CString> for Rc<CStr> { impl From<CString> for Rc<CStr> {
/// Converts a [`CString`] into an [`Rc`]`<CStr>` without copying or allocating. /// Converts a [`CString`] into an <code>[Rc]<[CStr]></code> without copying or allocating.
#[inline] #[inline]
fn from(s: CString) -> Rc<CStr> { fn from(s: CString) -> Rc<CStr> {
let rc: Rc<[u8]> = Rc::from(s.into_inner()); let rc: Rc<[u8]> = Rc::from(s.into_inner());
@ -1352,13 +1351,13 @@ impl CStr {
unsafe { &*(&self.inner as *const [c_char] as *const [u8]) } unsafe { &*(&self.inner as *const [c_char] as *const [u8]) }
} }
/// Yields a [`&str`] slice if the `CStr` contains valid UTF-8. /// Yields a <code>&[str]</code> slice if the `CStr` contains valid UTF-8.
/// ///
/// If the contents of the `CStr` are valid UTF-8 data, this /// If the contents of the `CStr` are valid UTF-8 data, this
/// function will return the corresponding [`&str`] slice. Otherwise, /// function will return the corresponding <code>&[str]</code> slice. Otherwise,
/// it will return an error with details of where UTF-8 validation failed. /// it will return an error with details of where UTF-8 validation failed.
/// ///
/// [`&str`]: prim@str /// [str]: prim@str "str"
/// ///
/// # Examples /// # Examples
/// ///
@ -1377,20 +1376,19 @@ impl CStr {
str::from_utf8(self.to_bytes()) str::from_utf8(self.to_bytes())
} }
/// Converts a `CStr` into a [`Cow`]`<`[`str`]`>`. /// Converts a `CStr` into a <code>[Cow]<[str]></code>.
/// ///
/// If the contents of the `CStr` are valid UTF-8 data, this /// If the contents of the `CStr` are valid UTF-8 data, this
/// function will return a [`Cow`]`::`[`Borrowed`]`(`[`&str`]`)` /// function will return a <code>[Cow]::[Borrowed]\(&[str])</code>
/// with the corresponding [`&str`] slice. Otherwise, it will /// with the corresponding <code>&[str]</code> slice. Otherwise, it will
/// replace any invalid UTF-8 sequences with /// replace any invalid UTF-8 sequences with
/// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a
/// [`Cow`]`::`[`Owned`]`(`[`String`]`)` with the result. /// <code>[Cow]::[Owned]\(&[str])</code> with the result.
/// ///
/// [`str`]: primitive@str /// [str]: prim@str "str"
/// [`&str`]: primitive@str /// [Borrowed]: Cow::Borrowed
/// [`Borrowed`]: Cow::Borrowed /// [Owned]: Cow::Owned
/// [`Owned`]: Cow::Owned /// [U+FFFD]: crate::char::REPLACEMENT_CHARACTER "std::char::REPLACEMENT_CHARACTER"
/// [U+FFFD]: crate::char::REPLACEMENT_CHARACTER
/// ///
/// # Examples /// # Examples
/// ///
@ -1423,7 +1421,7 @@ impl CStr {
String::from_utf8_lossy(self.to_bytes()) String::from_utf8_lossy(self.to_bytes())
} }
/// Converts a [`Box`]`<CStr>` into a [`CString`] without copying or allocating. /// Converts a <code>[Box]<[CStr]></code> into a [`CString`] without copying or allocating.
/// ///
/// # Examples /// # Examples
/// ///

View File

@ -64,15 +64,15 @@
//! string: it is nul-terminated, and has no internal nul characters. //! string: it is nul-terminated, and has no internal nul characters.
//! Rust code can create a [`CString`] out of a normal string (provided //! Rust code can create a [`CString`] out of a normal string (provided
//! that the string doesn't have nul characters in the middle), and //! that the string doesn't have nul characters in the middle), and
//! then use a variety of methods to obtain a raw `*mut `[`u8`] that can //! then use a variety of methods to obtain a raw <code>\*mut [u8]</code> that can
//! then be passed as an argument to functions which use the C //! then be passed as an argument to functions which use the C
//! conventions for strings. //! conventions for strings.
//! //!
//! * **From C to Rust:** [`CStr`] represents a borrowed C string; it //! * **From C to Rust:** [`CStr`] represents a borrowed C string; it
//! is what you would use to wrap a raw `*const `[`u8`] that you got from //! is what you would use to wrap a raw <code>\*const [u8]</code> that you got from
//! a C function. A [`CStr`] is guaranteed to be a nul-terminated array //! a C function. A [`CStr`] is guaranteed to be a nul-terminated array
//! of bytes. Once you have a [`CStr`], you can convert it to a Rust //! of bytes. Once you have a [`CStr`], you can convert it to a Rust
//! [`&str`][`str`] if it's valid UTF-8, or lossily convert it by adding //! <code>&[str]</code> if it's valid UTF-8, or lossily convert it by adding
//! replacement characters. //! replacement characters.
//! //!
//! [`OsString`] and [`OsStr`] are useful when you need to transfer //! [`OsString`] and [`OsStr`] are useful when you need to transfer
@ -86,9 +86,9 @@
//! library, various APIs that transfer strings to/from the operating //! library, various APIs that transfer strings to/from the operating
//! system use [`OsString`] instead of plain strings. For example, //! system use [`OsString`] instead of plain strings. For example,
//! [`env::var_os()`] is used to query environment variables; it //! [`env::var_os()`] is used to query environment variables; it
//! returns an [`Option`]`<`[`OsString`]`>`. If the environment variable //! returns an <code>[Option]<[OsString]></code>. If the environment variable
//! exists you will get a [`Some`]`(os_string)`, which you can *then* try to //! exists you will get a <code>[Some]\(os_string)</code>, which you can
//! convert to a Rust string. This yields a [`Result`], so that //! *then* try to convert to a Rust string. This yields a [`Result`], so that
//! your code can detect errors in case the environment variable did //! your code can detect errors in case the environment variable did
//! not in fact contain valid Unicode data. //! not in fact contain valid Unicode data.
//! //!
@ -102,44 +102,44 @@
//! ## On Unix //! ## On Unix
//! //!
//! On Unix, [`OsStr`] implements the //! On Unix, [`OsStr`] implements the
//! `std::os::unix::ffi::`[`OsStrExt`][unix.OsStrExt] trait, which //! <code>std::os::unix::ffi::[OsStrExt][unix.OsStrExt]</code> trait, which
//! augments it with two methods, [`from_bytes`] and [`as_bytes`]. //! augments it with two methods, [`from_bytes`] and [`as_bytes`].
//! These do inexpensive conversions from and to UTF-8 byte slices. //! These do inexpensive conversions from and to UTF-8 byte slices.
//! //!
//! Additionally, on Unix [`OsString`] implements the //! Additionally, on Unix [`OsString`] implements the
//! `std::os::unix::ffi::`[`OsStringExt`][unix.OsStringExt] trait, //! <code>std::os::unix::ffi::[OsStringExt][unix.OsStringExt]</code> trait,
//! which provides [`from_vec`] and [`into_vec`] methods that consume //! which provides [`from_vec`] and [`into_vec`] methods that consume
//! their arguments, and take or produce vectors of [`u8`]. //! their arguments, and take or produce vectors of [`u8`].
//! //!
//! ## On Windows //! ## On Windows
//! //!
//! On Windows, [`OsStr`] implements the //! On Windows, [`OsStr`] implements the
//! `std::os::windows::ffi::`[`OsStrExt`][windows.OsStrExt] trait, //! <code>std::os::windows::ffi::[OsStrExt][windows.OsStrExt]</code> trait,
//! which provides an [`encode_wide`] method. This provides an //! which provides an [`encode_wide`] method. This provides an
//! iterator that can be [`collect`]ed into a vector of [`u16`]. //! iterator that can be [`collect`]ed into a vector of [`u16`].
//! //!
//! Additionally, on Windows [`OsString`] implements the //! Additionally, on Windows [`OsString`] implements the
//! `std::os::windows:ffi::`[`OsStringExt`][windows.OsStringExt] //! <code>std::os::windows:ffi::[OsStringExt][windows.OsStringExt]</code>
//! trait, which provides a [`from_wide`] method. The result of this //! trait, which provides a [`from_wide`] method. The result of this
//! method is an [`OsString`] which can be round-tripped to a Windows //! method is an [`OsString`] which can be round-tripped to a Windows
//! string losslessly. //! string losslessly.
//! //!
//! [Unicode scalar value]: https://www.unicode.org/glossary/#unicode_scalar_value //! [Unicode scalar value]: https://www.unicode.org/glossary/#unicode_scalar_value
//! [Unicode code point]: https://www.unicode.org/glossary/#code_point //! [Unicode code point]: https://www.unicode.org/glossary/#code_point
//! [`env::set_var()`]: crate::env::set_var //! [`env::set_var()`]: crate::env::set_var "env::set_var"
//! [`env::var_os()`]: crate::env::var_os //! [`env::var_os()`]: crate::env::var_os "env::var_os"
//! [unix.OsStringExt]: crate::os::unix::ffi::OsStringExt //! [unix.OsStringExt]: crate::os::unix::ffi::OsStringExt "os::unix::ffi::OsStringExt"
//! [`from_vec`]: crate::os::unix::ffi::OsStringExt::from_vec //! [`from_vec`]: crate::os::unix::ffi::OsStringExt::from_vec "os::unix::ffi::OsStringExt::from_vec"
//! [`into_vec`]: crate::os::unix::ffi::OsStringExt::into_vec //! [`into_vec`]: crate::os::unix::ffi::OsStringExt::into_vec "os::unix::ffi::OsStringExt::into_vec"
//! [unix.OsStrExt]: crate::os::unix::ffi::OsStrExt //! [unix.OsStrExt]: crate::os::unix::ffi::OsStrExt "os::unix::ffi::OsStrExt"
//! [`from_bytes`]: crate::os::unix::ffi::OsStrExt::from_bytes //! [`from_bytes`]: crate::os::unix::ffi::OsStrExt::from_bytes "os::unix::ffi::OsStrExt::from_bytes"
//! [`as_bytes`]: crate::os::unix::ffi::OsStrExt::as_bytes //! [`as_bytes`]: crate::os::unix::ffi::OsStrExt::as_bytes "os::unix::ffi::OsStrExt::as_bytes"
//! [`OsStrExt`]: crate::os::unix::ffi::OsStrExt //! [`OsStrExt`]: crate::os::unix::ffi::OsStrExt "os::unix::ffi::OsStrExt"
//! [windows.OsStrExt]: crate::os::windows::ffi::OsStrExt //! [windows.OsStrExt]: crate::os::windows::ffi::OsStrExt "os::windows::ffi::OsStrExt"
//! [`encode_wide`]: crate::os::windows::ffi::OsStrExt::encode_wide //! [`encode_wide`]: crate::os::windows::ffi::OsStrExt::encode_wide "os::windows::ffi::OsStrExt::encode_wide"
//! [`collect`]: crate::iter::Iterator::collect //! [`collect`]: crate::iter::Iterator::collect "iter::Iterator::collect"
//! [windows.OsStringExt]: crate::os::windows::ffi::OsStringExt //! [windows.OsStringExt]: crate::os::windows::ffi::OsStringExt "os::windows::ffi::OsStringExt"
//! [`from_wide`]: crate::os::windows::ffi::OsStringExt::from_wide //! [`from_wide`]: crate::os::windows::ffi::OsStringExt::from_wide "os::windows::ffi::OsStringExt::from_wide"
#![stable(feature = "rust1", since = "1.0.0")] #![stable(feature = "rust1", since = "1.0.0")]

View File

@ -33,7 +33,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
/// of this is that `OsString` instances are *not* `NUL` terminated; in order /// of this is that `OsString` instances are *not* `NUL` terminated; in order
/// to pass to e.g., Unix system call, you should create a [`CStr`]. /// to pass to e.g., Unix system call, you should create a [`CStr`].
/// ///
/// `OsString` is to [`&OsStr`] as [`String`] is to [`&str`]: the former /// `OsString` is to <code>&[OsStr]</code> as [`String`] is to <code>&[str]</code>: the former
/// in each pair are owned strings; the latter are borrowed /// in each pair are owned strings; the latter are borrowed
/// references. /// references.
/// ///
@ -47,18 +47,18 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
/// # Creating an `OsString` /// # Creating an `OsString`
/// ///
/// **From a Rust string**: `OsString` implements /// **From a Rust string**: `OsString` implements
/// [`From`]`<`[`String`]`>`, so you can use `my_string.from` to /// <code>[From]<[String]></code>, so you can use <code>my_string.[into]\()</code> to
/// create an `OsString` from a normal Rust string. /// create an `OsString` from a normal Rust string.
/// ///
/// **From slices:** Just like you can start with an empty Rust /// **From slices:** Just like you can start with an empty Rust
/// [`String`] and then [`String::push_str`] `&str` /// [`String`] and then [`String::push_str`] some <code>&[str]</code>
/// sub-string slices into it, you can create an empty `OsString` with /// sub-string slices into it, you can create an empty `OsString` with
/// the [`OsString::new`] method and then push string slices into it with the /// the [`OsString::new`] method and then push string slices into it with the
/// [`OsString::push`] method. /// [`OsString::push`] method.
/// ///
/// # Extracting a borrowed reference to the whole OS string /// # Extracting a borrowed reference to the whole OS string
/// ///
/// You can use the [`OsString::as_os_str`] method to get an `&`[`OsStr`] from /// You can use the [`OsString::as_os_str`] method to get an <code>&[OsStr]</code> from
/// an `OsString`; this is effectively a borrowed reference to the /// an `OsString`; this is effectively a borrowed reference to the
/// whole string. /// whole string.
/// ///
@ -67,10 +67,9 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
/// See the [module's toplevel documentation about conversions][conversions] for a discussion on /// See the [module's toplevel documentation about conversions][conversions] for a discussion on
/// the traits which `OsString` implements for [conversions] from/to native representations. /// the traits which `OsString` implements for [conversions] from/to native representations.
/// ///
/// [`&OsStr`]: OsStr
/// [`&str`]: str
/// [`CStr`]: crate::ffi::CStr /// [`CStr`]: crate::ffi::CStr
/// [conversions]: super#conversions /// [conversions]: super#conversions
/// [into]: Into::into
#[cfg_attr(not(test), rustc_diagnostic_item = "OsString")] #[cfg_attr(not(test), rustc_diagnostic_item = "OsString")]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub struct OsString { pub struct OsString {
@ -86,13 +85,12 @@ impl crate::sealed::Sealed for OsString {}
/// This type represents a borrowed reference to a string in the operating system's preferred /// This type represents a borrowed reference to a string in the operating system's preferred
/// representation. /// representation.
/// ///
/// `&OsStr` is to [`OsString`] as [`&str`] is to [`String`]: the former in each pair are borrowed /// `&OsStr` is to [`OsString`] as <code>&[str]</code> is to [`String`]: the
/// references; the latter are owned strings. /// former in each pair are borrowed references; the latter are owned strings.
/// ///
/// See the [module's toplevel documentation about conversions][conversions] for a discussion on /// See the [module's toplevel documentation about conversions][conversions] for a discussion on
/// the traits which `OsStr` implements for [conversions] from/to native representations. /// the traits which `OsStr` implements for [conversions] from/to native representations.
/// ///
/// [`&str`]: str
/// [conversions]: super#conversions /// [conversions]: super#conversions
#[cfg_attr(not(test), rustc_diagnostic_item = "OsStr")] #[cfg_attr(not(test), rustc_diagnostic_item = "OsStr")]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@ -162,9 +160,7 @@ impl OsString {
self.inner.into_string().map_err(|buf| OsString { inner: buf }) self.inner.into_string().map_err(|buf| OsString { inner: buf })
} }
/// Extends the string with the given [`&OsStr`] slice. /// Extends the string with the given <code>&[OsStr]</code> slice.
///
/// [`&OsStr`]: OsStr
/// ///
/// # Examples /// # Examples
/// ///
@ -563,12 +559,10 @@ impl OsStr {
unsafe { &mut *(inner as *mut Slice as *mut OsStr) } unsafe { &mut *(inner as *mut Slice as *mut OsStr) }
} }
/// Yields a [`&str`] slice if the `OsStr` is valid Unicode. /// Yields a <code>&[str]</code> slice if the `OsStr` is valid Unicode.
/// ///
/// This conversion may entail doing a check for UTF-8 validity. /// This conversion may entail doing a check for UTF-8 validity.
/// ///
/// [`&str`]: str
///
/// # Examples /// # Examples
/// ///
/// ``` /// ```
@ -583,7 +577,7 @@ impl OsStr {
self.inner.to_str() self.inner.to_str()
} }
/// Converts an `OsStr` to a [`Cow`]`<`[`str`]`>`. /// Converts an `OsStr` to a <code>[Cow]<[str]></code>.
/// ///
/// Any non-Unicode sequences are replaced with /// Any non-Unicode sequences are replaced with
/// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD]. /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD].
@ -701,7 +695,7 @@ impl OsStr {
self.inner.inner.len() self.inner.inner.len()
} }
/// Converts a [`Box`]`<OsStr>` into an [`OsString`] without copying or allocating. /// Converts a <code>[Box]<[OsStr]></code> into an [`OsString`] without copying or allocating.
#[stable(feature = "into_boxed_os_str", since = "1.20.0")] #[stable(feature = "into_boxed_os_str", since = "1.20.0")]
pub fn into_os_string(self: Box<OsStr>) -> OsString { pub fn into_os_string(self: Box<OsStr>) -> OsString {
let boxed = unsafe { Box::from_raw(Box::into_raw(self) as *mut Slice) }; let boxed = unsafe { Box::from_raw(Box::into_raw(self) as *mut Slice) };
@ -870,7 +864,7 @@ impl From<Cow<'_, OsStr>> for Box<OsStr> {
#[stable(feature = "os_string_from_box", since = "1.18.0")] #[stable(feature = "os_string_from_box", since = "1.18.0")]
impl From<Box<OsStr>> for OsString { impl From<Box<OsStr>> for OsString {
/// Converts a [`Box`]`<`[`OsStr`]`>` into an [`OsString`] without copying or /// Converts a <code>[Box]<[OsStr]></code> into an [`OsString`] without copying or
/// allocating. /// allocating.
#[inline] #[inline]
fn from(boxed: Box<OsStr>) -> OsString { fn from(boxed: Box<OsStr>) -> OsString {
@ -880,7 +874,7 @@ impl From<Box<OsStr>> for OsString {
#[stable(feature = "box_from_os_string", since = "1.20.0")] #[stable(feature = "box_from_os_string", since = "1.20.0")]
impl From<OsString> for Box<OsStr> { impl From<OsString> for Box<OsStr> {
/// Converts an [`OsString`] into a [`Box`]`<OsStr>` without copying or allocating. /// Converts an [`OsString`] into a <code>[Box]<[OsStr]></code> without copying or allocating.
#[inline] #[inline]
fn from(s: OsString) -> Box<OsStr> { fn from(s: OsString) -> Box<OsStr> {
s.into_boxed_os_str() s.into_boxed_os_str()
@ -897,7 +891,7 @@ impl Clone for Box<OsStr> {
#[stable(feature = "shared_from_slice2", since = "1.24.0")] #[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl From<OsString> for Arc<OsStr> { impl From<OsString> for Arc<OsStr> {
/// Converts an [`OsString`] into an [`Arc`]`<OsStr>` without copying or allocating. /// Converts an [`OsString`] into an <code>[Arc]<[OsStr]></code> without copying or allocating.
#[inline] #[inline]
fn from(s: OsString) -> Arc<OsStr> { fn from(s: OsString) -> Arc<OsStr> {
let arc = s.inner.into_arc(); let arc = s.inner.into_arc();
@ -916,7 +910,7 @@ impl From<&OsStr> for Arc<OsStr> {
#[stable(feature = "shared_from_slice2", since = "1.24.0")] #[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl From<OsString> for Rc<OsStr> { impl From<OsString> for Rc<OsStr> {
/// Converts an [`OsString`] into an [`Rc`]`<OsStr>` without copying or allocating. /// Converts an [`OsString`] into an <code>[Rc]<[OsStr]></code> without copying or allocating.
#[inline] #[inline]
fn from(s: OsString) -> Rc<OsStr> { fn from(s: OsString) -> Rc<OsStr> {
let rc = s.inner.into_rc(); let rc = s.inner.into_rc();

View File

@ -106,7 +106,7 @@ pub struct Metadata(fs_imp::FileAttr);
/// Iterator over the entries in a directory. /// Iterator over the entries in a directory.
/// ///
/// This iterator is returned from the [`read_dir`] function of this module and /// This iterator is returned from the [`read_dir`] function of this module and
/// will yield instances of [`io::Result`]`<`[`DirEntry`]`>`. Through a [`DirEntry`] /// will yield instances of <code>[io::Result]<[DirEntry]></code>. Through a [`DirEntry`]
/// information like the entry's path and possibly other metadata can be /// information like the entry's path and possibly other metadata can be
/// learned. /// learned.
/// ///
@ -786,17 +786,17 @@ impl OpenOptions {
/// If a file is opened with both read and append access, beware that after /// If a file is opened with both read and append access, beware that after
/// opening, and after every write, the position for reading may be set at the /// opening, and after every write, the position for reading may be set at the
/// end of the file. So, before writing, save the current position (using /// end of the file. So, before writing, save the current position (using
/// [`seek`]`(`[`SeekFrom`]`::`[`Current`]`(0))`), and restore it before the next read. /// <code>[seek]\([SeekFrom]::[Current]\(0))</code>), and restore it before the next read.
/// ///
/// ## Note /// ## Note
/// ///
/// This function doesn't create the file if it doesn't exist. Use the /// This function doesn't create the file if it doesn't exist. Use the
/// [`OpenOptions::create`] method to do so. /// [`OpenOptions::create`] method to do so.
/// ///
/// [`write()`]: Write::write /// [`write()`]: Write::write "io::Write::write"
/// [`flush()`]: Write::flush /// [`flush()`]: Write::flush "io::Write::flush"
/// [`seek`]: Seek::seek /// [seek]: Seek::seek "io::Seek::seek"
/// [`Current`]: SeekFrom::Current /// [Current]: SeekFrom::Current "io::SeekFrom::Current"
/// ///
/// # Examples /// # Examples
/// ///
@ -2043,7 +2043,7 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
/// Returns an iterator over the entries within a directory. /// Returns an iterator over the entries within a directory.
/// ///
/// The iterator will yield instances of [`io::Result`]`<`[`DirEntry`]`>`. /// The iterator will yield instances of <code>[io::Result]<[DirEntry]></code>.
/// New errors may be encountered after an iterator is initially constructed. /// New errors may be encountered after an iterator is initially constructed.
/// Entries for the current and parent directories (typically `.` and `..`) are /// Entries for the current and parent directories (typically `.` and `..`) are
/// skipped. /// skipped.

View File

@ -15,7 +15,7 @@ use crate::io::{
/// *repeated* read calls to the same file or network socket. It does not /// *repeated* read calls to the same file or network socket. It does not
/// help when reading very large amounts at once, or reading just one or a few /// help when reading very large amounts at once, or reading just one or a few
/// times. It also provides no advantage when reading from a source that is /// times. It also provides no advantage when reading from a source that is
/// already in memory, like a [`Vec`]`<u8>`. /// already in memory, like a <code>[Vec]\<u8></code>.
/// ///
/// When the `BufReader<R>` is dropped, the contents of its buffer will be /// When the `BufReader<R>` is dropped, the contents of its buffer will be
/// discarded. Creating multiple instances of a `BufReader<R>` on the same /// discarded. Creating multiple instances of a `BufReader<R>` on the same
@ -347,7 +347,7 @@ where
impl<R: Seek> Seek for BufReader<R> { impl<R: Seek> Seek for BufReader<R> {
/// Seek to an offset, in bytes, in the underlying reader. /// Seek to an offset, in bytes, in the underlying reader.
/// ///
/// The position used for seeking with [`SeekFrom::Current`]`(_)` is the /// The position used for seeking with <code>[SeekFrom::Current]\(_)</code> is the
/// position the underlying reader would be at if the `BufReader<R>` had no /// position the underlying reader would be at if the `BufReader<R>` had no
/// internal buffer. /// internal buffer.
/// ///
@ -360,11 +360,11 @@ impl<R: Seek> Seek for BufReader<R> {
/// ///
/// See [`std::io::Seek`] for more details. /// See [`std::io::Seek`] for more details.
/// ///
/// Note: In the edge case where you're seeking with [`SeekFrom::Current`]`(n)` /// Note: In the edge case where you're seeking with <code>[SeekFrom::Current]\(n)</code>
/// where `n` minus the internal buffer length overflows an `i64`, two /// where `n` minus the internal buffer length overflows an `i64`, two
/// seeks will be performed instead of one. If the second seek returns /// seeks will be performed instead of one. If the second seek returns
/// [`Err`], the underlying reader will be left at the same position it would /// [`Err`], the underlying reader will be left at the same position it would
/// have if you called `seek` with [`SeekFrom::Current`]`(0)`. /// have if you called `seek` with <code>[SeekFrom::Current]\(0)</code>.
/// ///
/// [`std::io::Seek`]: Seek /// [`std::io::Seek`]: Seek
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {

View File

@ -18,7 +18,7 @@ use crate::ptr;
/// *repeated* write calls to the same file or network socket. It does not /// *repeated* write calls to the same file or network socket. It does not
/// help when writing very large amounts at once, or writing just one or a few /// help when writing very large amounts at once, or writing just one or a few
/// times. It also provides no advantage when writing to a destination that is /// times. It also provides no advantage when writing to a destination that is
/// in memory, like a [`Vec`]`<u8>`. /// in memory, like a <code>[Vec]\<u8></code>.
/// ///
/// It is critical to call [`flush`] before `BufWriter<W>` is dropped. Though /// It is critical to call [`flush`] before `BufWriter<W>` is dropped. Though
/// dropping will attempt to flush the contents of the buffer, any errors /// dropping will attempt to flush the contents of the buffer, any errors

View File

@ -12,13 +12,13 @@ use core::convert::TryInto;
/// [`Seek`] implementation. /// [`Seek`] implementation.
/// ///
/// `Cursor`s are used with in-memory buffers, anything implementing /// `Cursor`s are used with in-memory buffers, anything implementing
/// [`AsRef`]`<[u8]>`, to allow them to implement [`Read`] and/or [`Write`], /// <code>[AsRef]<\[u8]></code>, to allow them to implement [`Read`] and/or [`Write`],
/// allowing these buffers to be used anywhere you might use a reader or writer /// allowing these buffers to be used anywhere you might use a reader or writer
/// that does actual I/O. /// that does actual I/O.
/// ///
/// The standard library implements some I/O traits on various types which /// The standard library implements some I/O traits on various types which
/// are commonly used as a buffer, like `Cursor<`[`Vec`]`<u8>>` and /// are commonly used as a buffer, like <code>Cursor<[Vec]\<u8>></code> and
/// `Cursor<`[`&[u8]`][bytes]`>`. /// <code>Cursor<[&\[u8\]][bytes]></code>.
/// ///
/// # Examples /// # Examples
/// ///
@ -26,7 +26,7 @@ use core::convert::TryInto;
/// code, but use an in-memory buffer in our tests. We can do this with /// code, but use an in-memory buffer in our tests. We can do this with
/// `Cursor`: /// `Cursor`:
/// ///
/// [bytes]: crate::slice /// [bytes]: crate::slice "slice"
/// [`File`]: crate::fs::File /// [`File`]: crate::fs::File
/// ///
/// ```no_run /// ```no_run

View File

@ -854,8 +854,8 @@ pub trait Read {
/// Transforms this `Read` instance to an [`Iterator`] over its bytes. /// Transforms this `Read` instance to an [`Iterator`] over its bytes.
/// ///
/// The returned type implements [`Iterator`] where the `Item` is /// The returned type implements [`Iterator`] where the [`Item`] is
/// [`Result`]`<`[`u8`]`, `[`io::Error`]`>`. /// <code>[Result]<[u8], [io::Error]></code>.
/// The yielded item is [`Ok`] if a byte was successfully read and [`Err`] /// The yielded item is [`Ok`] if a byte was successfully read and [`Err`]
/// otherwise. EOF is mapped to returning [`None`] from this iterator. /// otherwise. EOF is mapped to returning [`None`] from this iterator.
/// ///
@ -863,9 +863,10 @@ pub trait Read {
/// ///
/// [`File`]s implement `Read`: /// [`File`]s implement `Read`:
/// ///
/// [`File`]: crate::fs::File /// [`Item`]: Iterator::Item
/// [`Result`]: crate::result::Result /// [`File`]: crate::fs::File "fs::File"
/// [`io::Error`]: self::Error /// [Result]: crate::result::Result "Result"
/// [io::Error]: self::Error "io::Error"
/// ///
/// ```no_run /// ```no_run
/// use std::io; /// use std::io;
@ -2191,13 +2192,13 @@ pub trait BufRead: Read {
/// `byte`. /// `byte`.
/// ///
/// The iterator returned from this function will return instances of /// The iterator returned from this function will return instances of
/// [`io::Result`]`<`[`Vec<u8>`]`>`. Each vector returned will *not* have /// <code>[io::Result]<[Vec]\<u8>></code>. Each vector returned will *not* have
/// the delimiter byte at the end. /// the delimiter byte at the end.
/// ///
/// This function will yield errors whenever [`read_until`] would have /// This function will yield errors whenever [`read_until`] would have
/// also yielded an error. /// also yielded an error.
/// ///
/// [`io::Result`]: self::Result /// [io::Result]: self::Result "io::Result"
/// [`read_until`]: BufRead::read_until /// [`read_until`]: BufRead::read_until
/// ///
/// # Examples /// # Examples
@ -2228,10 +2229,10 @@ pub trait BufRead: Read {
/// Returns an iterator over the lines of this reader. /// Returns an iterator over the lines of this reader.
/// ///
/// The iterator returned from this function will yield instances of /// The iterator returned from this function will yield instances of
/// [`io::Result`]`<`[`String`]`>`. Each string returned will *not* have a newline /// <code>[io::Result]<[String]></code>. Each string returned will *not* have a newline
/// byte (the `0xA` byte) or `CRLF` (`0xD`, `0xA` bytes) at the end. /// byte (the `0xA` byte) or `CRLF` (`0xD`, `0xA` bytes) at the end.
/// ///
/// [`io::Result`]: self::Result /// [io::Result]: self::Result "io::Result"
/// ///
/// # Examples /// # Examples
/// ///

View File

@ -19,7 +19,7 @@ pub struct Empty;
/// Constructs a new handle to an empty reader. /// Constructs a new handle to an empty reader.
/// ///
/// All reads from the returned reader will return [`Ok`]`(0)`. /// All reads from the returned reader will return <code>[Ok]\(0)</code>.
/// ///
/// # Examples /// # Examples
/// ///

View File

@ -765,15 +765,15 @@ impl hash::Hash for SocketAddrV6 {
/// ///
/// * [`SocketAddr`]: [`to_socket_addrs`] is the identity function. /// * [`SocketAddr`]: [`to_socket_addrs`] is the identity function.
/// ///
/// * [`SocketAddrV4`], [`SocketAddrV6`], `(`[`IpAddr`]`, `[`u16`]`)`, /// * [`SocketAddrV4`], [`SocketAddrV6`], <code>([IpAddr], [u16])</code>,
/// `(`[`Ipv4Addr`]`, `[`u16`]`)`, `(`[`Ipv6Addr`]`, `[`u16`]`)`: /// <code>([Ipv4Addr], [u16])</code>, <code>([Ipv6Addr], [u16])</code>:
/// [`to_socket_addrs`] constructs a [`SocketAddr`] trivially. /// [`to_socket_addrs`] constructs a [`SocketAddr`] trivially.
/// ///
/// * `(`[`&str`]`, `[`u16`]`)`: [`&str`] should be either a string representation /// * <code>(&[str], [u16])</code>: <code>&[str]</code> should be either a string representation
/// of an [`IpAddr`] address as expected by [`FromStr`] implementation or a host /// of an [`IpAddr`] address as expected by [`FromStr`] implementation or a host
/// name. [`u16`] is the port number. /// name. [`u16`] is the port number.
/// ///
/// * [`&str`]: the string should be either a string representation of a /// * <code>&[str]</code>: the string should be either a string representation of a
/// [`SocketAddr`] as expected by its [`FromStr`] implementation or a string like /// [`SocketAddr`] as expected by its [`FromStr`] implementation or a string like
/// `<host_name>:<port>` pair where `<port>` is a [`u16`] value. /// `<host_name>:<port>` pair where `<port>` is a [`u16`] value.
/// ///
@ -789,11 +789,10 @@ impl hash::Hash for SocketAddrV6 {
/// Addresses returned by the operating system that are not IP addresses are /// Addresses returned by the operating system that are not IP addresses are
/// silently ignored. /// silently ignored.
/// ///
/// [`FromStr`]: crate::str::FromStr /// [`FromStr`]: crate::str::FromStr "std::str::FromStr"
/// [`&str`]: str /// [`TcpStream`]: crate::net::TcpStream "net::TcpStream"
/// [`TcpStream`]: crate::net::TcpStream
/// [`to_socket_addrs`]: ToSocketAddrs::to_socket_addrs /// [`to_socket_addrs`]: ToSocketAddrs::to_socket_addrs
/// [`UdpSocket`]: crate::net::UdpSocket /// [`UdpSocket`]: crate::net::UdpSocket "net::UdpSocket"
/// ///
/// # Examples /// # Examples
/// ///
@ -872,7 +871,7 @@ pub trait ToSocketAddrs {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
type Iter: Iterator<Item = SocketAddr>; type Iter: Iterator<Item = SocketAddr>;
/// Converts this object to an iterator of resolved `SocketAddr`s. /// Converts this object to an iterator of resolved [`SocketAddr`]s.
/// ///
/// The returned iterator might not actually yield any values depending on the /// The returned iterator might not actually yield any values depending on the
/// outcome of any resolution performed. /// outcome of any resolution performed.

View File

@ -44,16 +44,16 @@ mod udp;
pub enum Shutdown { pub enum Shutdown {
/// The reading portion of the [`TcpStream`] should be shut down. /// The reading portion of the [`TcpStream`] should be shut down.
/// ///
/// All currently blocked and future [reads] will return [`Ok`]`(0)`. /// All currently blocked and future [reads] will return <code>[Ok]\(0)</code>.
/// ///
/// [reads]: crate::io::Read /// [reads]: crate::io::Read "io::Read"
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
Read, Read,
/// The writing portion of the [`TcpStream`] should be shut down. /// The writing portion of the [`TcpStream`] should be shut down.
/// ///
/// All currently blocked and future [writes] will return an error. /// All currently blocked and future [writes] will return an error.
/// ///
/// [writes]: crate::io::Write /// [writes]: crate::io::Write "io::Write"
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
Write, Write,
/// Both the reading and the writing portions of the [`TcpStream`] should be shut down. /// Both the reading and the writing portions of the [`TcpStream`] should be shut down.

View File

@ -2552,7 +2552,7 @@ impl Path {
/// Returns an iterator over the entries within a directory. /// Returns an iterator over the entries within a directory.
/// ///
/// The iterator will yield instances of [`io::Result`]`<`[`fs::DirEntry`]`>`. New /// The iterator will yield instances of <code>[io::Result]<[fs::DirEntry]></code>. New
/// errors may be encountered after an iterator is initially constructed. /// errors may be encountered after an iterator is initially constructed.
/// ///
/// This is an alias to [`fs::read_dir`]. /// This is an alias to [`fs::read_dir`].

View File

@ -450,7 +450,7 @@ impl SystemTime {
/// as the system clock being adjusted either forwards or backwards). /// as the system clock being adjusted either forwards or backwards).
/// [`Instant`] can be used to measure elapsed time without this risk of failure. /// [`Instant`] can be used to measure elapsed time without this risk of failure.
/// ///
/// If successful, [`Ok`]`(`[`Duration`]`)` is returned where the duration represents /// If successful, <code>[Ok]\([Duration])</code> is returned where the duration represents
/// the amount of time elapsed from the specified measurement to this one. /// the amount of time elapsed from the specified measurement to this one.
/// ///
/// Returns an [`Err`] if `earlier` is later than `self`, and the error /// Returns an [`Err`] if `earlier` is later than `self`, and the error
@ -477,7 +477,7 @@ impl SystemTime {
/// ///
/// This function may fail as the underlying system clock is susceptible to /// This function may fail as the underlying system clock is susceptible to
/// drift and updates (e.g., the system clock could go backwards), so this /// drift and updates (e.g., the system clock could go backwards), so this
/// function might not always succeed. If successful, [`Ok`]`(`[`Duration`]`)` is /// function might not always succeed. If successful, <code>[Ok]\([Duration])</code> is
/// returned where the duration represents the amount of time elapsed from /// returned where the duration represents the amount of time elapsed from
/// this time measurement to the current time. /// this time measurement to the current time.
/// ///