]> git.lizzy.rs Git - rust.git/blob - src/libstd/lib.rs
87c4ef1046f1a490405395c7431bf4789b244ec6
[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`](../core/ptr/index.html), [`mem`](../core/mem/index.html),
20 //! and [`cast`](../core/cast/index.html) modules deal with unsafe pointers,
21 //! memory manipulation, and coercion.
22 //! [`kinds`](../core/kinds/index.html) defines the special built-in traits,
23 //! and [`raw`](../core/raw/index.html) the runtime representation of Rust types.
24 //! These are some of the lowest-level building blocks of Rust
25 //! abstractions.
26 //!
27 //! ## Math on primitive types and math traits
28 //!
29 //! Although basic operations on primitive types are implemented
30 //! directly by the compiler, the standard library additionally
31 //! defines many common operations through traits defined in
32 //! mod [`num`](num/index.html).
33 //!
34 //! ## Pervasive types
35 //!
36 //! The [`option`](option/index.html) and [`result`](result/index.html)
37 //! modules define optional and error-handling types, `Option` and `Result`.
38 //! [`iter`](../core/iter/index.html) defines Rust's iterator protocol
39 //! along with a wide variety of iterators.
40 //! [`Cell` and `RefCell`](../core/cell/index.html) are for creating types that
41 //! manage their own mutability.
42 //!
43 //! ## Vectors, slices and strings
44 //!
45 //! The common container type, `Vec`, a growable vector backed by an
46 //! array, lives in the [`vec`](vec/index.html) module. References to
47 //! arrays, `&[T]`, more commonly called "slices", are built-in types
48 //! for which the [`slice`](slice/index.html) module defines many
49 //! methods.
50 //!
51 //! UTF-8 strings, `~str` and `&str`, are built-in types, and the
52 //! standard library defines methods for them on a variety of traits
53 //! in the [`str`](str/index.html) module. Rust strings are immutable;
54 //! use the `StrBuf` type defined in [`strbuf`](strbuf/index.html)
55 //! for a mutable string builder.
56 //!
57 //! For converting to strings use the [`format!`](fmt/index.html)
58 //! macro, and for converting from strings use the
59 //! [`FromStr`](from_str/index.html) trait.
60 //!
61 //! ## Platform abstractions
62 //!
63 //! Besides basic data types, the standard library is largely concerned
64 //! with abstracting over differences in common platforms, most notably
65 //! Windows and Unix derivatives. The [`os`](os/index.html) module
66 //! provides a number of basic functions for interacting with the
67 //! operating environment, including program arguments, environment
68 //! variables, and directory navigation. The [`path`](path/index.html)
69 //! module encapsulates the platform-specific rules for dealing
70 //! with file paths.
71 //!
72 //! `std` also includes modules for interoperating with the
73 //! C language: [`c_str`](c_str/index.html) and
74 //! [`c_vec`](c_vec/index.html).
75 //!
76 //! ## Concurrency, I/O, and the runtime
77 //!
78 //! The [`task`](task/index.html) module contains Rust's threading abstractions,
79 //! while [`comm`](comm/index.html) contains the channel types for message
80 //! passing. [`sync`](sync/index.html) contains further, primitive, shared
81 //! memory types, including [`atomics`](sync/atomics/index.html).
82 //!
83 //! Common types of I/O, including files, TCP, UPD, pipes, Unix domain sockets,
84 //! timers, and process spawning, are defined in the [`io`](io/index.html) module.
85 //!
86 //! Rust's I/O and concurrency depends on a small runtime interface
87 //! that lives, along with its support code, in mod [`rt`](rt/index.html).
88 //! While a notable part of the standard library's architecture, this
89 //! module is not intended for public use.
90 //!
91 //! ## The Rust prelude and macros
92 //!
93 //! Finally, the [`prelude`](prelude/index.html) defines a
94 //! common set of traits, types, and functions that are made available
95 //! to all code by default. [`macros`](macros/index.html) contains
96 //! all the standard macros, such as `assert!`, `fail!`, `println!`,
97 //! and `format!`, also available to all Rust code.
98
99 #![crate_id = "std#0.11.0-pre"]
100 #![comment = "The Rust standard library"]
101 #![license = "MIT/ASL2"]
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://static.rust-lang.org/doc/master")]
107 #![feature(macro_rules, globs, asm, managed_boxes, thread_local, link_args,
108            simd, linkage, default_type_params, phase, concat_idents, quad_precision_float)]
109
110 // Don't link to std. We are std.
111 #![no_std]
112
113 #![allow(deprecated)]
114 #![deny(missing_doc)]
115
116 // When testing libstd, bring in libuv as the I/O backend so tests can print
117 // things and all of the std::io tests have an I/O interface to run on top
118 // of
119 #[cfg(test)] extern crate rustuv;
120 #[cfg(test)] extern crate native;
121 #[cfg(test)] extern crate green;
122 #[cfg(test)] #[phase(syntax, link)] extern crate log;
123
124 // Make and rand accessible for benchmarking/testcases
125 #[cfg(test)] extern crate rand;
126
127 extern crate libc;
128 extern crate core;
129
130 // Make std testable by not duplicating lang items. See #2912
131 #[cfg(test)] extern crate realstd = "std";
132 #[cfg(test)] pub use kinds = realstd::kinds;
133 #[cfg(test)] pub use ops = realstd::ops;
134 #[cfg(test)] pub use cmp = realstd::cmp;
135 #[cfg(test)] pub use ty = realstd::ty;
136 #[cfg(test)] pub use owned = realstd::owned;
137
138 #[cfg(not(test))] pub use cmp = core::cmp;
139 #[cfg(not(test))] pub use kinds = core::kinds;
140 #[cfg(not(test))] pub use ops = core::ops;
141 #[cfg(not(test))] pub use ty = core::ty;
142
143 pub use core::any;
144 pub use core::bool;
145 pub use core::cell;
146 pub use core::char;
147 pub use core::clone;
148 pub use core::container;
149 pub use core::default;
150 pub use core::intrinsics;
151 pub use core::iter;
152 pub use core::mem;
153 pub use core::ptr;
154 pub use core::raw;
155 pub use core::tuple;
156
157 // Run tests with libgreen instead of libnative.
158 //
159 // FIXME: This egregiously hacks around starting the test runner in a different
160 //        threading mode than the default by reaching into the auto-generated
161 //        '__test' module.
162 #[cfg(test)] #[start]
163 fn start(argc: int, argv: **u8) -> int {
164     green::start(argc, argv, rustuv::event_loop, __test::main)
165 }
166
167 /* Exported macros */
168
169 pub mod macros;
170 pub mod bitflags;
171
172 mod rtdeps;
173
174 /* The Prelude. */
175
176 pub mod prelude;
177
178
179 /* Primitive types */
180
181 #[path = "num/float_macros.rs"] mod float_macros;
182 #[path = "num/int_macros.rs"]   mod int_macros;
183 #[path = "num/uint_macros.rs"]  mod uint_macros;
184
185 #[path = "num/int.rs"]  pub mod int;
186 #[path = "num/i8.rs"]   pub mod i8;
187 #[path = "num/i16.rs"]  pub mod i16;
188 #[path = "num/i32.rs"]  pub mod i32;
189 #[path = "num/i64.rs"]  pub mod i64;
190
191 #[path = "num/uint.rs"] pub mod uint;
192 #[path = "num/u8.rs"]   pub mod u8;
193 #[path = "num/u16.rs"]  pub mod u16;
194 #[path = "num/u32.rs"]  pub mod u32;
195 #[path = "num/u64.rs"]  pub mod u64;
196
197 #[path = "num/f32.rs"]   pub mod f32;
198 #[path = "num/f64.rs"]   pub mod f64;
199
200 pub mod slice;
201 pub mod vec;
202 pub mod str;
203 pub mod strbuf;
204
205 pub mod ascii;
206
207 pub mod rc;
208 pub mod gc;
209 #[cfg(not(test))]
210 pub mod owned;
211
212 /* Common traits */
213
214 pub mod from_str;
215 pub mod num;
216 pub mod to_str;
217 pub mod hash;
218
219 /* Common data structures */
220
221 pub mod result;
222 pub mod option;
223
224 /* Tasks and communication */
225
226 pub mod task;
227 pub mod comm;
228 pub mod local_data;
229 pub mod sync;
230
231
232 /* Runtime and platform support */
233
234 pub mod c_str;
235 pub mod c_vec;
236 pub mod os;
237 pub mod io;
238 pub mod path;
239 pub mod fmt;
240 pub mod cleanup;
241
242 /* Unsupported interfaces */
243
244 #[unstable]
245 pub mod repr;
246 #[unstable]
247 pub mod reflect;
248
249 // Private APIs
250 #[unstable]
251 pub mod unstable;
252
253 /* For internal use, not exported */
254
255 mod unicode;
256
257 // FIXME #7809: This shouldn't be pub, and it should be reexported under 'unstable'
258 // but name resolution doesn't work without it being pub.
259 #[unstable]
260 pub mod rt;
261
262 // A curious inner-module that's not exported that contains the binding
263 // 'std' so that macro-expanded references to std::error and such
264 // can be resolved within libstd.
265 #[doc(hidden)]
266 mod std {
267     pub use clone;
268     pub use cmp;
269     pub use comm;
270     pub use fmt;
271     pub use hash;
272     pub use io;
273     pub use kinds;
274     pub use local_data;
275     pub use option;
276     pub use os;
277     pub use rt;
278     pub use str;
279     pub use to_str;
280     pub use ty;
281     pub use unstable;
282     pub use vec;
283
284     // The test runner requires std::slice::Vector, so re-export std::slice just for it.
285     #[cfg(test)] pub use slice;
286 }