Crate std [] [src]

The Rust Standard Library

The Rust Standard Library provides the essential runtime functionality for building portable Rust software.

The rust standard library is available to all rust crates by default, just as if contained an extern crate std`extern crate stdimport at the crate root. Therefore the standard library can be accessed in` import at the crate root. Therefore the standard library can be accessed in use`usestatements through the path` statements through the path std`std, as in`, as in use std::thread`use std::thread, or in expressions through the absolute path`, or in expressions through the absolute path ::std`::std, as in`, as in ::std::thread::sleep_ms(100)`::std::thread::sleep_ms(100)`.

Furthermore, the standard library defines The Rust Prelude, a small collection of items, mostly traits, that are imported into and available in every module.

What is in the standard library

The standard library is minimal, a set of battle-tested core types and shared abstractions for the broader Rust ecosystem to build on.

The primitive types, though not defined in the standard library, are documented here, as are the predefined macros.

Containers and collections

The option`option` and result`result` modules define optional and error-handling types, Option`Optionand` and Result`Result. The [`. The iter`iter` module defines Rust's iterator trait, Iterator`Iterator`, which works with the for`for` loop to access collections.

The common container type, Vec`Vec, a growable vector backed by an array, lives in the [`, a growable vector backed by an array, lives in the vec`vec` module. Contiguous, unsized regions of memory, [T]`[T], commonly called "slices", and their borrowed versions,`, commonly called "slices", and their borrowed versions, &[T]`&[T], commonly called "borrowed slices", are built-in types for which the [`, commonly called "borrowed slices", are built-in types for which the slice`slice` module defines many methods.

&str`&str, a UTF-8 string, is a built-in type, and the standard library defines methods for it on a variety of traits in the [`, a UTF-8 string, is a built-in type, and the standard library defines methods for it on a variety of traits in the str`str` module. Rust strings are immutable; use the String`Stringtype defined in [` type defined in string`string` for a mutable string builder.

For converting to strings use the format!`format!` macro, and for converting from strings use the FromStr`FromStr` trait.

Data may be shared by placing it in a reference-counted box or the [Rc`Rc][rc/index.html] type, and if further contained in a [`][rc/index.html] type, and if further contained in a Cell`Cellor` or RefCell`RefCell`, may be mutated as well as shared. Likewise, in a concurrent setting it is common to pair an atomically-reference-counted box, Arc`Arc`, with a Mutex`Mutex` to get the same effect.

The collections`collections` module defines maps, sets, linked lists and other typical collection types, including the common HashMap`HashMap`.

Platform abstractions and I/O

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`io`, fs`fs`, and net`net` modules.

The thread`thread` module contains Rust's threading abstractions. sync`sync` contains further primitive shared memory types, including atomic`atomic` and mpsc`mpsc`, which contains the channel types for message passing.

Primitive Types

array

The fixed-size array type ([T; n]`[T; n]`).

bool

The boolean type

char

Character manipulation (char`char` type, Unicode Scalar Value)

f32

Operations and constants for 32-bits floats (f32`f32` type)

f64

Operations and constants for 64-bits floats (f64`f64` type)

i16

Operations and constants for signed 16-bits integers (i16`i16` type)

i32

Operations and constants for signed 32-bits integers (i32`i32` type)

i64

Operations and constants for signed 64-bits integers (i64`i64` type)

i8

Operations and constants for signed 8-bits integers (i8`i8` type)

isize

Operations and constants for pointer-sized signed integers (isize`isize` type)

pointer

Operations on unsafe pointers, *const T`*const T, and`, and *mut T`*mut T`.

slice

Utilities for slice manipulation

str

Unicode string manipulation (the str`str` type).

tuple

Operations on tuples

u16

Operations and constants for unsigned 16-bits integers (u16`u16` type)

u32

Operations and constants for unsigned 32-bits integers (u32`u32` type)

u64

Operations and constants for unsigned 64-bits integer (u64`u64` type)

u8

Operations and constants for unsigned 8-bits integers (u8`u8` type)

usize

Operations and constants for pointer-sized unsigned integers (usize`usize` type)

Modules

any

Traits for dynamic typing of any 'static`'static` type (through runtime reflection)

ascii

Operations on ASCII strings and characters

borrow

A module for working with borrowed data.

boxed

A pointer type for heap allocation.

cell

Shareable mutable containers.

char

Character manipulation (char`char` type, Unicode Scalar Value)

clone

The Clone`Clone` trait for types that cannot be 'implicitly copied'

cmp

Functionality for ordering and comparison.

collections

Collection types.

convert

Traits for conversions between types.

default

The Default`Default` trait for types which may have meaningful default values.

env

Inspection and manipulation of the process's environment.

error

Traits for working with Errors.

f32

Operations and constants for 32-bits floats (f32`f32` type)

f64

Operations and constants for 64-bits floats (f64`f64` type)

ffi

Utilities related to FFI bindings.

fmt

Utilities for formatting and printing strings

fs

Filesystem manipulation operations

hash

Generic hashing support.

i16

Operations and constants for signed 16-bits integers (i16`i16` type)

i32

Operations and constants for signed 32-bits integers (i32`i32` type)

i64

Operations and constants for signed 64-bits integers (i64`i64` type)

i8

Operations and constants for signed 8-bits integers (i8`i8` type)

io

Traits, helpers, and type definitions for core I/O functionality.

isize

Operations and constants for pointer-sized signed integers (isize`isize` type)

iter

Composable external iterators

marker

Primitive traits and marker types representing basic 'kinds' of types.

mem

Basic functions for dealing with memory

net

Networking primitives for TCP/UDP communication.

num

Numeric traits and functions for generic mathematics

ops

Overloadable operators

option

Optional values

os

OS-specific functionality

path

Cross-platform path manipulation.

prelude

The Rust Prelude

process

Working with processes.

ptr

Operations on unsafe pointers, *const T`*const T, and`, and *mut T`*mut T`.

rc

Thread-local reference-counted boxes (the Rc<T>`Rc` type).

result

Error handling with the Result`Result` type

slice

Utilities for slice manipulation

str

Unicode string manipulation (the str`str` type).

string

An owned, growable string that enforces that its contents are valid UTF-8.

sync

Useful synchronization primitives

thread

Native threads

u16

Operations and constants for unsigned 16-bits integers (u16`u16` type)

u32

Operations and constants for unsigned 32-bits integers (u32`u32` type)

u64

Operations and constants for unsigned 64-bits integer (u64`u64` type)

u8

Operations and constants for unsigned 8-bits integers (u8`u8` type)

usize

Operations and constants for pointer-sized unsigned integers (usize`usize` type)

vec

A growable list type with heap-allocated contents, written Vec<T>`Vec` but pronounced 'vector.'

dynamic_lib [Unstable]

Dynamic library facilities.

intrinsics [Unstable]

rustc compiler intrinsics.

raw [Unstable]

Contains struct definitions for the layout of compiler built-in types.

rt [Unstable]

Runtime services

simd [Unstable]

SIMD vectors.

thunk [Unstable]
time [Unstable]

Temporal quantification.

Macros

assert!

Ensure that a boolean expression is true`true` at runtime.

assert_eq!

Asserts that two expressions are equal to each other.

cfg!

Boolean evaluation of configuration flags.

column!

A macro which expands to the column number on which it was invoked.

concat!

Concatenates literals into a static string slice.

concat_idents!

Concatenate identifiers into one identifier.

debug_assert!

Ensure that a boolean expression is true`true` at runtime.

debug_assert_eq!

Asserts that two expressions are equal to each other, testing equality in both directions.

env!

Inspect an environment variable at compile time.

file!

A macro which expands to the file name from which it was invoked.

format!

Use the syntax described in std::fmt`std::fmtto create a value of type` to create a value of type String`String. See`. See std::fmt`std::fmt` for more information.

format_args!

The core macro for formatted string creation & output.

include!

Parse the current given file as an expression.

include_bytes!

Includes a file as a byte slice.

include_str!

Includes a utf8-encoded file as a string.

line!

A macro which expands to the line number on which it was invoked.

module_path!

Expands to a string that represents the current module path.

option_env!

Optionally inspect an environment variable at compile time.

panic!

The entry point for panic of Rust threads.

print!

Macro for printing to the standard output.

println!

Macro for printing to the standard output.

scoped_thread_local!

Declare a new scoped thread local storage key.

select!

A macro to select an event from a number of receivers.

stringify!

A macro which stringifies its argument.

thread_local!

Declare a new thread local storage key of type std::thread::LocalKey`std::thread::LocalKey`.

try!

Helper macro for unwrapping Result`Resultvalues while returning early with an error if the value of the expression is` values while returning early with an error if the value of the expression is Err`Err`.

unimplemented!

A standardised placeholder for marking unfinished code. It panics with the message "not yet implemented"`"not yet implemented"` when executed.

unreachable!

A utility macro for indicating unreachable code.

vec!

Creates a Vec`Vec` containing the arguments.

write!

Use the format!`format!syntax to write data into a buffer of type` syntax to write data into a buffer of type &mut Write`&mut Write. See`. See std::fmt`std::fmt` for more information.

writeln!

Equivalent to the write!`write!` macro, except that a newline is appended after the message is written.