doc.rust-lang.org
pub const fn as_mut(&mut self) -> Result<&mut T, &mut E>
...Examples
fn mutate(r: &mut Result<i32, i32>) {
match r.as_mut() {
Ok(v) => *v = 42,
Err(e) => *e = 0,
}
}
let mut x: Result<i32, i32> = Ok(2);
mutate(&mut x);
assert_eq!(x.unwrap(), 42);
let mut x: Result<i32, i32> = Err(13);
mutate(&mut x);
assert_eq!(x...
method
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub struct UnixListener
...UnixStream) {
// ...
}
fn main() -> std::io::Result<()> {
let listener = UnixListener::bind("/path/to/the/socket")?;
// accept connections and process them, spawning a new thread for each one
for stream in listener.incoming() {
match stream {
Ok(stream) => {
/* connection succeeded */
thread::spawn(|| handle_client(stream));
}
Err(err) => {
/* connection failed */
break;
}
}
}
Ok(())
}
struct
std
Stable since 1.10.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn contains_key<Q>(&self, key: &Q) -> bool
...The key may be any borrowed form of the map's key type, but the ordering on the borrowed form must match the ordering on the key type.
Examples
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.contains_key(&1), true);
assert...
method
alloc
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub macro ready!
...let num = match fut.poll(cx) {
Poll::Ready(t) => t,
Poll::Pending => return Poll::Pending,
};
macro
core
Stable since 1.64.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn contains_key<Q>(&self, k: &Q) -> bool
...The key may be any borrowed form of the map's key type, but Hash and Eq on the borrowed form must match those for the key type.
Examples
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.contains_key(&1), true);
assert...
method
std
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn remove<Q>(&mut self, value: &Q) -> bool
...The value may be any borrowed form of the set's value type, but Hash and Eq on the borrowed form must match those for the value type.
Examples
use std::collections::HashSet;
let mut set = HashSet::new();
set.insert(2);
assert_eq!(set.remove(&2), true);
assert_eq!(set...
method
std
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn accept(&self) -> io::Result<(UnixStream, SocketAddr)>
...Examples
use std::os::unix::net::UnixListener;
fn main() -> std::io::Result<()> {
let listener = UnixListener::bind("/path/to/the/socket")?;
match listener.accept() {
Ok((socket, addr)) => println!("Got a client: {addr:?}"),
Err(e) => println!("accept function failed: {e:?}"),
}
Ok(())
}
method
std
Stable since 1.10.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
...The key may be any borrowed form of the map's key type, but the ordering on the borrowed form must match the ordering on the key type.
Examples
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
if let Some(x) = map.get_mut(&1...
method
alloc
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn align(&self) -> Option<Alignment>
...Examples
use std::fmt::{self, Alignment};
struct Foo;
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = if let Some(s) = formatter.align() {
match s {
Alignment::Left => "left",
Alignment::Right => "right",
Alignment::Center => "center",
}
} else {
"into the void"
};
write!(formatter, "{s}")
}
}
assert_eq...
method
core
Stable since 1.28.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
...The key may be any borrowed form of the map's key type, but Hash and Eq on the borrowed form must match those for the key type.
Examples
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
if let Some(x) = map.get_mut(&1...
method
std
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub const fn _mm_set_ps(a: f32, b: f32, c: f32, d: f32) -> __m128
...This matches the standard way of writing bit patterns on x86:
bit 127 .. 96 95 .. 64 63 .. 32 31 .. 0
+---------+---------+---------+---------+
| a | b | c | d | result
+---------+---------+---------+---------+
Alternatively:
let v = _mm_set_ps(d, c, b, a);
Intel's documentation
function
core
Stable since 1.27.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn get<Q>(&self, value: &Q) -> Option<&T>
...The value may be any borrowed form of the set's element type, but the ordering on the borrowed form must match the ordering on the element type.
Examples
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
assert_eq!(set.get(&2), Some(&2));
assert_eq!(set...
method
alloc
Stable since 1.9.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn take<Q>(&mut self, value: &Q) -> Option<T>
...The value may be any borrowed form of the set's element type, but the ordering on the borrowed form must match the ordering on the element type.
Examples
use std::collections::BTreeSet;
let mut set = BTreeSet::from([1, 2, 3]);
assert_eq!(set.take(&2), Some(2));
assert_eq...
method
alloc
Stable since 1.9.0
Version 1.100.0-nightly
doc.rust-lang.org
pub trait Neg
...use std::ops::Neg;
#[derive(Debug, PartialEq)]
enum Sign {
Negative,
Zero,
Positive,
}
impl Neg for Sign {
type Output = Self;
fn neg(self) -> Self::Output {
match self {
Sign::Negative => Sign::Positive,
Sign::Zero => Sign::Zero,
Sign::Positive => Sign::Negative,
}
}
}
// A negative positive is a negative.
assert_eq!(-Sign::Positive, Sign::Negative...
trait
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn get<Q>(&self, value: &Q) -> Option<&T>
...The value may be any borrowed form of the set's value type, but Hash and Eq on the borrowed form must match those for the value type.
Examples
use std::collections::HashSet;
let set = HashSet::from([1, 2, 3]);
assert_eq!(set.get(&2), Some(&2));
assert_eq!(set...
method
std
Stable since 1.9.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn take<Q>(&mut self, value: &Q) -> Option<T>
...The value may be any borrowed form of the set's value type, but Hash and Eq on the borrowed form must match those for the value type.
Examples
use std::collections::HashSet;
let mut set = HashSet::from([1, 2, 3]);
assert_eq!(set.take(&2), Some(2));
assert_eq...
method
std
Stable since 1.9.0
Version 1.100.0-nightly
doc.rust-lang.org
pub struct SystemTimeError
...Examples
use std::thread::sleep;
use std::time::{Duration, SystemTime};
let sys_time = SystemTime::now();
sleep(Duration::from_secs(1));
let new_sys_time = SystemTime::now();
match sys_time.duration_since(new_sys_time) {
Ok(_) => {}
Err(e) => println!("SystemTimeError difference: {:?}", e.duration()),
}
struct
std
Stable since 1.8.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn take_error(&self) -> io::Result<Option<io::Error>>
...Examples
use std::net::UdpSocket;
let socket = UdpSocket::bind("127.0.0.1:34254").expect("bind should succeed");
match socket.take_error() {
Ok(Some(error)) => println!("UdpSocket error: {error:?}"),
Ok(None) => println!("No error"),
Err(error) => println!("UdpSocket.take_error failed: {error:?}"),
}
method
std
Stable since 1.9.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn starts_with<P>(&self, base: P) -> bool
...Only considers whole path components to match.
Examples
use std::path::Path;
let path = Path::new("/etc/passwd");
assert!(path.starts_with("/etc"));
assert!(path.starts_with("/etc/"));
assert!(path.starts_with("/etc/passwd"));
assert!(path.starts_with("/etc/passwd/")); // extra slash is okay
assert!(path.starts_with("/etc/passwd...
method
std
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
...The key may be any borrowed form of the map's key type, but the ordering on the borrowed form must match the ordering on the key type.
Examples
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.remove(&1), Some("a"));
assert...
method
alloc
Stable since 1.0.0
Version 1.100.0-nightly