home.expurple.me
Table of Contents“Using thiserror for libraries and anyhow for applications”Pattern matching isn’t the only reason to use structured errorsThe tradeoffsTo be continuedRelated readingDiscussTL;DR I prefer thiserror enums over anyhow, even for application code that
simply propagates errors. Custom error types require additional effort, but make
the...
Observations/Thoughts
2025-06-04
~8 min read
notes.eatonphil.com
...Vec<char> = contents.chars().collect();
let tokens = match lex::lex(&raw) {
Ok(tokens) => tokens,
Err(msg) => panic!("{}", msg),
};
let ast = match parse::parse(&raw, tokens) {
Ok(ast) => ast,
Err(msg) => panic!("{}", msg),
};
let pgrm = eval::compile(&raw, ast);
eval::eval(pgrm);
}
Easy peasy. Now let's implement lex.
Lexical analysisLexical...
Rust Walkthroughs
2021-12-29
~25 min read
blog.veeso.dev
...Option<Vec<(ColumnDef, Value)>>, op: &Operation,) -> Option<Vec<(ColumnDef, Value)>> { match (row, op) { (_, Operation::Insert(_, record)) => Some(record.clone()), (_, Operation::Delete(_)) => None, (None, Operation::Update(_, _)) => None, (Some(mut existing_row), Operation::Update(_, updates)) => { for (col_name, new_value) in updates { if let Some((_, value)) = existing_row .iter_mut() .find(|(col...
Observations/Thoughts
2025-12-10
~6 min read
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
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
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
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
quickwit.io
...The query parser already supports this feature, for instance "quickwit tan"* will match documents containing "quickwit tantivy" and "quickwit tango".Regex tokenizer: Tokenization based on regex patterns.Coerce option: Convert values instead of returning an error during indexing.Slop in phrase queries supports now transpositions. "quickwit tantivy"~2 will match...
Project/Tooling Updates
2023-06-21
~2 min read
rust-analyzer.github.io
#11869 (first contribution) allow tildes as code block fences:
#11866 (first contribution) avoid underflows in range conversion.
#11857, #11886 decrease relevance of postfix completions.
#11840 fix another const generic panic.
#11842 fix duplicate type mismatches with blocks.
#11844 fix divergence detection for bare match arms.
#11852 expand asm! to infinite...
Project/Tooling Updates
2022-04-06
~1 min read
rust-analyzer.github.io
...the augmentsSyntaxTokens capability on VS Code.
#14802 fix layout for hir_ty::Ty and friends.
#14820 expand format_args! with more details.
#14851 handle match scrutinee in closure captures.
#14855 consider block impls in lookup_impl_assoc_item_for_trait_ref.
#14863 consider all tokens in macro calls when analyzing...
Project/Tooling Updates
2023-05-24
~1 min read
mortenvistisen.com
...Tera = {
10 let mut tera = match Tera::new("templates/**/*.html") {
11 Ok(t) => t,
12 Err(e) => {
13 println!("Parsing error(s): {}", e);
14 ::std::process::exit(1);
15 }
16 };
17 tera.autoescape_on(vec![".html", ".sql"]);
18 tera
19 };
20}
21
22pub fn start_blog(listener: TcpListener) -> Result<Server...
Rust Walkthroughs
2022-09-07
~24 min read
www.ntietz.com
...It's just a big old match statement.
We check the byte that's passed in and we return the appropriate value.
pub fn parse_system_realtime(status_byte: u8) -> SystemRealtime {
match status_byte {
0xf8 => SystemRealtime::Clock,
0xf9 => SystemRealtime::Tick,
0xfa => SystemRealtime::Start,
0xfb => SystemRealtime::Continue,
0xfc => SystemRealtime::Stop,
0xfe...
Rust Walkthroughs
2024-12-11
~16 min read
oxc.rs
...These 200 bytes have to be passed around, and also accessed every time we do a matches!(expr, Expression::Variant(_)) check, which is not very cache friendly for performance.So to make memory access efficient, it is best to box the enum variants.The perf-book describes additional info on...
Project/Tooling Updates
2024-10-09
~18 min read