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