kerkour.com
...For that, we use the Host extractor and pattern matching:
#[tokio::main]
async fn main() {
// ...
let app = Router::new()
.route(
"/*path",
any(|Host(hostname): Host, request: Request<Body>| async move {
match hostname.as_str() {
"api.mydomain.com" => api_router.oneshot(request).await,
_ => website_router.oneshot(request).await,
}
}),
)
.layer(Extension(state...
Rust Walkthroughs
2022-04-20
~1 min read
www.goldsborough.me
...Below is the code for the match arm handling GET requests. It’s slightly more
logic than before:
(&Get, "/") => {
let time_range = match request.query() {
Some(query) => parse_query(query),
None => Ok(TimeRange {
before: None,
after: None,
}),
};
let response = match time_range {
Ok(time_range) => make_get_response(query_db...
News & Blog Posts
2018-03-06
~23 min read
docs.rs
...Click, click, click!", termion::clear::All, termion::cursor::Goto(1, 1)).unwrap(); stdout.flush().unwrap(); for c in stdin.events() { let evt = c.unwrap(); match evt { Event::Key(Key::Char('q')) => break, Event::Mouse(me) => { match me { MouseEvent::Press(_, x, y) => { write!(stdout, "{}x", termion::cursor::Goto(x, y)).unwrap...
Crate
v4.0.6
2025-11-21
sentry.io
...use sentry::integrations::tracing::EventFilter; use tracing_subscriber::prelude::*; let sentry_layer = sentry::integrations::tracing::layer() .event_filter(|md| match *md.level() { tracing::Level::ERROR => EventFilter::Event, _ => EventFilter::Ignore, }) .span_filter(|md| matches!(*md.level(), tracing::Level::ERROR | tracing::Level::WARN)); tracing_subscriber::registry() .with(tracing_subscriber::fmt::layer()) .with...
Crate
v0.49.1
2026-08-03
doc.rust-lang.org
...In the search_case_insensitive function we’re about to add, the query "rUsT" should match the line containing "Rust:" with a capital R and match the line "Trust me." even though both have different casing from the query. This is our failing test, and it will fail to compile...
The Rust Programming Language
Book
2024-02-01
~6 min read
fnordig.de
...extern crate hyper;
extern crate hubcaps;
use std::{env, process};
use hyper::Client;
use hubcaps::{Github, ReleaseOptions};
fn main() {
let token = match env::var("GITHUB_TOKEN").ok() {
Some(token) => token,
_ => {
println!("example missing GITHUB_TOKEN");
process::exit(1);
}
};
let client = Client::new();
let github = Github::new("hubcaps/0.1.1...
News & Blog Posts
2016-02-29
~1 min read
mdguerrero.com
...fn string_csv_contains(args: &HashMap<String, Value>) -> Result<Value> {
let mut out = false;
let check_str = match args.get("check_str") {
Some(val) => match tera::from_value::<String>(val.clone()) {
Ok(v) => v,
Err(_) => "".to_string(),
},
None => "".to_string(),
};
let csv = match args.get("csv") {
Some(val) => match tera...
Miscellaneous
2022-02-02
~12 min read
benkonz.github.io
...Just read every character and match the character with a command. If the character isn’t a command, just skip it and move to the next character.
Commands
Character
Meaning
>
increment data pointer
<
decrement data pointer
+
increment the byte at the data pointer
-
decrement the byte at the data pointer...
Learn More Rust
2020-08-11
~10 min read
seanmonstar.com
...However, we couldn’t add it in 0.1 due to an unexpected compiler behavior that allowed exhaustive matching on the Version constants even though the internal enum wasn’t exposed. This time, we’ve made sure to prevent exhaustive matches, so we can add new versions in the future...
News & Blog Posts
2019-12-03
~1 min read
tuckersiemens.com
...Even so, Rust's (appreciated)
insistence on exhaustively matching patterns would make us write code like
this.
match packet(&data)? {
Packet::Data => handle_data(),
Packet::Ack => handle_ack(),
Packet::Error => handle_error(),
_ => unreachable!("Didn't we already handle this?"),
}
Also, you might be tempted to use unreachable! for such code...
Observations/Thoughts
2023-01-04
~21 min read
hackeryarn.com
...Evaluate if you need a macro
Design the simplest possible invocation first (determine what your DSL looks like)
Try to implement a match arms and adjust the invocation as needed
Work one match arm at a time
Write sub macros where possible
Some of these steps might not mean much...
Rust Walkthroughs
2025-08-20
~6 min read
blog.dend.ro
...Vec<Matching>,
}
#[derive(Deserialize, Debug)]
pub struct Matching {
pub geometry: String,
}
Then our client:pub struct OsrmClient {
client: Client,
base_url: String,
}
impl OsrmClient {
pub fn new(base_url: String) -> Self {
let client = Client::new();
Self { client, base_url }
}
pub fn match_map(
&self,
profile: &str,
points: &[Point],
) -> Result<MultiLineString...
Rust Walkthroughs
2022-01-19
~9 min read
xuanwo.io
...start_match = start_pattern.match(line)
if start_match:
timestamp, file_name, data_size = start_match.groups()
starts[file_name] = (datetime.fromisoformat(timestamp), int(data_size))
end_match = end_pattern.match(line)
if end_match:
timestamp, file_name, _ = end_match.groups()
ends[file_name] = datetime.fromisoformat(timestamp)
read_times = []
for...
Observations/Thoughts
2024-01-24
~11 min read
aidancully.blogspot.com
...Pin<&mut BarGenerator>, cx: &mut Context<'_>) ->
GeneratorState<() /* yield type */, usize /* result type */>
{
loop {
match vars {
Variant1 { ref var1 } => {
let var2 = &var1;
let await_point = baz();
*vars = Variant2 { var1, var2, await_point };
}
Variant2 { ref var1, ref var2, ref await_point } => {
match Pin::new_unchecked(&mut await_point).poll(&mut cx) {
Poll...
Observations/Thoughts
2022-08-10
~5 min read
cfallin.org
...This function is essentially just a large match
statement over the opcode of the root CLIF instruction, with the match-arms
looking deeper as needed.
Here is a simplified version of the match-arm for an integer add operation
lowered to AArch64 (the full version is
here):
match op {
// ...
Opcode...
Observations/Thoughts
2020-09-23
~25 min read
blog.burntsushi.net
...Vec<StateID>,
// Whether a particular state ID corresponds to a match state.
// Guaranteed to have length equal to the number of states.
is_match_id: Vec<bool>,
}
impl DFA {
// Returns true if the DFA matches the entire 'haystack'.
// This routine always returns either true or false for all inputs.
// It...
Observations/Thoughts
2022-08-10
~33 min read
docs.rs
The tree-sitter Language type, used by the library and by language implementations Tree-sitter Language This crate provides a LanguageFn type for grammars to create Language instances from a parser, without having to worry about the tree-sitter crate version not matching.
Crate
v0.1.7
2026-02-01
rustc-dev-guide.rust-lang.org
...In the names->numbers phase, if the query has only one name in it, the editDistance function is used to find a near match if the exact match fails, but if there's multiple items in the query, non-matching items are treated as generics instead. This means hahsmap will...
Guide to Rustc Development
Book
2024-01-01
~16 min read
steveklabnik.com
...u32 = match guess.trim().parse() {
Ok(num) => num,
Err(_) => continue,
};
println!("You guessed: {}", guess);
match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal => {
println!("You win!");
break;
}
}
}
}
We aren’t quite properly re-using the buffer here, but we could modify this...
Learn Simple Rust
2020-10-21
~4 min read
matthewkmayer.github.io
...pub fn is_commit_event(&self) -> bool {
self.is_accepted_pr() || self.is_direct_push_event()
}
pub fn is_accepted_pr(&self) -> bool {
if self.event_type != "PullRequestEvent" {
return false;
}
match self.payload {
Some(ref payload) => match payload.pull_request {
Some(ref pr) => match pr.merged {
Some(merged) => merged,
None...
Learn
2020-07-28
~11 min read