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
docs.rs
...Originally intended to be a way to just parse the semver spec into data structures, with no logic around matching and such, this functionality now lives in the semver crate, and therefore, is no longer used.
Crate
v0.10.3
2024-11-18
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
doc.rust-lang.org
pub enum Cow<'a, B>
...v }
}
}
// Creates a container from borrowed values of a slice
let readonly = [1, 2];
let borrowed = Items::new((&readonly[..]).into());
match borrowed {
Items { values: Cow::Borrowed(b) } => println!("borrowed {b:?}"),
_ => panic!("expect borrowed value"),
}
let mut clone_on_write = borrowed;
// Mutates the data from slice into owned vec and pushes...
enum
alloc
Stable since 1.0.0
Version 1.100.0-nightly
docs.rs
...TomlError { message: "data did not match any variant of untagged enum Ohno", original: Some("\ninteger = 42\nstring = \"we want this to be spanned\"\n"), keys: ["string"], span: Some(23..51) } } } To understand why this fails we can look at what #[derive(serde::Deserialize)] expand to for Ohno in HIR. #[allow...
Crate
v0.7.1
2026-03-06
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
crates.io
...Vec<OsString>) -> windows_service::Result<()> { let event_handler = move |control_event| -> ServiceControlHandlerResult { match control_event { ServiceControl::Stop | ServiceControl::Interrogate => { ServiceControlHandlerResult::NoError } _ => ServiceControlHandlerResult::NotImplemented, } }; // Register system service event handler let status_handle = service_control_handler::register("my_service_name", event_handler)?; let next_status = ServiceStatus { // Should match the one from system...
Crate
v0.8.1
2026-05-08
docs.rs
...It offers means to match your type's signature - <T as zvariant::Type>::signature() - with a corresponding signature retrieved from a DBus XML file. This way zbus-lockstep prevents definitions from drifting apart. Motivation In the context of IPC over DBus - especially when there are multiple implementations of servers and...
Crate
v0.7.0
2026-07-27
crates.io
...u32) -> u32 { match n { 1 | 2 => 1, _ => fibonacci_native(n - 1) + fibonacci_native(n - 2), } } #[napi] fn get_cwd<T: Fn(String) -> Result<()>>(callback: T) { callback(env::current_dir().unwrap().to_string_lossy().to_string()).unwrap(); }
Crate
v3.6.3
2026-08-10
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
doc.rust-lang.org
pub const unsafe fn swap<T>(x: *mut T, y: *mut T)
...to them be `[2, 3]`, so that indices `0..3` are
// `[1, 2, 3]` (matching `y` before the `swap`); or for them to be `[0, 1]`
// so that indices `1..4` are `[0, 1, 2]` (matching `x` before the `swap`).
// This implementation is defined to make the latter choice.
assert...
function
core
Stable since 1.0.0
Version 1.100.0-nightly
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