2014-01-24 07:40:54 +00:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-04 00:48:01 +00:00
|
|
|
// 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.
|
|
|
|
|
2014-04-25 07:39:58 +00:00
|
|
|
//! # The Rust Standard Library
|
2013-10-31 22:09:24 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! The Rust Standard Library is the foundation of portable Rust software, a
|
|
|
|
//! set of minimal and battle-tested shared abstractions for the [broader Rust
|
|
|
|
//! ecosystem][crates.io]. It offers core types, like [`Vec<T>`] and
|
|
|
|
//! [`Option<T>`], library-defined [operations on language
|
|
|
|
//! primitives](#primitives), [standard macros](#macros), [I/O] and
|
|
|
|
//! [multithreading], among [many other things][other].
|
|
|
|
//!
|
|
|
|
//! `std` is available to all Rust crates by default, just as if each one
|
|
|
|
//! contained an `extern crate std;` import at the [crate root]. Therefore the
|
|
|
|
//! standard library can be accessed in [`use`] statements through the path
|
|
|
|
//! `std`, as in [`use std::env`], or in expressions through the absolute path
|
2017-03-12 18:04:52 +00:00
|
|
|
//! `::std`, as in [`::std::env::args`].
|
2013-10-31 22:09:24 +00:00
|
|
|
//!
|
2015-07-11 19:12:19 +00:00
|
|
|
//! # How to read this documentation
|
|
|
|
//!
|
2015-12-17 18:55:20 +00:00
|
|
|
//! If you already know the name of what you are looking for, the fastest way to
|
2015-10-30 21:18:26 +00:00
|
|
|
//! find it is to use the <a href="#" onclick="focusSearchBar();">search
|
|
|
|
//! bar</a> at the top of the page.
|
2015-07-11 19:12:19 +00:00
|
|
|
//!
|
|
|
|
//! Otherwise, you may want to jump to one of these useful sections:
|
|
|
|
//!
|
|
|
|
//! * [`std::*` modules](#modules)
|
|
|
|
//! * [Primitive types](#primitives)
|
|
|
|
//! * [Standard macros](#macros)
|
|
|
|
//! * [The Rust Prelude](prelude/index.html)
|
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! If this is your first time, the documentation for the standard library is
|
|
|
|
//! written to be casually perused. Clicking on interesting things should
|
|
|
|
//! generally lead you to interesting places. Still, there are important bits
|
|
|
|
//! you don't want to miss, so read on for a tour of the standard library and
|
|
|
|
//! its documentation!
|
2015-07-11 19:12:19 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! Once you are familiar with the contents of the standard library you may
|
|
|
|
//! begin to find the verbosity of the prose distracting. At this stage in your
|
|
|
|
//! development you may want to press the **[-]** button near the top of the
|
|
|
|
//! page to collapse it into a more skimmable view.
|
2015-07-11 19:12:19 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! While you are looking at that **[-]** button also notice the **[src]**
|
|
|
|
//! button. Rust's API documentation comes with the source code and you are
|
|
|
|
//! encouraged to read it. The standard library source is generally high
|
|
|
|
//! quality and a peek behind the curtains is often enlightening.
|
2015-07-11 19:12:19 +00:00
|
|
|
//!
|
|
|
|
//! # What is in the standard library documentation?
|
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! First of all, The Rust Standard Library is divided into a number of focused
|
|
|
|
//! modules, [all listed further down this page](#modules). These modules are
|
|
|
|
//! the bedrock upon which all of Rust is forged, and they have mighty names
|
|
|
|
//! like [`std::slice`] and [`std::cmp`]. Modules' documentation typically
|
|
|
|
//! includes an overview of the module along with examples, and are a smart
|
|
|
|
//! place to start familiarizing yourself with the library.
|
2015-07-11 19:12:19 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! Second, implicit methods on [primitive types] are documented here. This can
|
2015-07-11 19:12:19 +00:00
|
|
|
//! be a source of confusion for two reasons:
|
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! 1. While primitives are implemented by the compiler, the standard library
|
|
|
|
//! implements methods directly on the primitive types (and it is the only
|
|
|
|
//! library that does so), which are [documented in the section on
|
|
|
|
//! primitives](#primitives).
|
|
|
|
//! 2. The standard library exports many modules *with the same name as
|
|
|
|
//! primitive types*. These define additional items related to the primitive
|
|
|
|
//! type, but not the all-important methods.
|
2015-07-11 19:12:19 +00:00
|
|
|
//!
|
|
|
|
//! So for example there is a [page for the primitive type
|
2015-10-30 21:18:26 +00:00
|
|
|
//! `i32`](primitive.i32.html) that lists all the methods that can be called on
|
|
|
|
//! 32-bit integers (very useful), and there is a [page for the module
|
|
|
|
//! `std::i32`](i32/index.html) that documents the constant values [`MIN`] and
|
2015-12-25 23:01:10 +00:00
|
|
|
//! [`MAX`](i32/constant.MAX.html) (rarely useful).
|
2015-10-30 21:18:26 +00:00
|
|
|
//!
|
2015-10-30 21:43:05 +00:00
|
|
|
//! Note the documentation for the primitives [`str`] and [`[T]`][slice] (also
|
|
|
|
//! called 'slice'). Many method calls on [`String`] and [`Vec<T>`] are actually
|
2017-08-04 11:03:58 +00:00
|
|
|
//! calls to methods on [`str`] and [`[T]`][slice] respectively, via [deref
|
|
|
|
//! coercions][deref-coercions].
|
2015-10-30 21:18:26 +00:00
|
|
|
//!
|
|
|
|
//! Third, the standard library defines [The Rust Prelude], a small collection
|
|
|
|
//! of items - mostly traits - that are imported into every module of every
|
|
|
|
//! crate. The traits in the prelude are pervasive, making the prelude
|
2015-07-14 00:56:31 +00:00
|
|
|
//! documentation a good entry point to learning about the library.
|
2015-07-11 19:12:19 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! And finally, the standard library exports a number of standard macros, and
|
|
|
|
//! [lists them on this page](#macros) (technically, not all of the standard
|
|
|
|
//! macros are defined by the standard library - some are defined by the
|
|
|
|
//! compiler - but they are documented here the same). Like the prelude, the
|
|
|
|
//! standard macros are imported by default into all crates.
|
2015-07-11 19:12:19 +00:00
|
|
|
//!
|
2017-03-23 17:29:04 +00:00
|
|
|
//! # Contributing changes to the documentation
|
|
|
|
//!
|
2017-04-07 20:42:56 +00:00
|
|
|
//! Check out the rust contribution guidelines [here](
|
|
|
|
//! https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md).
|
2017-03-31 01:54:10 +00:00
|
|
|
//! The source for this documentation can be found on [Github](https://github.com/rust-lang).
|
2017-03-23 17:48:32 +00:00
|
|
|
//! To contribute changes, make sure you read the guidelines first, then submit
|
|
|
|
//! pull-requests for your suggested changes.
|
2017-04-07 20:42:56 +00:00
|
|
|
//!
|
2017-03-23 17:48:32 +00:00
|
|
|
//! Contributions are appreciated! If you see a part of the docs that can be
|
2017-03-31 01:54:10 +00:00
|
|
|
//! improved, submit a PR, or chat with us first on irc.mozilla.org #rust-docs.
|
2017-03-23 17:29:04 +00:00
|
|
|
//!
|
2015-07-11 19:12:19 +00:00
|
|
|
//! # A Tour of The Rust Standard Library
|
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! The rest of this crate documentation is dedicated to pointing out notable
|
|
|
|
//! features of The Rust Standard Library.
|
2013-10-31 22:09:24 +00:00
|
|
|
//!
|
2015-05-08 22:15:03 +00:00
|
|
|
//! ## Containers and collections
|
2013-10-31 22:09:24 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! The [`option`] and [`result`] modules define optional and error-handling
|
|
|
|
//! types, [`Option<T>`] and [`Result<T, E>`]. The [`iter`] module defines
|
|
|
|
//! Rust's iterator trait, [`Iterator`], which works with the [`for`] loop to
|
|
|
|
//! access collections.
|
2014-04-25 07:39:58 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! The standard library exposes three common ways to deal with contiguous
|
2015-07-14 00:56:31 +00:00
|
|
|
//! regions of memory:
|
2014-04-25 07:39:58 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! * [`Vec<T>`] - A heap-allocated *vector* that is resizable at runtime.
|
2015-10-30 21:43:05 +00:00
|
|
|
//! * [`[T; n]`][array] - An inline *array* with a fixed size at compile time.
|
|
|
|
//! * [`[T]`][slice] - A dynamically sized *slice* into any other kind of contiguous
|
2015-10-30 21:18:26 +00:00
|
|
|
//! storage, whether heap-allocated or not.
|
2015-07-14 00:56:31 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! Slices can only be handled through some kind of *pointer*, and as such come
|
|
|
|
//! in many flavors such as:
|
2015-07-14 00:56:31 +00:00
|
|
|
//!
|
|
|
|
//! * `&[T]` - *shared slice*
|
|
|
|
//! * `&mut [T]` - *mutable slice*
|
2015-10-30 21:43:05 +00:00
|
|
|
//! * [`Box<[T]>`][owned slice] - *owned slice*
|
2015-07-14 17:25:54 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! [`str`], a UTF-8 string slice, is a primitive type, and the standard library
|
|
|
|
//! defines many methods for it. Rust [`str`]s are typically accessed as
|
|
|
|
//! immutable references: `&str`. Use the owned [`String`] for building and
|
|
|
|
//! mutating strings.
|
2014-04-25 07:39:58 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! For converting to strings use the [`format!`] macro, and for converting from
|
|
|
|
//! strings use the [`FromStr`] trait.
|
2014-04-25 07:39:58 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! Data may be shared by placing it in a reference-counted box or the [`Rc`]
|
|
|
|
//! type, and if further contained in a [`Cell`] or [`RefCell`], may be mutated
|
|
|
|
//! as well as shared. Likewise, in a concurrent setting it is common to pair an
|
|
|
|
//! atomically-reference-counted box, [`Arc`], with a [`Mutex`] to get the same
|
|
|
|
//! effect.
|
2015-05-08 22:15:03 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! The [`collections`] module defines maps, sets, linked lists and other
|
|
|
|
//! typical collection types, including the common [`HashMap<K, V>`].
|
2015-05-08 22:15:03 +00:00
|
|
|
//!
|
|
|
|
//! ## Platform abstractions and I/O
|
2014-04-25 07:39:58 +00:00
|
|
|
//!
|
2015-10-30 21:18:26 +00:00
|
|
|
//! Besides basic data types, the standard library is largely concerned with
|
|
|
|
//! abstracting over differences in common platforms, most notably Windows and
|
|
|
|
//! Unix derivatives.
|
|
|
|
//!
|
|
|
|
//! Common types of I/O, including [files], [TCP], [UDP], are defined in the
|
|
|
|
//! [`io`], [`fs`], and [`net`] modules.
|
|
|
|
//!
|
|
|
|
//! The [`thread`] module contains Rust's threading abstractions. [`sync`]
|
|
|
|
//! contains further primitive shared memory types, including [`atomic`] and
|
|
|
|
//! [`mpsc`], which contains the channel types for message passing.
|
|
|
|
//!
|
|
|
|
//! [I/O]: io/index.html
|
2015-12-11 21:00:54 +00:00
|
|
|
//! [`MIN`]: i32/constant.MIN.html
|
2015-10-30 21:18:26 +00:00
|
|
|
//! [TCP]: net/struct.TcpStream.html
|
|
|
|
//! [The Rust Prelude]: prelude/index.html
|
|
|
|
//! [UDP]: net/struct.UdpSocket.html
|
2017-03-12 18:04:52 +00:00
|
|
|
//! [`::std::env::args`]: env/fn.args.html
|
2015-10-30 21:18:26 +00:00
|
|
|
//! [`Arc`]: sync/struct.Arc.html
|
2015-10-30 21:43:05 +00:00
|
|
|
//! [owned slice]: boxed/index.html
|
2015-10-30 21:18:26 +00:00
|
|
|
//! [`Cell`]: cell/struct.Cell.html
|
|
|
|
//! [`FromStr`]: str/trait.FromStr.html
|
|
|
|
//! [`HashMap<K, V>`]: collections/struct.HashMap.html
|
|
|
|
//! [`Iterator`]: iter/trait.Iterator.html
|
|
|
|
//! [`Mutex`]: sync/struct.Mutex.html
|
|
|
|
//! [`Option<T>`]: option/enum.Option.html
|
|
|
|
//! [`Rc`]: rc/index.html
|
|
|
|
//! [`RefCell`]: cell/struct.RefCell.html
|
|
|
|
//! [`Result<T, E>`]: result/enum.Result.html
|
|
|
|
//! [`String`]: string/struct.String.html
|
|
|
|
//! [`Vec<T>`]: vec/index.html
|
2015-10-30 21:43:05 +00:00
|
|
|
//! [array]: primitive.array.html
|
|
|
|
//! [slice]: primitive.slice.html
|
2015-10-30 21:18:26 +00:00
|
|
|
//! [`atomic`]: sync/atomic/index.html
|
|
|
|
//! [`collections`]: collections/index.html
|
2017-03-15 16:13:55 +00:00
|
|
|
//! [`for`]: ../book/first-edition/loops.html#for
|
2016-08-15 22:36:39 +00:00
|
|
|
//! [`format!`]: macro.format.html
|
2015-10-30 21:18:26 +00:00
|
|
|
//! [`fs`]: fs/index.html
|
|
|
|
//! [`io`]: io/index.html
|
|
|
|
//! [`iter`]: iter/index.html
|
|
|
|
//! [`mpsc`]: sync/mpsc/index.html
|
|
|
|
//! [`net`]: net/index.html
|
|
|
|
//! [`option`]: option/index.html
|
|
|
|
//! [`result`]: result/index.html
|
|
|
|
//! [`std::cmp`]: cmp/index.html
|
|
|
|
//! [`std::slice`]: slice/index.html
|
|
|
|
//! [`str`]: primitive.str.html
|
|
|
|
//! [`sync`]: sync/index.html
|
|
|
|
//! [`thread`]: thread/index.html
|
|
|
|
//! [`use std::env`]: env/index.html
|
2017-03-15 16:13:55 +00:00
|
|
|
//! [`use`]: ../book/first-edition/crates-and-modules.html#importing-modules-with-use
|
|
|
|
//! [crate root]: ../book/first-edition/crates-and-modules.html#basic-terminology-crates-and-modules
|
2015-10-30 21:18:26 +00:00
|
|
|
//! [crates.io]: https://crates.io
|
2017-08-03 19:17:31 +00:00
|
|
|
//! [deref-coercions]: ../book/second-edition/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods
|
2015-10-30 21:18:26 +00:00
|
|
|
//! [files]: fs/struct.File.html
|
|
|
|
//! [multithreading]: thread/index.html
|
|
|
|
//! [other]: #what-is-in-the-standard-library-documentation
|
2017-03-15 16:13:55 +00:00
|
|
|
//! [primitive types]: ../book/first-edition/primitive-types.html
|
2015-05-08 22:15:03 +00:00
|
|
|
|
2015-01-24 05:48:20 +00:00
|
|
|
#![stable(feature = "rust1", since = "1.0.0")]
|
2015-08-09 21:15:05 +00:00
|
|
|
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
2015-05-15 23:04:01 +00:00
|
|
|
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
2015-08-09 21:15:05 +00:00
|
|
|
html_root_url = "https://doc.rust-lang.org/nightly/",
|
|
|
|
html_playground_url = "https://play.rust-lang.org/",
|
2015-08-16 15:22:50 +00:00
|
|
|
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
|
2015-06-09 18:18:03 +00:00
|
|
|
test(no_crate_inject, attr(deny(warnings))),
|
|
|
|
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
|
2014-06-17 23:00:04 +00:00
|
|
|
|
2016-10-01 01:38:29 +00:00
|
|
|
// Don't link to std. We are std.
|
|
|
|
#![no_std]
|
|
|
|
|
|
|
|
#![deny(missing_docs)]
|
2016-11-25 18:21:49 +00:00
|
|
|
#![deny(missing_debug_implementations)]
|
2016-10-01 01:38:29 +00:00
|
|
|
|
|
|
|
// Tell the compiler to link to either panic_abort or panic_unwind
|
2016-05-24 05:28:15 +00:00
|
|
|
#![needs_panic_runtime]
|
|
|
|
|
2016-10-01 01:38:29 +00:00
|
|
|
// Turn warnings into errors, but only after stage0, where it can be useful for
|
|
|
|
// code to emit warnings during language transitions
|
2016-12-29 17:47:34 +00:00
|
|
|
#![deny(warnings)]
|
2016-10-01 01:38:29 +00:00
|
|
|
|
|
|
|
// std may use features in a platform-specific way
|
|
|
|
#![allow(unused_features)]
|
|
|
|
|
|
|
|
// std is implemented with unstable features, many of which are internal
|
|
|
|
// compiler details that will never be stable
|
2015-01-30 20:26:44 +00:00
|
|
|
#![feature(alloc)]
|
2017-06-13 19:57:49 +00:00
|
|
|
#![feature(allocator_api)]
|
2017-06-03 21:54:08 +00:00
|
|
|
#![feature(alloc_system)]
|
|
|
|
#![feature(allocator_internals)]
|
2017-08-08 15:22:51 +00:00
|
|
|
#![feature(allow_internal_unsafe)]
|
2015-04-28 23:36:22 +00:00
|
|
|
#![feature(allow_internal_unstable)]
|
2017-09-13 10:20:39 +00:00
|
|
|
#![feature(align_offset)]
|
2017-09-29 17:30:03 +00:00
|
|
|
#![feature(array_error_internals)]
|
2017-10-03 15:39:31 +00:00
|
|
|
#![feature(ascii_ctype)]
|
2015-11-03 00:23:22 +00:00
|
|
|
#![feature(asm)]
|
2017-09-29 19:58:11 +00:00
|
|
|
#![feature(attr_literals)]
|
2015-01-07 14:15:34 +00:00
|
|
|
#![feature(box_syntax)]
|
2016-10-14 19:31:15 +00:00
|
|
|
#![feature(cfg_target_has_atomic)]
|
2015-12-11 20:42:29 +00:00
|
|
|
#![feature(cfg_target_thread_local)]
|
2016-07-27 10:10:31 +00:00
|
|
|
#![feature(cfg_target_vendor)]
|
2017-05-27 22:12:16 +00:00
|
|
|
#![feature(char_error_internals)]
|
2015-06-09 18:18:03 +00:00
|
|
|
#![feature(char_internals)]
|
2016-10-17 19:26:29 +00:00
|
|
|
#![feature(collections_range)]
|
2016-09-13 19:27:26 +00:00
|
|
|
#![feature(compiler_builtins_lib)]
|
2015-05-27 08:18:36 +00:00
|
|
|
#![feature(const_fn)]
|
2015-06-09 18:18:03 +00:00
|
|
|
#![feature(core_float)]
|
|
|
|
#![feature(core_intrinsics)]
|
2016-12-28 22:47:10 +00:00
|
|
|
#![feature(dropck_eyepatch)]
|
2016-12-03 20:59:00 +00:00
|
|
|
#![feature(exact_size_is_empty)]
|
2017-11-07 17:23:56 +00:00
|
|
|
#![feature(fs_read_write)]
|
2017-09-29 17:30:03 +00:00
|
|
|
#![feature(fixed_size_array)]
|
2015-11-03 00:23:22 +00:00
|
|
|
#![feature(float_from_str_radix)]
|
2016-03-07 17:20:25 +00:00
|
|
|
#![feature(fn_traits)]
|
2016-07-27 10:10:31 +00:00
|
|
|
#![feature(fnbox)]
|
2016-08-13 18:42:36 +00:00
|
|
|
#![feature(fused)]
|
2016-12-28 22:47:10 +00:00
|
|
|
#![feature(generic_param_attrs)]
|
2016-01-21 18:28:39 +00:00
|
|
|
#![feature(hashmap_hasher)]
|
2016-07-27 10:10:31 +00:00
|
|
|
#![feature(heap_api)]
|
2017-01-26 21:10:48 +00:00
|
|
|
#![feature(i128)]
|
|
|
|
#![feature(i128_type)]
|
2016-01-28 16:20:48 +00:00
|
|
|
#![feature(inclusive_range)]
|
2015-06-09 18:18:03 +00:00
|
|
|
#![feature(int_error_internals)]
|
2016-10-14 19:31:15 +00:00
|
|
|
#![feature(integer_atomics)]
|
2015-04-28 23:36:22 +00:00
|
|
|
#![feature(into_cow)]
|
2015-02-11 12:57:40 +00:00
|
|
|
#![feature(lang_items)]
|
2015-01-23 02:22:03 +00:00
|
|
|
#![feature(libc)]
|
2015-11-03 00:23:22 +00:00
|
|
|
#![feature(link_args)]
|
|
|
|
#![feature(linkage)]
|
2015-04-28 23:36:22 +00:00
|
|
|
#![feature(macro_reexport)]
|
2017-04-19 02:29:40 +00:00
|
|
|
#![feature(macro_vis_matcher)]
|
2016-07-27 10:10:31 +00:00
|
|
|
#![feature(needs_panic_runtime)]
|
2017-03-16 03:07:28 +00:00
|
|
|
#![feature(never_type)]
|
2015-12-12 22:38:03 +00:00
|
|
|
#![feature(num_bits_bytes)]
|
2016-01-15 18:07:52 +00:00
|
|
|
#![feature(old_wrapping)]
|
2015-08-31 15:51:53 +00:00
|
|
|
#![feature(on_unimplemented)]
|
2015-06-09 18:52:41 +00:00
|
|
|
#![feature(oom)]
|
2015-01-30 20:26:44 +00:00
|
|
|
#![feature(optin_builtin_traits)]
|
2017-08-22 01:30:51 +00:00
|
|
|
#![feature(panic_unwind)]
|
2017-01-11 03:11:56 +00:00
|
|
|
#![feature(peek)]
|
2015-02-12 10:30:16 +00:00
|
|
|
#![feature(placement_in_syntax)]
|
2017-03-09 07:50:48 +00:00
|
|
|
#![feature(placement_new_protocol)]
|
2016-08-22 19:47:38 +00:00
|
|
|
#![feature(prelude_import)]
|
2015-01-23 02:22:03 +00:00
|
|
|
#![feature(rand)]
|
2015-06-09 18:18:03 +00:00
|
|
|
#![feature(raw)]
|
2017-09-29 19:58:11 +00:00
|
|
|
#![feature(repr_align)]
|
2016-07-27 10:10:31 +00:00
|
|
|
#![feature(repr_simd)]
|
2016-03-10 19:20:09 +00:00
|
|
|
#![feature(rustc_attrs)]
|
2015-08-31 15:51:53 +00:00
|
|
|
#![feature(shared)]
|
2016-06-21 21:27:15 +00:00
|
|
|
#![feature(sip_hash_13)]
|
2015-06-09 18:18:03 +00:00
|
|
|
#![feature(slice_bytes)]
|
2015-11-03 00:23:22 +00:00
|
|
|
#![feature(slice_concat_ext)]
|
2015-04-28 23:36:22 +00:00
|
|
|
#![feature(slice_patterns)]
|
2015-01-30 20:26:44 +00:00
|
|
|
#![feature(staged_api)]
|
2016-01-05 20:30:14 +00:00
|
|
|
#![feature(stmt_expr_attributes)]
|
2015-04-28 23:36:22 +00:00
|
|
|
#![feature(str_char)]
|
2015-06-09 18:18:03 +00:00
|
|
|
#![feature(str_internals)]
|
2015-11-03 00:23:22 +00:00
|
|
|
#![feature(str_utf16)]
|
|
|
|
#![feature(test, rustc_private)]
|
|
|
|
#![feature(thread_local)]
|
2017-04-13 09:48:46 +00:00
|
|
|
#![feature(toowned_clone_into)]
|
2016-07-27 10:10:31 +00:00
|
|
|
#![feature(try_from)]
|
2015-01-30 20:26:44 +00:00
|
|
|
#![feature(unboxed_closures)]
|
|
|
|
#![feature(unicode)]
|
2015-02-23 19:39:16 +00:00
|
|
|
#![feature(unique)]
|
2017-02-10 17:55:00 +00:00
|
|
|
#![feature(untagged_unions)]
|
2015-09-11 18:10:43 +00:00
|
|
|
#![feature(unwind_attributes)]
|
2015-06-09 21:39:23 +00:00
|
|
|
#![feature(vec_push_all)]
|
2017-08-05 06:39:46 +00:00
|
|
|
#![feature(doc_cfg)]
|
2017-08-22 01:20:21 +00:00
|
|
|
#![feature(doc_masked)]
|
2017-10-05 03:00:22 +00:00
|
|
|
#![feature(doc_spotlight)]
|
2016-08-10 16:32:35 +00:00
|
|
|
#![cfg_attr(test, feature(update_panic_count))]
|
2017-11-24 17:18:22 +00:00
|
|
|
#![cfg_attr(windows, feature(used))]
|
2017-09-08 18:26:54 +00:00
|
|
|
|
2017-07-17 16:32:08 +00:00
|
|
|
#![default_lib_allocator]
|
2017-06-03 21:54:08 +00:00
|
|
|
|
2017-08-01 14:37:10 +00:00
|
|
|
// Always use alloc_system during stage0 since we don't know if the alloc_*
|
2017-08-10 13:40:42 +00:00
|
|
|
// crate the stage0 compiler will pick by default is enabled (e.g.
|
|
|
|
// if the user has disabled jemalloc in `./configure`).
|
2017-08-28 15:57:37 +00:00
|
|
|
// `force_alloc_system` is *only* intended as a workaround for local rebuilds
|
|
|
|
// with a rustc without jemalloc.
|
2017-08-31 14:07:54 +00:00
|
|
|
// FIXME(#44236) shouldn't need MSVC logic
|
|
|
|
#![cfg_attr(all(not(target_env = "msvc"),
|
|
|
|
any(stage0, feature = "force_alloc_system")),
|
2017-08-28 15:55:45 +00:00
|
|
|
feature(global_allocator))]
|
2017-08-31 14:07:54 +00:00
|
|
|
#[cfg(all(not(target_env = "msvc"),
|
|
|
|
any(stage0, feature = "force_alloc_system")))]
|
2017-08-01 14:37:10 +00:00
|
|
|
#[global_allocator]
|
|
|
|
static ALLOC: alloc_system::System = alloc_system::System;
|
|
|
|
|
2016-10-01 01:38:29 +00:00
|
|
|
// Explicitly import the prelude. The compiler uses this same unstable attribute
|
|
|
|
// to import the prelude implicitly when building crates that depend on std.
|
2016-08-22 19:47:38 +00:00
|
|
|
#[prelude_import]
|
|
|
|
#[allow(unused)]
|
|
|
|
use prelude::v1::*;
|
|
|
|
|
2016-10-01 01:38:29 +00:00
|
|
|
// Access to Bencher, etc.
|
2015-02-01 04:24:36 +00:00
|
|
|
#[cfg(test)] extern crate test;
|
2017-11-01 19:32:13 +00:00
|
|
|
#[cfg(test)] extern crate rand;
|
2013-10-22 22:13:18 +00:00
|
|
|
|
2015-07-30 00:01:14 +00:00
|
|
|
// We want to reexport a few macros from core but libcore has already been
|
|
|
|
// imported by the compiler (via our #[no_std] attribute) In this case we just
|
|
|
|
// add a new crate name so we can attach the reexports to it.
|
2016-07-27 17:47:19 +00:00
|
|
|
#[macro_reexport(assert, assert_eq, assert_ne, debug_assert, debug_assert_eq,
|
|
|
|
debug_assert_ne, unreachable, unimplemented, write, writeln, try)]
|
2015-07-30 00:01:14 +00:00
|
|
|
extern crate core as __core;
|
2015-01-01 04:43:46 +00:00
|
|
|
|
|
|
|
#[macro_use]
|
2014-09-07 21:57:26 +00:00
|
|
|
#[macro_reexport(vec, format)]
|
2014-09-16 02:29:47 +00:00
|
|
|
extern crate alloc;
|
2017-06-03 21:54:08 +00:00
|
|
|
extern crate alloc_system;
|
2016-11-29 19:38:08 +00:00
|
|
|
extern crate std_unicode;
|
2017-08-21 18:43:45 +00:00
|
|
|
#[doc(masked)]
|
2014-06-04 03:09:39 +00:00
|
|
|
extern crate libc;
|
2014-02-24 18:16:03 +00:00
|
|
|
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 23:18:40 +00:00
|
|
|
// We always need an unwinder currently for backtraces
|
2017-08-21 18:43:45 +00:00
|
|
|
#[doc(masked)]
|
2017-08-22 01:30:51 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 23:18:40 +00:00
|
|
|
extern crate unwind;
|
|
|
|
|
2016-07-25 02:42:11 +00:00
|
|
|
// compiler-rt intrinsics
|
2017-08-21 18:43:45 +00:00
|
|
|
#[doc(masked)]
|
2016-07-25 02:42:11 +00:00
|
|
|
extern crate compiler_builtins;
|
|
|
|
|
2016-10-01 01:38:29 +00:00
|
|
|
// During testing, this crate is not actually the "real" std library, but rather
|
|
|
|
// it links to the real std library, which was compiled from this same source
|
|
|
|
// code. So any lang items std defines are conditionally excluded (or else they
|
|
|
|
// wolud generate duplicate lang item errors), and any globals it defines are
|
|
|
|
// _not_ the globals used by "real" std. So this import, defined only during
|
|
|
|
// testing gives test-std access to real-std lang items and globals. See #2912
|
2015-03-25 01:13:54 +00:00
|
|
|
#[cfg(test)] extern crate std as realstd;
|
2014-05-20 17:38:05 +00:00
|
|
|
|
2016-10-01 01:38:29 +00:00
|
|
|
// The standard macros that are not built-in to the compiler.
|
|
|
|
#[macro_use]
|
|
|
|
mod macros;
|
|
|
|
|
|
|
|
// The Rust prelude
|
|
|
|
pub mod prelude;
|
2014-05-01 03:22:55 +00:00
|
|
|
|
2016-10-01 01:38:29 +00:00
|
|
|
// Public module declarations and reexports
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2014-05-01 03:36:58 +00:00
|
|
|
pub use core::any;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2014-05-01 18:19:56 +00:00
|
|
|
pub use core::cell;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2014-05-01 03:55:38 +00:00
|
|
|
pub use core::clone;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-07-28 23:22:05 +00:00
|
|
|
pub use core::cmp;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-03-18 16:14:54 +00:00
|
|
|
pub use core::convert;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2014-05-01 03:46:51 +00:00
|
|
|
pub use core::default;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
std: Stabilize the std::hash module
This commit aims to prepare the `std::hash` module for alpha by formalizing its
current interface whileholding off on adding `#[stable]` to the new APIs. The
current usage with the `HashMap` and `HashSet` types is also reconciled by
separating out composable parts of the design. The primary goal of this slight
redesign is to separate the concepts of a hasher's state from a hashing
algorithm itself.
The primary change of this commit is to separate the `Hasher` trait into a
`Hasher` and a `HashState` trait. Conceptually the old `Hasher` trait was
actually just a factory for various states, but hashing had very little control
over how these states were used. Additionally the old `Hasher` trait was
actually fairly unrelated to hashing.
This commit redesigns the existing `Hasher` trait to match what the notion of a
`Hasher` normally implies with the following definition:
trait Hasher {
type Output;
fn reset(&mut self);
fn finish(&self) -> Output;
}
This `Hasher` trait emphasizes that hashing algorithms may produce outputs other
than a `u64`, so the output type is made generic. Other than that, however, very
little is assumed about a particular hasher. It is left up to implementors to
provide specific methods or trait implementations to feed data into a hasher.
The corresponding `Hash` trait becomes:
trait Hash<H: Hasher> {
fn hash(&self, &mut H);
}
The old default of `SipState` was removed from this trait as it's not something
that we're willing to stabilize until the end of time, but the type parameter is
always required to implement `Hasher`. Note that the type parameter `H` remains
on the trait to enable multidispatch for specialization of hashing for
particular hashers.
Note that `Writer` is not mentioned in either of `Hash` or `Hasher`, it is
simply used as part `derive` and the implementations for all primitive types.
With these definitions, the old `Hasher` trait is realized as a new `HashState`
trait in the `collections::hash_state` module as an unstable addition for
now. The current definition looks like:
trait HashState {
type Hasher: Hasher;
fn hasher(&self) -> Hasher;
}
The purpose of this trait is to emphasize that the one piece of functionality
for implementors is that new instances of `Hasher` can be created. This
conceptually represents the two keys from which more instances of a
`SipHasher` can be created, and a `HashState` is what's stored in a
`HashMap`, not a `Hasher`.
Implementors of custom hash algorithms should implement the `Hasher` trait, and
only hash algorithms intended for use in hash maps need to implement or worry
about the `HashState` trait.
The entire module and `HashState` infrastructure remains `#[unstable]` due to it
being recently redesigned, but some other stability decision made for the
`std::hash` module are:
* The `Writer` trait remains `#[experimental]` as it's intended to be replaced
with an `io::Writer` (more details soon).
* The top-level `hash` function is `#[unstable]` as it is intended to be generic
over the hashing algorithm instead of hardwired to `SipHasher`
* The inner `sip` module is now private as its one export, `SipHasher` is
reexported in the `hash` module.
And finally, a few changes were made to the default parameters on `HashMap`.
* The `RandomSipHasher` default type parameter was renamed to `RandomState`.
This renaming emphasizes that it is not a hasher, but rather just state to
generate hashers. It also moves away from the name "sip" as it may not always
be implemented as `SipHasher`. This type lives in the
`std::collections::hash_map` module as `#[unstable]`
* The associated `Hasher` type of `RandomState` is creatively called...
`Hasher`! This concrete structure lives next to `RandomState` as an
implemenation of the "default hashing algorithm" used for a `HashMap`. Under
the hood this is currently implemented as `SipHasher`, but it draws an
explicit interface for now and allows us to modify the implementation over
time if necessary.
There are many breaking changes outlined above, and as a result this commit is
a:
[breaking-change]
2014-12-09 20:37:23 +00:00
|
|
|
pub use core::hash;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2014-05-01 03:04:56 +00:00
|
|
|
pub use core::intrinsics;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2014-05-01 04:41:03 +00:00
|
|
|
pub use core::iter;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-07-28 23:22:05 +00:00
|
|
|
pub use core::marker;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2014-05-01 03:13:05 +00:00
|
|
|
pub use core::mem;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-07-28 23:22:05 +00:00
|
|
|
pub use core::ops;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2014-05-01 03:17:50 +00:00
|
|
|
pub use core::ptr;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2014-05-01 03:38:31 +00:00
|
|
|
pub use core::raw;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2014-05-10 20:46:05 +00:00
|
|
|
pub use core::result;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2014-06-02 22:49:42 +00:00
|
|
|
pub use core::option;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-08-17 20:23:36 +00:00
|
|
|
pub use core::isize;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-08-17 20:23:36 +00:00
|
|
|
pub use core::i8;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-08-17 20:23:36 +00:00
|
|
|
pub use core::i16;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-08-17 20:23:36 +00:00
|
|
|
pub use core::i32;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-08-17 20:23:36 +00:00
|
|
|
pub use core::i64;
|
2016-08-23 00:56:52 +00:00
|
|
|
#[unstable(feature = "i128", issue = "35118")]
|
|
|
|
pub use core::i128;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-08-17 20:23:36 +00:00
|
|
|
pub use core::usize;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-08-17 20:23:36 +00:00
|
|
|
pub use core::u8;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-08-17 20:23:36 +00:00
|
|
|
pub use core::u16;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-08-17 20:23:36 +00:00
|
|
|
pub use core::u32;
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-08-17 20:23:36 +00:00
|
|
|
pub use core::u64;
|
2016-10-01 01:38:29 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
pub use alloc::boxed;
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
pub use alloc::rc;
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2017-06-13 22:52:59 +00:00
|
|
|
pub use alloc::borrow;
|
2016-10-01 01:38:29 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2017-06-13 22:52:59 +00:00
|
|
|
pub use alloc::fmt;
|
2016-10-01 01:38:29 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2017-06-13 22:52:59 +00:00
|
|
|
pub use alloc::slice;
|
2016-10-01 01:38:29 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2017-06-13 22:52:59 +00:00
|
|
|
pub use alloc::str;
|
2016-10-01 01:38:29 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2017-06-13 22:52:59 +00:00
|
|
|
pub use alloc::string;
|
2016-10-01 01:38:29 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2017-06-13 22:52:59 +00:00
|
|
|
pub use alloc::vec;
|
2016-10-01 01:38:29 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2016-11-29 19:38:08 +00:00
|
|
|
pub use std_unicode::char;
|
2016-08-23 00:56:52 +00:00
|
|
|
#[unstable(feature = "i128", issue = "35118")]
|
|
|
|
pub use core::u128;
|
2013-05-13 01:14:40 +00:00
|
|
|
|
2016-10-01 23:07:17 +00:00
|
|
|
pub mod f32;
|
|
|
|
pub mod f64;
|
2012-11-30 08:47:45 +00:00
|
|
|
|
2015-01-06 17:24:46 +00:00
|
|
|
#[macro_use]
|
2015-03-20 07:46:13 +00:00
|
|
|
pub mod thread;
|
2016-10-01 01:38:29 +00:00
|
|
|
pub mod ascii;
|
2015-03-20 07:46:13 +00:00
|
|
|
pub mod collections;
|
|
|
|
pub mod env;
|
2016-10-01 01:38:29 +00:00
|
|
|
pub mod error;
|
2014-11-25 21:28:35 +00:00
|
|
|
pub mod ffi;
|
2015-02-03 05:39:14 +00:00
|
|
|
pub mod fs;
|
2015-03-20 07:46:13 +00:00
|
|
|
pub mod io;
|
2015-02-06 00:50:11 +00:00
|
|
|
pub mod net;
|
2016-10-01 01:38:29 +00:00
|
|
|
pub mod num;
|
2014-11-14 22:20:57 +00:00
|
|
|
pub mod os;
|
2015-08-31 15:51:53 +00:00
|
|
|
pub mod panic;
|
2014-11-14 22:20:57 +00:00
|
|
|
pub mod path;
|
2015-02-06 17:42:57 +00:00
|
|
|
pub mod process;
|
2013-12-13 01:27:37 +00:00
|
|
|
pub mod sync;
|
2015-03-20 07:46:13 +00:00
|
|
|
pub mod time;
|
2017-06-03 21:54:08 +00:00
|
|
|
pub mod heap;
|
2012-02-22 12:06:38 +00:00
|
|
|
|
2016-10-01 01:38:29 +00:00
|
|
|
// Platform-abstraction modules
|
2015-03-10 03:04:35 +00:00
|
|
|
#[macro_use]
|
2016-09-30 23:26:44 +00:00
|
|
|
mod sys_common;
|
2016-09-30 22:11:46 +00:00
|
|
|
mod sys;
|
2014-10-01 00:03:56 +00:00
|
|
|
|
2016-10-01 01:38:29 +00:00
|
|
|
// Private support modules
|
2015-02-14 03:59:53 +00:00
|
|
|
mod panicking;
|
2016-10-01 01:38:29 +00:00
|
|
|
mod memchr;
|
|
|
|
|
|
|
|
// The runtime entry point and a few unstable public functions used by the
|
|
|
|
// compiler
|
|
|
|
pub mod rt;
|
2012-11-30 08:47:45 +00:00
|
|
|
|
2015-07-21 00:12:59 +00:00
|
|
|
// Include a number of private modules that exist solely to provide
|
|
|
|
// the rustdoc documentation for primitive types. Using `include!`
|
|
|
|
// because rustdoc only looks for these modules at the crate level.
|
2015-07-20 18:21:02 +00:00
|
|
|
include!("primitive_docs.rs");
|