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.

Const debug

u32

The debug log level

Const error

u32

The error log level

Const info

u32

The info log level

Const warn

u32

The warning log level

Type path

type path = str

A path or fragment of a filesystem path

Enum option

The option type

Variants

Implementation extensions for str

Extension methods for strings

Method trim

fn trim() -> str

Returns a string with leading and trailing whitespace removed

Method trim_left

fn trim_left() -> str

Returns a string with leading whitespace removed

Method trim_right

fn trim_right() -> str

Returns a string with trailing whitespace removed

Method +

pure fn +(rhs: str/& ) -> str

Concatenate two strings: operator version

Implementation extensions for str/&

Extension methods for strings

Method all

fn all(it: fn(char) -> bool) -> bool

Return true if a predicate matches all characters or if the string contains no characters

Method 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)

Method contains

fn contains(needle: str/&a ) -> bool

Returns true if one string contains another

Method contains_char

fn contains_char(needle: char) -> bool

Returns true if a string contains a char

Method each

fn each(it: fn(u8) -> bool)

Iterate over the bytes in a string

Method eachi

fn eachi(it: fn(uint, u8) -> bool)

Iterate over the bytes in a string, with indices

Method each_char

fn each_char(it: fn(char) -> bool)

Iterate over the chars in a string

Method each_chari

fn each_chari(it: fn(uint, char) -> bool)

Iterate over the chars in a string, with indices

Method ends_with

fn ends_with(needle: str/& ) -> bool

Returns true if one string ends with another

Method is_empty

fn is_empty() -> bool

Returns true if the string has length 0

Method is_not_empty

fn is_not_empty() -> bool

Returns true if the string has length greater than 0

Method is_whitespace

fn is_whitespace() -> bool

Returns true if the string contains only whitespace

Whitespace characters are determined by char::is_whitespace

Method is_alphanumeric

fn is_alphanumeric() -> bool

Returns true if the string contains only alphanumerics

Alphanumeric characters are determined by char::is_alphanumeric

Method len

pure fn len() -> uint

Returns the size in bytes not counting the null terminator

Method 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

Method split

fn split(sepfn: fn(char) -> bool) -> ~[str]

Splits a string into substrings using a character function

Method split_char

fn split_char(sep: char) -> ~[str]

Splits a string into substrings at each occurrence of a given character

Method split_str

fn split_str(sep: str/&a ) -> ~[str]

Splits a string into a vector of the substrings separated by a given string

Method starts_with

fn starts_with(needle: str/&a ) -> bool

Returns true if one string starts with another

Method substr

fn substr(begin: uint, n: uint) -> str

Take a substring of another.

Returns a string containing n characters starting at byte offset begin.

Method to_lower

fn to_lower() -> str

Convert a string to lowercase

Method to_upper

fn to_upper() -> str

Convert a string to uppercase

Method escape_default

fn escape_default() -> str

Escape each char in s with char::escape_default.

Method escape_unicode

fn escape_unicode() -> str

Escape each char in s with char::escape_unicode.

Implementation extensions for ~[T]

Method +

pure fn +(rhs: & [const T]) -> ~[T]

Implementation extensions for ~[mut T]

Method +

pure fn +(rhs: & [const T]) -> ~[mut T]

Implementation extensions for & [const T]

Extension methods for vectors

Method is_empty

pure fn is_empty() -> bool

Returns true if a vector contains no elements

Method is_not_empty

pure fn is_not_empty() -> bool

Returns true if a vector contains some elements

Method len

pure fn len() -> uint

Returns the length of a vector

Implementation extensions for & [const T]

Extension methods for vectors

Method head

pure fn head() -> T

Returns the first element of a vector

Method init

pure fn init() -> ~[T]

Returns all but the last elemnt of a vector

Method last

pure fn last() -> T

Returns the last element of a v, failing if the vector is empty.

Method slice

pure fn slice(start: uint, end: uint) -> ~[T]

Returns a copy of the elements from [start..end) from v.

Method tail

pure fn tail() -> ~[T]

Returns all but the first element of a vector

Implementation extensions for & [T]

Extension methods for vectors

Method foldr

pure fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U

