1 //! # The Rust core allocation and collections library
3 //! This library provides smart pointers and collections for managing
4 //! heap-allocated values.
6 //! This library, like libcore, normally doesn’t need to be used directly
7 //! since its contents are re-exported in the [`std` crate](../std/index.html).
8 //! Crates that use the `#![no_std]` attribute however will typically
9 //! not depend on `std`, so they’d use this crate instead.
13 //! The [`Box`](boxed/index.html) type is a smart pointer type. There can
14 //! only be one owner of a `Box`, and the owner can decide to mutate the
15 //! contents, which live on the heap.
17 //! This type can be sent among threads efficiently as the size of a `Box` value
18 //! is the same as that of a pointer. Tree-like data structures are often built
19 //! with boxes because each node often has only one owner, the parent.
21 //! ## Reference counted pointers
23 //! The [`Rc`](rc/index.html) type is a non-threadsafe reference-counted pointer
24 //! type intended for sharing memory within a thread. An `Rc` pointer wraps a
25 //! type, `T`, and only allows access to `&T`, a shared reference.
27 //! This type is useful when inherited mutability (such as using `Box`) is too
28 //! constraining for an application, and is often paired with the `Cell` or
29 //! `RefCell` types in order to allow mutation.
31 //! ## Atomically reference counted pointers
33 //! The [`Arc`](sync/index.html) type is the threadsafe equivalent of the `Rc`
34 //! type. It provides all the same functionality of `Rc`, except it requires
35 //! that the contained type `T` is shareable. Additionally, `Arc<T>` is itself
36 //! sendable while `Rc<T>` is not.
38 //! This type allows for shared access to the contained data, and is often
39 //! paired with synchronization primitives such as mutexes to allow mutation of
44 //! Implementations of the most common general purpose data structures are
45 //! defined in this library. They are re-exported through the
46 //! [standard collections library](../std/collections/index.html).
48 //! ## Heap interfaces
50 //! The [`alloc`](alloc/index.html) module defines the low-level interface to the
51 //! default global allocator. It is not compatible with the libc allocator API.
53 #![allow(unused_attributes)]
54 #![stable(feature = "alloc", since = "1.36.0")]
55 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
56 issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
57 test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
61 #![warn(deprecated_in_future)]
62 #![warn(missing_docs)]
63 #![warn(missing_debug_implementations)]
64 #![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings
66 #![deny(rust_2018_idioms)]
67 #![allow(explicit_outlives_requirements)]
69 #![cfg_attr(not(test), feature(generator_trait))]
70 #![cfg_attr(test, feature(test))]
72 #![feature(allocator_api)]
73 #![feature(allow_internal_unstable)]
74 #![feature(arbitrary_self_types)]
75 #![feature(box_into_raw_non_null)]
76 #![feature(box_patterns)]
77 #![feature(box_syntax)]
78 #![feature(cfg_target_has_atomic)]
79 #![feature(coerce_unsized)]
80 #![feature(dispatch_from_dyn)]
81 #![feature(core_intrinsics)]
82 #![feature(custom_attribute)]
83 #![feature(dropck_eyepatch)]
84 #![feature(exact_size_is_empty)]
85 #![feature(fmt_internals)]
86 #![feature(fn_traits)]
87 #![feature(fundamental)]
88 #![feature(lang_items)]
91 #![feature(optin_builtin_traits)]
93 #![feature(ptr_internals)]
94 #![feature(ptr_offset_from)]
95 #![feature(rustc_attrs)]
96 #![feature(receiver_trait)]
97 #![feature(specialization)]
98 #![feature(staged_api)]
99 #![feature(std_internals)]
100 #![feature(str_internals)]
101 #![feature(trusted_len)]
102 #![feature(try_reserve)]
103 #![feature(unboxed_closures)]
104 #![feature(unicode_internals)]
106 #![feature(unsized_locals)]
107 #![feature(allocator_internals)]
108 #![feature(on_unimplemented)]
109 #![feature(rustc_const_unstable)]
110 #![feature(const_vec_new)]
111 #![feature(slice_partition_dedup)]
112 #![feature(maybe_uninit_extra, maybe_uninit_slice, maybe_uninit_array)]
113 #![feature(alloc_layout_extra)]
114 #![feature(try_trait)]
115 #![feature(iter_nth_back)]
117 // Allow testing this library
125 // Module with internal macros used by other modules (needs to be included before other modules).
129 // Heaps provided for low-level allocation strategies
133 // Primitive types using the heaps above
135 // Need to conditionally define the mod from `boxed.rs` to avoid
136 // duplicating the lang-items when building in test cfg; but also need
137 // to allow code to have `use boxed::Box;` declarations.
142 pub use std::boxed::Box;
147 #[cfg(all(target_has_atomic = "ptr", target_has_atomic = "cas"))]
161 pub use core::ops; // RangeFull