dev.to
...fn normalize_next_url(next: &str, base: &str) -> String {
let path_and_query = match next.find("://") {
Some(scheme_end) => {
let after_scheme = &next[scheme_end + 3..];
match after_scheme.find('/') {
Some(path_start) => &after_scheme[path_start..],
None => "/",
}
}
None => next,
};
format!("{}{}", base, path_and_query)
}
Enter fullscreen mode
Exit fullscreen...
Rust Walkthroughs
2026-07-22
~3 min read
erickt.github.io
...Token) -> Result<Point, E> {
try!(state.expect_struct_start(token, "Point"));
let mut x = None;
let mut y = None;
loop {
let idx = match try!(state.expect_struct_field_or_end(&["x", "y"])) {
Some(idx) => idx,
None => { break ; }
};
match idx {
Some(0us) => { x = Some(try!(state.expect_struct_value())); }
Some(1us...
Project Updates
2015-02-16
~4 min read
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.6
2026-11-16
github.com
...0.3.8 Tracking upstream to match version 0.7.1 Recommended to upgrade from 0.3.7 to get an important bug fix. 0.3.7 Tracking upstream to match version 0.7 0.3.4 Tracking upstream to version 0.6.2. 0.3.3 Tracking upstream to...
Crate
v0.7.6
2026-10-02
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
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
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
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
doc.rust-lang.org
Destructuring
A match block can destructure items in a variety of ways.
• Destructuring Tuples
• Destructuring Arrays and Slices
• Destructuring Enums
• Destructuring Pointers
• Destructuring Structures
See also:
The Rust Reference for Destructuring
Rust by Example
Book
2024-01-01
~1 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
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
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
crates.io
GraphQL introspection query and response types. graphql-introspection-query This crate defines structs implementing serde::Deserialize that match the shape returned by a spec-compliant GraphQL API presented with the introspection query.
Crate
v0.3.0
2025-12-08
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
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
rust-lang.github.io
...A filter option evaluates to true if the corresponding generic parameter in the trait definition matches the specified type. The provided message/note/label options are only emitted if the filter operation evaluates to true.
The any and all options allow to combine multiple filter options. The any option matches...
RFC 3368
RFC
2023-01-06
~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
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
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
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