]> git.lizzy.rs Git - rust.git/blob - src/libstd/lib.rs
Rollup merge of #23738 - alexcrichton:snapshots, r=cmr
[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 //! It is linked to all Rust crates by default.
16 //!
17 //! ## Intrinsic types and operations
18 //!
19 //! The [`ptr`](ptr/index.html) and [`mem`](mem/index.html)
20 //! modules deal with unsafe pointers and memory manipulation.
21 //! [`marker`](marker/index.html) defines the special built-in traits,
22 //! and [`raw`](raw/index.html) the runtime representation of Rust types.
23 //! These are some of the lowest-level building blocks in Rust.
24 //!
25 //! ## Math on primitive types and math traits
26 //!
27 //! Although basic operations on primitive types are implemented
28 //! directly by the compiler, the standard library additionally
29 //! defines many common operations through traits defined in
30 //! mod [`num`](num/index.html).
31 //!
32 //! ## Pervasive types
33 //!
34 //! The [`option`](option/index.html) and [`result`](result/index.html)
35 //! modules define optional and error-handling types, `Option` and `Result`.
36 //! [`iter`](iter/index.html) defines Rust's iterator protocol
37 //! along with a wide variety of iterators.
38 //! [`Cell` and `RefCell`](cell/index.html) are for creating types that
39 //! manage their own mutability.
40 //!
41 //! ## Vectors, slices and strings
42 //!
43 //! The common container type, `Vec`, a growable vector backed by an array,
44 //! lives in the [`vec`](vec/index.html) module. Contiguous, unsized regions
45 //! of memory, `[T]`, commonly called "slices", and their borrowed versions,
46 //! `&[T]`, commonly called "borrowed slices", are built-in types for which the
47 //! for which the [`slice`](slice/index.html) module defines many methods.
48 //!
49 //! `&str`, a UTF-8 string, is a built-in type, and the standard library
50 //! defines methods for it on a variety of traits in the
51 //! [`str`](str/index.html) module. Rust strings are immutable;
52 //! use the `String` type defined in [`string`](string/index.html)
53 //! for a mutable string builder.
54 //!
55 //! For converting to strings use the [`format!`](fmt/index.html)
56 //! macro, and for converting from strings use the
57 //! [`FromStr`](str/trait.FromStr.html) trait.
58 //!
59 //! ## Platform abstractions
60 //!
61 //! Besides basic data types, the standard library is largely concerned
62 //! with abstracting over differences in common platforms, most notably
63 //! Windows and Unix derivatives. The [`os`](os/index.html) module
64 //! provides a number of basic functions for interacting with the
65 //! operating environment, including program arguments, environment
66 //! variables, and directory navigation. The [`path`](path/index.html)
67 //! module encapsulates the platform-specific rules for dealing
68 //! with file paths.
69 //!
70 //! `std` also includes modules for interoperating with the
71 //! C language: [`c_str`](c_str/index.html) and
72 //! [`c_vec`](c_vec/index.html).
73 //!
74 //! ## Concurrency, I/O, and the runtime
75 //!
76 //! The [`thread`](thread/index.html) module contains Rust's threading abstractions.
77 //! [`sync`](sync/index.html) contains further, primitive, shared memory types,
78 //! including [`atomic`](sync/atomic/index.html), and [`mpsc`](sync/mpsc/index.html),
79 //! which contains the channel types for message passing.
80 //!
81 //! Common types of I/O, including files, TCP, UDP, pipes, Unix domain sockets,
82 //! timers, and process spawning, are defined in the
83 //! [`old_io`](old_io/index.html) module.
84 //!
85 //! Rust's I/O and concurrency depends on a small runtime interface
86 //! that lives, along with its support code, in mod [`rt`](rt/index.html).
87 //! While a notable part of the standard library's architecture, this
88 //! module is not intended for public use.
89 //!
90 //! ## The Rust prelude and macros
91 //!
92 //! Finally, the [`prelude`](prelude/index.html) defines a
93 //! common set of traits, types, and functions that are made available
94 //! to all code by default. [`macros`](macros/index.html) contains
95 //! all the standard macros, such as `assert!`, `panic!`, `println!`,
96 //! and `format!`, also available to all Rust code.
97 // Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
98 #![cfg_attr(stage0, feature(custom_attribute))]
99 #![crate_name = "std"]
100 #![stable(feature = "rust1", since = "1.0.0")]
101 #![staged_api]
102 #![crate_type = "rlib"]
103 #![crate_type = "dylib"]
104 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
105        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
106        html_root_url = "http://doc.rust-lang.org/nightly/",
107        html_playground_url = "http://play.rust-lang.org/")]
108 #![doc(test(no_crate_inject))]
109
110 #![feature(alloc)]
111 #![feature(box_syntax)]
112 #![feature(collections)]
113 #![feature(core)]
114 #![feature(lang_items)]
115 #![feature(libc)]
116 #![feature(linkage, thread_local, asm)]
117 #![feature(old_impl_check)]
118 #![feature(optin_builtin_traits)]
119 #![feature(rand)]
120 #![feature(staged_api)]
121 #![feature(unboxed_closures)]
122 #![feature(unicode)]
123 #![feature(unsafe_destructor)]
124 #![feature(unsafe_no_drop_flag)]
125 #![feature(macro_reexport)]
126 #![feature(int_uint)]
127 #![feature(unique)]
128 #![feature(convert)]
129 #![feature(allow_internal_unstable)]
130 #![feature(str_char)]
131 #![feature(into_cow)]
132 #![cfg_attr(test, feature(test, rustc_private, std_misc))]
133
134 // Don't link to std. We are std.
135 #![feature(no_std)]
136 #![no_std]
137
138 #![allow(trivial_casts)]
139 #![allow(trivial_numeric_casts)]
140 #![deny(missing_docs)]
141
142 #[cfg(test)] extern crate test;
143 #[cfg(test)] #[macro_use] extern crate log;
144
145 #[macro_use]
146 #[macro_reexport(assert, assert_eq, debug_assert, debug_assert_eq,
147     unreachable, unimplemented, write, writeln)]
148 extern crate core;
149
150 #[macro_use]
151 #[macro_reexport(vec, format)]
152 extern crate collections as core_collections;
153
154 #[allow(deprecated)] extern crate rand as core_rand;
155 extern crate alloc;
156 extern crate unicode;
157 extern crate libc;
158
159 #[macro_use] #[no_link] extern crate rustc_bitflags;
160
161 // Make std testable by not duplicating lang items. See #2912
162 #[cfg(test)] extern crate std as realstd;
163 #[cfg(test)] pub use realstd::marker;
164 #[cfg(test)] pub use realstd::ops;
165 #[cfg(test)] pub use realstd::cmp;
166 #[cfg(test)] pub use realstd::boxed;
167
168
169 // NB: These reexports are in the order they should be listed in rustdoc
170
171 pub use core::any;
172 pub use core::cell;
173 pub use core::clone;
174 #[cfg(not(test))] pub use core::cmp;
175 pub use core::convert;
176 pub use core::default;
177 #[allow(deprecated)]
178 pub use core::finally;
179 pub use core::hash;
180 pub use core::intrinsics;
181 pub use core::iter;
182 #[cfg(not(test))] pub use core::marker;
183 pub use core::mem;
184 #[cfg(not(test))] pub use core::ops;
185 pub use core::ptr;
186 pub use core::raw;
187 pub use core::simd;
188 pub use core::result;
189 pub use core::option;
190 pub use core::error;
191
192 #[cfg(not(test))] pub use alloc::boxed;
193 pub use alloc::rc;
194
195 pub use core_collections::borrow;
196 pub use core_collections::fmt;
197 pub use core_collections::slice;
198 pub use core_collections::str;
199 pub use core_collections::string;
200 #[stable(feature = "rust1", since = "1.0.0")]
201 pub use core_collections::vec;
202
203 pub use unicode::char;
204
205 /* Exported macros */
206
207 #[macro_use]
208 mod macros;
209
210 mod rtdeps;
211
212 /* The Prelude. */
213
214 pub mod prelude;
215
216
217 /* Primitive types */
218
219 // NB: slice and str are primitive types too, but their module docs + primitive doc pages
220 // are inlined from the public re-exports of core_collections::{slice, str} above.
221
222 #[path = "num/float_macros.rs"]
223 #[macro_use]
224 mod float_macros;
225
226 #[path = "num/int_macros.rs"]
227 #[macro_use]
228 mod int_macros;
229
230 #[path = "num/uint_macros.rs"]
231 #[macro_use]
232 mod uint_macros;
233
234 #[path = "num/isize.rs"]  pub mod isize;
235 #[path = "num/i8.rs"]   pub mod i8;
236 #[path = "num/i16.rs"]  pub mod i16;
237 #[path = "num/i32.rs"]  pub mod i32;
238 #[path = "num/i64.rs"]  pub mod i64;
239
240 #[path = "num/usize.rs"] pub mod usize;
241 #[path = "num/u8.rs"]   pub mod u8;
242 #[path = "num/u16.rs"]  pub mod u16;
243 #[path = "num/u32.rs"]  pub mod u32;
244 #[path = "num/u64.rs"]  pub mod u64;
245
246 #[path = "num/f32.rs"]   pub mod f32;
247 #[path = "num/f64.rs"]   pub mod f64;
248
249 pub mod ascii;
250 pub mod thunk;
251
252 /* Common traits */
253
254 pub mod num;
255
256 /* Runtime and platform support */
257
258 #[macro_use]
259 pub mod thread;
260
261 pub mod collections;
262 pub mod dynamic_lib;
263 pub mod env;
264 pub mod ffi;
265 pub mod fs;
266 pub mod io;
267 pub mod net;
268 pub mod old_io;
269 pub mod old_path;
270 pub mod os;
271 pub mod path;
272 pub mod process;
273 pub mod rand;
274 pub mod sync;
275 pub mod time;
276
277 #[macro_use]
278 #[path = "sys/common/mod.rs"] mod sys_common;
279
280 #[cfg(unix)]
281 #[path = "sys/unix/mod.rs"] mod sys;
282 #[cfg(windows)]
283 #[path = "sys/windows/mod.rs"] mod sys;
284
285 pub mod rt;
286 mod panicking;
287
288 // Modules that exist purely to document + host impl docs for primitive types
289
290 mod array;
291 mod bool;
292 mod unit;
293 mod tuple;
294
295 // A curious inner-module that's not exported that contains the binding
296 // 'std' so that macro-expanded references to std::error and such
297 // can be resolved within libstd.
298 #[doc(hidden)]
299 mod std {
300     pub use sync; // used for select!()
301     pub use error; // used for try!()
302     pub use fmt; // used for any formatting strings
303     #[allow(deprecated)]
304     pub use old_io; // used for println!()
305     pub use option; // used for bitflags!{}
306     pub use rt; // used for panic!()
307     pub use vec; // used for vec![]
308     pub use cell; // used for tls!
309     pub use thread; // used for thread_local!
310     pub use marker;  // used for tls!
311     pub use ops; // used for bitflags!
312
313     // The test runner calls ::std::env::args() but really wants realstd
314     #[cfg(test)] pub use realstd::env as env;
315     // The test runner requires std::slice::Vector, so re-export std::slice just for it.
316     //
317     // It is also used in vec![]
318     pub use slice;
319
320     pub use boxed; // used for vec![]
321 }