about
RustStory Libraries
9/24/2022
Chapter 5. - Rust Libraries
std, collectons, fs, net, error, time, thread, process
5.0 Prologue
Source code is provided for all the std libraries.
simply go here,
browse around and click any of the [src] tabs.
5.1 std Libraries
5.2 std::convert - conversions between types
- AsRef trait provides cheap (re-interprets) reference-to-reference conversions.
- AsMut trait provides cheap (re-interprets) mutable-to-mutable conversions.
- From trait provides consuming (move) value-to-value conversions.
-
AsRef:
pub trait AsRef<T> where T: ?Sized, { fn as_ref(&self) -> &T } Partial List of Implementors:
-
[T]::as_ref<[T]>() -> &[T]; -
Vec<T>::as_ref<[T]>() -> &[T]; -
Vec<T>::as_ref<Vec<T>>() -> &Vec<T> -
Box<T>::as_ref<T>() -> &T;
where T: ?Sized -
Arc<T>::as_ref<T>() -> &T;
where T: ?Sized -
str::as_ref<[u8]>() -> &[u8]; -
str::as_ref<str>() -> &str; -
str::as_ref<OsStr>() -> &OsStr; -
String::as_ref<[u8]>() -> &[u8]; -
String::as_ref<str>() -> &str; -
String::as_ref<OsStr>() -> &OsStr; -
String::as_ref<Path>() -> &Path; -
CStr::as_ref<CStr>() -> &CStr; -
CString::as_ref<CStr>() -> &CStr; -
OsStr::as_ref<OsStr>() -> &OsStr; -
OsString::as_ref<OsStr>() -> &OsStr; -
Path::as_ref<OsStr>() -> &OsStr; -
PathBuf::as_ref<OsStr>() -> &OsStr; -
PathBuf::as_ref<OsStr>() -> &Path;
-
-
AsMut:
pub trait AsMut<T> where T: ?Sized, { fn as_mut(&mut self) -> &mut T; } Partial List of Implementors
-
String::as_mut() -> &mut str -
[T]::as_mut() -> &mut [T] -
Vec<T>::as_mut() -> &mut [T] -
Vec<T>::as_mut() -> &mut Vec<T> -
Box<T: ?Sized>::as_mut() -> &mut T
-
-
From:
pub trait From<T> { fn from(T) -> Self } Partial List of Implementors
- String::from(&str)
- String::from(Box<str>)
- char::from(u8)
- PathBuf::from(String)
- Pathbuf::from(OsString)
- OsString::from(String)
- OsString::From(PathBuf)
- u32::from(char)
- isize::from(i16)
- f64::from(f32)
- f64::from(i16)
- AtomicI16::from(i16)
- Vec<u8>::from(String)
- Vec<T>::from(BinaryHeap<T>)
- Vec<T>::from(VecDeque<T>)
- VecDeque<T>::from(Vec<T>)
- BinaryHeap<T>::from(Vec<T>)
- Mutex<T>::from(T)
- RWLock<T>::from(T)
- Box<[u8]>::from(Box>str>)
- Box<str>::from(&str)
- Arc<OsStr>::from(OsString)
- Arc<Path>::From(PathBuf)
- Arc<String>::from(String)
- Arc<T>::from(T)
- Error::from(kind: ErrorKind)
- Stdio::from(File)
- Stdio::from(ChildStdin)
- Stdio::from(ChildStdout)
5.3 std::collections - containers and iterators
The std namespace has a set of std::collections similar to other languages:Collection | Description |
---|---|
Vec<T> |
Sequence container: A self expanding indexable array of items of type T, occupying a contiguous block of memory. Constant time access to indexed item, linear time insertion and removal. |
VecDeque<T> |
Sequence container: A self expanding indexable array of items of type T, with constant-time access, insertion, and removal on either end. |
LinkedList<T> |
Sequence container: A doubly linked list of items of type T, with linear-time traversal. |
HashMap<K, V> |
Associative container: A hashed container with almost constant time access. Elements are randomly ordered (if the hash function works well for T) |
BTreeMap<K, V> |
Associative container: A balanced binary tree container with log n time access. Elements are sorted. |
HashSet<K> |
Set container: A hashed container with almost constant time access. Elements are randomly ordered (if the hash function works well for T) |
BTreeSet<K> |
Set container: A balanced binary tree container with log n time access. Elements are sorted. |
BinaryHeap<T> |
Priority queue: Largest element is accessed in constant time. |
Example: std::collections::echo
5.3.1 Iterators
- iter(), which iterates over &T
- iter_mut(), which iterates over &mut T
- into_iter(), which iterates over T
-
trait Iterator { type Item; fn next(&mut self) -> Option<Self::Item> fn count(self) -> usize fn last(self) -> Option<Self::Item> fn nth(&mut self, n: usize) -> Option<Self::Item> fn skip(self, n: usize) -> Skip<Self> fn step_by(self, step: usize) -> StepBy<Self> fn map<B, F>(self, f: F) -> Map<Self, F> where F: FnMut(Self::Item) -> B fn for_each<F>(self, f: F) where F: FnMut(Self::Item) fn filter<P>(self, predicate: P) -> Filter<Self, P> where P: FnMut(&Self::Item) -> bool ... } -
trait IntoIterator { type Item; type IntoIter: Iterator fn into_iter(self) -> Self::IntoIter }
Partial List of Iterator Adapters
-
fn next(&mut self) -> Option<Self::Item>
Advances and returns value. -
fn map<B, F>(self, f:F) -> Map<Self, F>
where F: FnMut(Self::Item) -> B
Takes a closure and creates an iterator that applies the closure to each item. -
fn filter<P>(self, predicate:P) -> Filter<Self, P>
where P: FnMust(&Self::Item) -> bool
Creates an iterator that determines if an item should be included. -
fn take(self, n:usize) -> Take<Self> -
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
where P: FnMut(&Self::Item) -> bool -
fn fold<B, F>(self, init:B, f:F) -> B
where FnMut(B, Self::Item) -> B -
fn skip(self, n:usize) -> Skip<Self> -
fn collect<B>(self) -> B
where B: FromIterator<Self::Item> -
step_by(self, step:usize) -> StepBy<Self> Skips step items on each iteration -
nth(&mut self, n:usize) -> Option<Self::item> Returns nth item, counting from zero -
last(self) -> Option<Self::item> Consumes iterator, returning last item -
fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
where FnMut(&Self::Item) -> bool -
fn position<P>(&mut self, predicate: P) -> Option<usize>
where P: FnMut(Self::Item) -> bool -
fn for_each<F>(self, f:F)
where F: FnMut(Self::Item)
Calls a closure on each element of an iterator. -
fn enumerate(self) -> Enumerate<Self> Creates an iterator returns a pair with current iteration count and next value. -
fn by_ref(&mut self) -> &mut Self -
fn all<F>(&mut self, f:F) -> bool
where F: FnMut(Self::Item) -> bool -
fn any<F>(&mut self, f:F) -> bool
where F: FnMut(Self::Item) -> bool -
fn count(self) -> usize Consumes iterator, counting number of iterations -
fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>
where U: IntoIterator<Self::Item> -
fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>
where U: IntoIterator -
fn sum<S>(self) -> S
where S: Sum<Self::Item> -
fn product<P>(self) -> P
where P: Product<Self::Item>
Example: iteration_echo
5.4 std::io - Base I/O, console operations
Partial List of Traits
-
pub trait Read { fn read(&mut self, buf: &mut [u8]) -> Result<usize> fn read_exact(&mut self, buf: &mut [u8]) -> Result<()> fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> fn read_to_string(&mut self, buf: &mut String) -> Result<usize> fn by_ref(&mut self) -> &mut Self, where Self: Sized, fn bytes(self) -> Bytes<Self>, where Self: Sized, ... } -
pub trait BufRead { fn fill_buf(&mut self) -> Result<&[u8]> fn consume(&mut self, amt: usize) fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize> fn read_line(&mut self, buf: &mut String) -> Result<usize> fn lines(self) -> Lines<Self> // an iterator ... } -
pub trait Write { fn write_all(&mut self, buf: &[u8]) -> Result<()> fn write(&mut self, buf: &[u8]) -> Result<usize> fn write_fmt(&mut self, fmt: Arguments) -> Result<()> fn by_ref(&mut self) -> &mut Self, where Self: Sized, fn flush(&mut self) -> Result<()>, ... } -
pub trait Seek { fn seek(&mut self, pos: SeekFrom) -> Result<u64> fn stream_len(&mut self) -> Result<u64> ... }
Partial List of Structs
-
BufReader Implements Traits BufRead, Debug, Read, Seek, ... pub fn new(inner: R) -> BufReader<R> where R: Read pub fn get_ref(&self) -> &R pub fn get_mut(&self) -> &mut R pub fn buffer(&self) -> &[u8] pub fn into_inner(self) -> R -
BufWriter Implements Traits Debug, Drop, Seek, Write ... pub fn new(inner: W) -> BufWriter<W> where W: Write pub fn get_ref(&self) -> &W pub fn get_mut(&self) -> &mut W pub fn buffer(&self) -> &[u8] pub fn into_inner(self) -> Result<W, IntoInnerError<BufWriter<W>>> -
Bytes Implements Traits Debug, Iterator ... -
Error Implements Traits Debug, Display, Error, From<ErrorKind>, ... pub fn new<E>(kind: ErrorKind, error: E) -> Error pub fn get_ref(&self) -> Option<&(dyn Error + Send + Sync + 'static')> pub fn get_mut(&mut self) -> Option<&mut (dyn Error + Send + Sync + 'static')> pub fn into_inner(self) -> Option<Box<dyn Error + Send + Sync>> pub fn kind(&self) -> ErrorKind -
LineWriter Implements Traits Debug, Write ... pub fn new(inner: W) -> LineWriter<W> where W: Write pub fn get_ref(&self) -> &W pub fn get_mut(&self) -> &mut W pub fn into_inner(self) -> Result<W, IntoInnerError<LineWriter<W>>> -
Lines Implements Traits Debug, Iterator ... -
Stdin Implements Traits Debug, Read ... pub fn lock(&self) -> StdinLock pub fn read_line(&self, buf: &mut String) -> Result<usize> -
Stdout Implements Traits Debug, Write ... pub fn lock(&self) -> StdoutLock
Partial List of Functions
-
pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> Result<u64> -
pub fn stderr() -> Stderr -
pub fn stdin() -> Stdin -
pub fn stdout() -> Stdout
Example: std::io::echo
5.5 std::fs - File system operations
List of Structs
-
DirBuilder Implements Traits Debug, ... pub fn new() -> DirBuilder pub fn create<P: AsRef<Path>>(&mut self, path: P) -> Result<()> pub fn recursive(&mut self, recursive: bool) -> &mut Self -
DirEntry Implements Traits Debug, ... pub fn path(&self) -> PathBuf pub fn metadata(&mut self) -> Result<Metadata> pub fn metadata(&mut self) -> Result<Metadata> pub fn metadata(&mut self) -> Result<Metadata> pub fn file_name(&mut self) -> OsString -
File Implements Traits Debug, Read, Seek, Write, ... pub fn open<P: AsRef<Path>>(path: P) -> Result<File> pub fn create<P: AsRef<Path>>(path: P) -> Result<File> pub fn set_len(&mut self, size: u64) -> Result<()> pub fn metadata(&mut self) -> Result<Metadata> pub fn set_permissions(&mut self, perm: Permissions) -> Result<()> -
FileType Implements Traits Clone, Copy, Debug, ... pub fn is_dir(&mut self) -> bool pub fn is_file(&mut self) -> bool -
Metadata Implements Traits Clone, Debug, ... pub fn file_type(&mut self) -> FileType pub fn is_dir(&mut self) -> bool pub fn is_file(&mut self) -> bool pub fn len(&mut self) -> u64 pub fn permissions(&mut self) -> Permissions pub fn modified(&mut self) -> Result<SystemTime> pub fn accessed(&mut self) -> Result<SystemTime> pub fn created(&mut self) -> Result<SystemTime> -
OpenOptions Implements Traits Clone, Debug, ... pub fn new() -> OpenOptions pub fn read(&mut self, read: bool) -> &mut OpenOptions pub fn write(&mut self, write: bool) -> &mut OpenOptions pub fn append(&mut self, append: bool) -> &mut OpenOptions pub fn truncate(&mut self, truncate: bool) -> &mut OpenOptions pub fn create(&mut self, create: bool) -> &mut OpenOptions pub fn create_new(&mut self, create_new: bool) -> &mut OpenOptions pub fn open<P: AsRef<Path>>(&self, path: P) -> Result<File> -
Permissions Implements Traits Clone, Debug, Eq, PartialEq, ... pub fn readonly(&self) -> bool pub fn set_readonly(&mut self, readonly: bool) -
ReadDir Implements Traits Debug, Iterator, ... Iterator over entries in a directory, returned from the read_dir(p: Path) function. Yields instances of io::Result<DirEntry>
Partial List of IO Functions
-
fn canonicalize<P: AsRef<Path>>(path: P) -> Result<PathBuf> -
fn create_dir<P: AsRef<Path>>(path: P) -> Result<()> -
fn read_dir<P: AsRef<Path>>(path: P) -> Result<ReadDir> -
fn remove_dir<P: AsRef<Path>>(path: P) -> Result<()> -
fn metadata<P: AsRef<Path>>(path: P) -> Result<Metadata> -
fn read<P: AsRef<Path>>(path: P) -> Result<Vec<u8>> -
fn read_dir<P: AsRef<Path>>(path: P) -> Result<ReadDir> -
fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String> -
fn write<P: AsRef<Path>>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> -
fn remove_file<P: AsRef<Path>>(path: P) -> Result<()> -
fn rename<P: AsRef<Path>>(path: P) -> Result<()> -
fn set_permissions<P: AsRef<Path>>(path: P, perm: Permissions) -> Result<()>
Example: std::fs::echo
5.6 net: - Socket operations
List of Structs
-
TcpListener Traits: Debug, ... pub fn bind<A: ToSocketAddrs>(addr: A) -> Result<TcpListener> pub fn accept(&self) -> Result<(TcpStrea,. SpcletAddr)> pub fn inoming(&self) -> Incoming pub fn take_error(&self) -> Result<Option<Error>> pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()> ... -
TcpStream Traits: Read, Write, Debug, ... pub fn connect<A: ToSoketAddrs>(addr: A) -> Result<TcpStream> pub fn shutdown(&self, how: Shutdown) -> Result<()> pub fn peek(&mut self, buf: &mut [u8]) -> Result<usize> pub fn take_error(&self) -> Result<Option<Error>> pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()> ... -
UdpSocket Traits: Debug, ... pub fn bind<A: ToSocketAddrs>(addr: A) -> Result<TcpListener> pub fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)> pub fn peek_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)> pub fn send_to<A: ToSocketAddrs>(&self, buf: &[u8], addr: A) -> Result<usize> pub fn set_broadcast(&self, broadcast: bool) -> Result<()> pub fn broadcast(&mut self) -> Result<bool> pub fn take_error(&self) -> Result<Option<Error>> pub fn connect<A: ToSocketAddrs>(&self, addr: A) -> Result<()> pub fn send(&self, buf: &mut [u8]) -> Result<usize> pub fn recv(&self, buf: &mut [u8]) -> Result<usize> pub fn peek(&self, buf: &mut [u8]) -> Result<usize> pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()> ... -
Ipv4Addr Implements Traits Debug, Display, copy, clone, Eq, PartialEq, From ... pub const fn new(a: u8, b: u8, c: u8, d: u8) -> IpvrAddr pub const LOCALHOST: Self pub const UNSPECIFIED: Self pub const BROADCAST: Self pub fn octets(&self) -> [u8; 4] pub fn is_unspecified(&self) -> bool pub fn is_loopback(&self) -> bool pub fn is_private(&self) -> bool pub fn is_multicast(&self) -> bool pub fn is_broadcast(&self) -> bool pub fn to_ipv6_compatible(&self) -> Ipv6Addr pub fn to_ipv6_mapped(&self) -> Ipv6Addr -
Ipv6Addr Implements Traits Debug, Display, copy, clone, Eq, PartialEq, From ... pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> IpvrAddr pub const LOCALHOST: Self pub const UNSPECIFIED: Self pub fn segments(&self) -> [u16; 8] pub fn octets(&self) -> [u8; 16] pub fn is_unspecified(&self) -> bool pub fn is_loopback(&self) -> bool pub fn is_multicast(&self) -> bool pub fn to_ipv4(&self) -> Ipv4Addr -
SocketAddrV4 Traits: Debug, Display, Copy, Clone, Eq, PartialEq, From, FromStr, ToSocketAddrs, ... pub fn new(ip: Ipv4Addr, port: u16) -> SocketAddrV4 pub fn ip(&self) -> &Ipv4Addr pub fn set_ip(&mut self, new_ip: Ipv4Addr) pub fn port(&self) -> u16 pub fn set_port(&mut self, new_port: u16) -
SocketAddrV6 Traits: Debug, Display, Copy, Clone, Eq, PartialEq, From, FromStr, ToSocketAddrs, ... pub fn new(ip: Ipv6Addr, port: u16, flowinfo: u32, scope_id: u32) -> SocketAddrV6 pub fn ip(&self) -> &Ipv6Addr pub fn set_ip(&mut self, new_ip: Ipv6Addr) pub fn port(&self) -> u16 pub fn set_port(&mut self, new_port: u16) pub fn flowinfo(&self) -> u32 pub fn set_flowinfo(&mut self, new_flowinfo: u32) pub fn scope_id(&self) -> u32 pub fn set_scope_id(&mut self, new_scope_id: u32) -
AddrParseError Traits: Error, Debug, Display, Clone, Eq, PartialEq, ...
List of net Enums
-
pub enum IpAddr { V4(Ipv4Addr), V6(Ipv6Addr), } -
pub enum SocketAddr { V4(SocketAddrV4), V6(SocketAddrV6), } -
pub enum Shutdown { Read, Write, Both, } -
pub enum Ipv6MulticastScope {
InterfaceLocal, LinkLocal, RealmLocal, AdminLocal, SiteLocal,
OrganizationLocal, Global,
}
Example: std::net::echo
5.7 Thread - basic threads
-
trait Send { } // marker trait // - types that can be transferred across thread boundaries -
trait Sync { } // marker trait // - types for which it is safe to share references between threads
List of Structs
-
Thread Traits: Debug, Clone, Send, Sync, ... pub fn id(&self) -> ThreadId pub fn name(&self) -> Option<&str> -
ThreadId Traits: Debug, Copy, Clone, Eq, PartialEq, Send, Sync, ... -
Builder Traits: Debug, Send, Sync, ... pub fn new() -> Builder pub fn name(self, name: String) -> Builder pub fn stack_size(self, size: usize) -> Builder pub fn spawn<F, T>(self, f: F) -> Result<JoinHandle<T>> where F: FnOnce() -> T, F: Send + 'static', T: Send + 'static' -
JoinHandle Traits: Debug, Send, Sync, ... pub fn thread(&self) -> &Thread pub fn join(self) -> Result<T> -
LocalKey Traits: Debug, Send, Sync, ... pub fn with<F, R>(&'static self, f: F) -> R where F: FnOnce(&T) -> R ... -
AccessError Traits: Debug, Display, Clone, Copy, Eq, PartialEq, Error, Send, Sync, ...
List of Functions
-
pub fn spawn<F, T>(f: F) -> JoinHandle<T> where F: FnOnce() -> T, F: Send + 'static, T: Send + 'static -
pub fn current() -> Thread -
pub fn sleep(dur: std::time::Duration) -
pub fn yield_now() -
...
Example: std::thread::Shared
5.8 sync - Serialization with Mutexes, Condvars
List of Structs
-
Arc Traits: Debug, Display, Default, AsRef<T>, Deref, From, FromIterator, Eq, PartialEq, Pointer, Send, Sync, ... pub fn new(data: T) -> Arc<T> pub fn try_unwrap(this: Arc<T>) -> Result<T, Arc<T>> pub fn downgrade(this: &Arc<T>) -> Weak<T> pub fn weak_count(this: &Arc<T>) -> usize pub fn strong_count(this: &Arc<T>) -> usize pub fn ptr_eq(this: &Arc<T>, other: &Arc<T>) -> bool pub fn make_mut(this: &Arc<) -> &mut T where T: Clone pub fn get_mut(this: &Arc<) -> Option<&mut T> where T: ?Sized -
Mutex Traits: Debug, Default, for, Send, Sync... pub fn new(t: T) -> Mutex<T> pub fn lock(&self) -> LockResult<MutexGuard<T>> where T: ?Sized pub fn try_lock(&self) -> TryLockResult<MutexGuard<T>> where T: ?Sized pub fn is_poisoned(&self) -> bool pub fn into_inner(self) -> LockResult<T> where T: Sized pub fn get_mut(&mut self) -> LockResult<&mut T> ... -
MutexGuard Traits: Debug, Default, Send, Sync, ... -
Condvar Traits: Debug, Default, Send, Sync, ... pub fn new() -> ConVar pub fn wait<'a, T>(&self, guard: MutexGuard<'a, T>) -> LockResult<MutexGuard<'a, T>> pub fn wait_while<'a, T, F>(&self, guard: MutexGuard<'a, T>, condition: F) -> LockResult<MutexGuard<'a, T>> where F: FnMut(&mut T) -> bool pub fn wait_timeout<'a, T>(&self, guard: MutexGuard<'a, T>, dur: Duration) -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)> pub fn notify_one(&self) pub fn notify_all(&self) -
RwLock Traits: rDebug, Default, From, Send, Sync, ... pub fn new(t: T) -> RwLock<T> pub fn read(&self) -> LockResult<RwLockReadGuard<T>> -
RwLockReadGuard Traits: Debug, Display, Deref, !Send, Sync, ... -
RwLockWriteGuard Traits: Debug, Display, Deref, DerefMut, !Send, Sync, ... -
Weak Traits: Debug, Default, Clone, Send, Sync, ... pub fn new() -> Weak<T> pub fn upgrade(&self) -> Option<Arc<T>> pub fn strong_count(&self) -> usize pub fn ptr_eq(&self, other: &Weak<T>) -> bool -
WaitTimeoutResult Traits: Debug, Copy, Clone, Eq, PartialEq, Send, Sync, ... pub fn timed_out(&self) -> bool -
Once Traits: Debug, Send, Sync, ... pub const fn new(&self) -> Once pub fn call_once<F>(&self, f: F) where F: FnOnce() pub fn is_completed<F>(&self) -> bool -
Barrier Traits: Debug, Send, Sync, ... pub fn new(n: usize) -> Barrier pub fn wait(&self) -> BarrierWaitResult -
BarrierWaitResult Traits: Debug, Send, Sync, ... - ...
Example: sync_demo
Example: Blocking Queue
5.9 mpsc - Message passing between threads
List of Structs
-
Receiver retrieves messages from a channel can only be owned by one thread Traits: Debug, IntoIterator, Drop, Send, !Sync, ... pub fn try_recv(&self) -> Result<T, TryRecvError> non-blocking pub fn recv(&self) -> Result<T, RecvError>blocks on no data pub fn recv_timeout(&self, timeout: Duration) -> Result<T, RecvTimeoutError> pub fn iter(&self) -> Iter<T> pub fn try_iter(&self) -> TryIter<T> -
Sender sends messages to a a channel, non-blocking can only be owned by one thread, but can be cloned Traits: Debug, Clone, Send, !Sync, Drop, ... pub fn send(&self, t: T) -> Result<(), SendError> -
SyncSender sends messages to a channel, blocks if there is not enough space in internal buffer Traits: Debug, Clone, Send, Drop, ... pub fn send(&self, t: T) -> Result<(), SendError> pub fn try_send(&self, t: T) -> Result<(), TrySendError> -
IntoIter blocks when next is called, waiting for a new message Traits: Debug, Iterator, ... -
Iter blocks when next is called, waiting for a new message Traits: Debug, Iterator, ... -
TryIter attempts to yield all pending values for a Receiver Traits: Debug, Iterator, ... -
SendError sends only fail if receiving end is disconnected. error contains un-sent message as payload Traits: Debug, Display, Clone, Copy, Eq, PartialEq, ... -
ReceiveError receives only fail if sending end is disconnected. error contains un-sent message as payload Traits: Debug, Display, Clone, Copy, Eq, PartialEq, ...
List of Functions
-
pub fn channel<T>() -> (Sender<T>, Receiver<T>) -
pub fn sync_channel<T>(bound: usize) -> (SyncSender<T>, Receiver<T>)
List of Enumerations
- Traits: Debug, Display, Clone, Copy, Error, Eq, PartialEq, ....
-
pub enum RecvTimeoutError { Timeout, Disconnected, } -
pub enum TryRecvError { Empty, Disconnected, } -
pub enum TrySendError<T>{ Full(T), Disconnected(T), }
Example: channel_demo
5.10 Async/Await - concurrent functions and blocks
5.11 process - Creating child processes
List of Structs
-
Command Traits: Debug, ... pub fn new<S: AsRef<OsStr>>(program: S) -> Command pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command pub fn args<I, S>(&mut self, args: I) -> &mut Command where I: IntoIterator<Item = S>, S: AsRef<OsStr>, pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Command where K: AsRef<OsStr>, V: AsRef<OsStr>, pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Command where I: IntoIterator<Item = (K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>, pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Command pub fn env_clear(&mut self) -> &mut Command pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Command pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command pub fn spawn(&mut self) -> Result<Child> pub fn output(&mut self) -> Result<Output> pub fn status(&mut self) -> Result<ExitStatus> -
Child Traits: Debug, ... pub fn kill(&mut self) -> Result<()> pub fn id(&mut self) -> u32 pub fn wait(&mut self) -> Result<ExitStatus> -
ChildStdin Traits: Debug, From, Write, ... -
ChildStdout Traits: Debug, From, Read, ... -
ChildStderr Traits: Debug, From, Read, ... -
Stdio Traits: Debug, From, ... pub fn piped() -> Stdio pub fn inherit() -> Stdio pub fn null() -> Stdio -
Output Traits: Debug, Clone, Eq, PartialEq, ... -
ExitStatus Traits: Debug, Display, Copy, Clone, Eq, PartialEq, ... pub fn success(&self) -> bool pub fn code(&self) -> Option<i32> - ...
List of Functions
-
pub fn abort() -> ! -
pub fn exit(code: i32) -> ! -
pub fn id() -> u32
Example: process_demo
5.12 time - System time, time durations
List of Structs
-
Duration Traits: Debug, Default, Clone, Copy, ... pub fn new(secs: u64, nanos: u32) -> Duration pub fn from_secs(secs: u64) -> Duration pub fn from_millis(millis: u64) -> Duration pub fn from_micros(micros: u64) -> Duration pub fn from_nanos(nanos: u64) -> Duration pub fn as_secs(&self) -> u64 pub fn as_millis(&self) -> u128 pub fn as_micros(&self) -> u128 pub fn as_nanos(&self) -> u128 pub fn checked_add(self, rhs: Duration) -> Option<Duration> pub fn checked_sub(self, rhs: Duration) -> Option<Duration> pub fn checked_mul(self, rhs: u32) -> Option<Duration> pub fn checked_div(self, rhs: u32) -> Option<Duration> s... -
Instant Traits: Debug, Clone, Copy, ... pub fn now() -> Instant pub fn duration_since(&mut self, earlier: Instant) -> Duration pub fn checked_duration_since(&mut self, earlier: Instant) -> Option<Duration> pub fn elapsed(&mut self) -> Duration ... -
SystemTime Traits: Debug, Clone, Copy, Eq, PartialEq, ... pub const UNIX_EPOCH: SystemTime pub fn now() -> SystemTime pub fn duration_since(&self, earlier: SystemTime) -> Result<Duration, SystemTimeError> pub fn elapsed(&self) -> Result<Duration, SystemTimeError> ... -
SystemTimeError Traits: Debug, Display, Clone, Error, ... Traits: Debug, Display, Clone, Error, ... pub fn duration(&self) -> Duration
Example: time_demo
5.13 Date - Date and time stamps
5.14 Epilogue
- hyper, an HTTP client and server api
- http-rs, HTTP client, server, and parts.
- async-std, an implementation of the async-await pattern and updates of some of the std libraries to incorporate it, e.g., fs, io, net, process, sync, ... It provides new libraries future, stream, and task. Here's a nice set of examples of its use.
- tokio, a widely used runtime for asynchronous applications.
- serde, framework for serializing and deserializing Rust data structures.
- awesome-rust, a large list of rust resources, mostly on github.
5.15 References
Reference Link | Description |
---|---|
A Gentle Introduction To Rust | First thing to read. |
The Rust Book | Rust docs - walkthrough of syntax |
The Rust Reference Book | Rust's approximation of a language standard. Clear and well written, with a glossary at the end. Its github site shows that changes are still being actively incorporated. |
Rust cheat sheet | Quite extensive list of cheats and helpers. |
Rust Containers | Container diagrams |
Rust IPC | Stackoverflow re Rust IPC |
Rust file io | Stackoverflow re Rust file io |
Rust metadata | Stackoverflow re reading metadata from cargo.toml |
RIP Tutorial on Rust | Comprehensive coverage from RIP, the stackoverflow archive |
Learning Rust ebook | Comprehensive coverage from RIP, stackoverflow archive |
Rust - Awesome Book | lots of interesting discussions from RIP, the Stackoverflow Archive |
std::regex | std docs on Regex |
Shared reference &T and exclusive reference &mut T | More accurate description than immutable reference and mutable reference |
Blog - Pascal's Scribbles | Pascal Hertleif - Rust contributor |
Blog - Barely Functional | Michael Gattozzi - Rust contributor |
Rust and the case for WebAssembly in 2018 | Michael Gattozzi - Rust contributor |
Blog - S.Noyberg | Examples of aysnc/await, tokio, lifetime, ... |
More References |