]> git.lizzy.rs Git - rust.git/blob - src/libstd/lib.rs
Stabilize `std::convert` and related code
[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 the [`ffi`](ffi/index.html) module for interoperating
71 //! with the C language.
72 //!
73 //! ## Concurrency, I/O, and the runtime
74 //!
75 //! The [`thread`](thread/index.html) module contains Rust's threading abstractions.
76 //! [`sync`](sync/index.html) contains further, primitive, shared memory types,
77 //! including [`atomic`](sync/atomic/index.html), and [`mpsc`](sync/mpsc/index.html),
78 //! which contains the channel types for message passing.
79 //!
80 //! Common types of I/O, including files, TCP, UDP, pipes, Unix domain sockets,
81 //! timers, and process spawning, are defined in the
82 //! [`old_io`](old_io/index.html) module.
83 //!
84 //! Rust's I/O and concurrency depends on a small runtime interface
85 //! that lives, along with its support code, in mod [`rt`](rt/index.html).
86 //! While a notable part of the standard library's architecture, this
87 //! module is not intended for public use.
88 //!
89 //! ## The Rust prelude and macros
90 //!
91 //! Finally, the [`prelude`](prelude/index.html) defines a
92 //! common set of traits, types, and functions that are made available
93 //! to all code by default. [`macros`](macros/index.html) contains
94 //! all the standard macros, such as `assert!`, `panic!`, `println!`,
95 //! and `format!`, also available to all Rust code.
96 // Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
97 #![cfg_attr(stage0, feature(custom_attribute))]
98 #![crate_name = "std"]
99 #![stable(feature = "rust1", since = "1.0.0")]
100 #![staged_api]
101 #![crate_type = "rlib"]
102 #![crate_type = "dylib"]
103 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
104        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
105        html_root_url = "http://doc.rust-lang.org/nightly/",
106        html_playground_url = "http://play.rust-lang.org/")]
107 #![doc(test(no_crate_inject))]
108
109 #![feature(alloc)]
110 #![feature(box_syntax)]
111 #![feature(collections)]
112 #![feature(core)]
113 #![feature(lang_items)]
114 #![feature(libc)]
115 #![feature(linkage, thread_local, asm)]
116 #![feature(optin_builtin_traits)]
117 #![feature(rand)]
118 #![feature(staged_api)]
119 #![feature(unboxed_closures)]
120 #![feature(unicode)]
121 #![feature(unsafe_destructor)]
122 #![feature(unsafe_no_drop_flag, filling_drop)]
123 #![feature(macro_reexport)]
124 #![feature(unique)]
125 #![feature(allow_internal_unstable)]
126 #![feature(str_char)]
127 #![feature(into_cow)]
128 #![feature(std_misc)]
129 #![feature(slice_patterns)]
130 #![feature(debug_builders)]
131 #![cfg_attr(test, feature(test, rustc_private, std_misc))]
132
133 // Don't link to std. We are std.
134 #![feature(no_std)]
135 #![no_std]
136
137 #![allow(trivial_casts)]
138 #![deny(missing_docs)]
139
140 #[cfg(test)] extern crate test;
141 #[cfg(test)] #[macro_use] extern crate log;
142
143 #[macro_use]
144 #[macro_reexport(assert, assert_eq, debug_assert, debug_assert_eq,
145     unreachable, unimplemented, write, writeln)]
146 extern crate core;
147
148 #[macro_use]
149 #[macro_reexport(vec, format)]
150 extern crate collections as core_collections;
151
152 #[allow(deprecated)] extern crate rand as core_rand;
153 extern crate alloc;
154 extern crate unicode;
155 extern crate libc;
156
157 #[macro_use] #[no_link] extern crate rustc_bitflags;
158
159 // Make std testable by not duplicating lang items. See #2912
160 #[cfg(test)] extern crate std as realstd;
161 #[cfg(test)] pub use realstd::marker;
162 #[cfg(test)] pub use realstd::ops;
163 #[cfg(test)] pub use realstd::cmp;
164 #[cfg(test)] pub use realstd::boxed;
165
166
167 // NB: These reexports are in the order they should be listed in rustdoc
168
169 pub use core::any;
170 pub use core::cell;
171 pub use core::clone;
172 #[cfg(not(test))] pub use core::cmp;
173 pub use core::convert;
174 pub use core::default;
175 #[allow(deprecated)]
176 pub use core::finally;
177 pub use core::hash;
178 pub use core::intrinsics;
179 pub use core::iter;
180 #[cfg(not(test))] pub use core::marker;
181 pub use core::mem;
182 #[cfg(not(test))] pub use core::ops;
183 pub use core::ptr;
184 pub use core::raw;
185 pub use core::simd;
186 pub use core::result;
187 pub use core::option;
188 pub use core::error;
189
190 #[cfg(not(test))] pub use alloc::boxed;
191 pub use alloc::rc;
192
193 pub use core_collections::borrow;
194 pub use core_collections::fmt;
195 pub use core_collections::slice;
196 pub use core_collections::str;
197 pub use core_collections::string;
198 #[stable(feature = "rust1", since = "1.0.0")]
199 pub use core_collections::vec;
200
201 pub use unicode::char;
202
203 /* Exported macros */
204
205 #[macro_use]
206 mod macros;
207
208 mod rtdeps;
209
210 /* The Prelude. */
211
212 pub mod prelude;
213
214
215 /* Primitive types */
216
217 // NB: slice and str are primitive types too, but their module docs + primitive doc pages
218 // are inlined from the public re-exports of core_collections::{slice, str} above.
219
220 #[path = "num/float_macros.rs"]
221 #[macro_use]
222 mod float_macros;
223
224 #[path = "num/int_macros.rs"]
225 #[macro_use]
226 mod int_macros;
227
228 #[path = "num/uint_macros.rs"]
229 #[macro_use]
230 mod uint_macros;
231
232 #[path = "num/isize.rs"]  pub mod isize;
233 #[path = "num/i8.rs"]   pub mod i8;
234 #[path = "num/i16.rs"]  pub mod i16;
235 #[path = "num/i32.rs"]  pub mod i32;
236 #[path = "num/i64.rs"]  pub mod i64;
237
238 #[path = "num/usize.rs"] pub mod usize;
239 #[path = "num/u8.rs"]   pub mod u8;
240 #[path = "num/u16.rs"]  pub mod u16;
241 #[path = "num/u32.rs"]  pub mod u32;
242 #[path = "num/u64.rs"]  pub mod u64;
243
244 #[path = "num/f32.rs"]   pub mod f32;
245 #[path = "num/f64.rs"]   pub mod f64;
246
247 pub mod ascii;
248 pub mod thunk;
249
250 /* Common traits */
251
252 pub mod num;
253
254 /* Runtime and platform support */
255
256 #[macro_use]
257 pub mod thread;
258
259 pub mod collections;
260 pub mod dynamic_lib;
261 pub mod env;
262 pub mod ffi;
263 pub mod fs;
264 pub mod io;
265 pub mod net;
266 pub mod old_io;
267 pub mod old_path;
268 pub mod os;
269 pub mod path;
270 pub mod process;
271 pub mod rand;
272 pub mod sync;
273 pub mod time;
274
275 #[macro_use]
276 #[path = "sys/common/mod.rs"] mod sys_common;
277
278 #[cfg(unix)]
279 #[path = "sys/unix/mod.rs"] mod sys;
280 #[cfg(windows)]
281 #[path = "sys/windows/mod.rs"] mod sys;
282
283 pub mod rt;
284 mod panicking;
285
286 // Modules that exist purely to document + host impl docs for primitive types
287
288 mod array;
289 mod bool;
290 mod unit;
291 mod tuple;
292
293 // A curious inner-module that's not exported that contains the binding
294 // 'std' so that macro-expanded references to std::error and such
295 // can be resolved within libstd.
296 #[doc(hidden)]
297 mod std {
298     pub use sync; // used for select!()
299     pub use error; // used for try!()
300     pub use fmt; // used for any formatting strings
301     #[allow(deprecated)]
302     pub use old_io; // used for println!()
303     pub use option; // used for bitflags!{}
304     pub use rt; // used for panic!()
305     pub use vec; // used for vec![]
306     pub use cell; // used for tls!
307     pub use thread; // used for thread_local!
308     pub use marker;  // used for tls!
309     pub use ops; // used for bitflags!
310
311     // The test runner calls ::std::env::args() but really wants realstd
312     #[cfg(test)] pub use realstd::env as env;
313     // The test runner requires std::slice::Vector, so re-export std::slice just for it.
314     //
315     // It is also used in vec![]
316     pub use slice;
317
318     pub use boxed; // used for vec![]
319 }