]> git.lizzy.rs Git - rust.git/blob - src/liballoc/lib.rs
Auto merge of #54601 - cuviper:prep-1.31, r=Mark-Simulacrum
[rust.git] / src / liballoc / lib.rs
1 // Copyright 2014-2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! # The Rust core allocation and collections library
12 //!
13 //! This library provides smart pointers and collections for managing
14 //! heap-allocated values.
15 //!
16 //! This library, like libcore, normally doesn’t need to be used directly
17 //! since its contents are re-exported in the [`std` crate](../std/index.html).
18 //! Crates that use the `#![no_std]` attribute however will typically
19 //! not depend on `std`, so they’d use this crate instead.
20 //!
21 //! ## Boxed values
22 //!
23 //! The [`Box`](boxed/index.html) type is a smart pointer type. There can
24 //! only be one owner of a `Box`, and the owner can decide to mutate the
25 //! contents, which live on the heap.
26 //!
27 //! This type can be sent among threads efficiently as the size of a `Box` value
28 //! is the same as that of a pointer. Tree-like data structures are often built
29 //! with boxes because each node often has only one owner, the parent.
30 //!
31 //! ## Reference counted pointers
32 //!
33 //! The [`Rc`](rc/index.html) type is a non-threadsafe reference-counted pointer
34 //! type intended for sharing memory within a thread. An `Rc` pointer wraps a
35 //! type, `T`, and only allows access to `&T`, a shared reference.
36 //!
37 //! This type is useful when inherited mutability (such as using `Box`) is too
38 //! constraining for an application, and is often paired with the `Cell` or
39 //! `RefCell` types in order to allow mutation.
40 //!
41 //! ## Atomically reference counted pointers
42 //!
43 //! The [`Arc`](sync/index.html) type is the threadsafe equivalent of the `Rc`
44 //! type. It provides all the same functionality of `Rc`, except it requires
45 //! that the contained type `T` is shareable. Additionally, `Arc<T>` is itself
46 //! sendable while `Rc<T>` is not.
47 //!
48 //! This type allows for shared access to the contained data, and is often
49 //! paired with synchronization primitives such as mutexes to allow mutation of
50 //! shared resources.
51 //!
52 //! ## Collections
53 //!
54 //! Implementations of the most common general purpose data structures are
55 //! defined in this library. They are re-exported through the
56 //! [standard collections library](../std/collections/index.html).
57 //!
58 //! ## Heap interfaces
59 //!
60 //! The [`alloc`](alloc/index.html) module defines the low-level interface to the
61 //! default global allocator. It is not compatible with the libc allocator API.
62
63 #![allow(unused_attributes)]
64 #![unstable(feature = "alloc",
65             reason = "this library is unlikely to be stabilized in its current \
66                       form or name",
67             issue = "27783")]
68 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
69        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
70        html_root_url = "https://doc.rust-lang.org/nightly/",
71        issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
72        test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
73 #![no_std]
74 #![needs_allocator]
75 #![deny(missing_debug_implementations)]
76
77 #![cfg_attr(not(test), feature(fn_traits))]
78 #![cfg_attr(not(test), feature(generator_trait))]
79 #![cfg_attr(test, feature(test))]
80
81 #![feature(allocator_api)]
82 #![feature(allow_internal_unstable)]
83 #![feature(arbitrary_self_types)]
84 #![feature(box_into_raw_non_null)]
85 #![feature(box_patterns)]
86 #![feature(box_syntax)]
87 #![feature(cfg_target_has_atomic)]
88 #![feature(coerce_unsized)]
89 #![feature(min_const_fn)]
90 #![feature(core_intrinsics)]
91 #![feature(custom_attribute)]
92 #![feature(dropck_eyepatch)]
93 #![feature(exact_size_is_empty)]
94 #![feature(fmt_internals)]
95 #![feature(fundamental)]
96 #![feature(futures_api)]
97 #![feature(lang_items)]
98 #![feature(libc)]
99 #![feature(needs_allocator)]
100 #![feature(nll)]
101 #![feature(optin_builtin_traits)]
102 #![feature(pattern)]
103 #![feature(pin)]
104 #![feature(ptr_internals)]
105 #![feature(ptr_offset_from)]
106 #![feature(rustc_attrs)]
107 #![feature(specialization)]
108 #![feature(split_ascii_whitespace)]
109 #![feature(staged_api)]
110 #![feature(str_internals)]
111 #![feature(trusted_len)]
112 #![feature(try_reserve)]
113 #![feature(unboxed_closures)]
114 #![feature(unicode_internals)]
115 #![feature(unsize)]
116 #![feature(allocator_internals)]
117 #![feature(on_unimplemented)]
118 #![feature(chunks_exact)]
119 #![feature(rustc_const_unstable)]
120 #![feature(const_vec_new)]
121 #![feature(slice_partition_dedup)]
122
123 // Allow testing this library
124
125 #[cfg(test)]
126 #[macro_use]
127 extern crate std;
128 #[cfg(test)]
129 extern crate test;
130 #[cfg(test)]
131 extern crate rand;
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 #[unstable(feature = "futures_api",
142            reason = "futures in libcore are unstable",
143            issue = "50547")]
144 pub mod task;
145 // Primitive types using the heaps above
146
147 // Need to conditionally define the mod from `boxed.rs` to avoid
148 // duplicating the lang-items when building in test cfg; but also need
149 // to allow code to have `use boxed::Box;` declarations.
150 #[cfg(not(test))]
151 pub mod boxed;
152 #[cfg(test)]
153 mod boxed {
154     pub use std::boxed::Box;
155 }
156 #[cfg(test)]
157 mod boxed_test;
158 pub mod collections;
159 #[cfg(all(target_has_atomic = "ptr", target_has_atomic = "cas"))]
160 pub mod sync;
161 pub mod rc;
162 pub mod raw_vec;
163 pub mod prelude;
164 pub mod borrow;
165 pub mod fmt;
166 pub mod slice;
167 pub mod str;
168 pub mod string;
169 pub mod vec;
170
171 #[cfg(not(test))]
172 mod std {
173     pub use core::ops;      // RangeFull
174 }