Reduce a vector from right to left

Method 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.

Method 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.

Method 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.

Method position_elem

pure fn position_elem(x: T) -> option<uint>

Find the first index containing a matching value

Method 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.

Method 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.

Method 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.

Method rposition_elem

pure fn rposition_elem(x: T) -> option<uint>

Find the last index containing a matching value

Method map

pure fn map<U>(f: fn(T) -> U) -> ~[U]

Apply a function to each element of a vector and return the results

Method 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

Method map_r

fn map_r<U>(f: fn(x: &self .T) -> U) -> ~[U]

Method 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.

Method 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

Method 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.

Implementation extensions for & [T]

Extension methods for vectors

Method 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.

Method 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.

Method 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.

Implementation extensions of iter::base_iter<A> for & [const A]

Method each

fn each(blk: fn(A) -> bool)

Method size_hint

fn size_hint() -> option<uint>

Method eachi

fn eachi(blk: fn(uint, A) -> bool)

Method all

fn all(blk: fn(A) -> bool) -> bool

Method any

fn any(blk: fn(A) -> bool) -> bool

Method foldl

fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B

Method contains

fn contains(x: A) -> bool

Method count

fn count(x: A) -> uint

Implementation extensions for & [const A]

Method filter_to_vec

fn filter_to_vec(pred: fn(A) -> bool) -> ~[A]

Method map_to_vec

fn map_to_vec<B>(op: fn(A) -> B) -> ~[B]

Method to_vec

fn to_vec() -> ~[A]

Method min

fn min() -> A

Method max

fn max() -> A

Implementation extensions for option<T>

Method 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.

Method 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

Method iter

fn iter(f: fn(T))

Performs an operation on the contained value or does nothing

Method is_none

fn is_none() -> bool

Returns true if the option equals none

Method is_some

fn is_some() -> bool

Returns true if the option contains some value

Method map

fn map<U: copy>(f: fn(T) -> U) -> option<U>

Maps a some value from one type to another

Implementation extensions for option<T>

Method get

fn get() -> T

Gets the value out of an option

Failure

Fails if the value equals none

Method get_default

fn get_default(def: T) -> T

Method expect

pure fn expect(reason: str) -> T

Gets the value out of an option, printing a specified message on failure

Failure

Fails if the value equals none

Implementation extensions of iter::base_iter<A> for IMPL_T<A>

Method each

fn each(blk: fn(A) -> bool)

Method size_hint

fn size_hint() -> option<uint>

Method eachi

fn eachi(blk: fn(uint, A) -> bool)

Method all

fn all(blk: fn(A) -> bool) -> bool

Method any

fn any(blk: fn(A) -> bool) -> bool

Method foldl

fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B

Method contains

fn contains(x: A) -> bool

Method count

fn count(x: A) -> uint

Method position

fn position(f: fn(A) -> bool) -> option<uint>

Implementation extensions for IMPL_T<A>

Method filter_to_vec

fn filter_to_vec(pred: fn(A) -> bool) -> ~[A]

Method map_to_vec

fn map_to_vec<B>(op: fn(A) -> B) -> ~[B]

Method to_vec

fn to_vec() -> ~[A]

Method min

fn min() -> A

Method max

fn max() -> A

Method find

fn find(p: fn(A) -> bool) -> option<A>

Implementation extensions for *T

Extension methods for pointers

Method is_null

pure fn is_null() -> bool

Returns true if the pointer is equal to the null pointer.

Method is_not_null

pure fn is_not_null() -> bool

Returns true if the pointer is not equal to the null pointer.

Implementation extensions for rng

Extension methods for random number generators

Method gen_int

fn gen_int() -> int

Return a random int

Method 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

Method gen_i8

fn gen_i8() -> i8

Return a random i8

Method gen_i16

fn gen_i16() -> i16

Return a random i16

Method gen_i32

fn gen_i32() -> i32

Return a random i32

Method gen_i64

fn gen_i64() -> i64

Return a random i64

Method gen_uint

fn gen_uint() -> uint

Return a random uint

Method 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

Method gen_u8

fn gen_u8() -> u8

Return a random u8

Method gen_u16

