]> git.lizzy.rs Git - rust.git/blob - src/libcollections/lib.rs
Auto merge of #42394 - ollie27:rustdoc_deref_box, r=QuietMisdreavus
[rust.git] / src / libcollections / lib.rs
1 // Copyright 2013-2014 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 //! Collection types.
12 //!
13 //! See [`std::collections`](../std/collections/index.html) for a detailed
14 //! discussion of collections in Rust.
15
16 #![crate_name = "collections"]
17 #![crate_type = "rlib"]
18 #![unstable(feature = "collections",
19             reason = "library is unlikely to be stabilized with the current \
20                       layout and name, use std::collections instead",
21             issue = "27783")]
22 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
23        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
24        html_root_url = "https://doc.rust-lang.org/nightly/",
25        html_playground_url = "https://play.rust-lang.org/",
26        issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
27        test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
28
29 #![cfg_attr(test, allow(deprecated))] // rand
30 #![deny(warnings)]
31 #![deny(missing_debug_implementations)]
32
33 #![feature(alloc)]
34 #![feature(allow_internal_unstable)]
35 #![feature(box_patterns)]
36 #![feature(box_syntax)]
37 #![cfg_attr(not(test), feature(char_escape_debug))]
38 #![cfg_attr(not(test), feature(core_float))]
39 #![feature(core_intrinsics)]
40 #![feature(dropck_eyepatch)]
41 #![feature(exact_size_is_empty)]
42 #![feature(fmt_internals)]
43 #![feature(fused)]
44 #![feature(generic_param_attrs)]
45 #![feature(heap_api)]
46 #![feature(i128_type)]
47 #![feature(inclusive_range)]
48 #![feature(lang_items)]
49 #![feature(manually_drop)]
50 #![feature(nonzero)]
51 #![feature(pattern)]
52 #![feature(placement_in)]
53 #![feature(placement_in_syntax)]
54 #![feature(placement_new_protocol)]
55 #![feature(shared)]
56 #![feature(slice_get_slice)]
57 #![feature(slice_patterns)]
58 #![cfg_attr(not(test), feature(slice_rotate))]
59 #![feature(slice_rsplit)]
60 #![cfg_attr(not(test), feature(sort_unstable))]
61 #![feature(specialization)]
62 #![feature(staged_api)]
63 #![feature(str_internals)]
64 #![feature(str_box_extras)]
65 #![feature(str_mut_extras)]
66 #![feature(trusted_len)]
67 #![feature(unicode)]
68 #![feature(unique)]
69 #![cfg_attr(not(test), feature(str_checked_slicing))]
70 #![cfg_attr(test, feature(rand, test))]
71 #![feature(offset_to)]
72
73 #![no_std]
74
75 extern crate std_unicode;
76 extern crate alloc;
77
78 #[cfg(test)]
79 #[macro_use]
80 extern crate std;
81 #[cfg(test)]
82 extern crate test;
83
84 #[doc(no_inline)]
85 pub use binary_heap::BinaryHeap;
86 #[doc(no_inline)]
87 pub use btree_map::BTreeMap;
88 #[doc(no_inline)]
89 pub use btree_set::BTreeSet;
90 #[doc(no_inline)]
91 pub use linked_list::LinkedList;
92 #[doc(no_inline)]
93 pub use vec_deque::VecDeque;
94 #[doc(no_inline)]
95 pub use string::String;
96 #[doc(no_inline)]
97 pub use vec::Vec;
98
99 // Needed for the vec! macro
100 pub use alloc::boxed;
101
102 #[macro_use]
103 mod macros;
104
105 pub mod binary_heap;
106 mod btree;
107 pub mod borrow;
108 pub mod fmt;
109 pub mod linked_list;
110 pub mod range;
111 pub mod slice;
112 pub mod str;
113 pub mod string;
114 pub mod vec;
115 pub mod vec_deque;
116
117 #[stable(feature = "rust1", since = "1.0.0")]
118 pub mod btree_map {
119     //! A map based on a B-Tree.
120     #[stable(feature = "rust1", since = "1.0.0")]
121     pub use btree::map::*;
122 }
123
124 #[stable(feature = "rust1", since = "1.0.0")]
125 pub mod btree_set {
126     //! A set based on a B-Tree.
127     #[stable(feature = "rust1", since = "1.0.0")]
128     pub use btree::set::*;
129 }
130
131 #[cfg(not(test))]
132 mod std {
133     pub use core::ops;      // RangeFull
134 }
135
136 /// An endpoint of a range of keys.
137 ///
138 /// # Examples
139 ///
140 /// `Bound`s are range endpoints:
141 ///
142 /// ```
143 /// #![feature(collections_range)]
144 ///
145 /// use std::collections::range::RangeArgument;
146 /// use std::collections::Bound::*;
147 ///
148 /// assert_eq!((..100).start(), Unbounded);
149 /// assert_eq!((1..12).start(), Included(&1));
150 /// assert_eq!((1..12).end(), Excluded(&12));
151 /// ```
152 ///
153 /// Using a tuple of `Bound`s as an argument to [`BTreeMap::range`].
154 /// Note that in most cases, it's better to use range syntax (`1..5`) instead.
155 ///
156 /// ```
157 /// use std::collections::BTreeMap;
158 /// use std::collections::Bound::{Excluded, Included, Unbounded};
159 ///
160 /// let mut map = BTreeMap::new();
161 /// map.insert(3, "a");
162 /// map.insert(5, "b");
163 /// map.insert(8, "c");
164 ///
165 /// for (key, value) in map.range((Excluded(3), Included(8))) {
166 ///     println!("{}: {}", key, value);
167 /// }
168 ///
169 /// assert_eq!(Some((&3, &"a")), map.range((Unbounded, Included(5))).next());
170 /// ```
171 ///
172 /// [`BTreeMap::range`]: btree_map/struct.BTreeMap.html#method.range
173 #[stable(feature = "collections_bound", since = "1.17.0")]
174 #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
175 pub enum Bound<T> {
176     /// An inclusive bound.
177     #[stable(feature = "collections_bound", since = "1.17.0")]
178     Included(T),
179     /// An exclusive bound.
180     #[stable(feature = "collections_bound", since = "1.17.0")]
181     Excluded(T),
182     /// An infinite endpoint. Indicates that there is no bound in this direction.
183     #[stable(feature = "collections_bound", since = "1.17.0")]
184     Unbounded,
185 }
186
187 /// An intermediate trait for specialization of `Extend`.
188 #[doc(hidden)]
189 trait SpecExtend<I: IntoIterator> {
190     /// Extends `self` with the contents of the given iterator.
191     fn spec_extend(&mut self, iter: I);
192 }