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(ascii_char_variants)]
105#![feature(async_fn_traits)]
106#![feature(async_iterator)]
107#![feature(borrowed_buf_init)]
108#![feature(byte_str)]
109#![feature(byte_str_internals)]
110#![feature(can_vector)]
111#![feature(case_ignorable)]
112#![feature(cast_maybe_uninit)]
113#![feature(cell_get_cloned)]
114#![feature(char_internals)]
115#![feature(clone_to_uninit)]
116#![feature(coerce_unsized)]
117#![feature(const_clone)]
118#![feature(const_cmp)]
119#![feature(const_convert)]
120#![feature(const_default)]
121#![feature(const_destruct)]
122#![feature(const_drop_in_place)]
123#![feature(const_eval_select)]
124#![feature(const_heap)]
125#![feature(const_index)]
126#![feature(const_option_ops)]
127#![feature(const_result_trait_fn)]
128#![feature(const_try)]
129#![feature(copied_into_inner)]
130#![feature(core_intrinsics)]
131#![feature(core_io)]
132#![feature(core_io_borrowed_buf)]
133#![feature(core_io_internals)]
134#![feature(cursor_split)]
135#![feature(deprecated_suggestion)]
136#![feature(deref_pure_trait)]
137#![feature(derive_const)]
138#![feature(diagnostic_on_move)]
139#![feature(dispatch_from_dyn)]
140#![feature(ergonomic_clones)]
141#![feature(error_generic_member_access)]
142#![feature(error_type_id_internal)]
143#![feature(exact_size_is_empty)]
144#![feature(extend_one)]
145#![feature(extend_one_unchecked)]
146#![feature(fmt_arguments_from_str)]
147#![feature(fmt_internals)]
148#![feature(fn_traits)]
149#![feature(formatting_options)]
150#![feature(freeze)]
151#![feature(generic_atomic)]
152#![feature(hasher_prefixfree_extras)]
153#![feature(inplace_iteration)]
154#![feature(io_const_error)]
155#![feature(io_const_error_internals)]
156#![feature(io_slice_as_bytes)]
157#![feature(iter_advance_by)]
158#![feature(iter_next_chunk)]
159#![feature(legacy_receiver_trait)]
160#![feature(likely_unlikely)]
161#![feature(local_waker)]
162#![feature(marker_trait_attr)]
163#![feature(maybe_uninit_array_assume_init)]
164#![feature(maybe_uninit_fill)]
165#![feature(maybe_uninit_uninit_array_transpose)]
166#![feature(panic_internals)]
167#![feature(pattern)]
168#![feature(pin_coerce_unsized_trait)]
169#![feature(ptr_alignment_type)]
170#![feature(ptr_cast_array)]
171#![feature(ptr_metadata)]
172#![feature(random)]
173#![feature(raw_os_error_ty)]
174#![feature(register_tool)]
175#![feature(rev_into_inner)]
176#![feature(seek_stream_len)]
177#![feature(set_ptr_value)]
178#![feature(share_trait)]
179#![feature(sized_type_properties)]
180#![feature(slice_from_ptr_range)]
181#![feature(slice_index_methods)]
182#![feature(slice_iter_mut_as_mut_slice)]
183#![feature(slice_ptr_get)]
184#![feature(slice_range)]
185#![feature(std_internals)]
186#![feature(temporary_niche_types)]
187#![feature(titlecase)]
188#![feature(transmutability)]
189#![feature(trivial_clone)]
190#![feature(trusted_fused)]
191#![feature(trusted_len)]
192#![feature(trusted_random_access)]
193#![feature(try_blocks)]
194#![feature(try_trait_v2)]
195#![feature(try_trait_v2_residual)]
196#![feature(tuple_trait)]
197#![feature(ub_checks)]
198#![feature(unicode_internals)]
199#![feature(unsize)]
200#![feature(write_all_vectored)]
201#![feature(wtf8_internals)]
202// tidy-alphabetical-end
203//
204// Language features:
205// tidy-alphabetical-start
206#![feature(allocator_internals)]
207#![feature(allow_internal_unstable)]
208#![feature(cfg_sanitize)]
209#![feature(const_closures)]
210#![feature(const_precise_live_drops)]
211#![feature(const_trait_impl)]
212#![feature(coroutine_trait)]
213#![feature(decl_macro)]
214#![feature(dropck_eyepatch)]
215#![feature(f16)]
216#![feature(f128)]
217#![feature(fundamental)]
218#![feature(impl_restriction)]
219#![feature(intrinsics)]
220#![feature(lang_items)]
221#![feature(min_specialization)]
222#![feature(multiple_supertrait_upcastable)]
223#![feature(negative_impls)]
224#![feature(rustc_attrs)]
225#![feature(slice_internals)]
226#![feature(staged_api)]
227#![feature(stmt_expr_attributes)]
228#![feature(strict_provenance_lints)]
229#![feature(unboxed_closures)]
230#![feature(unsized_fn_params)]
231#![feature(with_negative_coherence)]
232#![rustc_preserve_ub_checks]
233// tidy-alphabetical-end
234
235// tidy-alphabetical-start
236#![register_tool(lint)]
237// tidy-alphabetical-end
238
239// Rustdoc features:
240#![feature(doc_cfg)]
241#![feature(doc_notable_trait)]
242// Technically, this is a bug in rustdoc: rustdoc sees the documentation on `#[lang = slice_alloc]`
243// blocks is for `&[T]`, which also has documentation using this feature in `core`, and gets mad
244// that the feature-gate isn't enabled. Ideally, it wouldn't check for the feature gate for docs
245// from other crates, but since this can only appear for lang items, it doesn't seem worth fixing.
246#![feature(intra_doc_pointers)]
247
248#[cfg(not(no_rc))]
249#[stable(feature = "rust1", since = "1.0.0")]
250pub use rcs::rc;
251
252// Module with internal macros used by other modules (needs to be included before other modules).
253#[macro_use]
254mod macros;
255
256mod raw_vec;
257
258/// Implementations of reference-counted pointers.
259#[cfg(not(no_rc))]
260mod rcs {
261    pub mod rc;
262
263    #[cfg(all(not(no_sync), target_has_atomic = "ptr"))]
264    pub(crate) mod arc;
265}
266
267// Heaps provided for low-level allocation strategies
268pub mod alloc;
269
270// Primitive types using the heaps above
271
272// Need to conditionally define the mod from `boxed.rs` to avoid
273// duplicating the lang-items when building in test cfg; but also need
274// to allow code to have `use boxed::Box;` declarations.
275pub mod borrow;
276pub mod boxed;
277#[unstable(feature = "byte_str", issue = "134915")]
278pub mod byte_str;
279pub mod collections;
280#[cfg(all(not(no_rc), not(no_sync), not(no_global_oom_handling)))]
281pub mod ffi;
282pub mod fmt;
283pub mod intrinsics;
284#[unstable(feature = "alloc_io", issue = "154046")]
285pub mod io;
286pub mod panicking;
287pub mod slice;
288pub mod str;
289pub mod string;
290#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
291pub mod sync;
292#[cfg(all(not(no_global_oom_handling), not(no_rc), not(no_sync)))]
293pub mod task;
294pub mod vec;
295#[cfg(all(not(no_rc), not(no_sync), not(no_global_oom_handling)))]
296pub mod wtf8;
297
298#[doc(hidden)]
299#[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
300pub mod __export {
301    pub use core::format_args;
302    pub use core::hint::must_use;
303}