Expand description
import 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 implemented and why:
std::ascii::AsciiExt
: adds theto_ascii_uppercase
onto&str
types.std::fmt::Debug
: allows you to define Debug manually.std::fmt::Write as FmtWrite
: addswrite_str
onto byte buffers (such asString
). RenamedFmtWrite
to avoid conflict withstd::io::Write
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::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::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
: necessary for performing operations on atomic types. For incrementing a counter useval.fetch_add(1, Ordering::SeqCst)
.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
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.
Structs§
- Arc
- A thread-safe reference-counting pointer. ‘Arc’ stands for ‘Atomically Reference Counted’.
- Atomic
Bool - A boolean type which can be safely shared between threads.
- Atomic
Isize - An integer type which can be safely shared between threads.
- Atomic
Usize - An integer type which can be safely shared between threads.
- BTree
Map - An ordered map based on a B-Tree.
- Duration
- A
Duration
type to represent a span of time, typically used for system timeouts. - File
- An object providing access to an open file on the filesystem.
- HashMap
- A hash map implemented with quadratic probing and SIMD lookup.
- HashSet
- A hash set implemented as a
HashMap
where the value is()
. - Mutex
- A mutual exclusion primitive useful for protecting shared data
- Open
Options - 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
str
). - PathBuf
- An owned, mutable path (akin to
String
). - Rc
- A single-threaded reference-counting pointer. ‘Rc’ stands for ‘Reference Counted’.
- ReadDir
- Iterator over the entries in a directory.
Enums§
- Ordering
- Atomic memory orderings
- Seek
From - Enumeration of possible methods to seek within an I/O object.
Constants§
- ATOMIC_
USIZE_ INIT Deprecated - An
AtomicUsize
initialized to0
.
Traits§
- Ascii
Ext Deprecated - Extension methods for ASCII-subset only operations.
- Debug
?
formatting.- Deref
- Used for immutable dereferencing operations, like
*v
. - Deref
Mut - Used for mutable dereferencing operations, like in
*v = 1;
. - FmtWrite
- A trait for writing or formatting into Unicode-accepting buffers or streams.
- From
Iterator - Conversion from an
Iterator
. - FromStr
- Parse a value from a string
- IoWrite
- A trait for objects which are byte-oriented sinks.
- Read
- The
Read
trait allows for reading bytes from a source. - Seek
- The
Seek
trait provides a cursor which can be moved within a stream of bytes.
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 at least the specified amount of time.
- spawn
- Spawns a new thread, returning a
JoinHandle
for it.
Derive Macros§
- Debug
- Derive macro generating an impl of the trait
Debug
.