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.
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 Standard Library
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.
17 //! ## Intrinsic types and operations
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.
25 //! ## Math on primitive types and math traits
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).
32 //! ## Pervasive types
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.
41 //! ## Vectors, slices and strings
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 //! [`slice`](slice/index.html) module defines many methods.
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.
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.
59 //! ## Platform abstractions
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
70 //! `std` also includes the [`ffi`](ffi/index.html) module for interoperating
71 //! with the C language.
73 //! ## Concurrency, I/O, and the runtime
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.
80 //! Common types of I/O, including files, TCP, UDP, pipes, Unix domain sockets, and
81 //! process spawning, are defined in the [`io`](io/index.html) module.
83 //! Rust's I/O and concurrency depends on a small runtime interface
84 //! that lives, along with its support code, in mod [`rt`](rt/index.html).
85 //! While a notable part of the standard library's architecture, this
86 //! module is not intended for public use.
88 //! ## The Rust prelude and macros
90 //! Finally, the [`prelude`](prelude/index.html) defines a
91 //! common set of traits, types, and functions that are made available
92 //! to all code by default. [`macros`](macros/index.html) contains
93 //! all the standard macros, such as `assert!`, `panic!`, `println!`,
94 //! and `format!`, also available to all Rust code.
95 // Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
96 #![cfg_attr(stage0, feature(custom_attribute))]
97 #![crate_name = "std"]
98 #![stable(feature = "rust1", since = "1.0.0")]
100 #![crate_type = "rlib"]
101 #![crate_type = "dylib"]
102 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
103 html_favicon_url = "http://www.rust-lang.org/favicon.ico",
104 html_root_url = "http://doc.rust-lang.org/nightly/",
105 html_playground_url = "http://play.rust-lang.org/")]
106 #![doc(test(no_crate_inject, attr(deny(warnings))))]
107 #![doc(test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
110 #![feature(allow_internal_unstable)]
111 #![feature(associated_consts)]
112 #![feature(box_syntax)]
113 #![feature(collections)]
115 #![feature(debug_builders)]
116 #![feature(into_cow)]
117 #![feature(lang_items)]
119 #![feature(linkage, thread_local, asm)]
120 #![feature(macro_reexport)]
121 #![feature(optin_builtin_traits)]
123 #![feature(slice_patterns)]
124 #![feature(staged_api)]
125 #![feature(std_misc)]
126 #![feature(str_char)]
127 #![feature(unboxed_closures)]
130 #![feature(unsafe_no_drop_flag, filling_drop)]
131 #![feature(zero_one)]
132 #![cfg_attr(test, feature(float_from_str_radix))]
133 #![cfg_attr(test, feature(test, rustc_private, std_misc))]
135 // Don't link to std. We are std.
139 #![allow(trivial_casts)]
140 #![deny(missing_docs)]
142 #[cfg(test)] extern crate test;
143 #[cfg(test)] #[macro_use] extern crate log;
146 #[macro_reexport(assert, assert_eq, debug_assert, debug_assert_eq,
147 unreachable, unimplemented, write, writeln)]
151 #[macro_reexport(vec, format)]
152 extern crate collections as core_collections;
154 #[allow(deprecated)] extern crate rand as core_rand;
156 extern crate rustc_unicode;
159 #[macro_use] #[no_link] extern crate rustc_bitflags;
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;
169 // NB: These reexports are in the order they should be listed in rustdoc
174 #[cfg(not(test))] pub use core::cmp;
175 pub use core::convert;
176 pub use core::default;
178 pub use core::intrinsics;
180 #[cfg(not(test))] pub use core::marker;
182 #[cfg(not(test))] pub use core::ops;
186 pub use core::result;
187 pub use core::option;
190 #[cfg(not(test))] pub use alloc::boxed;
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;
201 pub use rustc_unicode::char;
203 /* Exported macros */
215 /* Primitive types */
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.
220 #[path = "num/float_macros.rs"]
224 #[path = "num/int_macros.rs"]
228 #[path = "num/uint_macros.rs"]
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;
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;
244 #[path = "num/f32.rs"] pub mod f32;
245 #[path = "num/f64.rs"] pub mod f64;
255 /* Runtime and platform support */
274 #[path = "sys/common/mod.rs"] mod sys_common;
277 #[path = "sys/unix/mod.rs"] mod sys;
279 #[path = "sys/windows/mod.rs"] mod sys;
285 // Some external utilities of the standard library rely on randomness (aka
286 // rustc_back::TempDir and tests) and need a way to get at the OS rng we've got
287 // here. This module is not at all intended for stabilization as-is, however,
288 // but it may be stabilized long-term. As a result we're exposing a hidden,
289 // unstable module so we can get our build working.
291 #[unstable(feature = "rand")]
293 pub use rand::{thread_rng, ThreadRng, Rng};
296 // Modules that exist purely to document + host impl docs for primitive types
303 // A curious inner-module that's not exported that contains the binding
304 // 'std' so that macro-expanded references to std::error and such
305 // can be resolved within libstd.
308 pub use sync; // used for select!()
309 pub use error; // used for try!()
310 pub use fmt; // used for any formatting strings
311 pub use option; // used for thread_local!{}
312 pub use rt; // used for panic!()
313 pub use vec; // used for vec![]
314 pub use cell; // used for tls!
315 pub use thread; // used for thread_local!
316 pub use marker; // used for tls!
318 // The test runner calls ::std::env::args() but really wants realstd
319 #[cfg(test)] pub use realstd::env as env;
320 // The test runner requires std::slice::Vector, so re-export std::slice just for it.
322 // It is also used in vec![]
325 pub use boxed; // used for vec![]