swatinem.de
...for item in iter {
let item = match item {
Ok(item) => item,
Err(_) => break,
};
// ...
}
// or we can skip over errors:
for item in iter {
let item = match item {
Ok(item) => item,
Err(_) => continue,
};
// ...
}
// or even simpler, since `Result` implements `IntoIterator`:
for item in iter.flatten() {
// ...
}
We can also directly collect this...
Observations/Thoughts
2022-07-13
~4 min read
rust-lang.github.io
...If you publish a crate with a cfg(windows) dependency then crates.io could expand this to all known triples which match cfg(windows) when storing the metadata internally. This would mean that crates using cfg syntax would continue to be compatible with older versions of Cargo so long as...
RFC 1361
RFC
2015-11-10
~4 min read
rust-analyzer.github.io
...emit fewer download progress notifications.
#7419, #7422 unquote strings when expanding concat!.
#7438 shorten hir::TypeParam ranges for traits in NavigationTarget.
#7406 don’t assume happy path in if_let_match.
#7464 export CARGO for proc. macros.
#7465 only hide parameter hints for path, field and methodcall expressions.
#7487 forbid...
Project/Tooling Updates
2021-02-03
~1 min read
rust-analyzer.github.io
#13805 (first contribution) complete enum variants without parens when snippets are disabled.
#13794 fix "parser seems stuck" panics when parsing colossal files.
#13795 use the correct edition when formatting code in path dependencies.
#13800 don’t match let expressions and inline consts in expr MBE fragments.
#13820 fix binding mode...
Project/Tooling Updates
2022-12-28
~1 min read
rust-analyzer.github.io
...boxed slices (~2 MB win on analysis-stats self).
#14151 enable smallvec's union feature (~4 MB win on analysis-stats self).
#14156 don’t reconstruct ref match completion in to_proto manually.
#14165 make CompletionItem more POD-like.
#14147 don’t rely on VSCode internal commands in the server.
Project/Tooling Updates
2023-02-22
~1 min read
doc.rust-lang.org
pub fn connect<P>(&self, path: P) -> io::Result<()>
...Examples
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
match sock.connect("/path/to/the/socket") {
Ok(sock) => sock,
Err(e) => {
println!("Couldn't connect: {e:?}");
return Err(e)
}
};
Ok(())
}
method
std
Stable since 1.10.0
Version 1.100.0-nightly
rust-lang.github.io
...possible extensions
match_cfg
The original version of this RFC was more expansive, and proposed a match_cfg macro that provided some additional checking.
The match_cfg macro takes a sequence of cfg patterns, followed by => and an expression. Its syntax and semantics resembles that of match. However, there are...
RFC 1868
RFC
2016-11-15
~20 min read
docs.rs
...MacroArgs = match syn::parse(args) { Ok(v) => v, Err(e) => { return e.to_compile_error().into(); } }; let _input = syn::parse_macro_input!(input as ItemFn); // do things with `args` unimplemented!() } Consuming Code use your_crate::your_attr; #[your_attr(path = "hello", timeout_ms = 15)] fn do_stuff() { println!("Hello"); } Features...
Crate
v0.24.1
2026-08-20
github.com
...use x509_parser::prelude::*; static IGCA_DER: &[u8] = include_bytes!("../assets/IGC_A.der"); let res = X509Certificate::from_der(IGCA_DER); match res { Ok((rem, cert)) => { assert!(rem.is_empty()); // assert_eq!(cert.version(), X509Version::V3); }, _ => panic!("x509 parsing failed: {:?}", res), } To parse a CRL and print information about revoked...
Crate
v0.18.1
2026-02-05
www.ncameron.org
...Pattern matching
The goal with the pattern matching API is to allow procedural macros to operate on tokens in the same way as macros-by-example. The pattern language is thus the same as that for macros-by-example.
There is a single macro, which I propose calling matches. Its...
News & Blog Posts
2016-01-25
~16 min read
poor.dev
...To make this work, we intercept this instruction in the rendered bytes with a regex, changing the document.title to match:
wsTerminal.onmessage = function (event) {
// ...
let data = event.data;
const titleRegex = /\x1b\]0;([^\x07\x1b]*?)(?:\x07|\x1b\\)/g;
let match;
while ((match = titleRegex.exec(data)) !== null) {
document.title = match[1...
Observations/Thoughts
2025-08-20
~12 min read
datafusion.apache.org
...It handles schema differences in file scans by rewriting expressions to match the physical schema, including type casting, missing columns, and partition values. For detailed documentation, see the PhysicalExprAdapter trait documentation. Most projects should use the datafusion crate directly, which re-exports this module. If you are already using the...
Crate
v56.0.0
2026-11-24
doc.rust-lang.org
pub fn back_mut(&mut self) -> Option<&mut T>
...Examples
use std::collections::LinkedList;
let mut dl = LinkedList::new();
assert_eq!(dl.back(), None);
dl.push_back(1);
assert_eq!(dl.back(), Some(&1));
match dl.back_mut() {
None => {},
Some(x) => *x = 5,
}
assert_eq!(dl.back(), Some(&5));
method
alloc
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn front_mut(&mut self) -> Option<&mut T>
...Examples
use std::collections::LinkedList;
let mut dl = LinkedList::new();
assert_eq!(dl.front(), None);
dl.push_front(1);
assert_eq!(dl.front(), Some(&1));
match dl.front_mut() {
None => {},
Some(x) => *x = 5,
}
assert_eq!(dl.front(), Some(&5));
method
alloc
Stable since 1.0.0
Version 1.100.0-nightly
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
git-cliff.org
...Thanks to @Kriskras99 for implementing this in #1173!
🧮 Support matching arrays via parsers
The commit parser has been extended to support regex matching on array values, such as remote.pr_labels.
For example, this makes it possible to group commits based on their GitHub labels as follows:
[git]commit...
Project/Tooling Updates
2025-07-30
~4 min read
cloudhead.io
...sources.wait(&mut events)?;
for (key, event) in events.iter() {
match key {
Source::Listener => loop {
// Accept as many connections as we can.
let (conn, addr) = match listener.accept() {
Ok((conn, addr)) => (conn, addr),
Err(e) if e.kind() == io::ErrorKind::WouldBlock => break,
Err(e) => return Err(e),
};
// Register the new...
News & Blog Posts
2020-07-21
~6 min read
llogiq.github.io
...Call into the element
chain recursively to remove it if found
Simply removing the existing code and coding up a match block with the three
cases led to much easier code and a performance win. Apparently this time the
compiler didn’t see through the second match and the extra...
News & Blog Posts
2018-08-07
~4 min read