]> git.lizzy.rs Git - rust.git/blob - src/libstd/lib.rs
std: Update crate docs
[rust.git] / src / libstd / lib.rs
1 // Copyright 2012-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 //! # The Rust Standard Library
12 //!
13 //! The Rust Standard Library provides the essential runtime
14 //! functionality for building portable Rust software.
15 //!
16 //! It is linked to all Rust crates by default as though they
17 //! contained a crate-level `extern crate std` crate import. Therefore
18 //! the standard library can be accessed in `use` statements through
19 //! the path `std`, as in `use std::thread`, or in expressions through
20 //! the absolute path `::std`, as in `::std::thread::sleep_ms(100)`.
21 //!
22 //! Furthermore, the standard library defines [The Rust
23 //! Prelude](prelude/index.html), a small collection of items, mostly
24 //! traits, that are imported into and available in every module.
25 //!
26 //! ## What is in the standard library
27 //!
28 //! The standard library is minimal, a set of battle-tested
29 //! core types and shared abstractions for the [broader Rust
30 //! ecosystem][https://crates.io] to build on.
31 //!
32 //! The [primitive types](#primitives), though not defined in the
33 //! standard library, are documented here, as are the predefined
34 //! [macros](#macros).
35 //!
36 //! ## Containers and collections
37 //!
38 //! The [`option`](option/index.html) and
39 //! [`result`](result/index.html) modules define optional and
40 //! error-handling types, `Option` and `Result`. The
41 //! [`iter`](iter/index.html) module defines Rust's iterator trait,
42 //! [`Iterater`](iter/trait.Iterator.html), which works with the `for`
43 //! loop to access collections.
44 //!
45 //! The common container type, `Vec`, a growable vector backed by an array,
46 //! lives in the [`vec`](vec/index.html) module. Contiguous, unsized regions
47 //! of memory, `[T]`, commonly called "slices", and their borrowed versions,
48 //! `&[T]`, commonly called "borrowed slices", are built-in types for which the
49 //! [`slice`](slice/index.html) module defines many methods.
50 //!
51 //! `&str`, a UTF-8 string, is a built-in type, and the standard library
52 //! defines methods for it on a variety of traits in the
53 //! [`str`](str/index.html) module. Rust strings are immutable;
54 //! use the `String` type defined in [`string`](string/index.html)
55 //! for a mutable string builder.
56 //!
57 //! For converting to strings use the [`format!`](fmt/index.html)
58 //! macro, and for converting from strings use the
59 //! [`FromStr`](str/trait.FromStr.html) trait.
60 //!
61 //! Data may be shared by placing it a reference-counted box, the
62 //! [`Rc`][rc/index.html] type, and if further contained in a [`Cell`
63 //! or `RefCell`](cell/index.html), may be mutated as well as shared.
64 //! Likewise, in a concurrent setting it is common to pair an
65 //! atomically-reference-counted box, [`Arc`](sync/struct.Arc.html),
66 //! with a [`Mutex`](sync/struct.Mutex.html) to get the same effect.
67 //!
68 //! The [`collections`](collections/index.html) module defines maps,
69 //! sets, linked lists and other typical collection types, including
70 //! the common [`HashMap`](collections/struct.HashMap.html).
71 //!
72 //! ## Platform abstractions and I/O
73 //!
74 //! Besides basic data types, the standard library is largely concerned
75 //! with abstracting over differences in common platforms, most notably
76 //! Windows and Unix derivatives.
77 //!
78 //! Common types of I/O, including [files](fs/struct.File.html),
79 //! [TCP](net/struct.TcpStream.html),
80 //! [UDP](net/struct.UdpSocket.html), are defined in the
81 //! [`io`](io/index.html), [`fs`](fs/index.html), and
82 //! [`net`](net/index.html) modulesu.
83 //!
84 //! The [`thread`](thread/index.html) module contains Rust's threading
85 //! abstractions.  [`sync`](sync/index.html) contains further,
86 //! primitive, shared memory types, including
87 //! [`atomic`](sync/atomic/index.html), and
88 //! [`mpsc`](sync/mpsc/index.html), which contains the channel types
89 //! for message passing.
90
91 // Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
92 #![cfg_attr(stage0, feature(custom_attribute))]
93 #![crate_name = "std"]
94 #![stable(feature = "rust1", since = "1.0.0")]
95 #![staged_api]
96 #![crate_type = "rlib"]
97 #![crate_type = "dylib"]
98 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
99        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
100        html_root_url = "http://doc.rust-lang.org/nightly/",
101        html_playground_url = "http://play.rust-lang.org/")]
102 #![doc(test(no_crate_inject, attr(deny(warnings))))]
103 #![doc(test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
104
105 #![feature(alloc)]
106 #![feature(allow_internal_unstable)]
107 #![feature(associated_consts)]
108 #![feature(box_syntax)]
109 #![feature(collections)]
110 #![feature(core)]
111 #![feature(debug_builders)]
112 #![feature(into_cow)]
113 #![feature(lang_items)]
114 #![feature(libc)]
115 #![feature(linkage, thread_local, asm)]
116 #![feature(macro_reexport)]
117 #![feature(optin_builtin_traits)]
118 #![feature(rand)]
119 #![feature(slice_patterns)]
120 #![feature(staged_api)]
121 #![feature(std_misc)]
122 #![feature(str_char)]
123 #![feature(unboxed_closures)]
124 #![feature(unicode)]
125 #![feature(unique)]
126 #![feature(unsafe_no_drop_flag, filling_drop)]
127 #![feature(zero_one)]
128 #![cfg_attr(test, feature(float_from_str_radix))]
129 #![cfg_attr(test, feature(test, rustc_private, std_misc))]
130
131 // Don't link to std. We are std.
132 #![feature(no_std)]
133 #![no_std]
134
135 #![allow(trivial_casts)]
136 #![deny(missing_docs)]
137
138 #[cfg(test)] extern crate test;
139 #[cfg(test)] #[macro_use] extern crate log;
140
141 #[macro_use]
142 #[macro_reexport(assert, assert_eq, debug_assert, debug_assert_eq,
143     unreachable, unimplemented, write, writeln)]
144 extern crate core;
145
146 #[macro_use]
147 #[macro_reexport(vec, format)]
148 extern crate collections as core_collections;
149
150 #[allow(deprecated)] extern crate rand as core_rand;
151 extern crate alloc;
152 extern crate rustc_unicode;
153 extern crate libc;
154
155 #[macro_use] #[no_link] extern crate rustc_bitflags;
156
157 // Make std testable by not duplicating lang items. See #2912
158 #[cfg(test)] extern crate std as realstd;
159 #[cfg(test)] pub use realstd::marker;
160 #[cfg(test)] pub use realstd::ops;
161 #[cfg(test)] pub use realstd::cmp;
162 #[cfg(test)] pub use realstd::boxed;
163
164
165 // NB: These reexports are in the order they should be listed in rustdoc
166
167 pub use core::any;
168 pub use core::cell;
169 pub use core::clone;
170 #[cfg(not(test))] pub use core::cmp;
171 pub use core::convert;
172 pub use core::default;
173 pub use core::hash;
174 pub use core::intrinsics;
175 pub use core::iter;
176 #[cfg(not(test))] pub use core::marker;
177 pub use core::mem;
178 #[cfg(not(test))] pub use core::ops;
179 pub use core::ptr;
180 pub use core::raw;
181 pub use core::simd;
182 pub use core::result;
183 pub use core::option;
184 pub mod error;
185
186 #[cfg(not(test))] pub use alloc::boxed;
187 pub use alloc::rc;
188
189 pub use core_collections::borrow;
190 pub use core_collections::fmt;
191 pub use core_collections::slice;
192 pub use core_collections::str;
193 pub use core_collections::string;
194 #[stable(feature = "rust1", since = "1.0.0")]
195 pub use core_collections::vec;
196
197 pub use rustc_unicode::char;
198
199 /* Exported macros */
200
201 #[macro_use]
202 mod macros;
203
204 mod rtdeps;
205
206 /* The Prelude. */
207
208 pub mod prelude;
209
210
211 /* Primitive types */
212
213 // NB: slice and str are primitive types too, but their module docs + primitive doc pages
214 // are inlined from the public re-exports of core_collections::{slice, str} above.
215
216 #[path = "num/float_macros.rs"]
217 #[macro_use]
218 mod float_macros;
219
220 #[path = "num/int_macros.rs"]
221 #[macro_use]
222 mod int_macros;
223
224 #[path = "num/uint_macros.rs"]
225 #[macro_use]
226 mod uint_macros;
227
228 #[path = "num/isize.rs"]  pub mod isize;
229 #[path = "num/i8.rs"]   pub mod i8;
230 #[path = "num/i16.rs"]  pub mod i16;
231 #[path = "num/i32.rs"]  pub mod i32;
232 #[path = "num/i64.rs"]  pub mod i64;
233
234 #[path = "num/usize.rs"] pub mod usize;
235 #[path = "num/u8.rs"]   pub mod u8;
236 #[path = "num/u16.rs"]  pub mod u16;
237 #[path = "num/u32.rs"]  pub mod u32;
238 #[path = "num/u64.rs"]  pub mod u64;
239
240 #[path = "num/f32.rs"]   pub mod f32;
241 #[path = "num/f64.rs"]   pub mod f64;
242
243 pub mod ascii;
244
245 pub mod thunk;
246
247 /* Common traits */
248
249 pub mod num;
250
251 /* Runtime and platform support */
252
253 #[macro_use]
254 pub mod thread;
255
256 pub mod collections;
257 pub mod dynamic_lib;
258 pub mod env;
259 pub mod ffi;
260 pub mod fs;
261 pub mod io;
262 pub mod net;
263 pub mod os;
264 pub mod path;
265 pub mod process;
266 pub mod sync;
267 pub mod time;
268
269 #[macro_use]
270 #[path = "sys/common/mod.rs"] mod sys_common;
271
272 #[cfg(unix)]
273 #[path = "sys/unix/mod.rs"] mod sys;
274 #[cfg(windows)]
275 #[path = "sys/windows/mod.rs"] mod sys;
276
277 pub mod rt;
278 mod panicking;
279 mod rand;
280
281 // Some external utilities of the standard library rely on randomness (aka
282 // rustc_back::TempDir and tests) and need a way to get at the OS rng we've got
283 // here. This module is not at all intended for stabilization as-is, however,
284 // but it may be stabilized long-term. As a result we're exposing a hidden,
285 // unstable module so we can get our build working.
286 #[doc(hidden)]
287 #[unstable(feature = "rand")]
288 pub mod __rand {
289     pub use rand::{thread_rng, ThreadRng, Rng};
290 }
291
292 // Modules that exist purely to document + host impl docs for primitive types
293
294 mod array;
295 mod bool;
296 mod unit;
297 mod tuple;
298
299 // A curious inner-module that's not exported that contains the binding
300 // 'std' so that macro-expanded references to std::error and such
301 // can be resolved within libstd.
302 #[doc(hidden)]
303 mod std {
304     pub use sync; // used for select!()
305     pub use error; // used for try!()
306     pub use fmt; // used for any formatting strings
307     pub use option; // used for thread_local!{}
308     pub use rt; // used for panic!()
309     pub use vec; // used for vec![]
310     pub use cell; // used for tls!
311     pub use thread; // used for thread_local!
312     pub use marker;  // used for tls!
313
314     // The test runner calls ::std::env::args() but really wants realstd
315     #[cfg(test)] pub use realstd::env as env;
316     // The test runner requires std::slice::Vector, so re-export std::slice just for it.
317     //
318     // It is also used in vec![]
319     pub use slice;
320
321     pub use boxed; // used for vec![]
322 }