Skip to main content

alloc/
lib.rs

1//! **You are viewing the documentation of the Rust core allocation and
2//! collections library as a part of the Fortanix Rust EDP.** There are no
3//! changes compared to the normal the core allocation and collections library.
4//!
5//! ---
6//!
7//! # The Rust core allocation and collections library
8//!
9//! This library provides smart pointers and collections for managing
10//! heap-allocated values.
11//!
12//! This library, like core, normally doesn’t need to be used directly
13//! since its contents are re-exported in the [`std` crate](../std/index.html).
14//! Crates that use the `#![no_std]` attribute however will typically
15//! not depend on `std`, so they’d use this crate instead.
16//!
17//! ## Boxed values
18//!
19//! The [`Box`] type is a smart pointer type. There can only be one owner of a
20//! [`Box`], and the owner can decide to mutate the contents, which live on the
21//! heap.
22//!
23//! This type can be sent among threads efficiently as the size of a `Box` value
24//! is the same as that of a pointer. Tree-like data structures are often built
25//! with boxes because each node often has only one owner, the parent.
26//!
27//! ## Reference counted pointers
28//!
29//! The [`Rc`] type is a non-threadsafe reference-counted pointer type intended
30//! for sharing memory within a thread. An [`Rc`] pointer wraps a type, `T`, and
31//! only allows access to `&T`, a shared reference.
32//!
33//! This type is useful when inherited mutability (such as using [`Box`]) is too
34//! constraining for an application, and is often paired with the [`Cell`] or
35//! [`RefCell`] types in order to allow mutation.
36//!
37//! ## Atomically reference counted pointers
38//!
39//! The [`Arc`] type is the threadsafe equivalent of the [`Rc`] type. It
40//! provides all the same functionality of [`Rc`], except it requires that the
41//! contained type `T` is shareable. Additionally, [`Arc<T>`][`Arc`] is itself
42//! sendable while [`Rc<T>`][`Rc`] is not.
43//!
44//! This type allows for shared access to the contained data, and is often
45//! paired with synchronization primitives such as mutexes to allow mutation of
46//! shared resources.
47//!
48//! ## Collections
49//!
50//! Implementations of the most common general purpose data structures are
51//! defined in this library. They are re-exported through the
52//! [standard collections library](../std/collections/index.html).
53//!
54//! ## Heap interfaces
55//!
56//! The [`alloc`](alloc/index.html) module defines the low-level interface to the
57//! default global allocator. It is not compatible with the libc allocator API.
58//!
59//! [`Arc`]: sync
60//! [`Box`]: boxed
61//! [`Cell`]: core::cell
62//! [`Rc`]: rc
63//! [`RefCell`]: core::cell
64
65#![allow(unused_features)]
66#![allow(incomplete_features)]
67#![expect(clippy::partialeq_ne_impl, reason = "we need to implement ne for a lot of alloc types")]
68#![stable(feature = "alloc", since = "1.36.0")]
69#![doc(
70    html_logo_url = "https://edp.fortanix.com/img/docs/edp-logo.svg",
71    html_favicon_url = "https://edp.fortanix.com/favicon.ico",
72    html_root_url = "https://edp.fortanix.com/docs/api/",
73    html_playground_url = "https://play.rust-lang.org/",
74    issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
75    test(no_crate_inject, attr(allow(unused_variables, duplicate_features), deny(warnings)))
76)]
77#![doc(auto_cfg(
78    hide(no_global_oom_handling, no_rc, no_sync),
79    hide(target_has_atomic, values("ptr")),
80))]
81#![doc(rust_logo)]
82#![feature(rustdoc_internals)]
83#![no_std]
84#![needs_allocator]
85// Lints:
86#![deny(unsafe_op_in_unsafe_fn)]
87#![deny(implicit_provenance_casts)]
88#![warn(deprecated_in_future)]
89#![warn(missing_debug_implementations)]
90#![warn(missing_docs)]
91#![allow(explicit_outlives_requirements)]
92#![warn(multiple_supertrait_upcastable)]
93#![allow(internal_features)]
94#![allow(rustdoc::redundant_explicit_links)]
95#![warn(rustdoc::unescaped_backticks)]
96#![deny(ffi_unwind_calls)]
97#![warn(unreachable_pub)]
98//
99// Library features:
100// tidy-alphabetical-start
101#![feature(allocator_ext)]
102#![feature(array_into_iter_constructors)]
103#![feature(ascii_char)]
104#![feature(async_fn_traits)]
105#![feature(async_iterator)]
106#![feature(borrowed_buf_init)]
107#![feature(byte_str)]
108#![feature(byte_str_internals)]
109#![feature(can_vector)]
110#![feature(case_ignorable)]
111#![feature(cast_maybe_uninit)]
112#![feature(cell_get_cloned)]
113#![feature(char_internals)]
114#![feature(clone_to_uninit)]
115#![feature(coerce_unsized)]
116#![feature(const_clone)]
117#![feature(const_cmp)]
118#![feature(const_convert)]
119#![feature(const_default)]
120#![feature(const_destruct)]
121#![feature(const_drop_in_place)]
122#![feature(const_eval_select)]
123#![feature(const_heap)]
124#![feature(const_index)]
125#![feature(const_option_ops)]
126#![feature(const_result_trait_fn)]
127#![feature(const_try)]
128#![feature(copied_into_inner)]
129#![feature(core_intrinsics)]
130#![feature(core_io)]
131#![feature(core_io_borrowed_buf)]
132#![feature(core_io_internals)]
133#![feature(cursor_split)]
134#![feature(deprecated_suggestion)]
135#![feature(deref_pure_trait)]
136#![feature(derive_const)]
137#![feature(diagnostic_on_move)]
138#![feature(dispatch_from_dyn)]
139#![feature(ergonomic_clones)]
140#![feature(error_generic_member_access)]
141#![feature(exact_size_is_empty)]
142#![feature(extend_one)]
143#![feature(extend_one_unchecked)]
144#![feature(fmt_arguments_from_str)]
145#![feature(fmt_internals)]
146#![feature(fn_traits)]
147#![feature(formatting_options)]
148#![feature(freeze)]
149#![feature(generic_atomic)]
150#![feature(hasher_prefixfree_extras)]
151#![feature(inplace_iteration)]
152#![feature(io_const_error)]
153#![feature(io_const_error_internals)]
154#![feature(io_slice_as_bytes)]
155#![feature(iter_advance_by)]
156#![feature(iter_next_chunk)]
157#![feature(legacy_receiver_trait)]
158#![feature(likely_unlikely)]
159#![feature(local_waker)]
160#![feature(marker_trait_attr)]
161#![feature(maybe_uninit_array_assume_init)]
162#![feature(maybe_uninit_fill)]
163#![feature(maybe_uninit_uninit_array_transpose)]
164#![feature(panic_internals)]
165#![feature(pattern)]
166#![feature(pin_coerce_unsized_trait)]
167#![feature(ptr_alignment_type)]
168#![feature(ptr_cast_slice)]
169#![feature(ptr_metadata)]
170#![feature(random)]
171#![feature(raw_os_error_ty)]
172#![feature(rev_into_inner)]
173#![feature(seek_stream_len)]
174#![feature(set_ptr_value)]
175#![feature(share_trait)]
176#![feature(sized_type_properties)]
177#![feature(slice_from_ptr_range)]
178#![feature(slice_index_methods)]
179#![feature(slice_iter_mut_as_mut_slice)]
180#![feature(slice_ptr_get)]
181#![feature(slice_range)]
182#![feature(std_internals)]
183#![feature(temporary_niche_types)]
184#![feature(titlecase)]
185#![feature(transmutability)]
186#![feature(trivial_clone)]
187#![feature(trusted_fused)]
188#![feature(trusted_len)]
189#![feature(trusted_random_access)]
190#![feature(try_blocks)]
191#![feature(try_trait_v2)]
192#![feature(try_trait_v2_residual)]
193#![feature(tuple_trait)]
194#![feature(ub_checks)]
195#![feature(unicode_internals)]
196#![feature(unsize)]
197#![feature(write_all_vectored)]
198#![feature(wtf8_internals)]
199// tidy-alphabetical-end
200//
201// Language features:
202// tidy-alphabetical-start
203#![feature(allocator_internals)]
204#![feature(allow_internal_unstable)]
205#![feature(cfg_sanitize)]
206#![feature(const_closures)]
207#![feature(const_precise_live_drops)]
208#![feature(const_trait_impl)]
209#![feature(coroutine_trait)]
210#![feature(decl_macro)]
211#![feature(dropck_eyepatch)]
212#![feature(fundamental)]
213#![feature(impl_restriction)]
214#![feature(intrinsics)]
215#![feature(lang_items)]
216#![feature(min_specialization)]
217#![feature(multiple_supertrait_upcastable)]
218#![feature(negative_impls)]
219#![feature(rustc_attrs)]
220#![feature(slice_internals)]
221#![feature(staged_api)]
222#![feature(stmt_expr_attributes)]
223#![feature(strict_provenance_lints)]
224#![feature(unboxed_closures)]
225#![feature(unsized_fn_params)]
226#![feature(with_negative_coherence)]
227#![rustc_preserve_ub_checks]
228// tidy-alphabetical-end
229//
230// Rustdoc features:
231#![feature(doc_cfg)]
232#![feature(doc_notable_trait)]
233// Technically, this is a bug in rustdoc: rustdoc sees the documentation on `#[lang = slice_alloc]`
234// blocks is for `&[T]`, which also has documentation using this feature in `core`, and gets mad
235// that the feature-gate isn't enabled. Ideally, it wouldn't check for the feature gate for docs
236// from other crates, but since this can only appear for lang items, it doesn't seem worth fixing.
237#![feature(intra_doc_pointers)]
238
239#[cfg(not(no_rc))]
240#[stable(feature = "rust1", since = "1.0.0")]
241pub use rcs::rc;
242
243// Module with internal macros used by other modules (needs to be included before other modules).
244#[macro_use]
245mod macros;
246
247mod raw_vec;
248
249/// Implementations of reference-counted pointers.
250#[cfg(not(no_rc))]
251mod rcs {
252    pub mod rc;
253
254    #[cfg(all(not(no_sync), target_has_atomic = "ptr"))]
255    pub(crate) mod arc;
256}
257
258// Heaps provided for low-level allocation strategies
259pub mod alloc;
260
261// Primitive types using the heaps above
262
263// Need to conditionally define the mod from `boxed.rs` to avoid
264// duplicating the lang-items when building in test cfg; but also need
265// to allow code to have `use boxed::Box;` declarations.
266pub mod borrow;
267pub mod boxed;
268#[unstable(feature = "byte_str", issue = "134915")]
269pub mod byte_str;
270pub mod collections;
271#[cfg(all(not(no_rc), not(no_sync), not(no_global_oom_handling)))]
272pub mod ffi;
273pub mod fmt;
274pub mod intrinsics;
275#[unstable(feature = "alloc_io", issue = "154046")]
276pub mod io;
277pub mod panicking;
278pub mod slice;
279pub mod str;
280pub mod string;
281#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
282pub mod sync;
283#[cfg(all(not(no_global_oom_handling), not(no_rc), not(no_sync)))]
284pub mod task;
285pub mod vec;
286#[cfg(all(not(no_rc), not(no_sync), not(no_global_oom_handling)))]
287pub mod wtf8;
288
289#[doc(hidden)]
290#[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
291pub mod __export {
292    pub use core::format_args;
293    pub use core::hint::must_use;
294}