fn gen_u16() -> u16

Return a random u16

Method gen_u32

fn gen_u32() -> u32

Return a random u32

Method gen_u64

fn gen_u64() -> u64

Return a random u64

Method gen_float

fn gen_float() -> float

Return a random float

Method gen_f32

fn gen_f32() -> f32

Return a random f32

Method gen_f64

fn gen_f64() -> f64

Return a random f64

Method gen_char

fn gen_char() -> char

Return a random char

Method gen_char_from

fn gen_char_from(chars: str) -> char

Return a char randomly chosen from chars, failing if chars is empty

Method gen_bool

fn gen_bool() -> bool

Return a random bool

Method gen_weighted_bool

fn gen_weighted_bool(n: uint) -> bool

Return a bool with a 1 in n chance of true

Method gen_str

fn gen_str(len: uint) -> str

Return a random string of the specified length composed of A-Z,a-z,0-9

Method gen_bytes

fn gen_bytes(len: uint) -> ~[u8]

Return a random byte string of the specified length

Method choose

fn choose<T: copy>(values: ~[T]) -> T

Choose an item randomly, failing if values is empty

Method choose_option

fn choose_option<T: copy>(values: ~[T]) -> option<T>

Choose some(item) randomly, returning none if values is empty

Method 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

Method 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

Method 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

Method shuffle

fn shuffle<T: copy>(values: ~[T]) -> ~[T]

Shuffle a vec

Method shuffle_mut

fn shuffle_mut<T>(&&values: ~[mut T])

Shuffle a mutable vec in place

Implementation extensions for result<T, E>

Method is_ok

fn is_ok() -> bool

Method is_err

fn is_err() -> bool

Method iter

fn iter(f: fn(T))

Method iter_err

fn iter_err(f: fn(E))

Implementation extensions for result<T, E>

Method get

fn get() -> T

Method map_err

fn map_err<F: copy>(op: fn(E) -> F) -> result<T, F>

Implementation extensions for result<T, E>

Method get_err

fn get_err() -> E

Method map

fn map<U: copy>(op: fn(T) -> U) -> result<U, E>

Implementation extensions for result<T, E>

Method chain

fn chain<U: copy>(op: fn(T) -> result<U, E>) -> result<U, E>

Method chain_err

fn chain_err<F: copy>(op: fn(E) -> result<T, F>) -> result<T, F>

Implementation num of num::num for T

Method add

fn add(&&other: T) -> T

Method sub

fn sub(&&other: T) -> T

Method mul

fn mul(&&other: T) -> T

Method div

fn div(&&other: T) -> T

Method modulo

fn modulo(&&other: T) -> T

Method neg

fn neg() -> T

Method to_int

fn to_int() -> int

Method from_int

fn from_int(n: int) -> T

Implementation num of num::num for T

Method add

fn add(&&other: T) -> T

Method sub

fn sub(&&other: T) -> T

Method mul

fn mul(&&other: T) -> T

Method div

fn div(&&other: T) -> T

Method modulo

fn modulo(&&other: T) -> T

Method neg

fn neg() -> T

Method to_int

fn to_int() -> int

Method from_int

fn from_int(n: int) -> T

Implementation num of num::num for T

Method add

fn add(&&other: T) -> T

Method sub

fn sub(&&other: T) -> T

Method mul

fn mul(&&other: T) -> T

Method div

fn div(&&other: T) -> T

Method modulo

fn modulo(&&other: T) -> T

Method neg

fn neg() -> T

Method to_int

fn to_int() -> int

Method from_int

fn from_int(n: int) -> T

Implementation num of num::num for T

Method add

fn add(&&other: T) -> T

Method sub

fn sub(&&other: T) -> T

Method mul

fn mul(&&other: T) -> T

Method div

fn div(&&other: T) -> T

Method modulo

fn modulo(&&other: T) -> T

Method neg

fn neg() -> T

Method to_int

fn to_int() -> int

Method from_int

fn from_int(n: int) -> T

Implementation num of num::num for T

Method add

fn add(&&other: T) -> T

Method sub

fn sub(&&other: T) -> T

Method mul

