The Rust core library provides functionality that is closely tied to the Rust built-in types and runtime services, or that is used in nearly every non-trivial program.
core
includes modules corresponding to each of the integer types, each of the floating point types, the bool
type, tuples, characters, strings, vectors (vec
), shared boxes (box
), and unsafe pointers (ptr
). Additionally, core
provides very commonly used built-in types and operations, concurrency primitives, platform abstractions, I/O, and complete bindings to the C standard library.
core
is linked by default to all crates and the contents imported. Implicitly, all crates behave as if they included the following prologue:
use core;
import core::*;
This behavior can be disabled with the #[no_core]
crate attribute.
debug
- The debug log levelerror
- The error log levelinfo
- The info log levelwarn
- The warning log levelpath
- A path or fragment of a filesystem pathoption
- The option typeextensions for str
- Extension methods for stringsextensions for str/&
- Extension methods for stringsextensions for ~[T]
extensions for ~[mut T]
extensions for & [const T]
- Extension methods for vectorsextensions for & [const T]
- Extension methods for vectorsextensions for & [T]
- Extension methods for vectorsextensions for & [T]
- Extension methods for vectorsextensions of iter::base_iter<A> for & [const A]
extensions for & [const A]
extensions for option<T>
extensions for option<T>
extensions of iter::base_iter<A> for IMPL_T<A>
extensions for IMPL_T<A>
extensions for *T
- Extension methods for pointersextensions for rng
- Extension methods for random number generatorsextensions for result<T, E>
extensions for result<T, E>
extensions for result<T, E>
extensions for result<T, E>
num of num::num for T
num of num::num for T
num of num::num for T
num of num::num for T
num of num::num for T
num of num::num for T
num of num::num for T
num of num::num for T
num of num::num for T
num of num::num for T
num of num::num for float
num of num::num for f32
num of num::num for f64
times of iter::times for T
times of iter::times for T
times of iter::times for T
times of iter::times for T
times of iter::times for T
times of iter::times for T
times of iter::times for T
times of iter::times for T
times of iter::times for T
times of iter::times for T
unreachable
- A standard function to use to indicate unreachable codearc
bool
- Boolean logicbox
- Operations on shared box typeschar
- Utilities for manipulating the char typecmp
comm
- Communication between tasksdvec
dvec_iter
either
- A type that represents one of two alternativesf32
- Operations and constants for f32
f64
- Operations and constants for f64
float
- Operations and constants for float
future
- A type representing values that may be computed concurrently and operations for working with them.i16
- Operations and constants for i16
i32
- Operations and constants for i32
i64
- Operations and constants for i64
i8
- Operations and constants for i8
int
- Operations and constants for int
io
iter
libc
- Bindings for libc.logging
- Loggingnum
option
- Operations on the ubiquitous option
type.option_iter
os
- Higher-level interfaces to libc::* functions and operating system services.path
- Path data type and helper functionspipes
ptr
- Unsafe pointer utility functionsrand
- Random number generationresult
- A type representing either success or failurerun
- Process spawningstr
- String manipulationsys
- Misc low level stufftask
- Task management.to_bytes
to_str
tuple
- Operations on tuplesu16
- Operations and constants for u16
u32
- Operations and constants for u32
u64
- Operations and constants for u64
u8
- Operations and constants for u8
uint
- Operations and constants for uint
unsafe
- Unsafe operationsvec
- Vectorsdebug
u32
The debug log level
error
u32
The error log level
info
u32
The info log level
warn
u32
The warning log level
path
type path = str
A path or fragment of a filesystem path
option
The option type
none
some(T)
extensions for str
Extension methods for strings
trim
fn trim() -> str
Returns a string with leading and trailing whitespace removed
trim_left
fn trim_left() -> str
Returns a string with leading whitespace removed
trim_right
fn trim_right() -> str
Returns a string with trailing whitespace removed
+
pure fn +(rhs: str/& ) -> str
Concatenate two strings: operator version
extensions for str/&
Extension methods for strings
all
fn all(it: fn(char) -> bool) -> bool
Return true if a predicate matches all characters or if the string contains no characters
any
fn any(it: fn(char) -> bool) -> bool
Return true if a predicate matches any character (and false if it matches none or there are no characters)
contains
fn contains(needle: str/&a ) -> bool
Returns true if one string contains another
contains_char
fn contains_char(needle: char) -> bool
Returns true if a string contains a char
each
fn each(it: fn(u8) -> bool)
Iterate over the bytes in a string
eachi
fn eachi(it: fn(uint, u8) -> bool)
Iterate over the bytes in a string, with indices
each_char
fn each_char(it: fn(char) -> bool)
Iterate over the chars in a string
each_chari
fn each_chari(it: fn(uint, char) -> bool)
Iterate over the chars in a string, with indices
ends_with
fn ends_with(needle: str/& ) -> bool
Returns true if one string ends with another
is_empty
fn is_empty() -> bool
Returns true if the string has length 0
is_not_empty
fn is_not_empty() -> bool
Returns true if the string has length greater than 0
is_whitespace
fn is_whitespace() -> bool
Returns true if the string contains only whitespace
Whitespace characters are determined by char::is_whitespace
is_alphanumeric
fn is_alphanumeric() -> bool
Returns true if the string contains only alphanumerics
Alphanumeric characters are determined by char::is_alphanumeric
len
pure fn len() -> uint
Returns the size in bytes not counting the null terminator
slice
fn slice(begin: uint, end: uint) -> str
Returns a slice of the given string from the byte range [begin
..end
)
Fails when begin
and end
do not point to valid characters or beyond the last character of the string
split
fn split(sepfn: fn(char) -> bool) -> ~[str]
Splits a string into substrings using a character function
split_char
fn split_char(sep: char) -> ~[str]
Splits a string into substrings at each occurrence of a given character
split_str
fn split_str(sep: str/&a ) -> ~[str]
Splits a string into a vector of the substrings separated by a given string
starts_with
fn starts_with(needle: str/&a ) -> bool
Returns true if one string starts with another
substr
fn substr(begin: uint, n: uint) -> str
Take a substring of another.
Returns a string containing n
characters starting at byte offset begin
.
to_lower
fn to_lower() -> str
Convert a string to lowercase
to_upper
fn to_upper() -> str
Convert a string to uppercase
escape_default
fn escape_default() -> str
Escape each char in s
with char::escape_default.
escape_unicode
fn escape_unicode() -> str
Escape each char in s
with char::escape_unicode.
extensions for ~[T]
+
pure fn +(rhs: & [const T]) -> ~[T]
extensions for ~[mut T]
+
pure fn +(rhs: & [const T]) -> ~[mut T]
extensions for & [const T]
Extension methods for vectors
is_empty
pure fn is_empty() -> bool
Returns true if a vector contains no elements
is_not_empty
pure fn is_not_empty() -> bool
Returns true if a vector contains some elements
len
pure fn len() -> uint
Returns the length of a vector
extensions for & [const T]
Extension methods for vectors
head
pure fn head() -> T
Returns the first element of a vector
init
pure fn init() -> ~[T]
Returns all but the last elemnt of a vector
last
pure fn last() -> T
Returns the last element of a v
, failing if the vector is empty.
slice
pure fn slice(start: uint, end: uint) -> ~[T]
Returns a copy of the elements from [start
..end
) from v
.
tail
pure fn tail() -> ~[T]
Returns all but the first element of a vector
extensions for & [T]
Extension methods for vectors
foldr
pure fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U
Reduce a vector from right to left
iter
pure fn iter(f: fn(T))
Iterates over a vector
Iterates over vector v
and, for each element, calls function f
with the element's value.
iteri
pure fn iteri(f: fn(uint, T))
Iterates over a vector's elements and indexes
Iterates over vector v
and, for each element, calls function f
with the element's value and index.
position
pure fn position(f: fn(T) -> bool) -> option<uint>
Find the first index matching some predicate
Apply function f
to each element of v
. When function f
returns true then an option containing the index is returned. If f
matches no elements then none is returned.
position_elem
pure fn position_elem(x: T) -> option<uint>
Find the first index containing a matching value
riter
pure fn riter(f: fn(T))
Iterates over a vector in reverse
Iterates over vector v
and, for each element, calls function f
with the element's value.
riteri
pure fn riteri(f: fn(uint, T))
Iterates over a vector's elements and indexes in reverse
Iterates over vector v
and, for each element, calls function f
with the element's value and index.
rposition
pure fn rposition(f: fn(T) -> bool) -> option<uint>
Find the last index matching some predicate
Apply function f
to each element of v
in reverse order. When function f
returns true then an option containing the index is returned. If f
matches no elements then none is returned.
rposition_elem
pure fn rposition_elem(x: T) -> option<uint>
Find the last index containing a matching value
map
pure fn map<U>(f: fn(T) -> U) -> ~[U]
Apply a function to each element of a vector and return the results
mapi
pure fn mapi<U>(f: fn(uint, T) -> U) -> ~[U]
Apply a function to the index and value of each element in the vector and return the results
map_r
fn map_r<U>(f: fn(x: &self .T) -> U) -> ~[U]
alli
pure fn alli(f: fn(uint, T) -> bool) -> bool
Returns true if the function returns true for all elements.
If the vector is empty, true is returned.
flat_map
pure fn flat_map<U>(f: fn(T) -> ~[U]) -> ~[U]
Apply a function to each element of a vector and return a concatenation of each result vector
filter_map
pure fn filter_map<U: copy>(f: fn(T) -> option<U>) -> ~[U]
Apply a function to each element of a vector and return the results
If function f
returns none
then that element is excluded from the resulting vector.
extensions for & [T]
Extension methods for vectors
filter
pure fn filter(f: fn(T) -> bool) -> ~[T]
Construct a new vector from the elements of a vector for which some predicate holds.
Apply function f
to each element of v
and return a vector containing only those elements for which f
returned true.
find
pure fn find(f: fn(T) -> bool) -> option<T>
Search for the first element that matches a given predicate
Apply function f
to each element of v
, starting from the first. When function f
returns true then an option containing the element is returned. If f
matches no elements then none is returned.
rfind
pure fn rfind(f: fn(T) -> bool) -> option<T>
Search for the last element that matches a given predicate
Apply function f
to each element of v
in reverse order. When function f
returns true then an option containing the element is returned. If f
matches no elements then none is returned.
extensions of iter::base_iter<A> for & [const A]
each
fn each(blk: fn(A) -> bool)
size_hint
fn size_hint() -> option<uint>
eachi
fn eachi(blk: fn(uint, A) -> bool)
all
fn all(blk: fn(A) -> bool) -> bool
any
fn any(blk: fn(A) -> bool) -> bool
foldl
fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B
contains
fn contains(x: A) -> bool
count
fn count(x: A) -> uint
extensions for & [const A]
filter_to_vec
fn filter_to_vec(pred: fn(A) -> bool) -> ~[A]
map_to_vec
fn map_to_vec<B>(op: fn(A) -> B) -> ~[B]
to_vec
fn to_vec() -> ~[A]
min
fn min() -> A
max
fn max() -> A
extensions for option<T>
chain
fn chain<U>(f: fn(T) -> option<U>) -> option<U>
Update an optional value by optionally running its content through a function that returns an option.
map_default
fn map_default<U: copy>(def: U, f: fn(T) -> U) -> U
Applies a function to the contained value or returns a default
iter
fn iter(f: fn(T))
Performs an operation on the contained value or does nothing
is_none
fn is_none() -> bool
Returns true if the option equals none
is_some
fn is_some() -> bool
Returns true if the option contains some value
map
fn map<U: copy>(f: fn(T) -> U) -> option<U>
Maps a some
value from one type to another
extensions for option<T>
get
fn get() -> T
Gets the value out of an option
Fails if the value equals none
get_default
fn get_default(def: T) -> T
expect
pure fn expect(reason: str) -> T
Gets the value out of an option, printing a specified message on failure
Fails if the value equals none
extensions of iter::base_iter<A> for IMPL_T<A>
each
fn each(blk: fn(A) -> bool)
size_hint
fn size_hint() -> option<uint>
eachi
fn eachi(blk: fn(uint, A) -> bool)
all
fn all(blk: fn(A) -> bool) -> bool
any
fn any(blk: fn(A) -> bool) -> bool
foldl
fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B
contains
fn contains(x: A) -> bool
count
fn count(x: A) -> uint
position
fn position(f: fn(A) -> bool) -> option<uint>
extensions for IMPL_T<A>
filter_to_vec
fn filter_to_vec(pred: fn(A) -> bool) -> ~[A]
map_to_vec
fn map_to_vec<B>(op: fn(A) -> B) -> ~[B]
to_vec
fn to_vec() -> ~[A]
min
fn min() -> A
max
fn max() -> A
find
fn find(p: fn(A) -> bool) -> option<A>
extensions for *T
Extension methods for pointers
is_null
pure fn is_null() -> bool
Returns true if the pointer is equal to the null pointer.
is_not_null
pure fn is_not_null() -> bool
Returns true if the pointer is not equal to the null pointer.
extensions for rng
Extension methods for random number generators
gen_int
fn gen_int() -> int
Return a random int
gen_int_range
fn gen_int_range(start: int, end: int) -> int
Return an int randomly chosen from the range [start, end), failing if start >= end
gen_i8
fn gen_i8() -> i8
Return a random i8
gen_i16
fn gen_i16() -> i16
Return a random i16
gen_i32
fn gen_i32() -> i32
Return a random i32
gen_i64
fn gen_i64() -> i64
Return a random i64
gen_uint
fn gen_uint() -> uint
Return a random uint
gen_uint_range
fn gen_uint_range(start: uint, end: uint) -> uint
Return a uint randomly chosen from the range [start, end), failing if start >= end
gen_u8
fn gen_u8() -> u8
Return a random u8
gen_u16
fn gen_u16() -> u16
Return a random u16
gen_u32
fn gen_u32() -> u32
Return a random u32
gen_u64
fn gen_u64() -> u64
Return a random u64
gen_float
fn gen_float() -> float
Return a random float
gen_f32
fn gen_f32() -> f32
Return a random f32
gen_f64
fn gen_f64() -> f64
Return a random f64
gen_char
fn gen_char() -> char
Return a random char
gen_char_from
fn gen_char_from(chars: str) -> char
Return a char randomly chosen from chars, failing if chars is empty
gen_bool
fn gen_bool() -> bool
Return a random bool
gen_weighted_bool
fn gen_weighted_bool(n: uint) -> bool
Return a bool with a 1 in n chance of true
gen_str
fn gen_str(len: uint) -> str
Return a random string of the specified length composed of A-Z,a-z,0-9
gen_bytes
fn gen_bytes(len: uint) -> ~[u8]
Return a random byte string of the specified length
choose
fn choose<T: copy>(values: ~[T]) -> T
Choose an item randomly, failing if values is empty
choose_option
fn choose_option<T: copy>(values: ~[T]) -> option<T>
Choose some(item) randomly, returning none if values is empty
choose_weighted
fn choose_weighted<T: copy>(v: ~[weighted<T>]) -> T
Choose an item respecting the relative weights, failing if the sum of the weights is 0
choose_weighted_option
fn choose_weighted_option<T: copy>(v: ~[weighted<T>]) -> option<T>
Choose some(item) respecting the relative weights, returning none if the sum of the weights is 0
weighted_vec
fn weighted_vec<T: copy>(v: ~[weighted<T>]) -> ~[T]
Return a vec containing copies of the items, in order, where the weight of the item determines how many copies there are
shuffle
fn shuffle<T: copy>(values: ~[T]) -> ~[T]
Shuffle a vec
shuffle_mut
fn shuffle_mut<T>(&&values: ~[mut T])
Shuffle a mutable vec in place
extensions for result<T, E>
is_ok
fn is_ok() -> bool
is_err
fn is_err() -> bool
iter
fn iter(f: fn(T))
iter_err
fn iter_err(f: fn(E))
extensions for result<T, E>
get
fn get() -> T
map_err
fn map_err<F: copy>(op: fn(E) -> F) -> result<T, F>
extensions for result<T, E>
get_err
fn get_err() -> E
map
fn map<U: copy>(op: fn(T) -> U) -> result<U, E>
extensions for result<T, E>
chain
fn chain<U: copy>(op: fn(T) -> result<U, E>) -> result<U, E>
chain_err
fn chain_err<F: copy>(op: fn(E) -> result<T, F>) -> result<T, F>
num of num::num for T
add
fn add(&&other: T) -> T
sub
fn sub(&&other: T) -> T
mul
fn mul(&&other: T) -> T
div
fn div(&&other: T) -> T
modulo
fn modulo(&&other: T) -> T
neg
fn neg() -> T
to_int
fn to_int() -> int
from_int
fn from_int(n: int) -> T
num of num::num for T
add
fn add(&&other: T) -> T
sub
fn sub(&&other: T) -> T
mul
fn mul(&&other: T) -> T
div
fn div(&&other: T) -> T
modulo
fn modulo(&&other: T) -> T
neg
fn neg() -> T
to_int
fn to_int() -> int
from_int
fn from_int(n: int) -> T
num of num::num for T
add
fn add(&&other: T) -> T
sub
fn sub(&&other: T) -> T
mul
fn mul(&&other: T) -> T
div
fn div(&&other: T) -> T
modulo
fn modulo(&&other: T) -> T
neg
fn neg() -> T
to_int
fn to_int() -> int
from_int
fn from_int(n: int) -> T
num of num::num for T
add
fn add(&&other: T) -> T
sub
fn sub(&&other: T) -> T
mul
fn mul(&&other: T) -> T
div
fn div(&&other: T) -> T
modulo
fn modulo(&&other: T) -> T
neg
fn neg() -> T
to_int
fn to_int() -> int
from_int
fn from_int(n: int) -> T
num of num::num for T
add
fn add(&&other: T) -> T
sub
fn sub(&&other: T) -> T
mul
fn mul(&&other: T) -> T
div
fn div(&&other: T) -> T
modulo
fn modulo(&&other: T) -> T
neg
fn neg() -> T
to_int
fn to_int() -> int
from_int
fn from_int(n: int) -> T
num of num::num for T
add
fn add(&&other: T) -> T
sub
fn sub(&&other: T) -> T
mul
fn mul(&&other: T) -> T
div
fn div(&&other: T) -> T
modulo
fn modulo(&&other: T) -> T
neg
fn neg() -> T
to_int
fn to_int() -> int
from_int
fn from_int(n: int) -> T
num of num::num for T
add
fn add(&&other: T) -> T
sub
fn sub(&&other: T) -> T
mul
fn mul(&&other: T) -> T
div
fn div(&&other: T) -> T
modulo
fn modulo(&&other: T) -> T
neg
fn neg() -> T
to_int
fn to_int() -> int
from_int
fn from_int(n: int) -> T
num of num::num for T
add
fn add(&&other: T) -> T
sub
fn sub(&&other: T) -> T
mul
fn mul(&&other: T) -> T
div
fn div(&&other: T) -> T
modulo
fn modulo(&&other: T) -> T
neg
fn neg() -> T
to_int
fn to_int() -> int
from_int
fn from_int(n: int) -> T
num of num::num for T
add
fn add(&&other: T) -> T
sub
fn sub(&&other: T) -> T
mul
fn mul(&&other: T) -> T
div
fn div(&&other: T) -> T
modulo
fn modulo(&&other: T) -> T
neg
fn neg() -> T
to_int
fn to_int() -> int
from_int
fn from_int(n: int) -> T
num of num::num for T
add
fn add(&&other: T) -> T
sub
fn sub(&&other: T) -> T
mul
fn mul(&&other: T) -> T
div
fn div(&&other: T) -> T
modulo
fn modulo(&&other: T) -> T
neg
fn neg() -> T
to_int
fn to_int() -> int
from_int
fn from_int(n: int) -> T
num of num::num for float
add
fn add(&&other: float) -> float
sub
fn sub(&&other: float) -> float
mul
fn mul(&&other: float) -> float
div
fn div(&&other: float) -> float
modulo
fn modulo(&&other: float) -> float
neg
fn neg() -> float
to_int
fn to_int() -> int
from_int
fn from_int(n: int) -> float
num of num::num for f32
add
fn add(&&other: f32) -> f32
sub
fn sub(&&other: f32) -> f32
mul
fn mul(&&other: f32) -> f32
div
fn div(&&other: f32) -> f32
modulo
fn modulo(&&other: f32) -> f32
neg
fn neg() -> f32
to_int
fn to_int() -> int
from_int
fn from_int(n: int) -> f32
num of num::num for f64
add
fn add(&&other: f64) -> f64
sub
fn sub(&&other: f64) -> f64
mul
fn mul(&&other: f64) -> f64
div
fn div(&&other: f64) -> f64
modulo
fn modulo(&&other: f64) -> f64
neg
fn neg() -> f64
to_int
fn to_int() -> int
from_int
fn from_int(n: int) -> f64
times of iter::times for T
times
fn times(it: fn() -> bool)
A convenience form for basic iteration. Given a variable x
of any numeric type, the expression for x.times { /* anything */ }
will execute the given function exactly x times. If we assume that x
is an int, this is functionally equivalent to for int::range(0, x) |_i| { /* anything */ }
.
times of iter::times for T
times
fn times(it: fn() -> bool)
A convenience form for basic iteration. Given a variable x
of any numeric type, the expression for x.times { /* anything */ }
will execute the given function exactly x times. If we assume that x
is an int, this is functionally equivalent to for int::range(0, x) |_i| { /* anything */ }
.
times of iter::times for T
times
fn times(it: fn() -> bool)
A convenience form for basic iteration. Given a variable x
of any numeric type, the expression for x.times { /* anything */ }
will execute the given function exactly x times. If we assume that x
is an int, this is functionally equivalent to for int::range(0, x) |_i| { /* anything */ }
.
times of iter::times for T
times
fn times(it: fn() -> bool)
A convenience form for basic iteration. Given a variable x
of any numeric type, the expression for x.times { /* anything */ }
will execute the given function exactly x times. If we assume that x
is an int, this is functionally equivalent to for int::range(0, x) |_i| { /* anything */ }
.
times of iter::times for T
times
fn times(it: fn() -> bool)
A convenience form for basic iteration. Given a variable x
of any numeric type, the expression for x.times { /* anything */ }
will execute the given function exactly x times. If we assume that x
is an int, this is functionally equivalent to for int::range(0, x) |_i| { /* anything */ }
.
times of iter::times for T
times
fn times(it: fn() -> bool)
A convenience form for basic iteration. Given a variable x
of any numeric type, the expression for x.times { /* anything */ }
will execute the given function exactly x times. If we assume that x
is an int, this is functionally equivalent to for int::range(0, x) |_i| { /* anything */ }
.
times of iter::times for T
times
fn times(it: fn() -> bool)
A convenience form for basic iteration. Given a variable x
of any numeric type, the expression for x.times { /* anything */ }
will execute the given function exactly x times. If we assume that x
is an int, this is functionally equivalent to for int::range(0, x) |_i| { /* anything */ }
.
times of iter::times for T
times
fn times(it: fn() -> bool)
A convenience form for basic iteration. Given a variable x
of any numeric type, the expression for x.times { /* anything */ }
will execute the given function exactly x times. If we assume that x
is an int, this is functionally equivalent to for int::range(0, x) |_i| { /* anything */ }
.
times of iter::times for T
times
fn times(it: fn() -> bool)
A convenience form for basic iteration. Given a variable x
of any numeric type, the expression for x.times { /* anything */ }
will execute the given function exactly x times. If we assume that x
is an int, this is functionally equivalent to for int::range(0, x) |_i| { /* anything */ }
.
times of iter::times for T
times
fn times(it: fn() -> bool)
A convenience form for basic iteration. Given a variable x
of any numeric type, the expression for x.times { /* anything */ }
will execute the given function exactly x times. If we assume that x
is an int, this is functionally equivalent to for int::range(0, x) |_i| { /* anything */ }
.
unreachable
fn unreachable() -> !
A standard function to use to indicate unreachable code. Because the function is guaranteed to fail typestate will correctly identify any code paths following the appearance of this function as unreachable.