siciarz.net
...extern crate libc;
use std::c_str::CString;
use libc::c_char;
#[no_mangle]
pub extern "C" fn count_substrings(value: *const c_char, substr: *const c_char) -> i32 {
let c_value = unsafe { CString::new(value, false) };
let c_substr = unsafe { CString::new(substr, false) };
match c_value.as_str...
The end of 24 Days of Rust
2014-12-29
~4 min read
blog.lanesawyer.dev
...And that order is important! When writing patterns, you want to start with the most specific at the top so that it's matched against before its more general version. Since None is a macro metavariable of type expr, putting the second pattern first would mean None matched that more...
Rust Walkthroughs
2021-09-08
~9 min read
joelmccracken.github.io
...DateTime<Local> = Local::now();
let formatted = local.format("%a, %b %d %Y %I:%M:%S %p\n").to_string();
let bytes = formatted.as_bytes();
let mut f = try!(File::create(filename));
try!(f.write_all(bytes));
Ok(())
}
fn main() {
match log_time("log.txt") {
Ok(..) => println!("File created!"),
Err(..) => println...
Notable Links
2015-06-07
~6 min read
blog.yoshuawuyts.com
...What if the compiler
actually used this information in the function body too? That would mean matching
on self would only need to account for the possible cases rather than all
cases:
match self {
Self::Orange => {}
Self::Flashing => {}
// no other cases need matching!
}
This isn't particularly relevant yet for...
Observations/Thoughts
2022-08-24
~20 min read
1:13:35
Rustacean Station
rustacean-station.org
Episode: What's New in the Rust 2024 Edition
...Right? You can say, oh, like, if is, like, if is a can be compiled to a match. I can transform this if into a match and then just write the code for the match once and generate code for a match. And you see this with, like, you know...
Podcast
2026-01-23
1:13:35
mmapped.blog
mmap(blog)
Posts
About
Atom Feed
β 2023-02-14
β 2023-02-16
Introduction
Objects, values, and references
When abstraction hurts
Common expression elimination
Monomorphism restriction
Functional abstraction
Newtype abstraction
Views and bundles
When composition hurts
Object composition
Pattern matching cannot see through boxes
Orphan rules
Fearless concurrency is a lie...
Observations/Thoughts
2023-03-01
~20 min read
git-cliff.org
...id
message
body
author.name
author.email
committer.email
committer.name
Glob -> Regex π§Άβ
[git].tag_pattern was only supporting glob patterns for matching (mostly due to the underlying support of such glob by git2), now it directly supports regular expressions:
[git]- # glob pattern for matching git tags+ # regex for...
Project/Tooling Updates
2023-11-01
~2 min read
dev.to
...How do you get the value inside? How do you decide what to do based on the outcome of the operation? The answer to both questions lies in pattern matching.
fn read_state(file: Result<i32,&str>) {
match file {
Ok(answer) => println!("Extracted from file {}", answer),
Err() => println!("Bitter disappointment...
Learn Simple Rust
2020-10-21
~4 min read
arXiv
arxiv.org
...A Rust macro-and-match dispatch layer keeps a single, backend-agnostic call site while emitting vendor-specific kernel strategies, and the type system enforces buffer-size and lifetime correctness at compile time. On a two-socket AMD Instinct MI210 node we measure GPU speedups from $1.03\times$ (bandwidth...
Distributed Computing
Ianna Osborne, Maxym Naumchyk, Tai Sakuma et al.
2026-09-21
arXiv:2609.24628
blog.yoshuawuyts.com
...But otherwise the logic is the same for both:
// `match` consumes a concrete `Result` type
match foo() {
Ok(x) => { .. }
Err(err) => { .. }
}
// `match` consumes an abstract `impl Try` type
// NOTE: this should probably become a combinator on `Try`
let res = match foo().branch() {
Break(b) => FromResidual::from_residual(b),
Continue(c...
Observations/Thoughts
2025-12-24
~11 min read
rust-lang.github.io
...Rc<[Wrap]> = Rc::from(arr.as_ref());
/// assert_eq!(rc.as_ref(), &arr); // The elements match.
/// assert_eq!(rc.len(), arr.len()); // The lengths match.
/// ```
///
/// Using the [`Into`][Into] trait:
///
/// ```
/// #![feature(shared_from_slice)]
/// use std::rc::Rc;
///
/// #[derive(PartialEq, Clone, Debug)]
/// struct Wrap(u8);
///
/// let rc: Rc<[Wrap]> = arr...
RFC 1845
RFC
2017-01-05
~12 min read
rapha.land
Archived: primary link replaced with an archive on 2026-10-09T10:11:12.565Z (UTC; replacement date, not snapshot date)
...Add a new variant later and every match site that doesnβt cover it stops compiling, with the type checker pointing at the exact line. That is the safety property pattern matching is for.
Match also works as an expression:
const name: []u8 = match (color) {
Color.Red { "red" }
Color.Green...
Project/Tooling Updates
2026-07-08
~26 min read
blog.yoshuawuyts.com
...create and return an error if the condition doesn't match
ensure_eq!: create and return an error if two expressions don't match
ensure_ne!: create and return an error if two expressions match
bail is kind of like panic, and ensure is kind of like assert. You can...
Rust Walkthroughs
2023-01-25
~4 min read
doc.rust-lang.org
...file in write-only mode, returns `io::Result<File>`
let mut file = match File::create(&path) {
Err(why) => panic!("couldn't create {}: {}", display, why),
Ok(file) => file,
};
// Write the `LOREM_IPSUM` string to `file`, returns `io::Result<()>`
match file.write_all(LOREM_IPSUM.as_bytes()) {
Err(why) => panic!("couldn't...
Rust by Example
Book
2024-01-01
~1 min read
github.com
...For instance, could we have `pub macro_helper_attr! skip` in the standard
library, namespaced under `core::derives` or similar? Could we let macros parse
that in a way that matches it in a namespaced fashion, so that:
- If you write `#[core::derives::skip]`, the macro matches it
- If you...
RFC 3698
RFC
2024-09-20
~9 min read
crates.io
...LanguageTag = "en-x-twain".parse().unwrap(); assert_eq!(langtag.primary_language(), "en"); assert_eq!(Vec::from_iter(langtag.private_use_subtags()), vec!["twain"]); You can check for equality, but more often you should test if two tags match. In this example we check if the resource in German language is...
Crate
v0.3.2
2021-05-24
blog.turbo.fish
...use syn::{Lit, NestedMeta};
let nested = match meta_list.nested.len() {
// `#[getter()]` without any arguments is a no-op
0 => return Ok(None),
1 => &meta_list.nested[0],
_ => {
return Err(syn::Error::new_spanned(
meta_list.nested,
"currently only a single getter attribute is supported",
));
}
};
let name_value = match nested...
Rust Walkthroughs
2021-05-12
~6 min read
blog.meilisearch.com
...frequency matching strategy
Meilisearch 1.9 introduces a new matching strategy to prioritize results that contain occurrences of the least frequent query terms. When using the frequency matching strategy, Meilisearch will deprioritize very common words.
Letβs take the example of the "the little prince" query. In our indexed documents...
Project/Tooling Updates
2024-07-03
~4 min read
amanjeev.com
...non-exhaustive patterns: `&_` not covered
--> src/main.rs:12:11
|
12 | match place {
| ^^^^^ pattern `&_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `&str`I do not enjoy writing tests and eating my...
Observations/Thoughts
2020-09-16
~13 min read
docs.rs
Procedural macro for html5ever.
Crate
v0.35.0
2025-07-02