rust-analyzer.github.io
...10264 don’t seek outside of character boundaries in completion handler.
#10260 fix name generation in "Generate function" assist.
#10267 narrow if-let to match assist range.
#10282 don’t allow two turbo-fishes in generic arguments.
#10289 only strip derive attributes when preparing macro input.
#10293 don’t bail...
Project/Tooling Updates
2021-09-22
~1 min read
fasterthanli.me
...2
Match arms are patterns
match arms are also patterns, just like if let:
fn print_number(n: Number) {
match n {
Number { odd: true, value } => println!("Odd number: {}", value),
Number { odd: false, value } => println!("Even number: {}", value),
}
}
// this prints the same as before
Exhaustive matches
A match has to be...
News & Blog Posts
2020-03-03
~31 min read
traxys.me
...We need to be careful when categorizing arguments, as we don't want --foo to match a short argument, nor do we want -- to match a long argument.
The reason for introducing a ShortArgument structure is that short arguments are inherently ambiguous.
-abc could be parsed as either -a -b...
Project/Tooling Updates
2024-10-02
~15 min read
wiki.cont.run
...Below is its comment.Desugar `<expr>.await` into:
```rust
match ::std::future::IntoFuture::into_future(<expr>) {
mut pinned => loop {
match unsafe { ::std::future::Future::poll(
<::std::pin::Pin>::new_unchecked(&mut pinned),
::std::future::get_context(task_context),
) } {
::std::task::Poll::Ready(result) => break result,
::std::task::Poll::Pending => {}
}
task...
Rust Walkthroughs
2022-01-26
~14 min read
zupzup.org
...println!("requests in flight: {}", request_contexts.len());
for ev in &events {
match ev.u64 {
100 => {
match listener.accept() {
Ok((stream, addr)) => {
stream.set_nonblocking(true)?;
println!("new client: {}", addr);
key += 1;
add_interest(epoll_fd, stream.as_raw_fd(), listener_read_event(key))?;
request_contexts.insert(key, RequestContext::new(stream...
Learn More Rust
2020-10-21
~15 min read
rust-analyzer.github.io
...broken code.
#14920 fix edits for convert_named_struct_to_tuple_struct.
#14950 support floating-point intrinsics in const eval.
#14951 fix string pattern matching in mir interpreter.
#14955 remove unnecessary StorageDead.
#14961 fix drop scopes problems in mir.
#14970 detect multiple bindings for one identifier in the same pattern...
Project/Tooling Updates
2023-06-07
~1 min read
blog.sheerluck.dev
...Arc<PathBuf>) {
let mut buf = vec![0u8; 8192];
// Read data from the socket
let n = match socket.read(&mut buf).await {
Ok(0) => return, // client closed immediately
Ok(n) => n,
Err(_) => return,
};
// Parse the request
let request = match parse_request(&buf[..n]) {
Some(req) => req,
None => {
let response = Response::new...
Rust Walkthroughs
2026-06-24
~30 min read
dev.to
...Environment variables are a good place to store such values and they are fairly easy to change.
# main.rs
fn main(){
match std::env::var("CLIENT_ID1") {
Ok(client_id) => println!("Client ID: {}", client_id),
Err(e) => panic!("Couldn't read CLIENT_ID ({})", e),
};
match std::env::var("CLIENT_SECRET1...
Learn More Rust
2020-08-11
~8 min read
rust-analyzer.github.io
#11894 (first contribution) complete pattern args based on type name
#11891 show error message when flycheck fails.
#11915 attempt to heuristically resolve paths in const arguments in IDE layer.
#11953 make extract_module more lazy.
#11896 show path to be created in the unresolved-module fix label.
#11899 skip match...
Project/Tooling Updates
2022-04-13
~1 min read
arthurtw.github.io
...For example, I think Rust’s match syntax:
match key.cmp(&node.key) {
Less => return insert(&mut node.left, key, value),
Greater => return insert(&mut node.right, key, value),
Equal => node.value = value,
}
looks clearer than Nim’s case statement:
case key
of "help", "h": echo usageString
of "ignore-case...
Blog Posts
2015-01-19
~17 min read
doc.rust-lang.org
fn source(&self) -> Option<&dyn Error + 'static>
...SuperErrorSideKick })
}
fn main() {
match get_super_error() {
Err(e) => {
println!("Error: {e}");
println!("Caused by: {}", e.source().unwrap());
}
_ => println!("No error"),
}
}
method
core
Stable since 1.30.0
Version 1.100.0-nightly
tavianator.com
...Bit) -> (Bit, Bit) {
match (a, b) {
(Zero, Zero) => (Zero, Zero),
(Zero, One) => (One, Zero),
(One, Zero) => (One, Zero),
(One, One) => (Zero, One),
}
}
let (s, c) = half_adder(One, One);
println!("One plus One is {:?}, carry the {:?}", s, c);
}
But we want to do all this at compile-time, not runtime...
Observations/Thoughts
2020-10-21
~22 min read
limpet.net
...fn get_color(layout_box: &LayoutBox, name: &str) -> Option<Color> {
match layout_box.box_type {
BlockNode(style) | InlineNode(style) => match style.value(name) {
Some(Value::ColorValue(color)) => Some(color),
_ => None
},
AnonymousBlock => None
}
}
The borders are similar, but instead of a single rectangle we draw
four—one for each edge of...
Blog Posts
2014-11-10
~7 min read
docs.rs
...use std::fs::File; use std::io::BufReader; use xml::reader::{EventReader, XmlEvent}; fn main() -> std::io::Result<()> { let file = File::open("file.xml")?; let file = BufReader::new(file); // Buffering is important for performance let parser = EventReader::new(file); let mut depth = 0; for e in parser { match e { Ok...
Crate
v1.4.0
2026-08-06
mattrighetti.com
...Form<LoginData>
) -> impl IntoResponse {
// dummy function to get a user
let user = match db::user::get(&app.pg_pool, &username, &password).await {
None => return Redirect::to("/signup").into_response()
Some(user) => user
};
// get/create a refresh token for the user
let refresh_token = match db::refresh_tokens::create(user.id...
Rust Walkthroughs
2025-05-07
~15 min read
blog.pnkfx.org
...As another example, one can step through the the instructions corresponding to
the subcomponents of a match pattern. This way, one might discover which parts
matched and which failed to match, and in what order they were evaluated.
Here is a concrete example of the latter:
1
2
3
4...
Observations/Thoughts
2022-01-12
~18 min read
malachite.rs
...The current floating-point string conversion functions are incomplete and will be changed in the future to match MPFR's behavior. Malachite is developed by Mikhail Hogrefe. Thanks to 43615, b4D8, Romain Billot, Maxim Biryukov, coolreader18, Dasaav-dsv, Duncan Freeman, florian1345, konstin, Rowan Hart, YunWon Jeong, Park Joon-Kyu, Antonio...
Crate
v0.15.0
2026-11-23
aibodh.com
...tinyrt/src/state_machine.rsPlace this inside the match armloop { match this { CartTotal::Start { socks, .. } => { match Pin::new(socks).poll(cx) { Poll::Pending => { println!("[cart] Start: socks price not back yet, waiting"); return Poll::Pending; } Poll::Ready(socks_price) => { println!( "[cart] Start -> GotSocks: socks are ${socks_price}" ); let CartTotal::Start...
Rust Walkthroughs
2026-07-01
~22 min read
doc.rust-lang.org
pub struct IntoInnerError<W>
...let stream = match stream.into_inner() {
Ok(s) => s,
Err(e) => {
// Here, e is an IntoInnerError
panic!("An error occurred");
}
};
struct
alloc
Stable since 1.0.0
Version 1.100.0-nightly
piware.de
...const char **matches = r_grep("ell", "Hello\nworld\ncan you tell?");
for (const char **m = matches; *m; m++)
printf("matched line: %s\n", *m);
free (matches);
However, I am fairly convinced that the strings inside the returned lists get
leaked. There is no CString::as_mut_ptr(), I can’t...
Rust Walkthroughs
2021-09-08
~6 min read