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
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
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
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
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
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
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
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
rust-lang.github.io
...Only types which have the "structural match" property can be used as const parameters. This would exclude floats, for example.
The structural match property is intended as a stopgap until a final solution for matching against consts has been arrived at. It is important for the purposes of type equality...
RFC 2000
RFC
2017-05-01
~11 min read
rust-lang.github.io
...The compiler's searching and file matching logic would be altered to only match crates based on name. If two versions of a crate are found, the compiler will unconditionally emit an error. It will be up to the user to move the two libraries on the filesystem and control...
RFC 109
RFC
2014-06-24
~7 min read
fitzgeraldnick.com
...bz_stream = mem::zeroed();
let result = BZ2_bzCompressInit(&mut stream as *mut _,
1, // 1 x 100000 block size
4, // verbosity (4 = most verbose)
0); // default work factor
match result {
r if r == (BZ_CONFIG_ERROR as _) => panic!("BZ_CONFIG_ERROR"),
r if r == (BZ_PARAM_ERROR as _) => panic!("BZ_PARAM...
News & Blog Posts
2016-12-20
~9 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
jorgeortiz.dev
...So we used the matches!() macro inside the assertion to verify this use
case. The expression used was assert!(matches!(...));, that is not as clarifying as it could be.
I have used similar expressions for quite a while, but I was secretly hoping that assert_matches!() would become part
of...
Rust Walkthroughs
2025-11-19
~13 min read
dev.to
...Self::Message) -> ShouldRender {
match msg {
Msg::Increment => self.value += 1,
Msg::Decrement => self.value -= 1,
}
true
}
fn change(&mut self, _props: Self::Properties) -> ShouldRender {
false
}
fn view(&self) -> Html {
html! {
<div>
<button onclick=self.link.callback(|_| Msg::Increment)>{"+"}</button>
<span style="width: 50px">{ self.value }</span>
<button onclick=self.link...
Rust Walkthroughs
2020-11-25
~5 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
arzg.github.io
...SyntaxNode) -> Option<Self> {
let result = match node.kind() {
SyntaxKind::InfixExpr => Self::BinaryExpr(BinaryExpr(node)),
SyntaxKind::Literal => Self::Literal(Literal(node)),
SyntaxKind::ParenExpr => Self::ParenExpr(ParenExpr(node)),
SyntaxKind::PrefixExpr => Self::UnaryExpr(UnaryExpr(node)),
SyntaxKind::VariableRef => Self::VariableRef(VariableRef(node)),
_ => return None,
};
Some(result)
}
}
We’re still missing an AST node, namely...
Rust Walkthroughs
2021-01-27
~21 min read
sabrinajewson.org
...We have to match on the Result for that:let blocks = match Blocks::from_file("Blocks.txt") {
Ok(blocks) => blocks,
Err(unicode_blocks::Error::Io(e)) if e.kind() == io::ErrorKind::NotFound => {
}
};
Great! But the compiler is yelling that the match arms aren’t exhaustive. Not too hard to fix...
Observations/Thoughts
2023-04-12
~23 min read
www.joshmcguigan.com
...fn main(){
loop {
print!("> ");
stdout().flush();
let mut input = String::new();
stdin().read_line(&mut input).unwrap();
let mut parts = input.trim().split_whitespace();
let command = parts.next().unwrap();
let args = parts;
match command {
"cd" => {
// default to '/' as new directory if one was not provided
let new_dir = args.peekable...
News & Blog Posts
2018-11-20
~7 min read