]> git.lizzy.rs Git - rust.git/blob - src/liballoc/lib.rs
Turn `#[allocator]` into a built-in attribute and rename it to `#[rustc_allocator]`
[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`](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.
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`](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.
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`](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.
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 #![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))))]
58 #![no_std]
59 #![needs_allocator]
60
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
65
66 #![deny(rust_2018_idioms)]
67 #![allow(explicit_outlives_requirements)]
68
69 #![cfg_attr(not(test), feature(generator_trait))]
70 #![cfg_attr(test, feature(test))]
71
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 #![feature(dispatch_from_dyn)]
81 #![feature(core_intrinsics)]
82 #![cfg_attr(bootstrap, feature(custom_attribute))]
83 #![feature(dropck_eyepatch)]
84 #![feature(exact_size_is_empty)]
85 #![feature(fmt_internals)]
86 #![feature(fn_traits)]
87 #![feature(fundamental)]
88 #![feature(lang_items)]
89 #![feature(libc)]
90 #![feature(nll)]
91 #![feature(optin_builtin_traits)]
92 #![feature(pattern)]
93 #![feature(ptr_internals)]
94 #![feature(ptr_offset_from)]
95 #![feature(rustc_attrs)]
96 #![feature(receiver_trait)]
97 #![feature(specialization)]
98 #![feature(staged_api)]
99 #![feature(std_internals)]
100 #![feature(str_internals)]
101 #![feature(trusted_len)]
102 #![feature(try_reserve)]
103 #![feature(unboxed_closures)]
104 #![feature(unicode_internals)]
105 #![feature(unsize)]
106 #![feature(unsized_locals)]
107 #![feature(allocator_internals)]
108 #![feature(on_unimplemented)]
109 #![feature(rustc_const_unstable)]
110 #![feature(const_vec_new)]
111 #![feature(slice_partition_dedup)]
112 #![feature(maybe_uninit_extra, maybe_uninit_slice, maybe_uninit_array)]
113 #![feature(alloc_layout_extra)]
114 #![feature(try_trait)]
115
116 // Allow testing this library
117
118 #[cfg(test)]
119 #[macro_use]
120 extern crate std;
121 #[cfg(test)]
122 extern crate test;
123
124 // Module with internal macros used by other modules (needs to be included before other modules).
125 #[macro_use]
126 mod macros;
127
128 // Heaps provided for low-level allocation strategies
129
130 pub mod alloc;
131
132 // Primitive types using the heaps above
133
134 // Need to conditionally define the mod from `boxed.rs` to avoid
135 // duplicating the lang-items when building in test cfg; but also need
136 // to allow code to have `use boxed::Box;` declarations.
137 #[cfg(not(test))]
138 pub mod boxed;
139 #[cfg(test)]
140 mod boxed {
141     pub use std::boxed::Box;
142 }
143 #[cfg(test)]
144 mod boxed_test;
145 pub mod collections;
146 #[cfg(all(target_has_atomic = "ptr", target_has_atomic = "cas"))]
147 pub mod sync;
148 pub mod rc;
149 pub mod raw_vec;
150 pub mod prelude;
151 pub mod borrow;
152 pub mod fmt;
153 pub mod slice;
154 pub mod str;
155 pub mod string;
156 pub mod vec;
157
158 #[cfg(not(test))]
159 mod std {
160     pub use core::ops; // RangeFull
161 }