github.com
...Rust already allows
[similar syntax for destructuring in pattern matches](https://doc.rust-lang.org/book/patterns.html#destructuring):
a pattern match can use `SomeStruct { field1, field2 } => ...` to match
`field1` and `field2` into values with the same names. This RFC introduces
symmetrical syntax for initializers.
A family of related structures...
RFC 1682
RFC
2016-07-18
~6 min read
doc.rust-lang.org
pub const fn is_err_and<F>(self, f: F) -> bool
Result::is_err_and — Returns true if the result is Err and the value inside of it matches a predicate.
Examples
use std::io::{Error, ErrorKind};
let x: Result<u32, Error> = Err(Error::new(ErrorKind::NotFound, "!"));
assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), true);
let x...
method
core
Stable since 1.70.0
Version 1.100.0-nightly
rust-analyzer.github.io
...for fill_match_arms with local enums.
#11795 correctly suggest auto importing traits from aliases.
#11791 fix and improve signature help.
#11802 add stubs to make proc macros work that use the SourceFile API.
#11825 don’t complete Drop::drop for qualified paths.
#11831 disable ref_match for qualified paths...
Project/Tooling Updates
2022-03-30
~1 min read
rust-analyzer.github.io
#8611 (first contribution) add support for boolean values to "Fill match arms".
#8658 (first contribution) check more carefully for cases when a rename can’t be done.
#8582 (first contribution) fix typo in comparison semantic token type.
#8600 fix project loading hang.
#8606 fix "Registering progress handler" error.
#8639 fix...
Project/Tooling Updates
2021-04-28
~1 min read
www.huy.rocks
...to get the current token
is_match(): to check if the current token matched the expected type or not
advance(): to consume the current token and move on to the next
These methods are not exclusive to a recursive descent parser, but they’re very helpful, as they keep the...
Rust Walkthroughs
2022-05-11
~6 min read
crates.io
...They're efficient and convenient for matching events or defining hardcoded keybindings. match key_event.into() { key!(ctrl-c) => { println!("Arg! You savagely killed me with a {}", fmt.to_string(key_event).red()); break; } key!(ctrl-q) => { println!("You typed {} which gracefully quits", fmt.to_string(key_event).green()); break...
Crate
v1.5.0
2026-07-24
xnacly.me
...Rust makes this enjoyable via the matches! macro and the patterns the
match statement accepts. For instance, checking if the current character is
a valid sqlite number can be done by a simple matches! macro invocation:RUST 1/// Specifically matches https://www.sqlite.org/syntax/numeric-literal.html
2fn is...
Rust Walkthroughs
2024-11-06
~18 min read
github.com
...Vec<(&'static str, Value)>, encoder: &'a Encoder, ) -> FutureRecord<'a> { let subject_name_strategy = SubjectNameStrategy::TopicNameStrategy(topic, false); let payload = match encoder.encode(values, &subject_name_strategy) { Ok(v) => v, Err(e) => panic!("Error getting payload: {}", e), }; FutureRecord { topic, partition: None, payload: Some(&payload), key, timestamp: None, headers: None, } } fn get...
Crate
v4.10.0
2026-07-13
fredrik.anderzon.se
...It will print the todos only for the matching filter. We've broken out printing of a single todo item to a print_todo function so that it's easy to call it in several branches of our match statement.
Matching on enums is very straight forward as you can...
News & Blog Posts
2016-06-27
~25 min read
adventures.michaelfbryan.com
...f32) -> Point {
let raw = match self.units {
Units::Millimetres => Point::new::<millimeter>(x, y, z),
Units::Inches => Point::new::<inch>(x, y, z),
};
match self.coordinate_mode {
CoordinateMode::Absolute => raw,
CoordinateMode::Relative => raw + self.current_location,
}
}
fn calculate_feed_rate(&self, command: &GCode) -> Velocity {
let raw = match command.value_for...
News & Blog Posts
2019-11-12
~12 min read
holovskyi.github.io
...client.subscribe("sensors/+/+/temperature", QoS::AtMostOnce).await?;
while let Ok(notification) = eventloop.poll().await {
match notification {
Event::Incoming(Packet::Publish(publish)) => {
let parts: Vec<&str> = publish.topic.split('/').collect();
if parts.len() == 4 && parts[0] == "sensors" && parts[3] == "temperature" {
let location = parts[1];
let sensor_id = parts[2];
match serde...
Project/Tooling Updates
2026-07-08
~4 min read
github.com
...This also means that `S{..}` patterns can be used to match structures and variants of any kind.
The desire to have such "match everything" patterns is sometimes expressed given
that number of fields in structures and variants can change from zero to non-zero and back during
development.
An extra...
RFC 1506
RFC
2016-02-07
~5 min read
crates.io
...Catch-all variant Sometimes it is desirable to have an Other variant which holds the otherwise un-matched value as a field. The #[num_enum(catch_all)] attribute allows you to mark at most one variant for this purpose. The variant it's applied to must be a tuple variant...
Crate
v0.7.6
2026-03-15
doc.rust-lang.org
pub macro pin!
...let mut pinned_fut = pin!(fut);
loop {
match pinned_fut.as_mut().poll(&mut cx) {
Poll::Pending => thread::park(),
Poll::Ready(res) => return res,
}
}
}
With Coroutines
#![feature(coroutines)]
#![feature(coroutine_trait)]
use core::{
ops::{Coroutine, CoroutineState},
pin::pin,
};
fn coroutine_fn() -> impl Coroutine<Yield = usize, Return = ()> /* not Unpin */ {
// Allow coroutine...
macro
core
Stable since 1.68.0
Version 1.100.0-nightly
noiseonthenet.space
...T ) {
match self.root{
None => {
self.root = Node::new(value).into();
}
Some(ref mut node) => {
Tree::<T>::insert_recursive(node, value);
}
}
}
fn insert_recursive(node : & mut Node<T>, value : T){
if value > node.value{
match node.right{
None => {
node.right = Node::new(value).into();
}
Some(ref mut n) => {
Tree::<T...
Observations/Thoughts
2024-04-17
~7 min read
dev.to
...Stripping unwanted trailing characters went from a slow regex match inside a loop:
// The old, slow regex way
pub(crate) fn trim_unwanted_end_chars<'a>(&self, phone_number: &'a str) -> &'a str {
// ... loop with regex.full_match() ...
}
Enter fullscreen mode
Exit fullscreen mode
To a single, native Rust iterator...
Project/Tooling Updates
2026-03-11
~7 min read
crates.io
...Catch-all variant Sometimes it is desirable to have an Other variant which holds the otherwise un-matched value as a field. The #[num_enum(catch_all)] attribute allows you to mark at most one variant for this purpose. The variant it's applied to must be a tuple variant...
Crate
v0.7.6
2026-03-15
arzg.github.io
...u8) {
let mut lhs = match p.peek() {
// snip
};
loop {
let op = match p.peek() {
Some(SyntaxKind::Plus) => InfixOp::Add,
Some(SyntaxKind::Minus) => InfixOp::Sub,
Some(SyntaxKind::Star) => InfixOp::Mul,
Some(SyntaxKind::Slash) => InfixOp::Div,
_ => return, // we’ll handle errors later.
};
let (left_binding_power, right_binding_power) = op.binding_power...
Rust Walkthroughs
2020-12-16
~16 min read
svartalf.info
...io_object_t) -> kern_return_t;
}
unsafe {
let match_dict = IOServiceMatching(
b"IOPMPowerSource\0".as_ptr() as *const c_char
);
let mut iterator: io_iterator_t = mem::uninitialized();
// TODO: Handle the possible error
let _result = IOServiceGetMatchingServices(
master_port,
match_dict,
&mut iterator,
);
}
IOServiceMatching documentation says that the returned match_dict...
News & Blog Posts
2019-06-04
~7 min read
doma.dev
...Equivalently, one can't solve the matching parentheses problem with a regular expression. The simplest stack machine is needed for that.
Stack automaton can be in several states at once. A state with no transitions "fizzles" on any input. (@\* matches character '(' with any stack state. ε@ε matches instantaneously as...
Rust Walkthroughs
2021-03-31
~8 min read