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