rustc-dev-guide.rust-lang.org
...Examples of such structures include but are not limited to
• Parenthesis
• Removed without replacement, the tree structure makes order explicit
• for loops
• Converted to match + loop + match
• Universal impl Trait
• Converted to generic arguments (but with some flags, to know that the user didn't write them)
• Existential impl Trait...
Guide to Rustc Development
Book
2024-01-01
~2 min read
cantrip.org
...On earlier versions of the Rust compiler, I had to use an iterator pipeline, using .scan(), match, .filter(), and .collect(), at twice the line count, to get tolerable performance. Now the loop is faster. A match would work here, but the code would be longer. Rust could have just one...
News & Blog Posts
2016-02-01
~13 min read
dev.to
...A match has to cover every possible case and yours misses one.
error[E0004]: non-exhaustive patterns: `Direction::South` not covered
--> src/main.rs:8:11
|
8 | match d {
| ^ pattern `Direction::South` not covered
|
note: `Direction` defined here
--> src/main.rs:1:6
|
1 | enum Direction {
| ^^^^^^^^^
2 | North,
3 | South...
Rust Walkthroughs
2026-08-26
~14 min read
blog.urth.org
...Then it generates a CSS file containing just those strings
which match actual Tailwind names.But this scanning process, because it matches so broadly, errs on the side of false positives, and
the tailwindcss program will not emit any warnings when it finds a string that could be a match...
Rust Walkthroughs
2022-02-23
~16 min read
esimmler.com
...DomainType<T>,
{
match val {
Val::Var(var) => {
let resolved = self.domain.values_as_ref().get(var);
match resolved {
// We found another Var, try to resolve deeper
Some(found) => self.resolve_val(found),
// We didn't find a binding, return the Var
None => val,
}
}
// This isn't a Var, just return...
News & Blog Posts
2020-07-14
~6 min read
docs.rs
...syn::DeriveInput) -> syn::Result<TokenStream> { let attrs = Attrs::parse_attrs("from", &input)?; match (attrs.forward.is_some(), !attrs.custom.is_empty()) { (true, true) => Err(syn::Error::new_spanned( input, "`forward` and `on` arguments are mutually exclusive", )), (false, false) => Err(syn::Error::new_spanned( input, "either `forward` or `on` argument is...
Crate
v0.5.1
2026-07-22
dev.to
...This method makes sure that the mock server received exactly one HTTP request that matched all the mock requirements. If not, it will fail the test with a detailed problem description (see next section).
Verification
Mock objects provide an assert method which ensures our app did actually send a request...
Rust Walkthroughs
2020-11-04
~6 min read
www.justanotherdot.com
...macro_rules! time {
($val:expr) => {
{
let beg = std::time::Instant::now();
match $val {
tmp => {
let end = std::time::Instant::now();
let time = (end - beg);
println!("[{}:{}] `{}' took {:?}", std::file!(), std::line!(), std::stringify!($val), time);
tmp
}
}
}
};
($($val:expr),+ $(,)?) => {
($(time!($val)),+,)
};
}
This change uses the repeat pattern matches of macros to consistently...
Observations/Thoughts
2020-08-26
~4 min read
system76.com
...System76 offers health benefits, paid vacation, matching 401k, sabbatical, and an awesome dog-friendly work environment where smart people are free to create.
We are committed to providing equal employment opportunities to all employees and applicants, regardless of race, color, creed, religion, sex, gender identity/expression, age, national origin, disabilities...
Rust Jobs
2019-01-08
~1 min read
docs.rs
...16) -> Result<Self, Self::Error> { match n { 0 => Ok(Foo::Bar), 100 => Ok(Foo::Baz), 200 => Ok(Foo::Quix), _ => Err(n), } } } fn main() { let bar = Foo::try_from(0); let baz = Foo::try_from(100); let quix = Foo::try_from(200); let bad = Foo::try_from(300); assert_eq!(bar...
Crate
v1.0.0
2020-03-30
doc.rust-lang.org
pub fn duration(&self) -> Duration
...Examples
use std::thread::sleep;
use std::time::{Duration, SystemTime};
let sys_time = SystemTime::now();
sleep(Duration::from_secs(1));
let new_sys_time = SystemTime::now();
match sys_time.duration_since(new_sys_time) {
Ok(_) => {}
Err(e) => println!("SystemTimeError difference: {:?}", e.duration()),
}
method
std
Stable since 1.8.0
Version 1.100.0-nightly
rauljordan.com
...Match statements are very flexible and structural in nature
Instead of nesting match statements, for example, one could bring values together as tuples and do
the following:
fn player_outcome(player: &Move, opp: &Move) -> Outcome {
use Move::*;
use Outcome::*;
match (player, opp) {
// Rock moves.
(Rock, Rock) => Draw,
(Rock, Paper) => Lose...
Rust Walkthroughs
2023-01-25
~26 min read
matklad.github.io
...u32,
) -> io::Result<Option<Widget>> {
let key = id.to_be_bytes();
let value = match self.db.load(&key)? {
None => return Ok(None),
Some(it) => it,
};
let widget: Widget =
bincode::deserialize(&value).map_err(|it| {
io::Error::new(io::ErrorKind::InvalidData, it)
})?;
Ok(Some(widget))
}
}
Now, for the sake of argument...
Rust Walkthroughs
2022-06-15
~6 min read
docs.rs
...use std::io::Read; use wl_clipboard_rs::{paste::{get_contents, ClipboardType, Error, MimeType, Seat}}; let result = get_contents(ClipboardType::Regular, Seat::Unspecified, MimeType::Text); match result { Ok((mut pipe, _)) => { let mut contents = vec![]; pipe.read_to_end(&mut contents)?; println!("Pasted: {}", String::from_utf8_lossy(&contents)); } Err(Error::NoSeats...
Crate
v0.9.5
2026-10-26
thume.ca
...Instead of using data tables like in the canonical Pratt parser implementation, we used Rust functions with match statements, which fill the same purpose but with more power and no need to keep a data structure around:
fn binding_power(cur: &SpannedToken) -> Option<u8> {
match &cur.tok {
Token::Operator(op...
News & Blog Posts
2019-05-28
~15 min read
doc.rust-lang.org
pub fn remove<Q>(&mut self, value: &Q) -> bool
...The value may be any borrowed form of the set's element type, but the ordering on the borrowed form must match the ordering on the element type.
Examples
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
set.insert(2);
assert_eq!(set.remove(&2), true);
assert_eq!(set...
method
alloc
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
...The key may be any borrowed form of the map's key type, but Hash and Eq on the borrowed form must match those for the key type.
Examples
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.remove_entry(&1), Some((1...
method
std
Stable since 1.27.0
Version 1.100.0-nightly
notes.iveselov.info
...if $s matched our tokens without trailing semicolon, won't it be logical to add that semicolon in the expansion part to compensate?The reason that it doesn't work like that is as follows. When we expand the macro, matched $s is not a token stream anymore! Since its...
News & Blog Posts
2020-05-12
~6 min read
system76.com
...System76 offers health benefits, paid vacation, matching 401k, sabbatical, and an awesome dog-friendly work environment where smart people are free to create.
We are committed to providing equal employment opportunities to all employees and applicants, regardless of race, color, creed, religion, sex, gender identity/expression, age, national origin, disabilities...
Rust Jobs
2020-06-10
~1 min read