Improve primitive/std docs separation and headers
This commit is contained in:
parent
dd01122b5c
commit
17ddcb434b
16 changed files with 127 additions and 128 deletions
|
@ -1,4 +1,4 @@
|
||||||
//! A pointer type for heap allocation.
|
//! The `Box<T>` type for heap allocation.
|
||||||
//!
|
//!
|
||||||
//! [`Box<T>`], casually referred to as a 'box', provides the simplest form of
|
//! [`Box<T>`], casually referred to as a 'box', provides the simplest form of
|
||||||
//! heap allocation in Rust. Boxes provide ownership for this allocation, and
|
//! heap allocation in Rust. Boxes provide ownership for this allocation, and
|
||||||
|
|
|
@ -1,82 +1,12 @@
|
||||||
//! A dynamically-sized view into a contiguous sequence, `[T]`.
|
//! Utilities for the slice primitive type.
|
||||||
//!
|
//!
|
||||||
//! *[See also the slice primitive type](slice).*
|
//! *[See also the slice primitive type](slice).*
|
||||||
//!
|
//!
|
||||||
//! Slices are a view into a block of memory represented as a pointer and a
|
//! Most of the structs in this module are iterator types which can only be created
|
||||||
//! length.
|
//! using a certain function. For example, `slice.iter()` yields an [`Iter`].
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! A few functions are provided to create a slice from a value reference
|
||||||
//! // slicing a Vec
|
//! or from a raw pointer.
|
||||||
//! let vec = vec![1, 2, 3];
|
|
||||||
//! let int_slice = &vec[..];
|
|
||||||
//! // coercing an array to a slice
|
|
||||||
//! let str_slice: &[&str] = &["one", "two", "three"];
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! Slices are either mutable or shared. The shared slice type is `&[T]`,
|
|
||||||
//! while the mutable slice type is `&mut [T]`, where `T` represents the element
|
|
||||||
//! type. For example, you can mutate the block of memory that a mutable slice
|
|
||||||
//! points to:
|
|
||||||
//!
|
|
||||||
//! ```
|
|
||||||
//! let x = &mut [1, 2, 3];
|
|
||||||
//! x[1] = 7;
|
|
||||||
//! assert_eq!(x, &[1, 7, 3]);
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! Here are some of the things this module contains:
|
|
||||||
//!
|
|
||||||
//! ## Structs
|
|
||||||
//!
|
|
||||||
//! There are several structs that are useful for slices, such as [`Iter`], which
|
|
||||||
//! represents iteration over a slice.
|
|
||||||
//!
|
|
||||||
//! ## Trait Implementations
|
|
||||||
//!
|
|
||||||
//! There are several implementations of common traits for slices. Some examples
|
|
||||||
//! include:
|
|
||||||
//!
|
|
||||||
//! * [`Clone`]
|
|
||||||
//! * [`Eq`], [`Ord`] - for slices whose element type are [`Eq`] or [`Ord`].
|
|
||||||
//! * [`Hash`] - for slices whose element type is [`Hash`].
|
|
||||||
//!
|
|
||||||
//! ## Iteration
|
|
||||||
//!
|
|
||||||
//! The slices implement `IntoIterator`. The iterator yields references to the
|
|
||||||
//! slice elements.
|
|
||||||
//!
|
|
||||||
//! ```
|
|
||||||
//! let numbers = &[0, 1, 2];
|
|
||||||
//! for n in numbers {
|
|
||||||
//! println!("{n} is a number!");
|
|
||||||
//! }
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! The mutable slice yields mutable references to the elements:
|
|
||||||
//!
|
|
||||||
//! ```
|
|
||||||
//! let mut scores = [7, 8, 9];
|
|
||||||
//! for score in &mut scores[..] {
|
|
||||||
//! *score += 1;
|
|
||||||
//! }
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! This iterator yields mutable references to the slice's elements, so while
|
|
||||||
//! the element type of the slice is `i32`, the element type of the iterator is
|
|
||||||
//! `&mut i32`.
|
|
||||||
//!
|
|
||||||
//! * [`.iter`] and [`.iter_mut`] are the explicit methods to return the default
|
|
||||||
//! iterators.
|
|
||||||
//! * Further methods that return iterators are [`.split`], [`.splitn`],
|
|
||||||
//! [`.chunks`], [`.windows`] and more.
|
|
||||||
//!
|
|
||||||
//! [`Hash`]: core::hash::Hash
|
|
||||||
//! [`.iter`]: slice::iter
|
|
||||||
//! [`.iter_mut`]: slice::iter_mut
|
|
||||||
//! [`.split`]: slice::split
|
|
||||||
//! [`.splitn`]: slice::splitn
|
|
||||||
//! [`.chunks`]: slice::chunks
|
|
||||||
//! [`.windows`]: slice::windows
|
|
||||||
#![stable(feature = "rust1", since = "1.0.0")]
|
#![stable(feature = "rust1", since = "1.0.0")]
|
||||||
// Many of the usings in this module are only used in the test configuration.
|
// Many of the usings in this module are only used in the test configuration.
|
||||||
// It's cleaner to just turn off the unused_imports warning than to fix them.
|
// It's cleaner to just turn off the unused_imports warning than to fix them.
|
||||||
|
|
|
@ -1,26 +1,6 @@
|
||||||
//! Unicode string slices.
|
//! Utilities for the `str` primitive type.
|
||||||
//!
|
//!
|
||||||
//! *[See also the `str` primitive type](str).*
|
//! *[See also the `str` primitive type](str).*
|
||||||
//!
|
|
||||||
//! The `&str` type is one of the two main string types, the other being `String`.
|
|
||||||
//! Unlike its `String` counterpart, its contents are borrowed.
|
|
||||||
//!
|
|
||||||
//! # Basic Usage
|
|
||||||
//!
|
|
||||||
//! A basic string declaration of `&str` type:
|
|
||||||
//!
|
|
||||||
//! ```
|
|
||||||
//! let hello_world = "Hello, World!";
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! Here we have declared a string literal, also known as a string slice.
|
|
||||||
//! String literals have a static lifetime, which means the string `hello_world`
|
|
||||||
//! is guaranteed to be valid for the duration of the entire program.
|
|
||||||
//! We can explicitly specify `hello_world`'s lifetime as well:
|
|
||||||
//!
|
|
||||||
//! ```
|
|
||||||
//! let hello_world: &'static str = "Hello, world!";
|
|
||||||
//! ```
|
|
||||||
|
|
||||||
#![stable(feature = "rust1", since = "1.0.0")]
|
#![stable(feature = "rust1", since = "1.0.0")]
|
||||||
// Many of the usings in this module are only used in the test configuration.
|
// Many of the usings in this module are only used in the test configuration.
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
//! This module contains the `Any` trait, which enables dynamic typing
|
//! Utilities for dynamic typing or type reflection.
|
||||||
//! of any `'static` type through runtime reflection. It also contains the
|
|
||||||
//! `Provider` trait and accompanying API, which enable trait objects to provide
|
|
||||||
//! data based on typed requests, an alternate form of runtime reflection.
|
|
||||||
//!
|
//!
|
||||||
//! # `Any` and `TypeId`
|
//! # `Any` and `TypeId`
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! Helper functions and types for fixed-length arrays.
|
//! Utilities for the array primitive type.
|
||||||
//!
|
//!
|
||||||
//! *[See also the array primitive type](array).*
|
//! *[See also the array primitive type](array).*
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! A module for working with borrowed data.
|
//! Utilities for working with borrowed data.
|
||||||
|
|
||||||
#![stable(feature = "rust1", since = "1.0.0")]
|
#![stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
//! A character type.
|
//! Utilities for the `char` primitive type.
|
||||||
|
//!
|
||||||
|
//! *[See also the `char` primitive type](primitive@char).*
|
||||||
//!
|
//!
|
||||||
//! The `char` type represents a single character. More specifically, since
|
//! The `char` type represents a single character. More specifically, since
|
||||||
//! 'character' isn't a well-defined concept in Unicode, `char` is a '[Unicode
|
//! 'character' isn't a well-defined concept in Unicode, `char` is a '[Unicode
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Functionality for ordering and comparison.
|
//! Utilities for comparing and ordering values.
|
||||||
//!
|
//!
|
||||||
//! This module contains various tools for ordering and comparing values. In
|
//! This module contains various tools for comparing and ordering values. In
|
||||||
//! summary:
|
//! summary:
|
||||||
//!
|
//!
|
||||||
//! * [`Eq`] and [`PartialEq`] are traits that allow you to define total and
|
//! * [`Eq`] and [`PartialEq`] are traits that allow you to define total and
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! The `Default` trait for types which may have meaningful default values.
|
//! The `Default` trait for types with a default value.
|
||||||
|
|
||||||
#![stable(feature = "rust1", since = "1.0.0")]
|
#![stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! Constants specific to the `f32` single-precision floating point type.
|
//! Constants for the `f32` single-precision floating point type.
|
||||||
//!
|
//!
|
||||||
//! *[See also the `f32` primitive type][f32].*
|
//! *[See also the `f32` primitive type][f32].*
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! Constants specific to the `f64` double-precision floating point type.
|
//! Constants for the `f64` double-precision floating point type.
|
||||||
//!
|
//!
|
||||||
//! *[See also the `f64` primitive type][f64].*
|
//! *[See also the `f64` primitive type][f64].*
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -801,11 +801,53 @@ mod prim_array {}
|
||||||
/// assert_eq!(2 * pointer_size, std::mem::size_of::<Box<[u8]>>());
|
/// assert_eq!(2 * pointer_size, std::mem::size_of::<Box<[u8]>>());
|
||||||
/// assert_eq!(2 * pointer_size, std::mem::size_of::<Rc<[u8]>>());
|
/// assert_eq!(2 * pointer_size, std::mem::size_of::<Rc<[u8]>>());
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// ## Trait Implementations
|
||||||
|
///
|
||||||
|
/// Some traits are implemented for slices if the element type implements
|
||||||
|
/// that trait. This includes [`Eq`], [`Hash`] and [`Ord`].
|
||||||
|
///
|
||||||
|
/// ## Iteration
|
||||||
|
///
|
||||||
|
/// The slices implement `IntoIterator`. The iterator yields references to the
|
||||||
|
/// slice elements.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// let numbers: &[i32] = &[0, 1, 2];
|
||||||
|
/// for n in numbers {
|
||||||
|
/// println!("{n} is a number!");
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// The mutable slice yields mutable references to the elements:
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// let mut scores: &mut [i32] = &mut [7, 8, 9];
|
||||||
|
/// for score in scores {
|
||||||
|
/// *score += 1;
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// This iterator yields mutable references to the slice's elements, so while
|
||||||
|
/// the element type of the slice is `i32`, the element type of the iterator is
|
||||||
|
/// `&mut i32`.
|
||||||
|
///
|
||||||
|
/// * [`.iter`] and [`.iter_mut`] are the explicit methods to return the default
|
||||||
|
/// iterators.
|
||||||
|
/// * Further methods that return iterators are [`.split`], [`.splitn`],
|
||||||
|
/// [`.chunks`], [`.windows`] and more.
|
||||||
|
///
|
||||||
|
/// [`Hash`]: core::hash::Hash
|
||||||
|
/// [`.iter`]: slice::iter
|
||||||
|
/// [`.iter_mut`]: slice::iter_mut
|
||||||
|
/// [`.split`]: slice::split
|
||||||
|
/// [`.splitn`]: slice::splitn
|
||||||
|
/// [`.chunks`]: slice::chunks
|
||||||
|
/// [`.windows`]: slice::windows
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
mod prim_slice {}
|
mod prim_slice {}
|
||||||
|
|
||||||
#[doc(primitive = "str")]
|
#[doc(primitive = "str")]
|
||||||
//
|
|
||||||
/// String slices.
|
/// String slices.
|
||||||
///
|
///
|
||||||
/// *[See also the `std::str` module](crate::str).*
|
/// *[See also the `std::str` module](crate::str).*
|
||||||
|
@ -816,19 +858,22 @@ mod prim_slice {}
|
||||||
///
|
///
|
||||||
/// String slices are always valid UTF-8.
|
/// String slices are always valid UTF-8.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Basic Usage
|
||||||
///
|
///
|
||||||
/// String literals are string slices:
|
/// String literals are string slices:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// let hello = "Hello, world!";
|
/// let hello_world = "Hello, World!";
|
||||||
///
|
|
||||||
/// // with an explicit type annotation
|
|
||||||
/// let hello: &'static str = "Hello, world!";
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// They are `'static` because they're stored directly in the final binary, and
|
/// Here we have declared a string slice initialized with a string literal.
|
||||||
/// so will be valid for the `'static` duration.
|
/// String literals have a static lifetime, which means the string `hello_world`
|
||||||
|
/// is guaranteed to be valid for the duration of the entire program.
|
||||||
|
/// We can explicitly specify `hello_world`'s lifetime as well:
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// let hello_world: &'static str = "Hello, world!";
|
||||||
|
/// ```
|
||||||
///
|
///
|
||||||
/// # Representation
|
/// # Representation
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! Interfaces for working with Errors.
|
//! The `Error` trait provides common functionality for errors.
|
||||||
//!
|
//!
|
||||||
//! # Error Handling In Rust
|
//! # Error Handling In Rust
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! Constants specific to the `f32` single-precision floating point type.
|
//! Constants for the `f32` single-precision floating point type.
|
||||||
//!
|
//!
|
||||||
//! *[See also the `f32` primitive type](primitive@f32).*
|
//! *[See also the `f32` primitive type](primitive@f32).*
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! Constants specific to the `f64` double-precision floating point type.
|
//! Constants for the `f64` double-precision floating point type.
|
||||||
//!
|
//!
|
||||||
//! *[See also the `f64` primitive type](primitive@f64).*
|
//! *[See also the `f64` primitive type](primitive@f64).*
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -801,11 +801,53 @@ mod prim_array {}
|
||||||
/// assert_eq!(2 * pointer_size, std::mem::size_of::<Box<[u8]>>());
|
/// assert_eq!(2 * pointer_size, std::mem::size_of::<Box<[u8]>>());
|
||||||
/// assert_eq!(2 * pointer_size, std::mem::size_of::<Rc<[u8]>>());
|
/// assert_eq!(2 * pointer_size, std::mem::size_of::<Rc<[u8]>>());
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// ## Trait Implementations
|
||||||
|
///
|
||||||
|
/// Some traits are implemented for slices if the element type implements
|
||||||
|
/// that trait. This includes [`Eq`], [`Hash`] and [`Ord`].
|
||||||
|
///
|
||||||
|
/// ## Iteration
|
||||||
|
///
|
||||||
|
/// The slices implement `IntoIterator`. The iterator yields references to the
|
||||||
|
/// slice elements.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// let numbers: &[i32] = &[0, 1, 2];
|
||||||
|
/// for n in numbers {
|
||||||
|
/// println!("{n} is a number!");
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// The mutable slice yields mutable references to the elements:
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// let mut scores: &mut [i32] = &mut [7, 8, 9];
|
||||||
|
/// for score in scores {
|
||||||
|
/// *score += 1;
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// This iterator yields mutable references to the slice's elements, so while
|
||||||
|
/// the element type of the slice is `i32`, the element type of the iterator is
|
||||||
|
/// `&mut i32`.
|
||||||
|
///
|
||||||
|
/// * [`.iter`] and [`.iter_mut`] are the explicit methods to return the default
|
||||||
|
/// iterators.
|
||||||
|
/// * Further methods that return iterators are [`.split`], [`.splitn`],
|
||||||
|
/// [`.chunks`], [`.windows`] and more.
|
||||||
|
///
|
||||||
|
/// [`Hash`]: core::hash::Hash
|
||||||
|
/// [`.iter`]: slice::iter
|
||||||
|
/// [`.iter_mut`]: slice::iter_mut
|
||||||
|
/// [`.split`]: slice::split
|
||||||
|
/// [`.splitn`]: slice::splitn
|
||||||
|
/// [`.chunks`]: slice::chunks
|
||||||
|
/// [`.windows`]: slice::windows
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
mod prim_slice {}
|
mod prim_slice {}
|
||||||
|
|
||||||
#[doc(primitive = "str")]
|
#[doc(primitive = "str")]
|
||||||
//
|
|
||||||
/// String slices.
|
/// String slices.
|
||||||
///
|
///
|
||||||
/// *[See also the `std::str` module](crate::str).*
|
/// *[See also the `std::str` module](crate::str).*
|
||||||
|
@ -816,19 +858,22 @@ mod prim_slice {}
|
||||||
///
|
///
|
||||||
/// String slices are always valid UTF-8.
|
/// String slices are always valid UTF-8.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Basic Usage
|
||||||
///
|
///
|
||||||
/// String literals are string slices:
|
/// String literals are string slices:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// let hello = "Hello, world!";
|
/// let hello_world = "Hello, World!";
|
||||||
///
|
|
||||||
/// // with an explicit type annotation
|
|
||||||
/// let hello: &'static str = "Hello, world!";
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// They are `'static` because they're stored directly in the final binary, and
|
/// Here we have declared a string slice initialized with a string literal.
|
||||||
/// so will be valid for the `'static` duration.
|
/// String literals have a static lifetime, which means the string `hello_world`
|
||||||
|
/// is guaranteed to be valid for the duration of the entire program.
|
||||||
|
/// We can explicitly specify `hello_world`'s lifetime as well:
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// let hello_world: &'static str = "Hello, world!";
|
||||||
|
/// ```
|
||||||
///
|
///
|
||||||
/// # Representation
|
/// # Representation
|
||||||
///
|
///
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue