Crate stdStable [stability]
[-] [+]
[src]
The Rust Standard Library
The Rust Standard Library provides the essential runtime functionality for building portable Rust software. It is linked to all Rust crates by default.
Intrinsic types and operations
The ptr
and mem
modules deal with unsafe pointers and memory manipulation.
marker
defines the special built-in traits,
and raw
the runtime representation of Rust types.
These are some of the lowest-level building blocks in Rust.
Math on primitive types and math traits
Although basic operations on primitive types are implemented
directly by the compiler, the standard library additionally
defines many common operations through traits defined in
mod num
.
Pervasive types
The option
and result
modules define optional and error-handling types, Option
and Result
.
iter
defines Rust's iterator protocol
along with a wide variety of iterators.
Cell
and RefCell
are for creating types that
manage their own mutability.
Vectors, slices and strings
The common container type, Vec
, a growable vector backed by an
array, lives in the vec
module. References to
arrays, &[T]
, more commonly called "slices", are built-in types
for which the slice
module defines many
methods.
&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
str
module. Rust strings are immutable;
use the String
type defined in string
for a mutable string builder.
For converting to strings use the format!
macro, and for converting from strings use the
FromStr
trait.
Platform abstractions
Besides basic data types, the standard library is largely concerned
with abstracting over differences in common platforms, most notably
Windows and Unix derivatives. The os
module
provides a number of basic functions for interacting with the
operating environment, including program arguments, environment
variables, and directory navigation. The path
module encapsulates the platform-specific rules for dealing
with file paths.
std
also includes modules for interoperating with the
C language: c_str
and
c_vec
.
Concurrency, I/O, and the runtime
The thread
module contains Rust's threading abstractions,
while comm
contains the channel types for message
passing. sync
contains further, primitive, shared
memory types, including atomic
.
Common types of I/O, including files, TCP, UDP, pipes, Unix domain sockets,
timers, and process spawning, are defined in the
old_io
module.
Rust's I/O and concurrency depends on a small runtime interface
that lives, along with its support code, in mod rt
.
While a notable part of the standard library's architecture, this
module is not intended for public use.
The Rust prelude and macros
Finally, the prelude
defines a
common set of traits, types, and functions that are made available
to all code by default. macros
contains
all the standard macros, such as assert!
, panic!
, println!
,
and format!
, also available to all Rust code.
Primitive Types
bool | The boolean type |
char | Character manipulation ( |
f32 | Operations and constants for 32-bits floats ( |
f64 | Operations and constants for 64-bits floats ( |
i16 | Operations and constants for signed 16-bits integers ( |
i32 | Operations and constants for signed 32-bits integers ( |
i64 | Operations and constants for signed 64-bits integers ( |
i8 | Operations and constants for signed 8-bits integers ( |
isize | Operations and constants for pointer-sized signed integers ( |
slice | Utilities for slice manipulation |
str | Unicode string manipulation ( |
tuple | Operations on tuples |
u16 | Operations and constants for unsigned 16-bits integers ( |
u32 | Operations and constants for unsigned 32-bits integers ( |
u64 | Operations and constants for unsigned 64-bits integer ( |
u8 | Operations and constants for unsigned 8-bits integers ( |
usize | Operations and constants for pointer-sized unsigned integers ( |
Modules
any | Traits for dynamic typing of any |
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 ( |
clone | The |
cmp | Functionality for ordering and comparison. |
collections | Collection types. |
default | The |
dynamic_lib | Dynamic library facilities. |
env | Inspection and manipulation of the process's environment. |
error | Traits for working with Errors. |
f32 | Operations and constants for 32-bits floats ( |
f64 | Operations and constants for 64-bits floats ( |
ffi | Utilities related to FFI bindings. |
finally | The Finally trait provides a method, |
fmt | Utilities for formatting and printing strings |
fs | Filesystem manipulation operations |
hash | Generic hashing support. |
i16 | Operations and constants for signed 16-bits integers ( |
i32 | Operations and constants for signed 32-bits integers ( |
i64 | Operations and constants for signed 64-bits integers ( |
i8 | Operations and constants for signed 8-bits integers ( |
int | Deprecated: replaced by |
intrinsics | rustc compiler intrinsics. |
io | Traits, helpers, and type definitions for core I/O functionality. |
isize | Operations and constants for pointer-sized signed integers ( |
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 |
old_io | I/O, including files, networking, timers, and processes |
old_path | Cross-platform path support |
ops | Overloadable operators |
option | Optional values |
os | Higher-level interfaces to libc::* functions and operating system services. |
path | Cross-platform path manipulation. |
prelude | The Rust prelude |
process | Working with processes. |
ptr | Operations on unsafe pointers, |
rand | Utilities for random number generation |
raw | Contains struct definitions for the layout of compiler built-in types. |
rc | Thread-local reference-counted boxes (the |
result | Error handling with the |
rt | Runtime services |
simd | SIMD vectors. |
slice | Utilities for slice manipulation |
str | Unicode string manipulation ( |
string | An owned, growable string that enforces that its contents are valid UTF-8. |
sync | Useful synchronization primitives |
thread | Native threads |
thread_local | Thread local storage |
thunk | |
time | Temporal quantification. |
u16 | Operations and constants for unsigned 16-bits integers ( |
u32 | Operations and constants for unsigned 32-bits integers ( |
u64 | Operations and constants for unsigned 64-bits integer ( |
u8 | Operations and constants for unsigned 8-bits integers ( |
uint | Deprecated: replaced by |
usize | Operations and constants for pointer-sized unsigned integers ( |
vec | A growable list type with heap-allocated contents, written |
Macros
assert! | Ensure that a boolean expression is |
assert_eq! | Asserts that two expressions are equal to each other, testing equality in both directions. |
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 |
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 |
format_args! | The core macro for formatted string creation & output. |
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 tasks. |
print! | Equivalent to the |
println! | Macro for printing to a task's stdout handle. |
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 |
try! | Helper macro for unwrapping |
unimplemented! | A standardised placeholder for marking unfinished code. It panics with the
message |
unreachable! | A utility macro for indicating unreachable code. |
vec! | Creates a |
write! | Use the |
writeln! | Equivalent to the |