jam1.re
...fn return_trait_object() -> Box<Any + Send + Sync> {
todo!()
}
And since this still parses in spite of being deprecated, that means we can use it for our own nefarious macro purposes! (until it is inevitably removed)
The Pattern Matching
Unlike the function itself, matching on the anonymous sum type requires...
Observations/Thoughts
2020-11-18
~9 min read
dev.to
...Second, I very much wrote this only for myself, so there isn't much in the way of robustness and error handling is only match statements and some if checks. I think that is something worth fixing.
Third and lastly, I really enjoyed traveling the internet under my own power...
Rust Walkthroughs
2020-11-04
~11 min read
blog.turbo.fish
...let meta = attr.parse_meta()?;
// Pattern matching and error handling…
}
When parsing into our own type, we can avoid all of the pattern matching and
even get some pretty good error handling "for free", but depending on the syntax
you want to parse, the parsing code can take a little...
Rust Walkthroughs
2021-12-29
~11 min read
xd009642.github.io
...while !pending_exprs.is_empty() {
assert!(tries_left > 0);
if index >= pending_exprs.len() {
index = 0;
tries_left -= 1;
}
let (expr_index, expr) = pending_exprs[index];
let lhs = region_ids.get(&expr.lhs);
let rhs = region_ids.get(&expr.rhs);
match (lhs, rhs) {
(Some(lhs), Some(rhs)) => {
pending_exprs.remove...
Observations/Thoughts
2025-05-14
~11 min read
rust-lang.github.io
...i32 = 3.pow(3);
match x {
CUBE => println!("three cubed"),
_ => {}
}
}
If that const is only used inside a single pattern, writing the code using an inline const block makes it easier to scan.
fn foo(x: i32) {
match x {
const { 3.pow(3) } => println!("three cubed"),
_ => {}
}
}
Reference-level explanation
This...
RFC 2920
RFC
2020-04-30
~7 min read
www.propelauth.com
...I find myself missing match in pretty much every other language I go to.However, if I was doing it over, I wouldn’t choose Rust.This advice is primarily for early startups (pre-product/pre-seed/seed). But first, it’s important to ask why we went with Rust...
Observations/Thoughts
2023-02-22
~3 min read
doc.rust-lang.org
The ref pattern
When doing pattern matching or destructuring via the let binding, the ref keyword can be used to take references to the fields of a struct/tuple. The example below shows a few instances where this can be useful:
#[derive(Clone, Copy)]
struct Point { x: i32, y: i32...
Rust by Example
Book
2024-01-01
~1 min read
julienblanchard.com
...extern crate regex;
use regex::Regex;
use std::env;
fn main() {
println!("Starting email-checker...");
let re = Regex::new(r"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$").unwrap();
match env::args().nth(1) {
Some(email) => {
if re.is_match(&email) {
println!("{} is a valid email.", email);
} else {
println!("{} is NOT a...
News & Blog Posts
2015-11-23
~3 min read
mtak-blog.github.io
...The write lock is no longer held and the version number matches the sequence number read at 1. The read is successful.
Other cases where a write lock is aquired after the read has acquired a sequence number are no different than a regular seqlock.
Now for a handwaving explanation...
News & Blog Posts
2019-03-26
~14 min read
diziet.dreamwidth.org
...macro_rules!’s pattern language doesn’t have a cooked way to match a data structure, so you have to hand-write a matcher for Rust syntax, in each macro. Writing such a matcher is very hard in the general case, because macro_rules lacks features for matching important parts...
Project/Tooling Updates
2025-02-19
~6 min read
seanchen1991.github.io
...For example, given the following student implementation of an Exercism exercise called two-fer
fn twofer(name: &str) -> String {
match name {
"" => "One for you, one for me.".to_string(),
// use the `format!` macro to return a formatted String
_ => format!("One for {}, one for me.", name),
}
}
would be transformed into the...
Learn More Rust
2020-08-04
~8 min read
redox-os.org
...Currently, it attempts to match the Arc theme as closely as possible. The goal is to have all of the
changes required contained where it is easy for other themes to override them.
The login screen has been completely overhauled, as well as the title bars and OrbTK color scheme...
Other Weeklies from Rust Community
2017-02-28
~1 min read
www.fluvio.io
...If version is dev, Kubernetes will expect an image in its local registry with a name matching the pattern infinyon/fluvio-connect-<your connector name>:latest.
Otherwise, the value of version will refer to the image tag to pull from Docker Hub.
e.g.
infinyon/fluvio-connect-<your connector name...
Project/Tooling Updates
2022-02-09
~1 min read
blog.yoshuawuyts.com
Async Cancellation I— 2021-11-10
tasks and futures
cancelling futures
cancelling tasks
propagating cancellation for futures
propagating cancellation for tasks
patching cancellation propagation
structured concurrency
cancelling a group of tasks
halt-safety
should tasks be detachable?
an async trait which can't be cancelled?
intermediate matching on cancellation?
defer...
Observations/Thoughts
2021-11-17
~24 min read
quodlibetor.github.io
...new ( ) ; match ( self , other ) { log_syntax ! ( ( & SingleUnitEnum :: One , & SingleUnitEnum :: One ) => { } ) } list } fn assert_equal_field_by_field ( & self , other : & SingleUnitEnum ) { let errs = self . fields_not_equal ( other ) ; if errs . len ( ) > 0 { let mut errmsg = String :: from ( "\n Items are not equal:\n" ) ; for field_err in errs { errmsg . push_str...
News & Blog Posts
2017-01-17
~9 min read
zenoh.io
...This effort has been undertaken for three main reasons:To avoid ambiguity in key expression definition and matching, which before could lead to undefined behaviour.To improve the key expression matcher for better performance.To allow future extensibility to be introduced for more complex matching and behaviours.Briefly, we can...
Project/Tooling Updates
2022-10-19
~8 min read
doc.rust-lang.org
...u8) -> bool {
matches!(n, 0...100) // should be `0..=100`
}
Migrations
If your Rust 2015 or 2018 code does not produce any warnings for bare_trait_objects or ellipsis_inclusive_range_patterns and you've not allowed these lints through the use of #![allow()] or some other mechanism, then there...
The Rust Edition Guide
Book
2024-01-01
~1 min read
gigapotential.dev
...Create a VM
let val = unsafe { hv_vm_create(std::ptr::null_mut()) };
match val {
HV_SUCCESS => println!("HV_SUCCESS: The operation completed successfully."),
HV_ERROR => eprintln!("HV_ERROR: The operation was unsuccessful."),
HV_BUSY => eprintln!(
"HV_BUSY: The operation was unsuccessful because the owning resource was busy."
),
HV_BAD...
Rust Walkthroughs
2026-04-22
~10 min read
sunshowers.io
...break;
}
}
},
recv(signal_receiver) -> internal_event => {
match internal_event {
// internal_event is a Result<SignalEvent, RecvError>.
Ok(event) => InternalEvent::Signal(event),
Err(_) => {
// Ignore the signal thread being dropped. This is done for
// noop signal handlers.
continue;
}
}
},
};
// ... process internal_event
}
If this loop received a test event, it would bubble that...
Observations/Thoughts
2022-10-05
~19 min read
marcobacis.com
...In the previous post, I implemented the policy update in this way:async fn next(&self, _request: &HttpRequest) -> String {
// Read servers list
let servers = &self.servers;
let max_server_idx = servers.len() - 1;
// Update index
let idx = self
.idx
.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |idx| match idx {
x if...
Rust Walkthroughs
2024-06-05
~8 min read