doc.rust-lang.org
pub const fn is_some_and(self, f: impl ~const FnOnce(T) -> bool) -> bool
Option::is_some_and — Returns true if the option is a Some and the value inside of it matches a predicate.
Examples
let x: Option<u32> = Some(2);
assert_eq!(x.is_some_and(|x| x > 1), true);
let x: Option<u32> = Some(0);
assert_eq!(x.is_some_and...
method
core
Stable since 1.70.0
Version 1.100.0-nightly
doc.rust-lang.org
pub const fn is_ok_and<F>(self, f: F) -> bool
Result::is_ok_and — Returns true if the result is Ok and the value inside of it matches a predicate.
Examples
let x: Result<u32, &str> = Ok(2);
assert_eq!(x.is_ok_and(|x| x > 1), true);
let x: Result<u32, &str> = Ok(0);
assert_eq!(x.is_ok...
method
core
Stable since 1.70.0
Version 1.100.0-nightly
dgroshev.com
...mpsc::Receiver<
oneshot::Sender<(RequestId, oneshot::Receiver<Response>)>,
>,
) {
loop {
tokio::select! {
usb_response = usb_rx.recv() => match usb_response {
Some((request_id, response)) =>
dispatcher.handle_usb_rx(request_id, response).await,
None => break
},
request = registration_requests.recv() => match request {
Some(reply_to) => dispatcher.register(reply_to).await,
None => break
}
}
}
}
Points...
Observations/Thoughts
2024-05-15
~5 min read
matthewkmayer.github.io
...let mut connbuilder = SslConnectorBuilder::new(SslMethod::tls()).unwrap();
// https://www.postgresql.org/docs/current/static/libpq-ssl.html describes the modes
match dbssl.to_lowercase().as_ref() {
"require" | "prefer" | "allow" => connbuilder.set_verify(postgres::tls::openssl::openssl::ssl::SSL_VERIFY_NONE),
_ => (), // by default we verify certs: it's like either...
News & Blog Posts
2018-09-18
~3 min read
ferrous-systems.com
...fill in the match statement below */
/* to make this code compile */
let noise = match animal {
/* Cow and Bull */ => {
"moo".to_string()
}
/* Chicken */ => {
"cluck, cluck!".to_string()
}
/* Dog */ => {
format!("woof, woof! I am {}!", name)
}
/* Worm– or all silent animals?*/ => {
"-- (silence)".to_string()
}
};
/* Bonus task: Give Dogs named Lassie */
/* a different output...
Observations/Thoughts
2021-05-05
~5 min read
doc.rust-lang.org
pub struct PrefixComponent<'a>
...Instances of this struct can be obtained by matching against the Prefix variant on Component.
Does not occur on Unix.
Examples
use std::path::{Component, Path, Prefix};
use std::ffi::OsStr;
let path = Path::new(r"c:\you\later\");
match path.components().next().unwrap() {
Component::Prefix(prefix_component) => {
assert_eq...
struct
std
Stable since 1.0.0
Version 1.100.0-nightly
dev.to
...String,
}
Enter fullscreen mode
Exit fullscreen mode
Now we know we have to match that same error code. Let's find in src/routes/user.rs when we insert a new user:
match user_coll.insert_one(document.to_owned(), None) {
Ok(inserted) => {
match inserted.inserted_id {
Some(id) => { ...},
None...
Rust Walkthroughs
2020-12-23
~12 min read
steveklabnik.com
...At their core, declarative macros allow you to write something similar to a Rust match statement:
match x {
4 => println!("four!"),
5 => println!("five!"),
_ => println!("something else"),
}
With match, x’s structure and value will be evaluated, and the right arm will execute based on what matches. So if x...
News & Blog Posts
2017-01-31
~12 min read
dev.to
...DO NOT USE THIS CODE IN PRODUCTION
let url = match json
.get(0)
.unwrap()
.get("data")
.unwrap()
.get("children")
.unwrap()
.get(0)
.unwrap()
.get("data")
.unwrap()
.get("url")
{
// Parse the youtube url from the string
// "https://www.youtube.com/playlist?list=PLf3u8NhoEikhTC5radGrmmqdkOK-xMDoZ"
// after trimming `"`
Some(url) => match url::Url...
Learn More Rust
2020-08-11
~8 min read
crates.io
...How to get a compatible version of protoc The protoc binary that you use to generate code needs to have a version that exactly matches the version of the protobuf crate you are using. More specifically, if you are using Rust protobuf x.y.z then you need to use...
Crate
v4.36.0-rc.2
2026-08-03
doc.rust-lang.org
pub fn next_if_map<R>(&mut self, f: impl FnOnce(<I as >::Item) -> Result<R, <I as >::Item>) -> Option<R>
...let mut iter = "125 GOTO 10".chars().peekable();
let mut line_num = 0_u32;
while let Some(digit) = iter.next_if_map(|c| c.to_digit(10).ok_or(c)) {
line_num = line_num * 10 + digit;
}
assert_eq!(line_num, 125);
assert_eq!(iter.collect::<String>(), " GOTO 10");
Matching custom...
method
core
Stable since 1.94.0
Version 1.100.0-nightly
tweedegolf.nl
...Next, there is an operation to turn this SIMD mask vector into an integer, resulting in:0b0111
Finally the .trailing_ones method can be used to count how many elements matched before the first one that didn't. For our example it returns 3, and indeed there are 3 matching...
Observations/Thoughts
2025-05-28
~4 min read
crates.io
...std::iter::Iterator<Item = <A as std::iter::Iterator>::Item>, { type Item = <A as std::iter::Iterator>::Item; fn next(&mut self) -> Option<Self::Item> { match self { Enum::A(x) => x.next(), Enum::B(x) => x.next(), } } fn size_hint(&self) -> (usize, Option<usize>) { match self { Enum::A(x) => x...
Crate
v0.16.0
2026-07-24
smallcultfollowing.com
...with Thin Traits, you write virtual methods
whereas with Extensible Enums, you write match statements – and I
think match statements are far more common in Rust today.Still, Thin Traits will be a very good fit for various use cases.
They are a good fit for Servo, for example, where...
News & Blog Posts
2015-10-12
~15 min read
doc.rust-lang.org
...Storing Matching Lines
To finish this function, we need a way to store the matching lines that we want to return. For that, we can make a mutable vector before the for loop and call the push method to store a line in the vector. After the for loop, we...
The Rust Programming Language
Book
2024-02-01
~6 min read
codeandbitters.com
...let value = rand::thread_rng().gen();
Self { value }
}
}
Match Ergonomics pattern changes §
Lint: rust-2024-incompatible-pat
Rust edition guide: Match ergonomics reservations
I found this change tricky. I was starting off at a disadvantage, because I didn't know what "match ergonomics" or "binding mode" meant. So the warnings...
Observations/Thoughts
2025-02-12
~18 min read
doc.rust-lang.org
pub fn div_euclid(self, rhs: f32) -> f32
f32::div_euclid — Calculates Euclidean division, the matching method for rem_euclid.
This computes the integer n such that self = n * rhs + self.rem_euclid(rhs). In other words, the result is self / rhs rounded to the integer n such that self >= n * rhs.
Precision
The result of this operation...
method
std
Stable since 1.38.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn div_euclid(self, rhs: f64) -> f64
f64::div_euclid — Calculates Euclidean division, the matching method for rem_euclid.
This computes the integer n such that self = n * rhs + self.rem_euclid(rhs). In other words, the result is self / rhs rounded to the integer n such that self >= n * rhs.
Precision
The result of this operation...
method
std
Stable since 1.38.0
Version 1.100.0-nightly
zupzup.org
...i32,
) -> Result<Vec<Bytes>> {
let https = HttpsConnector::new()?;
let client = Client::builder().build::<_, hyper::Body>(https);
let group = config.group.as_ref();
let user = config.user.as_ref();
let uri = match group {
Some(v) => format!(
"https://gitlab.com/api/v4/groups/{}/{}?per_page={}",
v, domain, per_page
),
None => match user...
News & Blog Posts
2019-11-26
~10 min read
phildawes.net
...uint,
callback: &mut |Match|) {
...
}
complete_from_file("foo", "myfile.rs", 3, |match| {
// do something with each match
});
This means the whole search happens regardless of whether you just want the first match. The main reason for doing this is because iterators are somewhat less easy to write for my brain...
Community Updates
2014-05-17
~5 min read