std.rs 5.4 KB
Newer Older
S
sevrak 已提交
1
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 3 4 5 6 7 8 9 10
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

11 12
/*!

13
# The Rust standard library
14

15 16 17 18 19 20 21 22 23 24 25 26 27 28
The Rust standard library is a group of interrelated modules defining
the core language traits, operations on built-in data types, collections,
platform abstractions, the task scheduler, runtime support for language
features and other common functionality.

`std` includes modules corresponding to each of the integer types,
each of the floating point types, the `bool` type, tuples, characters,
strings (`str`), vectors (`vec`), managed boxes (`managed`), owned
boxes (`owned`), and unsafe and borrowed pointers (`ptr`, `borrowed`).
Additionally, `std` provides pervasive types (`option` and `result`),
task creation and communication primitives (`task`, `comm`), platform
abstractions (`os` and `path`), basic I/O abstractions (`io`), common
traits (`kinds`, `ops`, `cmp`, `num`, `to_str`), and complete bindings
to the C standard library (`libc`).
29

30
# Standard library injection and the Rust prelude
31

32
`std` is imported at the topmost level of every crate by default, as
33
if the first line of each crate was
34

35
    extern mod std;
36

37 38
This means that the contents of std can be accessed from any context
with the `std::` path prefix, as in `use std::vec`, `use std::task::spawn`,
39 40
etc.

41
Additionally, `std` contains a `prelude` module that reexports many of the
42
most common types, traits and functions. The contents of the prelude are
43
imported into every *module* by default.  Implicitly, all modules behave as if
44 45
they contained the following prologue:

46
    use std::prelude::*;
47 48 49

*/

50

51
#[link(name = "std",
B
Brian Anderson 已提交
52
       vers = "0.8-pre",
53
       uuid = "c70c24a7-5551-4f73-8e37-380b11d80be8",
54
       url = "https://github.com/mozilla/rust/tree/master/src/libstd")];
55

56
#[comment = "The Rust standard library"];
57
#[license = "MIT/ASL2"];
58
#[crate_type = "lib"];
59

60 61
// Don't link to std. We are std.
#[no_std];
B
Brian Anderson 已提交
62

63
#[deny(non_camel_case_types)];
64
#[deny(missing_doc)];
65

66 67 68
// Make extra accessible for benchmarking
#[cfg(test)] extern mod extra(vers="0.8-pre");

69
// Make std testable by not duplicating lang items. See #2912
70 71 72 73
#[cfg(test)] extern mod realstd(name = "std");
#[cfg(test)] pub use kinds = realstd::kinds;
#[cfg(test)] pub use ops = realstd::ops;
#[cfg(test)] pub use cmp = realstd::cmp;
74

P
Patrick Walton 已提交
75 76
// On Linux, link to the runtime with -lrt.
#[cfg(target_os = "linux")]
77
#[doc(hidden)]
P
Patrick Walton 已提交
78 79
pub mod linkhack {
    #[link_args="-lrustrt -lrt"]
80
    #[link_args = "-lpthread"]
P
Patrick Walton 已提交
81 82 83 84
    extern {
    }
}

85 86 87
// Internal macros
mod macros;

88 89 90
/* The Prelude. */

pub mod prelude;
91

92
/* Primitive types */
93

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
#[path = "num/int_macros.rs"]   mod int_macros;
#[path = "num/uint_macros.rs"]  mod uint_macros;

#[path = "num/int.rs"]  pub mod int;
#[path = "num/i8.rs"]   pub mod i8;
#[path = "num/i16.rs"]  pub mod i16;
#[path = "num/i32.rs"]  pub mod i32;
#[path = "num/i64.rs"]  pub mod i64;

#[path = "num/uint.rs"] pub mod uint;
#[path = "num/u8.rs"]   pub mod u8;
#[path = "num/u16.rs"]  pub mod u16;
#[path = "num/u32.rs"]  pub mod u32;
#[path = "num/u64.rs"]  pub mod u64;

#[path = "num/float.rs"] pub mod float;
#[path = "num/f32.rs"]   pub mod f32;
#[path = "num/f64.rs"]   pub mod f64;
112

113
pub mod unit;
114
pub mod bool;
115
pub mod char;
116
pub mod tuple;
117 118 119 120 121

pub mod vec;
pub mod at_vec;
pub mod str;

M
Marvin Löbel 已提交
122 123
#[path = "str/ascii.rs"]
pub mod ascii;
M
Marvin Löbel 已提交
124
pub mod send_str;
M
Marvin Löbel 已提交
125

126
pub mod ptr;
T
Tim Chevalier 已提交
127
pub mod owned;
128
pub mod managed;
129
pub mod borrow;
130 131


132 133
/* Core language traits */

134 135 136
#[cfg(not(test))] pub mod kinds;
#[cfg(not(test))] pub mod ops;
#[cfg(not(test))] pub mod cmp;
137 138 139 140 141


/* Common traits */

pub mod from_str;
142
#[path = "num/num.rs"]
143
pub mod num;
144
pub mod iter;
145 146
pub mod to_str;
pub mod to_bytes;
B
Brian Anderson 已提交
147
pub mod clone;
148 149
pub mod io;
pub mod hash;
150
pub mod container;
C
Corey Richardson 已提交
151
pub mod default;
152

153 154 155 156 157
/* Common data structures */

pub mod option;
pub mod result;
pub mod either;
D
Daniel Micay 已提交
158
pub mod hashmap;
159
pub mod cell;
160
pub mod trie;
M
Marijn Haverbeke 已提交
161

162 163 164

/* Tasks and communication */

B
Brian Anderson 已提交
165
pub mod task;
166
pub mod comm;
167
pub mod select;
168
pub mod local_data;
M
Marijn Haverbeke 已提交
169

170 171

/* Runtime and platform support */
172

173
pub mod libc;
174
pub mod c_str;
175 176 177 178 179 180
pub mod os;
pub mod path;
pub mod rand;
pub mod run;
pub mod sys;
pub mod cast;
181
pub mod fmt;
182 183 184
#[cfg(stage0)] #[path = "repr_stage0.rs"]
pub mod repr;
#[cfg(not(stage0))]
185 186
pub mod repr;
pub mod cleanup;
187 188 189
#[cfg(stage0)] #[path = "reflect_stage0.rs"]
pub mod reflect;
#[cfg(not(stage0))]
190
pub mod reflect;
191
pub mod condition;
192 193
pub mod logging;
pub mod util;
194

195 196 197 198

/* Unsupported interfaces */

// Private APIs
199
pub mod unstable;
200 201 202

/* For internal use, not exported */

203
mod unicode;
204
#[path = "num/cmath.rs"]
205
mod cmath;
206

207
// FIXME #7809: This shouldn't be pub, and it should be reexported under 'unstable'
208 209
// but name resolution doesn't work without it being pub.
pub mod rt;
210

B
Brian Anderson 已提交
211
// A curious inner-module that's not exported that contains the binding
212 213
// 'std' so that macro-expanded references to std::error and such
// can be resolved within libstd.
214
#[doc(hidden)]
215 216 217 218 219 220
mod std {
    pub use clone;
    pub use cmp;
    pub use condition;
    pub use option;
    pub use kinds;
221
    pub use local_data;
222
    pub use logging;
223
    pub use sys;
224 225 226
    pub use unstable;
    pub use str;
    pub use os;
227 228
    pub use fmt;
    pub use to_bytes;
229
}