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`] type is a smart pointer type. There can only be one owner of a
14 //! [`Box`], and the owner can decide to mutate the contents, which live on the
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`] type is a non-threadsafe reference-counted pointer type intended
24 //! for sharing memory within a thread. An [`Rc`] pointer wraps a type, `T`, and
25 //! 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`] type is the threadsafe equivalent of the [`Rc`] type. It
34 //! provides all the same functionality of [`Rc`], except it requires that the
35 //! contained type `T` is shareable. Additionally, [`Arc<T>`][`Arc`] is itself
36 //! sendable while [`Rc<T>`][`Rc`] 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.
55 //! [`Cell`]: core::cell
57 //! [`RefCell`]: core::cell
59 // To run liballoc tests without x.py without ending up with two copies of liballoc, Miri needs to be
60 // able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
61 // rustc itself never sets the feature, so this line has no affect there.
62 #![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
63 #![allow(unused_attributes)]
64 #![stable(feature = "alloc", since = "1.36.0")]
66 html_playground_url = "https://play.rust-lang.org/",
67 issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
68 test(no_crate_inject, attr(allow(unused_variables), deny(warnings)))
72 #![warn(deprecated_in_future)]
73 #![warn(missing_docs)]
74 #![warn(missing_debug_implementations)]
75 #![allow(explicit_outlives_requirements)]
76 #![deny(unsafe_op_in_unsafe_fn)]
77 #![feature(rustc_allow_const_fn_unstable)]
78 #![cfg_attr(not(test), feature(generator_trait))]
79 #![cfg_attr(test, feature(test))]
80 #![cfg_attr(test, feature(new_uninit))]
81 #![feature(allocator_api)]
82 #![feature(array_chunks)]
83 #![feature(array_methods)]
84 #![feature(array_windows)]
85 #![feature(allow_internal_unstable)]
86 #![feature(arbitrary_self_types)]
87 #![feature(async_stream)]
88 #![cfg_attr(bootstrap, feature(bindings_after_at))]
89 #![feature(box_patterns)]
90 #![feature(box_syntax)]
91 #![feature(cfg_sanitize)]
92 #![feature(cfg_target_has_atomic)]
93 #![feature(coerce_unsized)]
94 #![cfg_attr(not(no_global_oom_handling), feature(const_btree_new))]
95 #![feature(const_fn_trait_bound)]
96 #![feature(cow_is_borrowed)]
97 #![feature(const_cow_is_borrowed)]
98 #![feature(const_trait_impl)]
99 #![feature(destructuring_assignment)]
100 #![feature(dispatch_from_dyn)]
101 #![feature(core_intrinsics)]
102 #![feature(dropck_eyepatch)]
103 #![feature(exact_size_is_empty)]
104 #![feature(exclusive_range_pattern)]
105 #![feature(extend_one)]
106 #![feature(fmt_internals)]
107 #![feature(fn_traits)]
108 #![feature(fundamental)]
109 #![feature(inplace_iteration)]
110 // Technically, this is a bug in rustdoc: rustdoc sees the documentation on `#[lang = slice_alloc]`
111 // blocks is for `&[T]`, which also has documentation using this feature in `core`, and gets mad
112 // that the feature-gate isn't enabled. Ideally, it wouldn't check for the feature gate for docs
113 // from other crates, but since this can only appear for lang items, it doesn't seem worth fixing.
114 #![feature(intra_doc_pointers)]
115 #![feature(iter_zip)]
116 #![feature(lang_items)]
117 #![feature(layout_for_ptr)]
118 #![feature(negative_impls)]
119 #![feature(never_type)]
121 #![feature(nonnull_slice_from_raw_parts)]
122 #![feature(auto_traits)]
123 #![feature(option_result_unwrap_unchecked)]
125 #![feature(ptr_internals)]
126 #![feature(rustc_attrs)]
127 #![feature(receiver_trait)]
128 #![feature(min_specialization)]
129 #![feature(set_ptr_value)]
130 #![feature(slice_ptr_get)]
131 #![feature(slice_ptr_len)]
132 #![feature(slice_range)]
133 #![feature(staged_api)]
134 #![feature(str_internals)]
135 #![feature(trusted_len)]
136 #![feature(unboxed_closures)]
137 #![feature(unicode_internals)]
139 #![feature(unsized_fn_params)]
140 #![feature(allocator_internals)]
141 #![feature(slice_partition_dedup)]
142 #![feature(maybe_uninit_extra, maybe_uninit_slice, maybe_uninit_uninit_array)]
143 #![feature(alloc_layout_extra)]
144 #![feature(trusted_random_access)]
145 #![feature(try_trait_v2)]
146 #![cfg_attr(bootstrap, feature(min_type_alias_impl_trait))]
147 #![cfg_attr(not(bootstrap), feature(type_alias_impl_trait))]
148 #![feature(associated_type_bounds)]
149 #![feature(slice_group_by)]
150 #![feature(decl_macro)]
151 // Allow testing this library
159 // Module with internal macros used by other modules (needs to be included before other modules).
163 // Heaps provided for low-level allocation strategies
167 // Primitive types using the heaps above
169 // Need to conditionally define the mod from `boxed.rs` to avoid
170 // duplicating the lang-items when building in test cfg; but also need
171 // to allow code to have `use boxed::Box;` declarations.
176 pub use std::boxed::Box;
187 #[cfg(target_has_atomic = "ptr")]
189 #[cfg(all(not(no_global_oom_handling), target_has_atomic = "ptr"))]
196 #[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
198 pub use core::format_args;