blog.urth.org
...That’s because I’m using Rust’s
enum-based pattern matching. The Node enum has over 100 variants. That’s a lot of matching!I also need to generate enum wrappers around many structs. Any time a struct references another
struct, I need the wrapper indirection. So for example...
Observations/Thoughts
2021-03-17
~9 min read
blog.cloudflare.com
...right hand side is parsed and used as a byte sequence (will match a URL "/1234567")Are there other examples of such ambiguities? Yup - for example, we can try using a single number with two decimal digits:tcp.port == 80: matches any traffic on the port 80 (HTTP)http.file...
News & Blog Posts
2019-03-05
~17 min read
github.com
...As such, the lang team will need to approve the high-level answer.
- **Do match guards have semantic meaning?**
Match guards are inserted by the compiler around match statements to ensure that if guards cannot change the value being matched on. Whether match guards should exist at all primarily affects...
RFC 3346
RFC
2022-11-07
~8 min read
ettolrach.com
...Expr::App(l, m) => match infer(*l, context)? {
Type::Arrow(a, b) => match check(*m.clone(), *a, context) {
Ok(_) => Ok(*b),
Err(TypeError {
kind:
ErrorKind::CheckedWrongType {
expected: a,
actual,
},
line,
column,
}) => Err(TypeError {
kind: ErrorKind::ArgWrongType {
expected: a,
actual,
},
line,
column,
}),
Err(e) => Err(e),
},
actual => Err(TypeError {
kind: ErrorKind...
Observations/Thoughts
2025-12-31
~15 min read
dev.to
...Option<&mut FdSet>) -> *mut libc::fd_set {
match opt {
None => ptr::null_mut(),
Some(&mut FdSet(ref mut raw_fd_set)) => raw_fd_set,
}
}
fn to_ptr<T>(opt: Option<&T>) -> *const T {
match opt {
None => ptr::null::<T>(),
Some(p) => p,
}
}
pub fn select(
nfds: libc::c_int,
readfds...
Rust Walkthroughs
2020-11-25
~12 min read
blog.sheerluck.dev
...LIKE and Pattern Matching#
LIKE does pattern matching on text. Two wildcards:
% matches any sequence of characters (including zero)
_ matches exactly one character
SELECT title FROM books WHERE title LIKE '%Rust%';
Output:
title
---------------------------
The Rust Programming Langua
%Rust% means “anything, then Rust, then anything.” It finds any title containing the...
Rust Walkthroughs
2026-07-01
~51 min read
ryangjchandler.co.uk
...fn compile_function(function: &Statement, source: &mut String) -> Result<(), CompileError> {
let (name, params, body) = match function {
Statement::Function { name, params, body, .. } => (name, params, body),
_ => unreachable!(),
};
source.push_str("fn ");
source.push_str(&name.name);
source.push('(');
for param in params {
source.push_str(match ¶m.name {
Expression::Variable(n) => &n...
Rust Walkthroughs
2022-08-24
~13 min read
marketplace.visualstudio.com
...this session),
"numfiles": (number of rs files in workspace),
"result": {
"fns": (hashmap of relevant function data),
"loops": (location and depth of loops),
"matches": (location and depth of matches),
"let_exprs": (`if let` patterns),
"iter_mthds": (methods on iterators),
"calls": (function calls and contexts),
"unsafe_blocks": (location of unsafe blocks),
"no...
Project/Tooling Updates
2023-11-29
~3 min read
llogiq.github.io
...synstructure::Structure has many useful methods to construct or match over
values. The variants() method returns a slice of VariantInfo for all
variants (one for structs, any number for enums), which one can iterate to
generate code for each variants. There is also an .each(..) method to
generate matches.
To...
News & Blog Posts
2018-08-28
~1 min read
chrissardegna.com
...let maybe_event = match event_source.try_read(poll_timeout.leftover()) { ... }
This event sends a buffer to fill with data from a predefined file descriptor.
match self.tty_fd.read(&mut self.tty_buffer, TTY_BUFFER_SIZE) { ... }
In the self.tty_fd.read() call, crossterm invokes the read() syscall on...
Observations/Thoughts
2022-08-03
~8 min read
robinmoussu.gitlab.io
...The concrete type of all the branches of any conditional expression (like if, match, any kind of loop, …) must match.
Oh right. I wish that the compiler would be smart enough to create a newtype
automatically, but that’s not the case currently and the lang team is already
working...
Observations/Thoughts
2021-03-31
~7 min read
developerlife.com
...let mut terminal_async = match maybe_terminal_async {
None => return Ok(()),
_ => maybe_terminal_async.unwrap(),
};
// Initialize tracing w/ the "async stdout".
tracing_setup::init(TracingConfig::new(Some(
terminal_async.clone_shared_writer(),
)))?;
// Start tasks.
let mut interval_1_task = interval(Duration::from_secs(1));
let mut interval_2_task = interval...
Project/Tooling Updates
2024-04-24
~3 min read
memo.barrucadu.co.uk
...impl RecordType {
pub fn matches(&self, qtype: &QueryType) -> bool {
match qtype {
QueryType::Wildcard => true,
QueryType::Record(rtype) => rtype == self,
}
}
}
#[derive(Debug, Copy, Clone)]
pub enum QueryClass {
Record(RecordClass),
Wildcard,
}
impl RecordClass {
pub fn matches(&self, qclass: &QueryClass) -> bool {
match qclass {
QueryClass::Wildcard => true,
QueryClass::Record(rclass) => rclass == self,
}
}
}
There are...
Rust Walkthroughs
2022-03-09
~21 min read
rust-analyzer.github.io
New Features
#6645 add diagnostics for unexpandable macros.
#6666 support "go to definition" for self parameter.
#6664 show type of self on hover.
#6606 support unsafe extern block syntax.
#6618, #6621 type inference for tuple patterns with ellipsis.
#6624 check structs for match exhaustiveness.
#6631 gate autoimports behind experimental completions...
Tooling
2020-12-02
~1 min read
acv.engineering
...The match flow keyword allow you to match on a variable, in this case, since I’m matching what’s passed into the CLI opt.cmd, and if command matches play, then call the play_file public function from play_loop and pass in the String that was passed in...
Rust Walkthroughs
2021-11-03
~8 min read
doc.rust-lang.org
...This can be matched as shown below, or used with
// `.expect()` if you would like the program to exit with a nice
// message instead of happily continue.
for i in 0..xs.len() + 1 { // Oops, one element too far!
match xs.get(i) {
Some(xval) => println!("{}: {}", i, xval),
None => println...
Rust by Example
Book
2024-01-01
~2 min read
tavianator.com
...Metric<T> = T> {
/// Returns the nearest match to `target` (or `None` if this index is empty).
fn nearest(&self, target: &U) -> Option<Neighbor<&T>>;
/// Returns the nearest match to `target` within the `threshold`, if one exists.
fn nearest_within(&self, target: &U, threshold: f64) -> Option<Neighbor<&T>>;
/// Returns the up...
News & Blog Posts
2020-05-27
~10 min read
simplabs.com
...base64::Config = match_config(opt);
let bytes = base64::decode_config(b64, config).expect("decode failed: invalid b64");
String::from_utf8(bytes).unwrap()
}
#[rustler::nif]
pub fn encode(s: String, opt: Atom) -> String {
let config: base64::Config = match_config(opt);
base64::encode_config(s.as_bytes(), config)
}
fn match_config(option...
News & Blog Posts
2020-07-14
~5 min read
natkr.com
...FairDice,
}
impl SimpleFuture<u8> for LoadedDice {
fn poll(&mut self) -> Poll<u8> {
match self.inner.poll() {
Poll::Ready(x) => Poll::Ready(x + 1),
Poll::Pending => Poll::Pending,
}
}
}
Now.. writing all those "match poll, if pending then return, if ready
then continue" blocks can also get pretty tedious. Thankfully, Rust
provides...
Rust Walkthroughs
2025-04-16
~10 min read
therohansharma.com
...fn extract_entities(tree: &Tree, source: &str) -> Vec<SemanticEntity> {
let mut cursor = tree.root_node().walk();
let mut entities = Vec::new();
for node in tree.root_node().children(&mut cursor) {
match node.kind() {
"function_item" | "function_definition" => {
entities.push(build_entity(node, source, "function"));
}
"class_definition" | "impl_item" => {
let class...
Project/Tooling Updates
2026-04-22
~13 min read