]> git.lizzy.rs Git - rust.git/blob - src/liballoc/lib.rs
Rollup merge of #59351 - phil-opp:llvm-ar, r=alexcrichton
[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 #![unstable(feature = "alloc",
55             reason = "this library is unlikely to be stabilized in its current \
56                       form or name",
57             issue = "27783")]
58 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
59        issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
60        test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
61 #![no_std]
62 #![needs_allocator]
63
64 #![deny(rust_2018_idioms)]
65 #![allow(explicit_outlives_requirements)]
66
67 #![warn(deprecated_in_future)]
68 #![warn(intra_doc_link_resolution_failure)]
69 #![warn(missing_debug_implementations)]
70
71 #![cfg_attr(not(test), feature(generator_trait))]
72 #![cfg_attr(test, feature(test))]
73
74 #![feature(allocator_api)]
75 #![feature(allow_internal_unstable)]
76 #![feature(arbitrary_self_types)]
77 #![feature(box_into_raw_non_null)]
78 #![feature(box_patterns)]
79 #![feature(box_syntax)]
80 #![feature(cfg_target_has_atomic)]
81 #![feature(coerce_unsized)]
82 #![feature(dispatch_from_dyn)]
83 #![feature(core_intrinsics)]
84 #![feature(custom_attribute)]
85 #![feature(dropck_eyepatch)]
86 #![feature(exact_size_is_empty)]
87 #![feature(fmt_internals)]
88 #![feature(fn_traits)]
89 #![feature(fundamental)]
90 #![feature(futures_api)]
91 #![feature(lang_items)]
92 #![feature(libc)]
93 #![feature(needs_allocator)]
94 #![feature(nll)]
95 #![feature(optin_builtin_traits)]
96 #![feature(pattern)]
97 #![feature(ptr_internals)]
98 #![feature(ptr_offset_from)]
99 #![feature(rustc_attrs)]
100 #![feature(receiver_trait)]
101 #![feature(specialization)]
102 #![feature(staged_api)]
103 #![feature(std_internals)]
104 #![feature(str_internals)]
105 #![feature(trusted_len)]
106 #![feature(try_reserve)]
107 #![feature(unboxed_closures)]
108 #![feature(unicode_internals)]
109 #![feature(unsize)]
110 #![feature(allocator_internals)]
111 #![feature(on_unimplemented)]
112 #![feature(rustc_const_unstable)]
113 #![feature(const_vec_new)]
114 #![feature(slice_partition_dedup)]
115 #![feature(maybe_uninit, maybe_uninit_slice, maybe_uninit_array)]
116 #![feature(alloc_layout_extra)]
117 #![feature(try_trait)]
118 #![feature(iter_nth_back)]
119
120 // Allow testing this library
121
122 #[cfg(test)]
123 #[macro_use]
124 extern crate std;
125 #[cfg(test)]
126 extern crate test;
127
128 // Module with internal macros used by other modules (needs to be included before other modules).
129 #[macro_use]
130 mod macros;
131
132 // Heaps provided for low-level allocation strategies
133
134 pub mod alloc;
135
136 // Primitive types using the heaps above
137
138 // Need to conditionally define the mod from `boxed.rs` to avoid
139 // duplicating the lang-items when building in test cfg; but also need
140 // to allow code to have `use boxed::Box;` declarations.
141 #[cfg(not(test))]
142 pub mod boxed;
143 #[cfg(test)]
144 mod boxed {
145     pub use std::boxed::Box;
146 }
147 #[cfg(test)]
148 mod boxed_test;
149 pub mod collections;
150 #[cfg(all(target_has_atomic = "ptr", target_has_atomic = "cas"))]
151 pub mod sync;
152 pub mod rc;
153 pub mod raw_vec;
154 pub mod prelude;
155 pub mod borrow;
156 pub mod fmt;
157 pub mod slice;
158 pub mod str;
159 pub mod string;
160 pub mod vec;
161
162 #[cfg(not(test))]
163 mod std {
164     pub use core::ops; // RangeFull
165 }