doc.rust-lang.org
pub trait Display
...As such, the output of Display might not be possible to parse, and even if it is, the result of parsing might not exactly match the original value.
However, if a type has a lossless Display implementation whose output is meant to be conveniently machine-parseable and not just meant...
trait
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub const fn carrying_mul(self, rhs: Self, carry: Self) -> (Self, Self)
...42, 0);
assert_eq!((r.0, r.1 != 0), u8::overflowing_mul(13, 42));
The value of the first field in the returned tuple matches what you'd get by combining the wrapping_mul and wrapping_add methods:
#![feature(const_unsigned_bigint_helpers)]
assert_eq!(
789_u16.carrying_mul(456...
method
core
Stable since 1.91.0
Version 1.100.0-nightly
doc.rust-lang.org
pub const fn carrying_mul(self, rhs: Self, carry: Self) -> (Self, Self)
...42, 0);
assert_eq!((r.0, r.1 != 0), u8::overflowing_mul(13, 42));
The value of the first field in the returned tuple matches what you'd get by combining the wrapping_mul and wrapping_add methods:
#![feature(const_unsigned_bigint_helpers)]
assert_eq!(
789_u16.carrying_mul(456...
method
core
Stable since 1.91.0
Version 1.100.0-nightly
doc.rust-lang.org
pub const fn carrying_mul(self, rhs: Self, carry: Self) -> (Self, Self)
...42, 0);
assert_eq!((r.0, r.1 != 0), u8::overflowing_mul(13, 42));
The value of the first field in the returned tuple matches what you'd get by combining the wrapping_mul and wrapping_add methods:
#![feature(const_unsigned_bigint_helpers)]
assert_eq!(
789_u16.carrying_mul(456...
method
core
Stable since 1.91.0
Version 1.100.0-nightly
doc.rust-lang.org
pub const fn carrying_mul(self, rhs: Self, carry: Self) -> (Self, Self)
...42, 0);
assert_eq!((r.0, r.1 != 0), u8::overflowing_mul(13, 42));
The value of the first field in the returned tuple matches what you'd get by combining the wrapping_mul and wrapping_add methods:
#![feature(const_unsigned_bigint_helpers)]
assert_eq!(
789_u16.carrying_mul(456...
method
core
Stable since 1.91.0
Version 1.100.0-nightly
doc.rust-lang.org
pub const fn carrying_mul(self, rhs: Self, carry: Self) -> (Self, Self)
...42, 0);
assert_eq!((r.0, r.1 != 0), u8::overflowing_mul(13, 42));
The value of the first field in the returned tuple matches what you'd get by combining the wrapping_mul and wrapping_add methods:
#![feature(const_unsigned_bigint_helpers)]
assert_eq!(
789_u16.carrying_mul(456...
method
core
Stable since 1.91.0
Version 1.100.0-nightly
doc.rust-lang.org
pub const fn carrying_mul(self, rhs: Self, carry: Self) -> (Self, Self)
...42, 0);
assert_eq!((r.0, r.1 != 0), u8::overflowing_mul(13, 42));
The value of the first field in the returned tuple matches what you'd get by combining the wrapping_mul and wrapping_add methods:
#![feature(const_unsigned_bigint_helpers)]
assert_eq!(
789_u16.carrying_mul(456...
method
core
Stable since 1.91.0
Version 1.100.0-nightly
doc.rust-lang.org
pub struct SystemTime
...use std::time::{Duration, SystemTime};
use std::thread::sleep;
fn main() {
let now = SystemTime::now();
// we sleep for 2 seconds
sleep(Duration::new(2, 0));
match now.elapsed() {
Ok(elapsed) => {
// it prints '2'
println!("{}", elapsed.as_secs());
}
Err(e) => {
// the system clock went backwards!
println!("Great Scott! {e:?}");
}
}
}
Platform-specific...
struct
std
Stable since 1.8.0
Version 1.100.0-nightly
doc.rust-lang.org
pub struct Mutex<T>
...panic!();
}).join();
// The lock is poisoned by this point, but the returned result can be
// pattern matched on to return the underlying guard on both branches.
let mut guard = match lock.lock() {
Ok(guard) => guard,
Err(poisoned) => poisoned.into_inner(),
};
*guard += 1;
To unlock a mutex guard sooner than the...
struct
std
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub mod any
...want to
// output the `String`'s length as well as its value. If not, it's a
// different type: just print it out unadorned.
match value_any.downcast_ref::<String>() {
Some(as_string) => {
println!("String ({}): {}", as_string.len(), as_string);
}
None => {
println!("{value:?}");
}
}
}
// This function wants to log its parameter...
module
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn into_inner(this: Self) -> Option<T>
...assert!(matches!(
(x_inner_value, y_inner_value),
(None, Some(3)) | (Some(3), None)
));
// The result could also be `(None, None)` if the threads called
// `Arc::try_unwrap(x).ok()` and `Arc::try_unwrap(y).ok()` instead.
A more practical example demonstrating the need for Arc::into_inner:
use std...
associated_function
alloc
Stable since 1.70.0
Version 1.100.0-nightly
doc.rust-lang.org
pub mod error
...the primary interfaces of the error system and the responsibilities they cover:
• Result (Propagating, Reacting)
• The Error trait (Reporting)
• User defined types (Constructing / Representing)
• match and downcast (Reacting)
• The question mark operator (?) (Propagating)
• The partially stable Try traits (Propagating, Constructing)
• Termination (Reporting)
Converting Errors into Panics
The panic and error...
module
core
Stable since 1.81.0
Version 1.100.0-nightly
doc.rust-lang.org
pub mod error
...the primary interfaces of the error system and the responsibilities they cover:
• Result (Propagating, Reacting)
• The Error trait (Reporting)
• User defined types (Constructing / Representing)
• match and downcast (Reacting)
• The question mark operator (?) (Propagating)
• The partially stable Try traits (Propagating, Constructing)
• Termination (Reporting)
Converting Errors into Panics
The panic and error...
module
std
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub struct BTreeMap<K, V, A>
...let to_find = ["Up!", "Office Space"];
for movie in &to_find {
match movie_reviews.get(movie) {
Some(review) => println!("{movie}: {review}"),
None => println!("{movie} is unreviewed.")
}
}
// Look up the value for a key (will panic if the key is not found).
println!("Movie review: {}", movie_reviews["Office Space"]);
// iterate over...
struct
alloc
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub trait PartialEq<Rhs>
...How can I implement PartialEq?
An example implementation for a domain in which two books are considered the same book if their ISBN matches, even if the formats differ:
enum BookFormat {
Paperback,
Hardback,
Ebook,
}
struct Book {
isbn: i32,
format: BookFormat,
}
impl PartialEq for Book {
fn eq(&self, other: &Self) -> bool...
trait
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub struct HashMap<K, V, S, A>
...let to_find = ["Pride and Prejudice", "Alice's Adventure in Wonderland"];
for &book in &to_find {
match book_reviews.get(book) {
Some(review) => println!("{book}: {review}"),
None => println!("{book} is unreviewed.")
}
}
// Look up the value for a key (will panic if the key is not found).
println!("Review for Jane...
struct
std
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub mod io
...Instead, you can call .unwrap() or match on the return value to catch any possible errors:
use std::io;
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
And a very common source of output is standard output:
use std::io;
use std::io::prelude::*;
fn main...
module
std
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub struct Vec<T, A>
...using unsafe code to write to the excess capacity, and then increasing the length to match, is always valid.
Currently, Vec does not guarantee the order in which elements are dropped. The order has changed in the past and may change again.
struct
alloc
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
primitive f32
...The result does not have to match what happens when executing the same code at runtime, and the result can vary depending on factors such as compiler version and flags.
Target-specific "extra" NaN values
| target_arch | Extra payloads possible on this platform | |---------------|------------------------------------------| | aarch64, arm, arm64ec, loongarch64, powerpc (except when...
primitive
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
primitive f32
...The result does not have to match what happens when executing the same code at runtime, and the result can vary depending on factors such as compiler version and flags.
Target-specific "extra" NaN values
| target_arch | Extra payloads possible on this platform | |---------------|------------------------------------------| | aarch64, arm, arm64ec, loongarch64, powerpc (except when...
primitive
std
Stable since 1.0.0
Version 1.100.0-nightly