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, is not intended for general usage, but rather as
17 //! a building block of other libraries. The types and interfaces in this
18 //! library are reexported through the [standard library](../std/index.html),
19 //! and should not be used through this library.
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`](arc/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 reexported through the
56 //! [standard collections library](../std/collections/index.html).
58 //! ## Heap interfaces
60 //! The [`heap`](heap/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))))]
76 #![deny(missing_debug_implementations)]
78 #![cfg_attr(test, allow(deprecated))] // rand
79 #![cfg_attr(test, feature(placement_in))]
80 #![cfg_attr(not(test), feature(core_float))]
81 #![cfg_attr(not(test), feature(exact_size_is_empty))]
82 #![cfg_attr(not(test), feature(slice_rotate))]
83 #![cfg_attr(not(test), feature(generator_trait))]
84 #![cfg_attr(test, feature(rand, test))]
85 #![feature(allow_internal_unstable)]
86 #![feature(box_patterns)]
87 #![feature(box_syntax)]
88 #![feature(cfg_target_has_atomic)]
89 #![feature(coerce_unsized)]
91 #![feature(core_intrinsics)]
92 #![feature(custom_attribute)]
93 #![feature(dropck_eyepatch)]
94 #![feature(exact_size_is_empty)]
95 #![feature(fmt_internals)]
96 #![feature(fundamental)]
98 #![feature(generic_param_attrs)]
99 #![feature(i128_type)]
100 #![feature(inclusive_range)]
101 #![feature(iter_rfold)]
102 #![feature(lang_items)]
103 #![feature(needs_allocator)]
105 #![feature(offset_to)]
106 #![feature(optin_builtin_traits)]
108 #![feature(placement_in_syntax)]
109 #![feature(placement_new_protocol)]
110 #![feature(rustc_attrs)]
112 #![feature(slice_get_slice)]
113 #![feature(slice_patterns)]
114 #![feature(slice_rsplit)]
115 #![feature(specialization)]
116 #![feature(staged_api)]
117 #![feature(str_internals)]
118 #![feature(trusted_len)]
119 #![feature(unboxed_closures)]
123 #![feature(allocator_internals)]
125 #![cfg_attr(not(test), feature(fused, fn_traits, placement_new_protocol, swap_with_slice, i128))]
126 #![cfg_attr(test, feature(test, box_heap))]
128 // Allow testing this library
136 extern crate std_unicode;
138 // Module with internal macros used by other modules (needs to be included before other modules).
142 // Allocator trait and helper struct definitions
146 // Heaps provided for low-level allocation strategies
150 // Primitive types using the heaps above
152 // Need to conditionally define the mod from `boxed.rs` to avoid
153 // duplicating the lang-items when building in test cfg; but also need
154 // to allow code to have `use boxed::HEAP;`
155 // and `use boxed::Box;` declarations.
160 pub use std::boxed::{Box, IntermediateBox, HEAP};
164 #[cfg(target_has_atomic = "ptr")]
169 // collections modules
182 #[stable(feature = "rust1", since = "1.0.0")]
184 //! A map based on a B-Tree.
185 #[stable(feature = "rust1", since = "1.0.0")]
186 pub use btree::map::*;
189 #[stable(feature = "rust1", since = "1.0.0")]
191 //! A set based on a B-Tree.
192 #[stable(feature = "rust1", since = "1.0.0")]
193 pub use btree::set::*;
198 pub use core::ops; // RangeFull
201 /// An endpoint of a range of keys.
205 /// `Bound`s are range endpoints:
208 /// #![feature(collections_range)]
210 /// use std::collections::range::RangeArgument;
211 /// use std::collections::Bound::*;
213 /// assert_eq!((..100).start(), Unbounded);
214 /// assert_eq!((1..12).start(), Included(&1));
215 /// assert_eq!((1..12).end(), Excluded(&12));
218 /// Using a tuple of `Bound`s as an argument to [`BTreeMap::range`].
219 /// Note that in most cases, it's better to use range syntax (`1..5`) instead.
222 /// use std::collections::BTreeMap;
223 /// use std::collections::Bound::{Excluded, Included, Unbounded};
225 /// let mut map = BTreeMap::new();
226 /// map.insert(3, "a");
227 /// map.insert(5, "b");
228 /// map.insert(8, "c");
230 /// for (key, value) in map.range((Excluded(3), Included(8))) {
231 /// println!("{}: {}", key, value);
234 /// assert_eq!(Some((&3, &"a")), map.range((Unbounded, Included(5))).next());
237 /// [`BTreeMap::range`]: btree_map/struct.BTreeMap.html#method.range
238 #[stable(feature = "collections_bound", since = "1.17.0")]
239 #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
241 /// An inclusive bound.
242 #[stable(feature = "collections_bound", since = "1.17.0")]
243 Included(#[stable(feature = "collections_bound", since = "1.17.0")] T),
244 /// An exclusive bound.
245 #[stable(feature = "collections_bound", since = "1.17.0")]
246 Excluded(#[stable(feature = "collections_bound", since = "1.17.0")] T),
247 /// An infinite endpoint. Indicates that there is no bound in this direction.
248 #[stable(feature = "collections_bound", since = "1.17.0")]
252 /// An intermediate trait for specialization of `Extend`.
254 trait SpecExtend<I: IntoIterator> {
255 /// Extends `self` with the contents of the given iterator.
256 fn spec_extend(&mut self, iter: I);
260 pub use binary_heap::BinaryHeap;
262 pub use btree_map::BTreeMap;
264 pub use btree_set::BTreeSet;
266 pub use linked_list::LinkedList;
268 pub use vec_deque::VecDeque;
270 pub use string::String;