2017-06-13 15:52:59 -07:00
|
|
|
|
//! # The Rust core allocation and collections library
|
2014-05-13 16:10:05 -07:00
|
|
|
|
//!
|
2017-06-13 15:52:59 -07:00
|
|
|
|
//! This library provides smart pointers and collections for managing
|
|
|
|
|
//! heap-allocated values.
|
2014-05-13 16:10:05 -07:00
|
|
|
|
//!
|
2018-06-23 21:48:56 +02:00
|
|
|
|
//! This library, like libcore, normally doesn’t need to be used directly
|
|
|
|
|
//! since its contents are re-exported in the [`std` crate](../std/index.html).
|
|
|
|
|
//! Crates that use the `#![no_std]` attribute however will typically
|
|
|
|
|
//! not depend on `std`, so they’d use this crate instead.
|
2014-05-13 16:10:05 -07:00
|
|
|
|
//!
|
2014-07-10 14:19:17 -07:00
|
|
|
|
//! ## Boxed values
|
2014-05-13 16:10:05 -07:00
|
|
|
|
//!
|
2015-06-09 16:26:21 -04:00
|
|
|
|
//! The [`Box`](boxed/index.html) type is a smart pointer type. There can
|
|
|
|
|
//! only be one owner of a `Box`, and the owner can decide to mutate the
|
|
|
|
|
//! contents, which live on the heap.
|
2014-05-13 16:10:05 -07:00
|
|
|
|
//!
|
2015-05-09 00:12:29 +09:00
|
|
|
|
//! This type can be sent among threads efficiently as the size of a `Box` value
|
2014-08-04 22:48:39 +12:00
|
|
|
|
//! is the same as that of a pointer. Tree-like data structures are often built
|
|
|
|
|
//! with boxes because each node often has only one owner, the parent.
|
2014-05-13 16:10:05 -07:00
|
|
|
|
//!
|
|
|
|
|
//! ## Reference counted pointers
|
|
|
|
|
//!
|
|
|
|
|
//! The [`Rc`](rc/index.html) type is a non-threadsafe reference-counted pointer
|
2015-05-09 00:12:29 +09:00
|
|
|
|
//! type intended for sharing memory within a thread. An `Rc` pointer wraps a
|
2014-05-13 16:10:05 -07:00
|
|
|
|
//! type, `T`, and only allows access to `&T`, a shared reference.
|
|
|
|
|
//!
|
2014-08-04 22:48:39 +12:00
|
|
|
|
//! This type is useful when inherited mutability (such as using `Box`) is too
|
|
|
|
|
//! constraining for an application, and is often paired with the `Cell` or
|
2014-05-13 16:10:05 -07:00
|
|
|
|
//! `RefCell` types in order to allow mutation.
|
|
|
|
|
//!
|
|
|
|
|
//! ## Atomically reference counted pointers
|
|
|
|
|
//!
|
2018-06-15 04:07:09 +02:00
|
|
|
|
//! The [`Arc`](sync/index.html) type is the threadsafe equivalent of the `Rc`
|
2014-05-13 16:10:05 -07:00
|
|
|
|
//! type. It provides all the same functionality of `Rc`, except it requires
|
|
|
|
|
//! that the contained type `T` is shareable. Additionally, `Arc<T>` is itself
|
|
|
|
|
//! sendable while `Rc<T>` is not.
|
|
|
|
|
//!
|
2017-01-28 22:16:16 +00:00
|
|
|
|
//! This type allows for shared access to the contained data, and is often
|
2014-05-13 16:10:05 -07:00
|
|
|
|
//! paired with synchronization primitives such as mutexes to allow mutation of
|
|
|
|
|
//! shared resources.
|
|
|
|
|
//!
|
2017-06-13 15:52:59 -07:00
|
|
|
|
//! ## Collections
|
|
|
|
|
//!
|
|
|
|
|
//! Implementations of the most common general purpose data structures are
|
2018-01-12 16:41:25 -05:00
|
|
|
|
//! defined in this library. They are re-exported through the
|
2017-06-13 15:52:59 -07:00
|
|
|
|
//! [standard collections library](../std/collections/index.html).
|
|
|
|
|
//!
|
2014-05-13 16:10:05 -07:00
|
|
|
|
//! ## Heap interfaces
|
|
|
|
|
//!
|
2018-04-03 14:41:15 +02:00
|
|
|
|
//! The [`alloc`](alloc/index.html) module defines the low-level interface to the
|
2014-10-24 17:34:57 -04:00
|
|
|
|
//! default global allocator. It is not compatible with the libc allocator API.
|
2014-05-13 16:10:05 -07:00
|
|
|
|
|
2015-06-25 10:07:01 -07:00
|
|
|
|
#![allow(unused_attributes)]
|
2015-06-09 11:52:41 -07:00
|
|
|
|
#![unstable(feature = "alloc",
|
|
|
|
|
reason = "this library is unlikely to be stabilized in its current \
|
2015-08-12 22:19:08 -07:00
|
|
|
|
form or name",
|
|
|
|
|
issue = "27783")]
|
2015-08-09 14:15:05 -07:00
|
|
|
|
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
2015-05-15 16:04:01 -07:00
|
|
|
|
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
2015-08-09 14:15:05 -07:00
|
|
|
|
html_root_url = "https://doc.rust-lang.org/nightly/",
|
2015-08-16 17:22:50 +02:00
|
|
|
|
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
|
2015-11-03 14:02:48 +00:00
|
|
|
|
test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
|
2014-05-13 16:10:05 -07:00
|
|
|
|
#![no_std]
|
2015-12-11 13:07:11 -08:00
|
|
|
|
#![needs_allocator]
|
2018-12-17 21:10:24 -05:00
|
|
|
|
|
2019-02-02 12:48:12 +01:00
|
|
|
|
#![deny(rust_2018_idioms)]
|
|
|
|
|
#![allow(explicit_outlives_requirements)]
|
|
|
|
|
|
2018-12-21 11:22:18 +01:00
|
|
|
|
#![warn(deprecated_in_future)]
|
2019-01-28 10:49:11 +01:00
|
|
|
|
#![warn(intra_doc_link_resolution_failure)]
|
|
|
|
|
#![warn(missing_debug_implementations)]
|
2015-06-09 11:18:03 -07:00
|
|
|
|
|
2018-07-25 14:27:27 +01:00
|
|
|
|
#![cfg_attr(not(test), feature(fn_traits))]
|
2017-07-07 15:31:03 -07:00
|
|
|
|
#![cfg_attr(not(test), feature(generator_trait))]
|
2018-07-25 14:27:27 +01:00
|
|
|
|
#![cfg_attr(test, feature(test))]
|
|
|
|
|
|
2018-03-28 22:37:37 +02:00
|
|
|
|
#![feature(allocator_api)]
|
2017-06-13 15:52:59 -07:00
|
|
|
|
#![feature(allow_internal_unstable)]
|
2018-06-08 16:45:27 -04:00
|
|
|
|
#![feature(arbitrary_self_types)]
|
2018-01-10 21:11:55 +01:00
|
|
|
|
#![feature(box_into_raw_non_null)]
|
2017-06-13 15:52:59 -07:00
|
|
|
|
#![feature(box_patterns)]
|
2015-06-09 11:18:03 -07:00
|
|
|
|
#![feature(box_syntax)]
|
2016-10-30 22:14:05 -05:00
|
|
|
|
#![feature(cfg_target_has_atomic)]
|
2015-06-09 11:18:03 -07:00
|
|
|
|
#![feature(coerce_unsized)]
|
2018-10-03 23:40:21 -04:00
|
|
|
|
#![feature(dispatch_from_dyn)]
|
2015-06-09 11:18:03 -07:00
|
|
|
|
#![feature(core_intrinsics)]
|
2015-03-30 17:52:00 -04:00
|
|
|
|
#![feature(custom_attribute)]
|
2016-12-28 17:47:10 -05:00
|
|
|
|
#![feature(dropck_eyepatch)]
|
2017-06-13 15:52:59 -07:00
|
|
|
|
#![feature(exact_size_is_empty)]
|
|
|
|
|
#![feature(fmt_internals)]
|
2015-03-30 17:52:00 -04:00
|
|
|
|
#![feature(fundamental)]
|
2018-05-30 18:23:10 -07:00
|
|
|
|
#![feature(futures_api)]
|
2015-04-27 14:10:49 -07:00
|
|
|
|
#![feature(lang_items)]
|
2018-04-04 18:57:48 +02:00
|
|
|
|
#![feature(libc)]
|
2016-01-22 23:49:57 -08:00
|
|
|
|
#![feature(needs_allocator)]
|
2018-09-26 14:26:46 -07:00
|
|
|
|
#![feature(nll)]
|
2015-01-11 11:09:53 +01:00
|
|
|
|
#![feature(optin_builtin_traits)]
|
2017-06-13 15:52:59 -07:00
|
|
|
|
#![feature(pattern)]
|
2017-12-22 19:29:16 +01:00
|
|
|
|
#![feature(ptr_internals)]
|
2018-03-31 22:35:37 -07:00
|
|
|
|
#![feature(ptr_offset_from)]
|
2017-08-22 14:36:49 -07:00
|
|
|
|
#![feature(rustc_attrs)]
|
Stabilize `Rc`, `Arc` and `Pin` as method receivers
This lets you write methods using `self: Rc<Self>`, `self: Arc<Self>`, `self: Pin<&mut Self>`, `self: Pin<Box<Self>`, and other combinations involving `Pin` and another stdlib receiver type, without needing the `arbitrary_self_types`. Other user-created receiver types can be used, but they still require the feature flag to use.
This is implemented by introducing a new trait, `Receiver`, which the method receiver's type must implement if the `arbitrary_self_types` feature is not enabled. To keep composed receiver types such as `&Arc<Self>` unstable, the receiver type is also required to implement `Deref<Target=Self>` when the feature flag is not enabled.
This lets you use `self: Rc<Self>` and `self: Arc<Self>` in stable Rust, which was not allowed previously. It was agreed that they would be stabilized in #55786. `self: Pin<&Self>` and other pinned receiver types do not require the `arbitrary_self_types` feature, but they cannot be used on stable because `Pin` still requires the `pin` feature.
2018-11-20 11:50:50 -05:00
|
|
|
|
#![feature(receiver_trait)]
|
2017-06-13 15:52:59 -07:00
|
|
|
|
#![feature(specialization)]
|
2015-06-09 11:18:03 -07:00
|
|
|
|
#![feature(staged_api)]
|
2017-06-13 15:52:59 -07:00
|
|
|
|
#![feature(str_internals)]
|
|
|
|
|
#![feature(trusted_len)]
|
2018-03-08 14:36:43 +00:00
|
|
|
|
#![feature(try_reserve)]
|
2015-01-26 14:39:58 -05:00
|
|
|
|
#![feature(unboxed_closures)]
|
2018-04-06 14:23:00 +02:00
|
|
|
|
#![feature(unicode_internals)]
|
2015-06-09 11:18:03 -07:00
|
|
|
|
#![feature(unsize)]
|
2017-07-17 09:32:08 -07:00
|
|
|
|
#![feature(allocator_internals)]
|
2017-10-09 14:45:41 +02:00
|
|
|
|
#![feature(on_unimplemented)]
|
2018-04-26 22:38:39 -05:00
|
|
|
|
#![feature(rustc_const_unstable)]
|
2018-05-05 16:34:43 +08:00
|
|
|
|
#![feature(const_vec_new)]
|
2018-09-16 23:32:16 +02:00
|
|
|
|
#![feature(slice_partition_dedup)]
|
2018-08-19 21:56:49 +02:00
|
|
|
|
#![feature(maybe_uninit)]
|
2018-10-25 23:48:27 +01:00
|
|
|
|
#![feature(alloc_layout_extra)]
|
2019-01-29 16:15:02 +01:00
|
|
|
|
#![feature(try_trait)]
|
2015-06-09 11:52:41 -07:00
|
|
|
|
|
2014-05-13 16:10:05 -07:00
|
|
|
|
// Allow testing this library
|
|
|
|
|
|
2015-09-24 10:00:54 +12:00
|
|
|
|
#[cfg(test)]
|
|
|
|
|
#[macro_use]
|
|
|
|
|
extern crate std;
|
2017-06-13 15:52:59 -07:00
|
|
|
|
#[cfg(test)]
|
|
|
|
|
extern crate test;
|
|
|
|
|
|
2016-10-15 16:32:14 +01:00
|
|
|
|
// Module with internal macros used by other modules (needs to be included before other modules).
|
|
|
|
|
#[macro_use]
|
|
|
|
|
mod macros;
|
|
|
|
|
|
2014-05-13 16:10:05 -07:00
|
|
|
|
// Heaps provided for low-level allocation strategies
|
|
|
|
|
|
2018-04-03 14:41:15 +02:00
|
|
|
|
pub mod alloc;
|
|
|
|
|
|
2018-05-30 18:23:10 -07:00
|
|
|
|
#[unstable(feature = "futures_api",
|
|
|
|
|
reason = "futures in libcore are unstable",
|
|
|
|
|
issue = "50547")]
|
|
|
|
|
pub mod task;
|
2014-05-13 16:10:05 -07:00
|
|
|
|
// Primitive types using the heaps above
|
|
|
|
|
|
2015-02-17 21:41:32 +01:00
|
|
|
|
// Need to conditionally define the mod from `boxed.rs` to avoid
|
|
|
|
|
// duplicating the lang-items when building in test cfg; but also need
|
2018-02-18 17:39:40 +00:00
|
|
|
|
// to allow code to have `use boxed::Box;` declarations.
|
2014-05-13 16:10:05 -07:00
|
|
|
|
#[cfg(not(test))]
|
2014-07-10 14:19:17 -07:00
|
|
|
|
pub mod boxed;
|
2015-01-20 23:57:56 +03:00
|
|
|
|
#[cfg(test)]
|
2015-09-24 10:00:54 +12:00
|
|
|
|
mod boxed {
|
2018-02-18 17:39:40 +00:00
|
|
|
|
pub use std::boxed::Box;
|
2015-09-24 10:00:54 +12:00
|
|
|
|
}
|
2015-02-17 21:41:32 +01:00
|
|
|
|
#[cfg(test)]
|
2015-01-20 23:57:56 +03:00
|
|
|
|
mod boxed_test;
|
2018-06-15 03:52:25 +02:00
|
|
|
|
pub mod collections;
|
2018-08-01 07:37:38 -06:00
|
|
|
|
#[cfg(all(target_has_atomic = "ptr", target_has_atomic = "cas"))]
|
2018-06-15 04:07:09 +02:00
|
|
|
|
pub mod sync;
|
2014-05-13 16:10:05 -07:00
|
|
|
|
pub mod rc;
|
2015-07-09 21:57:21 -07:00
|
|
|
|
pub mod raw_vec;
|
2018-07-07 00:43:11 +02:00
|
|
|
|
pub mod prelude;
|
2017-06-13 15:52:59 -07:00
|
|
|
|
pub mod borrow;
|
|
|
|
|
pub mod fmt;
|
|
|
|
|
pub mod slice;
|
|
|
|
|
pub mod str;
|
|
|
|
|
pub mod string;
|
|
|
|
|
pub mod vec;
|
|
|
|
|
|
|
|
|
|
#[cfg(not(test))]
|
|
|
|
|
mod std {
|
2019-02-02 10:34:36 +01:00
|
|
|
|
pub use core::ops; // RangeFull
|
2017-06-13 15:52:59 -07:00
|
|
|
|
}
|