Crate std_prelude [−] [src]
use std_prelude::*
so you can be ready to code!
Traits
Not having common traits imported is one of the most annoying gotchas in rust when coming from
other languages. When you are used to the language, you expect the methods you are used to to
always work... not so. Using Vec::from_iter
is extremely common, but you must first import
the FromIterator
trait.
The following are the traits that are exported and why:
std::ascii::AsciiExt
: adds theto_ascii_uppercase
onto&str
types.std::fmt::Debug
: allows you to define Debug manually.std::hash::{Hash, Hasher}
: allows you to easily implementHash
on your types.std::fmt::Write as FmtWrite
: addswrite_str
onto byte buffers (such asString
). RenamedFmtWrite
to avoid conflict withstd::io::Write
std::io::BufRead
: theBufRead
trait allows you to use the methods associated with theBufReader
struct.std::io::Read
: allows you to usefile.read()
std::io::Seek
: allows you to usefile.seek()
std::io::Write as IoWrite
: allows you to usefile.write()
andfile.write_all()
. RenamedIoWrite
to avoid conflict withstd::fmt::Write
std::ops::{Deref, DerefMut}
: allows deref through*v
and also enables Deref coercionsstd::str::FromStr
: allows you to usetype::from_str
constructor for several types. This is what is implicitly called withstr::parse<_>()
structs
These are extremely commonly used types and it is annoying to have to reimport them all the time.
std::collections::{BTreeMap, HashMap, HashSet}
: ordered-dict, dict and setstd::cmp::{Ord, PartialOrd, Ordering}
: for defining theOrd
andPartialOrd
trait, as well as working with types that use them.std::ffi::OsString
: os agnostic (non unicode) string typestd::path::PathBuf
uses this.std::fs::File
: for opening files.File::open
to open a file for readingFile::write
to open a file for writing
std::fs::OpenOptions
for more file opening optionsstd::fs::ReadDir
: to iterate over the entries in a directory.std::io::BufReader
: the BufRead struct wrapsio::Read
using a buffer reducing the number of OS calls and giving helpful methodsread_line()
: read a single linelines()
: return an iterator over all lines.split(byte: u8)
: return an iterator which splits at the chosen byte.
std::io::BufWriter
: similar toBufReader
, buffers writes to reduce the number of calls to the OS. Provides no new methods.std::path::{Path, PathBuf}
: specifies an os path.std::rc::Rc
: reference counted pointerstd::sync::Arc
: atomically reference counted pointerstd::sync::Mutex
: mutual exclusion primitive for threading.std::sync::atomic::{AtomicBool, AtomicIsize, AtomicUsize}
: basic atomic types. Good for unique ids and lots of other use cases.std::sync::atomic::Ordering as AtomicOrdering
: necessary for performing operations on atomic types. For incrementing a counter useval.fetch_add(1, AtomicOrdering::SeqCst)
. Renamed to not conflict withstd::cmp::Ordering
.std::sync::atomic::ATOMIC_USIZE_INIT
: initializedAtomicUsize
of 0. Use withstatic COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;
std::time::Duration
: an amount of time, used forstd::thread::sleep
.
functions
These are mostly just "nice to have" functions and it is really unlikely that they would ever be overriden.
std::mem::{size_of, size_of_val}
: get the size of a type. This is safe and common enough that it should be always available.std::thread::sleep
: put the thread to sleep for aDuration
.std::thread::spawn
: spawn a function in a new thread. In rust this is memory safe, so it is nice to have it always available.
primitive-type modules
The following modules are imported so that it is easy to access their relevant constants and constructors.
u8 u16 u64 usize
: unsigned integer modules withMAX
andMIN
i8 i16 i64 isize
: signed integer modules withMAX
andMIN
f32 f64
: floating point modules with not justMAX
andMIN
but alsoNAN
,INFINITY
, etc as well as aconsts
module with basic mathematical constants likePI
andE
.str
: core string type withfrom_utf8
function.
Modules
f32 |
This module provides constants which are specific to the implementation
of the |
f64 |
This module provides constants which are specific to the implementation
of the |
i8 |
The 8-bit signed integer type. |
i16 |
The 16-bit signed integer type. |
i64 |
The 64-bit signed integer type. |
isize |
The pointer-sized signed integer type. |
str |
Unicode string slices. |
u8 |
The 8-bit unsigned integer type. |
u16 |
The 16-bit unsigned integer type. |
u64 |
The 64-bit unsigned integer type. |
usize |
The pointer-sized unsigned integer type. |
Structs
Arc |
A thread-safe reference-counting pointer. 'Arc' stands for 'Atomically Reference Counted'. |
AtomicBool |
A boolean type which can be safely shared between threads. |
AtomicIsize |
An integer type which can be safely shared between threads. |
AtomicUsize |
An integer type which can be safely shared between threads. |
BTreeMap |
A map based on a B-Tree. |
BufReader |
The |
BufWriter |
Wraps a writer and buffers its output. |
Duration |
A |
File |
A reference to an open file on the filesystem. |
HashMap |
A hash map implemented with linear probing and Robin Hood bucket stealing. |
HashSet |
A hash set implemented as a |
Mutex |
A mutual exclusion primitive useful for protecting shared data |
OpenOptions |
Options and flags which can be used to configure how a file is opened. |
OsString |
A type that can represent owned, mutable platform-native strings, but is cheaply inter-convertible with Rust strings. |
Path |
A slice of a path (akin to |
PathBuf |
An owned, mutable path (akin to |
Rc |
A single-threaded reference-counting pointer. 'Rc' stands for 'Reference Counted'. |
ReadDir |
Iterator over the entries in a directory. |
Enums
AtomicOrdering |
Atomic memory orderings |
Ordering |
An |
SeekFrom |
Enumeration of possible methods to seek within an I/O object. |
Constants
ATOMIC_USIZE_INIT |
An atomic integer initialized to |
Traits
AsciiExt |
Extension methods for ASCII-subset only operations. |
BufRead |
A |
Debug |
Format trait for the |
Deref |
Used for immutable dereferencing operations, like |
DerefMut |
Used for mutable dereferencing operations, like in |
FmtWrite |
A collection of methods that are required to format a message into a stream. |
FromIterator |
Conversion from an |
FromStr |
A trait to abstract the idea of creating a new instance of a type from a string. |
Hash |
A hashable type. |
Hasher |
A trait for hashing an arbitrary stream of bytes. |
IoWrite |
A trait for objects which are byte-oriented sinks. |
Ord |
Trait for types that form a total order. |
PartialOrd |
Trait for values that can be compared for a sort-order. |
Read |
The |
Seek |
The |
Functions
size_of |
Returns the size of a type in bytes. |
size_of_val |
Returns the size of the pointed-to value in bytes. |
sleep |
Puts the current thread to sleep for the specified amount of time. |
spawn |
Spawns a new thread, returning a |