durka.github.io
...fn main() {
let dir = PathBuf::from(env::args().skip(1).next().unwrap());
match local_du(&dir) {
Ok(bytes) => println!("{} {}", bytes, dir.display()),
Err(error) => println!("ERROR: {:?}", error),
}
}
v1: quick and dirty
Here is the first version of my local_du function. You’ll notice that I like chaining iterators. The...
News & Blog Posts
2017-08-15
~7 min read
recursion.wtf
...let result = recursive_tree.collapse_layers(|expr| {
use ExprLayer::*;
match expr {
Add { a, b } => a + b,
Sub { a, b } => a - b,
Mul { a, b } => a * b,
LiteralInt { literal } => literal,
}
})
Expand and Collapse in a Single Pass
As a reminder, the RecursiveTree representing (5 - 3) * (3 + 12) looks like this:
Here...
Observations/Thoughts
2022-10-12
~7 min read
postacnormalna.pl
...Dlatego zaczynamy od match. Zwróćmy uwagę na słowo kluczowe ref w ramieniu Some(ref base_obj). Dzięki temu Rust nie krzyczy. Jeśli je pominiemy, wypluje taki błąd:
match self.base_template {
| ^^^^^^^^^^^^^^^^^^ help: consider borrowing here: `&self.base_template`
49 | Some(base_obj) => {
| --------
| |
| data moved here
| move occurs because `base_obj...
Rust Walkthroughs
2020-11-18
~11 min read
tweedegolf.nl
...So there are a lot of code patterns that get optimized for us.For example:pub fn process_command() {
match get_command() {
CommandId::A => send_response(123),
CommandId::B => send_response(456),
}
}
Once compiled with optimizations turned on, the compiler generates the following assembly:; x86-64
process_command:
push rax...
Rust Walkthroughs
2026-04-15
~11 min read
ianjk.com
...If it succeeds we insert the component with component_vec[entity] = Some(component); and return;
What if a component_vec doesn't exist in the World yet? Let's handle that case by creating a new component_vec if there isn't a matching one:
/* continued from above */
// No matching...
Rust Walkthroughs
2021-03-24
~12 min read
fredrik.anderzon.se
...if let Ok(num) = _req.param("id").unwrap().parse::<i16>() {
match _req.param("action").unwrap() {
"toggle" => {
store.dispatch( Todos( Toggle(num) ) )
},
"remove" => store.dispatch( Todos( Remove(num) ) ),
_ => (),
}
} else {
// Otherwise look for a show action
match _req.param("action").unwrap() {
"show" => {
match _req.param("id").unwrap() {
"all" => store.dispatch( Visibility( ShowAll...
News & Blog Posts
2016-07-19
~33 min read
maniagnosis.crsr.net
...So I broke down and created some macros: #[macro_export]macro_rules! unpack { ($e:expr,$m:expr) => ( match $e { Ok(v) => v, Err(e) => panic!(format!("{}: {}", $m, e.to_string())), })}#[macro_export]macro_rules! expect { ($e:expr,$m:expr) => ( match $e { Some(e) => e, None => panic!($m), })}#[macro_export]macro...
From the Blogosphere
2015-07-27
~11 min read
deepfence.io
...It usually relies on the haystack finding approach but also regular expression matching approaches. Matching happens on different parts of the HTTP message, it can be headers, port, or even HTML body. Needless to say that such operations are CPU intensive. Here is a rule example:alert http $HOME_NET...
Project/Tooling Updates
2022-07-27
~16 min read
rsdlt.github.io
...another sequence of units based on of the dictionary.Make the Key and the Message have the same size (number of units or characters).Encode / Decode by matching each unit (or character) in the message and the key in the Vigenére table.For example:Dictionary: ABCDVigenére Matrix:ABCDBCDACDABDABCKey: DCABADMessage: BADCADEncode...
Rust Walkthroughs
2022-09-28
~18 min read
www.sheshbabu.com
...Self::Message) -> ShouldRender {
match message {
+ Msg::GetProducts => {
+ self.state.get_products_loaded = false;
+ let handler =
+ self.link
+ .callback(move |response: api::FetchResponse<Vec<Product>>| {
+ let (_, Json(data)) = response.into_parts();
+ match data {
+ Ok(products) => Msg::GetProductsSuccess(products),
+ Err(err) => Msg::GetProductsError(err),
+ }
+ });
+ self.task = Some(api::get_products(handler));
+ true...
Learn More Rust
2020-08-11
~29 min read
cryptographycaffe.sandboxaq.com
...Specifically, the properties we aim to prove ensure that the configuration defined by a Sandwich user matches what Sandwich actually sets when interacting with the cryptographic library.In this initial effort, we focused on the OpenSSL 3 version of Sandwich and defined the following security properties.Safe TLS Protocol VersionsPolicy...
Miscellaneous
2025-04-02
~9 min read
rust-analyzer.github.io
#8156 correctly lower `TraitRef`s with default params.
#8144 (first contribution) fix crash when trying to display closure types.
#8142 hide incorrect ref match completions for struct fields/methods.
#8138 set up a search scope when searching for MBE macro references.
#8159 try to ignore proc-macro stdout to prevent...
Project/Tooling Updates
2021-03-31
~1 min read
www.greyblake.com
...Vehicle) -> VehicleRecord {
let Vehicle { id , vehicle_type } = vehicle;
let (kind, fuel, max_speed_kph) = match vehicle_type {
VehicleType::Car { fuel, max_speed_kph } => {
(
"Car".to_owned(),
Some(fuel_to_str(fuel).to_owned()),
max_speed_kph.map(|speed| speed.try_into().unwrap() )
)
}
Bicycle => {
(
"Bicycle".to_owned(),
None,
None,
)
}
};
let id...
Rust Walkthroughs
2022-11-02
~7 min read
www.techofnote.com
...Vec<_> = self
.cell_positions()
.iter()
.map(|pos| self.cell(pos))
.filter_map(|cell| match &cell.symbol {
Some(symbol) => match symbol {
Symbol::Square(colour) | Symbol::Sun(colour) => Some((colour, &cell.region)),
},
None => None,
})
.collect();
let square_regions: Vec<_> = self
.cell_positions()
.iter()
.map(|pos| self.cell(pos))
.filter_map(|cell| match...
Rust Walkthroughs
2022-09-07
~9 min read
insanitybit.github.io
...self.queue_url.clone()
};
match self.sqs_client.delete_message_batch(&req) {
Ok(res) => {
unimplemented!()
},
Err(e) => {
println!("Failed to deleted {} messages {}", msg_count ,e);
}
}
}
}
A message for communicating to it:
pub enum MessageDeleterMessage {
DeleteMessages {
receipts: Vec<(String, Instant)>,
},
}
A ‘route_msg’ function to destructure the message and pass it...
News & Blog Posts
2017-07-18
~9 min read
passcod.name
...U8) -> U8 {{
match n {{
\u{FFA0}0 => \u{FFA0}1,
\u{FFA0}1 => \u{FFA0}1,
_ => fibonacci(n - \u{FFA0}1) + fibonacci(n - \u{FFA0}2),
}}
}}
fn factorial(n: U12) -> U12 {{
match n {{
\u{FFA0}\u{FFA0}0 | \u{FFA0}\u{FFA0}1 => \u{FFA0}\u{FFA0}1,
_ => factorial(n...
Rust Walkthroughs
2021-10-06
~18 min read
rust-lang.github.io
...If we consider a program such as ripgrep, where should hypothetical uses of dbg! print to in the case of rg some_word < input_file > matching_lines? Should they end up on the terminal or in the file matching_lines? Clearly the former is correct in this case.
Outputting lit...
RFC 2361
RFC
2018-03-13
~7 min read
andreabergia.com
...pub fn push(&mut self, string: &str)
-> Result<(), ClassPathParseError> { /* ... */ }
/// Attempts to resolve a class from the various entries.
/// Stops at the first entry that has a match or an error.
pub fn resolve(&self, class_name: &str)
-> Result<Option<Vec<u8>>, ClassLoadingError> { /* ... */ }
}
The implementation of ClassPath will simply iterate through...
Observations/Thoughts
2023-08-30
~12 min read
www.chriskrycho.com
...Pattern matching and the value of expression blocks.
Functions, closures, and an awful lot of Swift syntax.
Sum types (enums) and more on pattern matching.
Classes and structs (product types), and reference and value types.
Hopes for the next generation of systems programming.
Properties: type and instance, stored and computed...
News & Blog Posts
2016-03-07
~3 min read
jrvidal.github.io
...The wildcard pattern _ [...] In this case it acts like a final "catchall" in this
match expression.
And more...
There are many more minor contextual details that I've enjoyed adding (some of them were already mentioned in my previous post):
Writing the receiver of a method explicitly: mut self: &Self...
Tooling
2020-12-16
~3 min read