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 #![cfg_attr(not(bootstrap), feature(const_in_array_repeat_expressions))]
81 #![feature(const_generic_impls_guard)]
82 #![feature(const_generics)]
83 #![feature(dispatch_from_dyn)]
84 #![feature(core_intrinsics)]
85 #![feature(dropck_eyepatch)]
86 #![feature(exact_size_is_empty)]
87 #![feature(fmt_internals)]
88 #![feature(fn_traits)]
89 #![feature(fundamental)]
90 #![feature(internal_uninit_const)]
91 #![feature(lang_items)]
94 #![feature(optin_builtin_traits)]
96 #![feature(ptr_internals)]
97 #![feature(ptr_offset_from)]
98 #![feature(rustc_attrs)]
99 #![feature(receiver_trait)]
100 #![feature(slice_from_raw_parts)]
101 #![feature(specialization)]
102 #![feature(staged_api)]
103 #![feature(std_internals)]
104 #![feature(str_internals)]
105 #![feature(trusted_len)]
106 #![feature(try_reserve)]
107 #![feature(unboxed_closures)]
108 #![feature(unicode_internals)]
110 #![feature(unsized_locals)]
111 #![feature(allocator_internals)]
112 #![feature(on_unimplemented)]
113 #![feature(rustc_const_unstable)]
114 #![feature(const_vec_new)]
115 #![feature(slice_partition_dedup)]
116 #![feature(maybe_uninit_extra, maybe_uninit_slice, maybe_uninit_array)]
117 #![feature(alloc_layout_extra)]
118 #![feature(try_trait)]
119 #![feature(mem_take)]
121 // Allow testing this library
129 // Module with internal macros used by other modules (needs to be included before other modules).
133 // Heaps provided for low-level allocation strategies
137 // Primitive types using the heaps above
139 // Need to conditionally define the mod from `boxed.rs` to avoid
140 // duplicating the lang-items when building in test cfg; but also need
141 // to allow code to have `use boxed::Box;` declarations.
146 pub use std::boxed::Box;
151 #[cfg(all(target_has_atomic = "ptr", target_has_atomic = "cas"))]
165 pub use core::ops; // RangeFull