www.joshmcguigan.com
...Serializer,
{
let mut serde_state = match Serializer::serialize_struct(
serializer,
"Point",
false as usize + 1 + 1,
) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
match SerializeStruct::serialize_field(&mut serde_state, "x", &self.x) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return...
News & Blog Posts
2019-11-19
~11 min read
doc.rust-lang.org
pub const fn eq_ignore_ascii_case(&self, other: &char) -> bool
char::eq_ignore_ascii_case — Checks that two values are an ASCII case-insensitive match.
Equivalent to to_ascii_lowercase(a) == to_ascii_lowercase(b).
Examples
let upper_a = 'A';
let lower_a = 'a';
let lower_z = 'z';
assert!(upper_a.eq_ignore_ascii_case(&lower_a));
assert!(upper_a...
method
core
Stable since 1.23.0
Version 1.100.0-nightly
doc.rust-lang.org
pub struct RSplitMut<'a, T, P>
RSplitMut — An iterator over the subslices of the vector which are separated by elements that match pred, starting from the end of the slice.
This struct is created by the rsplit_mut method on slices.
Example
let mut slice = [11, 22, 33, 0, 44, 55];
let iter = slice.rsplit_mut...
struct
core
Stable since 1.27.0
Version 1.100.0-nightly
corrode.dev
...If we use slice pattern matching instead, we’ll only get access to the element if the correct match arm is executed.
match matching_users.as_slice() {
[] => todo!("What to do if no users found!?"),
[existing_user] => { // Safe! Compiler guarantees exactly one element
// No need to index into the vector...
Observations/Thoughts
2025-11-05
~16 min read
doc.rust-lang.org
pub fn eq_ignore_ascii_case<S>(&self, other: S) -> bool
OsStr::eq_ignore_ascii_case — Checks that two strings are an ASCII case-insensitive match.
Same as to_ascii_lowercase(a) == to_ascii_lowercase(b), but without allocating and copying temporaries.
Examples
use std::ffi::OsString;
assert!(OsString::from("Ferris").eq_ignore_ascii_case("FERRIS"));
assert!(OsString::from("Ferrös").eq...
method
std
Stable since 1.53.0
Version 1.100.0-nightly
rust-lang.github.io
...match *self {
AnimationValue::Color(_) => LonghandId::Color,
AnimationValue::Height(_) => LonghandId::Height,
AnimationValue::TransformOrigin(_) => LonghandId::TransformOrigin,
}
}
}
This is not sustainable, as the jump table generated by rustc to compile this huge match expression is larger than 4KB in the final Gecko binary, when this operation could be a trivial u16 copy. This...
RFC 2363
RFC
2018-03-11
~4 min read
rust-analyzer.github.io
#12937 (first contribution) implement syntax fix-up for match and for loops.
#13010 actually call rustc from the RUSTC_WRAPPER when run by build scripts (fixes feature detection for anyhow).
#12942 make concat! work with characters.
#12990 improve whitespace insertion in macro-expansion.
#12992 infer byte string pattern as &[u8...
Project/Tooling Updates
2022-08-17
~1 min read
ideas.reify.ing
...Pin<&mut _> = this.stream;
match stream.poll_next(cx) {
Poll::Ready(response) => {
match response {
None => Poll::Ready(None), // end of the stream
Some(result) => match result {
Ok(event) => match event {
Event::Open => unreachable!(), // it has been filtered out
Event::Message(message) => {
if message.data == "[DONE]" {
Poll::Ready(None) // end of...
Project/Tooling Updates
2024-04-17
~6 min read
ohadravid.github.io
...poly_match_rs.poly_match_rs.find_close_polygons() takes no arguments (3 given)
v1 - A naive Rust translationWe’ll start with matching the expected API.PyO3 is pretty smart about Python to Rust conversions, so that’s going to be pretty easy:#[pyfunction]
fn find_close_polygons(polygons: Vec...
Rust Walkthroughs
2023-03-29
~17 min read
doc.rust-lang.org
...No element was found
These cases can either be explicitly handled via match or implicitly with unwrap. Implicit handling will either return the inner element or panic.
Note that it's possible to manually customize panic with expect, but unwrap otherwise leaves us with a less meaningful output than explicit...
Rust by Example
Book
2024-01-01
~1 min read
doc.rust-lang.org
pub mod option
...f64) -> Option<f64> {
if denominator == 0.0 {
None
} else {
Some(numerator / denominator)
}
}
// The return value of the function is an option
let result = divide(2.0, 3.0);
// Pattern match to retrieve the value
match result {
// The division was valid
Some(x) => println!("Result: {x}"),
// The division was invalid
None...
module
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub struct RSplitNMut<'a, T, P>
RSplitNMut — An iterator over subslices separated by elements that match a predicate function, limited to a given number of splits, starting from the end of the slice.
This struct is created by the rsplitn_mut method on slices.
Example
let mut slice = [10, 40, 30, 20, 60, 50];
let iter...
struct
core
Stable since 1.0.0
Version 1.100.0-nightly
andidog.de
...Here’s how I could match
State::Failed(String):
$enum_name::$enum_variant(..) => $int_value
Note that this is not a solution because now it won’t match State::Succeeded and State::Timeout anymore (maybe it
used to work earlier), but this article is more about getting to
understand the...
Blog Posts
2016-11-01
~4 min read
academy.fpblock.com
...an uninhabited type (Infallible or a custom enum Never {}), and
an exhaustive match over that type.
We'll implement this using a macro:
macro_rules! absurd {
($x:expr) => {
match $x {}
};
}
This matches the meaning from Haskell: given a value of an uninhabited type, we can produce any type we want...
Miscellaneous
2025-11-19
~21 min read
doc.rust-lang.org
pub struct RSplit<'a, T, P>
RSplit — An iterator over subslices separated by elements that match a predicate function, starting from the end of the slice.
This struct is created by the rsplit method on slices.
Example
let slice = [11, 22, 33, 0, 44, 55];
let mut iter = slice.rsplit(|num| *num == 0);
assert_eq!(iter...
struct
core
Stable since 1.27.0
Version 1.100.0-nightly
doc.rust-lang.org
pub struct SplitN<'a, T, P>
SplitN — An iterator over subslices separated by elements that match a predicate function, limited to a given number of splits.
This struct is created by the splitn method on slices.
Example
let slice = [10, 40, 30, 20, 60, 50];
let mut iter = slice.splitn(2, |num| *num % 3 == 0);
assert...
struct
core
Stable since 1.0.0
Version 1.100.0-nightly
docs.rs
...The database can match a font using CSS-like queries. See Database::query . The database can try to load system fonts. Currently, this is implemented by scanning predefined directories. The library does not interact with the system API. Provides a unique ID for each font face. Non-goals Advanced font...
Crate
v0.24.0
2026-07-29
github.com
...use file_diff::{diff_files}; use std::fs::{File}; let mut file1 = match File::open("./src/lib.rs") { Ok(f) => f, Err(e) => panic!("{}", e), }; let mut file2 = match File::open("./src/lib.rs") { Ok(f) => f, Err(e) => panic!("{}", e), }; diff_files(&mut file1, &mut file2); The diff() function...
Crate
v1.0.0
2016-04-10
blog.davimiku.com
...match guardsThe if keyword after the match variable is a match guard. This arm of the match expression is only matched if the match guard is true.
We've introduced a new function, tokenize_float. Time to implement this:
fn tokenize_float(chars: &Vec<char>, curr_idx: &mut usize) -> Result...
Rust Walkthroughs
2024-11-13
~43 min read
fasterthanli.me
...Sure! But you can match the “scrutinee” (x in match x { ... }) with various
patterns, in various “arms” (true => {}, false => {} in the example above).
use rand::Rng;
fn main() {
let msg = match rand::thread_rng().gen_range(0..=10) {
// match only 10
10 => "Overwhelming victory",
// match anything 5 or above
5...
Observations/Thoughts
2022-02-16
~42 min read