fast.github.io
...fn parse_value_iterative(tokens: &mut TokenStream) -> JsonValue { let mut stack = vec![ParseState::ParseValue]; let mut results = Vec::new(); while let Some(state) = stack.pop() { match state { ParseState::ParseValue => { match tokens.peek() { Token::LeftBrace => { stack.push(ParseState::ParseObject(HashMap::new())); } Token::LeftBracket => { stack.push(ParseState::ParseArray(Vec::new())); } _ => { results.push...
Project/Tooling Updates
2025-07-23
~4 min read
docs.rs
...end() Match end of input. any() Match any symbol and return the symbol. sym(t) Match a single terminal symbol t . seq(s) Match sequence of symbols. list(p,s) Match list of p , separated by s . one_of(set) Success when current input symbol is one of the set...
Crate
v3.4.0
2024-03-06
docs.rs
...Each bit in the bitmap indicates a bit matching pattern: bit 0 1 2 3 4 5 6 7 match * 0* 1* 00* 01* 10* 11* 000* bit 8 9 10 11 12 13 14 15 match 001* 010* 011* 100* 101* 110* 111* endnode-bit The last bit here...
Crate
v0.5.0
2020-03-30
doc.rust-lang.org
...Since pattern matching is like reading the union with a particular field, it has to be placed in unsafe blocks as well.
# union MyUnion { f1: u32, f2: f32 }
#
fn f(u: MyUnion) {
unsafe {
match u {
MyUnion { f1: 10 } => { println!("ten"); }
MyUnion { f2 } => { println!("{}", f2); }
}
}
}
Pattern matching may match a union...
The Rust Reference
Book
2024-01-01
~4 min read
doc.rust-lang.org
...Finally, it is useful for the reader to keep in mind that according to the definitions of this formalism, no simple NT matches the empty fragment, and likewise no token matches the empty fragment of Rust syntax. (Thus, the only NT that can match the empty fragment is a complex...
The Rust Reference
Book
2024-01-01
~13 min read
anoopelias.github.io
...Sample code below,macro_rules! assert_match {
($exp:expr, $pattern1:pat_param | $pattern2:pat) => {
match $exp {
$pattern1 => {
println!("Pattern 1 match");
}
$pattern2 => {
println!("Pattern 2 match");
}
_ => panic!("Failed match"),
}
}
}
fn main() {
let value = 2;
assert_match!(value, 1 | 2);
}
metaMeta specifier is used to send #[xxx] type attributes to the...
Rust Walkthroughs
2024-02-07
~8 min read
doc.rust-lang.org
?
Chaining results using match can get pretty untidy; luckily, the ? operator can be used to make things pretty again. ? is used at the end of an expression returning a Result, and is equivalent to a match expression, where the Err(err) branch expands to an early return Err(From::from...
Rust by Example
Book
2024-01-01
~1 min read
doc.rust-lang.org
pub fn contains<P>(&self, pat: P) -> bool
str::contains — Returns true if the given pattern matches a sub-slice of this string slice.
Returns false if it does not.
The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.
Examples
let bananas = "bananas";
assert!(bananas...
method
core
Stable since 1.0.0
Version 1.100.0-nightly
github.com
...ReverseSearcher<&'a Self>;
pub fn trim_matches<'a, P>(&'a self, pat: P) -> &'a Self
where
P: Pattern<&'a Self>,
P::Searcher: DoubleEndedSearcher<&'a Self>;
pub fn trim_left_matches<'a, P>(&'a self, pat: P) -> &'a Self
where
P: Pattern<&'a Self>;
pub fn trim_right_matches<'a, P...
RFC 2295
RFC
2018-01-16
~14 min read
doc.rust-lang.org
...The exception is that the outer delimiters for the matcher will match any pair of delimiters. Thus, for instance, the matcher (()) will match {()} but not {{}}. The character $ cannot be matched or transcribed literally.
Forwarding a matched fragment
When forwarding a matched fragment to another macro-by-example, matchers in the...
The Rust Reference
Book
2024-01-01
~18 min read
huonw.github.io
Rust’s match statement can do a lot of things, even C-style fallthough to the next branch, despite having no real support for it. It turns out to be a “shallow” feature, where the C to Rust translation is easily done, without needing to understand the code itself. The...
Observations/Thoughts
2025-03-05
~8 min read
blog.meilisearch.com
...IS EMPTY matches existing attributes with empty value while IS NULL matches fields with a null value.
Here’s an example considering the following documents:
[
{
"id": 0,
"color": []
},
{
"id": 1,
"color": null
},
{
"id": 2,
}
]
The new filter operators work like this:
color IS EMPTY: matches document 0
color IS NULL...
Project/Tooling Updates
2023-06-07
~4 min read
stopa.io
...fn env_get(k: &str, env: &RispEnv) -> Option<RispExp> {
match env.data.get(k) {
Some(exp) => Some(exp.clone()),
None => {
match &env.outer {
Some(outer_env) => env_get(k, &outer_env),
None => None
}
}
}
}
fn eval(exp: &RispExp, env: &mut RispEnv) -> Result<RispExp, RispErr> {
match exp {
RispExp::Symbol(k) =>
env_get...
Rust Walkthroughs
2020-12-02
~15 min read
doc.rust-lang.org
pub fn ends_with<P>(&self, pat: P) -> bool
str::ends_with — Returns true if the given pattern matches a suffix of this string slice.
Returns false if it does not.
The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.
Examples
let bananas = "bananas";
assert!(bananas...
method
core
Stable since 1.0.0
Version 1.100.0-nightly
docs.rs
...import re re.compile('(a|b|ab)*bc').match('ab' * 28 + 'ac') In Python (tested on both 2.7 and 3.5), this match takes 91s, and doubles for each additional repeat of 'ab'. Thus, many proponents advocate a purely NFA (nondeterministic finite automaton) based approach. Even so, backreferences and...
Crate
v0.19.0
2026-07-28
dev.to
...fn read_username_from_file() -> Result<String, io::Error> {
let f = File::open("username.txt");
let mut f = match f {
Ok(file) => file,
Err(e) => return Err(e),
};
let mut s = String::new();
match f.read_to_string(&mut s) {
Ok(_) => Ok(s),
Err(e) => Err(e),
}
}
Enter fullscreen mode...
Learn Simple Rust
2020-10-21
~4 min read
leshow.github.io
...Write,
{
match var {
Var::One => serde_json::to_writer(&mut writer, &Foo),
Var::Two => serde_json::to_writer(&mut writer, &Bar),
}
}
fn write_pretty<W>(var: Var, mut writer: W) -> serde_json::Result<()>
where
W: Write,
{
match var {
Var::One => serde_json::to_writer_pretty(&mut writer, &Foo),
Var::Two...
News & Blog Posts
2020-05-05
~5 min read
flinect.com
...One macro I really like is matches!.
It's basically a single-arm match expression, but you can readably use it in if statements.
So, this:
match data_type.id {
ParsedDataTypeId::Standard(ref data_type_id) if data_type_id == "data-trait-name" => {
// ...
}
_ => {}
}
Can be written as:
if matches!(data...
Rust Walkthroughs
2023-11-29
~6 min read
doc.rust-lang.org
pub const fn eq_ignore_ascii_case(&self, other: &str) -> bool
str::eq_ignore_ascii_case — Checks that two strings are an ASCII case-insensitive match.
Same as to_ascii_lowercase(a) == to_ascii_lowercase(b), but without allocating and copying temporaries.
For Unicode-aware case-insensitive matching, consider str::eq_ignore_case_unnormalized.
Examples
assert!("Ferris".eq_ignore_ascii_case...
method
core
Stable since 1.23.0
Version 1.100.0-nightly
gsquire.github.io
...This is a powerful construct in that it can match multiple patterns that you provide in a single
scan. Using this idea, I thought it would be fun to write a router with a RegexSet matching
requests under the hood.
The result of this is reroute. This crate provides a...
News & Blog Posts
2016-06-20
~2 min read