]> git.lizzy.rs Git - rust.git/blob - src/liballoc/lib.rs
Rollup merge of #67543 - JohnTitor:regression-tests, r=Centril
[rust.git] / src / liballoc / lib.rs
1 //! # The Rust core allocation and collections library
2 //!
3 //! This library provides smart pointers and collections for managing
4 //! heap-allocated values.
5 //!
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.
10 //!
11 //! ## Boxed values
12 //!
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
15 //! heap.
16 //!
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.
20 //!
21 //! ## Reference counted pointers
22 //!
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.
26 //!
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.
30 //!
31 //! ## Atomically reference counted pointers
32 //!
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.
37 //!
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
40 //! shared resources.
41 //!
42 //! ## Collections
43 //!
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).
47 //!
48 //! ## Heap interfaces
49 //!
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.
52 //!
53 //! [`Arc`]: sync/index.html
54 //! [`Box`]: boxed/index.html
55 //! [`Cell`]: ../core/cell/index.html
56 //! [`Rc`]: rc/index.html
57 //! [`RefCell`]: ../core/cell/index.html
58
59 #![allow(unused_attributes)]
60 #![stable(feature = "alloc", since = "1.36.0")]
61 #![doc(
62     html_root_url = "https://doc.rust-lang.org/nightly/",
63     issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
64     test(no_crate_inject, attr(allow(unused_variables), deny(warnings)))
65 )]
66 #![no_std]
67 #![needs_allocator]
68 #![warn(deprecated_in_future)]
69 #![warn(missing_docs)]
70 #![warn(missing_debug_implementations)]
71 #![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings
72 #![allow(explicit_outlives_requirements)]
73 #![allow(incomplete_features)]
74 #![cfg_attr(not(test), feature(generator_trait))]
75 #![cfg_attr(test, feature(test))]
76 #![feature(allocator_api)]
77 #![feature(allow_internal_unstable)]
78 #![feature(arbitrary_self_types)]
79 #![feature(box_into_raw_non_null)]
80 #![feature(box_patterns)]
81 #![feature(box_syntax)]
82 #![feature(cfg_target_has_atomic)]
83 #![feature(coerce_unsized)]
84 #![feature(const_generic_impls_guard)]
85 #![feature(const_generics)]
86 #![feature(const_in_array_repeat_expressions)]
87 #![feature(const_if_match)]
88 #![feature(cow_is_borrowed)]
89 #![feature(dispatch_from_dyn)]
90 #![feature(core_intrinsics)]
91 #![feature(container_error_extra)]
92 #![feature(dropck_eyepatch)]
93 #![feature(exact_size_is_empty)]
94 #![feature(fmt_internals)]
95 #![feature(fn_traits)]
96 #![feature(fundamental)]
97 #![feature(internal_uninit_const)]
98 #![feature(lang_items)]
99 #![feature(libc)]
100 #![feature(nll)]
101 #![feature(optin_builtin_traits)]
102 #![feature(pattern)]
103 #![feature(ptr_internals)]
104 #![feature(ptr_offset_from)]
105 #![feature(rustc_attrs)]
106 #![feature(receiver_trait)]
107 #![feature(slice_from_raw_parts)]
108 #![feature(specialization)]
109 #![feature(staged_api)]
110 #![feature(std_internals)]
111 #![feature(str_internals)]
112 #![feature(trusted_len)]
113 #![feature(try_reserve)]
114 #![feature(unboxed_closures)]
115 #![feature(unicode_internals)]
116 #![feature(unsize)]
117 #![feature(unsized_locals)]
118 #![feature(allocator_internals)]
119 #![feature(slice_partition_dedup)]
120 #![feature(maybe_uninit_extra, maybe_uninit_slice)]
121 #![feature(alloc_layout_extra)]
122 #![feature(try_trait)]
123 #![feature(associated_type_bounds)]
124
125 // Allow testing this library
126
127 #[cfg(test)]
128 #[macro_use]
129 extern crate std;
130 #[cfg(test)]
131 extern crate test;
132
133 // Module with internal macros used by other modules (needs to be included before other modules).
134 #[macro_use]
135 mod macros;
136
137 // Heaps provided for low-level allocation strategies
138
139 pub mod alloc;
140
141 // Primitive types using the heaps above
142
143 // Need to conditionally define the mod from `boxed.rs` to avoid
144 // duplicating the lang-items when building in test cfg; but also need
145 // to allow code to have `use boxed::Box;` declarations.
146 #[cfg(not(test))]
147 pub mod boxed;
148 #[cfg(test)]
149 mod boxed {
150     pub use std::boxed::Box;
151 }
152 pub mod borrow;
153 pub mod collections;
154 pub mod fmt;
155 pub mod prelude;
156 pub mod raw_vec;
157 pub mod rc;
158 pub mod slice;
159 pub mod str;
160 pub mod string;
161 #[cfg(target_has_atomic = "ptr")]
162 pub mod sync;
163 #[cfg(test)]
164 mod tests;
165 pub mod vec;
166
167 #[cfg(not(test))]
168 mod std {
169     pub use core::ops; // RangeFull
170 }
171
172 #[doc(hidden)]
173 #[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
174 pub mod __export {
175     pub use core::format_args;
176 }