www.slowtec.de
...Vec<_> = key.split(".").collect();
match deep_lookup(&keys, locale) {
Some(res) => res,
None => key.to_string(),
}
}
None => key.to_string(),
}
}
}
fn deep_lookup(keys: &[&str], map: &Map<String, Value>) -> Option<String> {
match &keys {
[] => None,
[last] => map.get(&last.to_string()).and_then(|x| match x {
Value::String(s) => Some(s...
News & Blog Posts
2020-03-03
~10 min read
www.sea-ql.org
...non-exhaustive patterns: `&_` not covered | | match table_ref { | ^^^^^^^^^ pattern `&_` not covered |note: `TableRef` defined here | | pub enum TableRef { | ^^^^^^^^^^^^^^^^^ = note: the matched value is of type `&TableRef` = note: `TableRef` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustivelyhelp: ensure that all possible cases are being handled by...
Project/Tooling Updates
2025-09-03
~11 min read
willcrichton.net
...tyrade! {
enum TList {
TNil,
TCons(Type, TList)
}
enum TOption {
TNone,
TSome(Type)
}
// Get the Nth item from the list, where Index is either Z or S<N>
fn Nth<List, Index>() {
match List {
TNil => TNone,
TCons(X, XS) => match Index {
Z => TSome(X),
S(IMinusOne) => Nth(XS, IMinusOne)
}
}
}
}
fn main...
Observations/Thoughts
2021-01-06
~7 min read
rodolfoghi.github.io
...2
Os casos do match também são padrões como if let:1
2
3
4
5
6
7
fn print_number(n: Number) {
match n {
Number { odd: true, value } => println!("Odd number: {}", value),
Number { odd: false, value } => println!("Even number: {}", value),
}
}
// isso imprime o mesmo de antes
Variáveis são imutáveis...
Learn Standard Rust
2020-08-11
~9 min read
rustc-dev-guide.rust-lang.org
...Pattern matching
match statements for enums with variants that have fields are lowered to TerminatorKind::SwitchInt, too, but the Operand refers to a Place where the discriminant of the value can be found. This often involves reading the discriminant to a new temporary variable.
Aggregate construction
Aggregate values of any...
Guide to Rustc Development
Book
2024-01-01
~4 min read
foon.uk
...Actually, this whole match statement is kind of bulky and I
had planned to get it working with match and then see if Rust had anything
like Scala's Map for Options. Since match is giving us grief, let's just
do that now. Guessing:
pub fn id_at(state...
Blog Posts
2014-11-10
~38 min read
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
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.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
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
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
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
...a hypothetical `#[cold]` attribute that indicates a
branch is unlikely), one can annotate `match` arms:
```rust
match cond {
#[attr] true => { ... }
#[attr] false => { ... }
}
```
## Drawbacks
This starts mixing attributes with nearly arbitrary code, possibly
dramatically restricting syntactic changes related to them, for
example, there was some consideration for using `@` for attributes,
this...
RFC 16
RFC
2014-03-20
~4 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
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
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
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
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
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
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