]> git.lizzy.rs Git - rust.git/blob - src/libstd/lib.rs
a67ed1c0b7919bf59584e7b5f8cf132f5ee3001b
[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 //! [`kinds`](kinds/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
44 //! array, lives in the [`vec`](vec/index.html) module. References to
45 //! arrays, `&[T]`, more commonly called "slices", are built-in types
46 //! for which the [`slice`](slice/index.html) module defines many
47 //! 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`](from_str/index.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 modules for interoperating with the
71 //! C language: [`c_str`](c_str/index.html) and
72 //! [`c_vec`](c_vec/index.html).
73 //!
74 //! ## Concurrency, I/O, and the runtime
75 //!
76 //! The [`task`](task/index.html) module contains Rust's threading abstractions,
77 //! while [`comm`](comm/index.html) contains the channel types for message
78 //! passing. [`sync`](sync/index.html) contains further, primitive, shared
79 //! memory types, including [`atomics`](sync/atomics/index.html).
80 //!
81 //! Common types of I/O, including files, TCP, UPD, pipes, Unix domain sockets,
82 //! timers, and process spawning, are defined in the [`io`](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!`, `fail!`, `println!`,
95 //! and `format!`, also available to all Rust code.
96
97 #![crate_id = "std#0.11.0-pre"]
98 #![comment = "The Rust standard library"]
99 #![license = "MIT/ASL2"]
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/")]
105 #![feature(macro_rules, globs, asm, managed_boxes, thread_local, link_args,
106            linkage, default_type_params, phase, concat_idents, quad_precision_float)]
107
108 // Don't link to std. We are std.
109 #![no_std]
110
111 #![allow(deprecated)]
112 #![deny(missing_doc)]
113
114 // When testing libstd, bring in libuv as the I/O backend so tests can print
115 // things and all of the std::io tests have an I/O interface to run on top
116 // of
117 #[cfg(test)] extern crate rustuv;
118 #[cfg(test)] extern crate native;
119 #[cfg(test)] extern crate green;
120 #[cfg(test)] extern crate debug;
121 #[cfg(test)] #[phase(syntax, link)] extern crate log;
122
123 extern crate alloc;
124 extern crate core;
125 extern crate libc;
126 extern crate core_rand = "rand";
127
128 // Make std testable by not duplicating lang items. See #2912
129 #[cfg(test)] extern crate realstd = "std";
130 #[cfg(test)] pub use realstd::kinds;
131 #[cfg(test)] pub use realstd::ops;
132 #[cfg(test)] pub use realstd::cmp;
133 #[cfg(test)] pub use realstd::ty;
134
135
136 // NB: These reexports are in the order they should be listed in rustdoc
137
138 pub use core::any;
139 pub use core::bool;
140 pub use core::cell;
141 pub use core::char;
142 pub use core::clone;
143 #[cfg(not(test))] pub use core::cmp;
144 pub use core::container;
145 pub use core::default;
146 pub use core::finally;
147 pub use core::intrinsics;
148 pub use core::iter;
149 #[cfg(not(test))] pub use core::kinds;
150 pub use core::mem;
151 #[cfg(not(test))] pub use core::ops;
152 pub use core::ptr;
153 pub use core::raw;
154 pub use core::simd;
155 pub use core::tuple;
156 #[cfg(not(test))] pub use core::ty;
157 pub use core::result;
158
159 pub use alloc::owned;
160 pub use alloc::rc;
161
162 // Run tests with libgreen instead of libnative.
163 //
164 // FIXME: This egregiously hacks around starting the test runner in a different
165 //        threading mode than the default by reaching into the auto-generated
166 //        '__test' module.
167 #[cfg(test)] #[start]
168 fn start(argc: int, argv: **u8) -> int {
169     green::start(argc, argv, rustuv::event_loop, __test::main)
170 }
171
172 /* Exported macros */
173
174 pub mod macros;
175 pub mod bitflags;
176
177 mod rtdeps;
178
179 /* The Prelude. */
180
181 pub mod prelude;
182
183
184 /* Primitive types */
185
186 #[path = "num/float_macros.rs"] mod float_macros;
187 #[path = "num/int_macros.rs"]   mod int_macros;
188 #[path = "num/uint_macros.rs"]  mod uint_macros;
189
190 #[path = "num/int.rs"]  pub mod int;
191 #[path = "num/i8.rs"]   pub mod i8;
192 #[path = "num/i16.rs"]  pub mod i16;
193 #[path = "num/i32.rs"]  pub mod i32;
194 #[path = "num/i64.rs"]  pub mod i64;
195
196 #[path = "num/uint.rs"] pub mod uint;
197 #[path = "num/u8.rs"]   pub mod u8;
198 #[path = "num/u16.rs"]  pub mod u16;
199 #[path = "num/u32.rs"]  pub mod u32;
200 #[path = "num/u64.rs"]  pub mod u64;
201
202 #[path = "num/f32.rs"]   pub mod f32;
203 #[path = "num/f64.rs"]   pub mod f64;
204
205 pub mod slice;
206 pub mod vec;
207 pub mod str;
208 pub mod string;
209 pub mod rand;
210
211 pub mod ascii;
212
213 pub mod gc;
214
215 /* Common traits */
216
217 pub mod from_str;
218 pub mod num;
219 pub mod to_str;
220 pub mod hash;
221
222 /* Common data structures */
223
224 pub mod option;
225
226 /* Tasks and communication */
227
228 pub mod task;
229 pub mod comm;
230 pub mod local_data;
231 pub mod sync;
232
233
234 /* Runtime and platform support */
235
236 pub mod c_str;
237 pub mod c_vec;
238 pub mod os;
239 pub mod io;
240 pub mod path;
241 pub mod fmt;
242 pub mod cleanup;
243
244 // Private APIs
245 #[unstable]
246 pub mod unstable;
247
248 /* For internal use, not exported */
249
250 mod unicode;
251
252 // FIXME #7809: This shouldn't be pub, and it should be reexported under 'unstable'
253 // but name resolution doesn't work without it being pub.
254 #[unstable]
255 pub mod rt;
256
257 // A curious inner-module that's not exported that contains the binding
258 // 'std' so that macro-expanded references to std::error and such
259 // can be resolved within libstd.
260 #[doc(hidden)]
261 mod std {
262     // mods used for deriving
263     pub use clone;
264     pub use cmp;
265     pub use hash;
266
267     pub use comm; // used for select!()
268     pub use fmt; // used for any formatting strings
269     pub use io; // used for println!()
270     pub use local_data; // used for local_data_key!()
271     pub use option; // used for bitflags!()
272     pub use rt; // used for fail!()
273     pub use vec; // used for vec![]
274
275     // The test runner calls ::std::os::args() but really wants realstd
276     #[cfg(test)] pub use os = realstd::os;
277     // The test runner requires std::slice::Vector, so re-export std::slice just for it.
278     #[cfg(test)] pub use slice;
279 }