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.
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.
11 //! # The Rust core allocation and collections library
13 //! This library provides smart pointers and collections for managing
14 //! heap-allocated values.
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.
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.
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.
31 //! ## Reference counted pointers
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.
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.
41 //! ## Atomically reference counted pointers
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.
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
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).
58 //! ## Heap interfaces
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.
63 #![allow(unused_attributes)]
64 #![unstable(feature = "alloc",
65 reason = "this library is unlikely to be stabilized in its current \
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))))]
75 #![deny(missing_debug_implementations)]
77 #![cfg_attr(not(test), feature(fn_traits))]
78 #![cfg_attr(not(test), feature(generator_trait))]
79 #![cfg_attr(test, feature(test))]
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 #![cfg_attr(stage0, 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)]
99 #![feature(needs_allocator)]
101 #![feature(optin_builtin_traits)]
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)]
116 #![feature(allocator_internals)]
117 #![feature(on_unimplemented)]
118 #![feature(rustc_const_unstable)]
119 #![feature(const_vec_new)]
120 #![feature(slice_partition_dedup)]
121 #![feature(maybe_uninit)]
123 // Allow testing this library
133 // Module with internal macros used by other modules (needs to be included before other modules).
137 // Heaps provided for low-level allocation strategies
141 #[unstable(feature = "futures_api",
142 reason = "futures in libcore are unstable",
145 // Primitive types using the heaps above
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.
154 pub use std::boxed::Box;
159 #[cfg(all(target_has_atomic = "ptr", target_has_atomic = "cas"))]
173 pub use core::ops; // RangeFull