fn mul(&&other: T) -> T

Method div

fn div(&&other: T) -> T

Method modulo

fn modulo(&&other: T) -> T

Method neg

fn neg() -> T

Method to_int

fn to_int() -> int

Method from_int

fn from_int(n: int) -> T

Implementation num of num::num for T

Method add

fn add(&&other: T) -> T

Method sub

fn sub(&&other: T) -> T

Method mul

fn mul(&&other: T) -> T

Method div

fn div(&&other: T) -> T

Method modulo

fn modulo(&&other: T) -> T

Method neg

fn neg() -> T

Method to_int

fn to_int() -> int

Method from_int

fn from_int(n: int) -> T

Implementation num of num::num for T

Method add

fn add(&&other: T) -> T

Method sub

fn sub(&&other: T) -> T

Method mul

fn mul(&&other: T) -> T

Method div

fn div(&&other: T) -> T

Method modulo

fn modulo(&&other: T) -> T

Method neg

fn neg() -> T

Method to_int

fn to_int() -> int

Method from_int

fn from_int(n: int) -> T

Implementation num of num::num for T

Method add

fn add(&&other: T) -> T

Method sub

fn sub(&&other: T) -> T

Method mul

fn mul(&&other: T) -> T

Method div

fn div(&&other: T) -> T

Method modulo

fn modulo(&&other: T) -> T

Method neg

fn neg() -> T

Method to_int

fn to_int() -> int

Method from_int

fn from_int(n: int) -> T

Implementation num of num::num for T

Method add

fn add(&&other: T) -> T

Method sub

fn sub(&&other: T) -> T

Method mul

fn mul(&&other: T) -> T

Method div

fn div(&&other: T) -> T

Method modulo

fn modulo(&&other: T) -> T

Method neg

fn neg() -> T

Method to_int

fn to_int() -> int

Method from_int

fn from_int(n: int) -> T

Implementation num of num::num for T

Method add

fn add(&&other: T) -> T

Method sub

fn sub(&&other: T) -> T

Method mul

fn mul(&&other: T) -> T

Method div

fn div(&&other: T) -> T

Method modulo

fn modulo(&&other: T) -> T

Method neg

fn neg() -> T

Method to_int

fn to_int() -> int

Method from_int

fn from_int(n: int) -> T

Implementation num of num::num for float

Method add

fn add(&&other: float) -> float

Method sub

fn sub(&&other: float) -> float

Method mul

fn mul(&&other: float) -> float

Method div

fn div(&&other: float) -> float

Method modulo

fn modulo(&&other: float) -> float

Method neg

fn neg() -> float

Method to_int

fn to_int() -> int

Method from_int

fn from_int(n: int) -> float

Implementation num of num::num for f32

Method add

fn add(&&other: f32) -> f32

Method sub

fn sub(&&other: f32) -> f32

Method mul

fn mul(&&other: f32) -> f32

Method div

fn div(&&other: f32) -> f32

Method modulo

fn modulo(&&other: f32) -> f32

Method neg

fn neg() -> f32

Method to_int

fn to_int() -> int

Method from_int

fn from_int(n: int) -> f32

Implementation num of num::num for f64

Method add

fn add(&&other: f64) -> f64

Method sub

fn sub(&&other: f64) -> f64

Method mul

fn mul(&&other: f64) -> f64

Method div

fn div(&&other: f64) -> f64

Method modulo

fn modulo(&&other: f64) -> f64

Method neg

fn neg() -> f64

Method to_int

fn to_int() -> int

Method from_int

fn from_int(n: int) -> f64

Implementation times of iter::times for T

Method 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 */ }.

Implementation times of iter::times for T

Method 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 */ }.

Implementation times of iter::times for T

Method 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 */ }.

Implementation times of iter::times for T

Method 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 */ }.

Implementation times of iter::times for T

Method 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 */ }.

Implementation times of iter::times for T

Method 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 */ }.

Implementation times of iter::times for T

Method 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 */ }.

Implementation times of iter::times for T

Method 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 */ }.

Implementation times of iter::times for T

Method 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 */ }.

Implementation times of iter::times for T

Method 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 */ }.

Function 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.