crates.io
...use googletest::prelude::*; #[gtest] fn strictly_between_9_and_11() { let value = 10; expect_that!(value, gt(9).and(not(ge(11)))); } Pattern-matching One can use the macro matches_pattern! to create a composite matcher for a struct or enum that matches fields with other matchers: use googletest::prelude...
Crate
v0.14.3
2026-06-04
github.com
...Each of the features has
a distinct motivation, and we should evaluate them independently.
## Unresolved questions
These questions should be satisfactorily resolved before stabilizing the
relevant features, at the latest.
### Optional `match` sugar
Originally, the RFC included the ability to `match` the errors caught
by a `catch` by writing `catch...
RFC 243
RFC
2014-09-16
~20 min read
doc.rust-lang.org
pub const fn eq_ignore_ascii_case(&self, other: &[u8]) -> bool
slice::eq_ignore_ascii_case — Checks that two slices are an ASCII case-insensitive match.
Same as to_ascii_lowercase(a) == to_ascii_lowercase(b), but without allocating and copying temporaries.
method
core
Stable since 1.23.0
Version 1.100.0-nightly
github.com
...must_match takes 1 string argument. It will error if the field mentioned is missing or has a different type than the field the attribute is on. Examples: #[validate(must_match(other = "password2"))] contains Tests whether the string contains the substring given or if a key is present in a...
Crate
v0.21.0
2026-07-27
rust-lang.github.io
...For instance, the following is an erroneous use of the match keyword:
fn match(needle: &str, haystack: &str) -> bool {
haystack.contains(needle)
}
error: expected identifier, found keyword `match`
--> src/lib.rs:1:4
|
1 | fn match(needle: &str, haystack: &str) -> bool {
| ^^^^^
It can instead be written as fn r#match...
Updates from Rust Core
2018-03-27
~4 min read
doc.rust-lang.org
pub fn shrink_to_fit(&mut self)
String::shrink_to_fit — Shrinks the capacity of this String to match its length.
Examples
let mut s = String::from("foo");
s.reserve(100);
assert!(s.capacity() >= 100);
s.shrink_to_fit();
assert_eq!(3, s.capacity());
method
alloc
Stable since 1.0.0
Version 1.100.0-nightly
www.ferrisfencing.org
...The Rules
Matches are contested between two fencers, each named Ferris, and each
running in their own VM.
The fencers square off on a one-dimensional grid 10 spaces wide.
Each match consists of 5 games. The player to win the most games wins the match.
Games consist of up...
News & Blog Posts
2019-10-29
~1 min read
hackeryarn.com
...Matching multi-field select
#[macro_export]
macro_rules! query {
( from $db:ident select $( $field:ident ),+ ) => {
...
};
}
That's quite a bit of new syntax, but it all breaks down to a single new matching construct.
Repetition match syntax
The general shape for matching repetition looks like:
$ ( ... ) sep rep => {
...
$ ( ... ) rep
...
}
We need...
Rust Walkthroughs
2025-09-03
~6 min read
blog.servo.org
...Selector matching has been extracted into an independent library! You can see it here.
We now have automation set up for our Gonk (Firefox OS) port, and gate on it.
Notable additions
Chris Paris landed fragment parsing in html5ever
and implemented the innerHTML setter in Servo.
Jack Moffitt added a...
Project Updates
2015-03-02
~1 min read
lifthrasiir.github.io
...MyTrait;
// @matches foo/trait.Bravo.html '//pre' "Bravo.*where.*B:.*MyTrait"
pub trait Bravo<B> where B: MyTrait {}
// @matches foo/fn.charlie.html '//pre' "charlie.*where.*C:.*MyTrait"
pub fn charlie<C>() where C: MyTrait {}
pub struct Delta<D>;
// @matches foo/struct.Delta.html '//*[@class="impl"]//code' "impl.*Delta.*where...
Blog Posts
2015-01-19
~2 min read
coaxion.net
...State::HaveHeader {ref header, ref mut have_header_state } => { match *have_header_state { HaveHeaderState::Skipping { to_skip: 0 } => { *have_header = HaveHeaderState::Streaming { audio: ...}; } }, } match self.state {
...
State::HaveHeader {ref header, ref mut have_header_state } => {
match *have_header_state {
HaveHeaderState::Skipping { to_skip: 0 } => {
*have_header = HaveHeaderState::Streaming { audio: ...};
}
},
} match...
News & Blog Posts
2016-11-29
~8 min read
sled.rs
...fn may_fail() -> Result<Happy, Sad> {
/* either returns Ok(Happy) or Err(Sad) */
}
fn caller() {
match may_fail() {
Ok(happy) => println!(":)"),
Err(sad) => {
eprintln!(":(");
/* handle error */
return;
}
}
match may_fail() {
Ok(happy) => println!(":)"),
Err(sad) => {
eprintln!(":(");
/* handle error */
return;
}
}
match may_fail() {
Ok(happy) => println!(":)"),
Err(sad) => {
eprintln!(":(");
/* handle error...
News & Blog Posts
2020-04-07
~16 min read
doc.rust-lang.org
...use std::collections::HashMap;
fn call(number: &str) -> &str {
match number {
"798-1364" => "We're sorry, the call cannot be completed as dialed.
Please hang up and try again.",
"645-7689" => "Hello, this is Mr. Awesome's Pizza. My name is Fred.
What can I get for you today?",
_ => "Hi...
Rust by Example
Book
2024-01-01
~1 min read
siciarz.net
...MATCH Option,166,9,/home/zbyszek/Development/Rust/rust/src/libcore/option.rs,Enum,pub enum Option<T> {
MATCH Item,774,11,/home/zbyszek/Development/Rust/rust/src/libcore/option.rs,Struct,pub struct Item<A> {
MATCH None,168,4,/home/zbyszek/Development/Rust/rust/src/libcore/option.rs,EnumVariant...
24 Days of Rust continues!
2014-12-15
~2 min read
pwy.io
...Date| -> Span {
// Check if `curr` matches any of the `BYDAY` rules
// (evaluates to `true` if `by_day` is empty)
let matches_by_day = recur.by_day.iter().any(|wd| {
curr.weekday() == wd
});
// Check if `curr` matches any of the `BYMONTHDAY` rules
// (evaluates to `true` when `by_month_day` is empty...
Observations/Thoughts
2025-04-23
~23 min read
unconj.ca
...These two processes can be represented using a simple function
that makes use of Rust’s match construct:
fn algae_rule(input: Algae) -> Vec<Algae> {
match input {
Algae::A => vec!(Algae::A, Algae::B),
Algae::B => vec!(Algae::A)
}
}
If we take the Algae type as representing the L-system...
Notable Links
2015-06-07
~7 min read
cbreeden.github.io
...usize) -> Test {
match n {
0 => Test::A,
1 => Test::B,
_ => unreachable!(),
}
}
We will need to fill in those branches with #(#match_usize)*. After that, the iterator is quite easy to implement. Match the current count with an enum variant, increment the count, and return that enum. That seems straightforward. So...
News & Blog Posts
2017-01-03
~11 min read
doc.rust-lang.org
pub const fn eq_ignore_ascii_case(&self, other: &u8) -> bool
u8::eq_ignore_ascii_case — Checks that two values are an ASCII case-insensitive match.
This is equivalent to to_ascii_lowercase(a) == to_ascii_lowercase(b).
Examples
let lowercase_a = 97u8;
let uppercase_a = 65u8;
assert!(lowercase_a.eq_ignore_ascii_case(&uppercase_a));
method
core
Stable since 1.23.0
Version 1.100.0-nightly
bodil.lol
...fn identifier(input: &str) -> Result<(&str, String), &str> { let mut matched = String::new(); let mut chars = input.chars(); match chars.next() { Some(next) if next.is_alphabetic() => matched.push(next), _ => return Err(input), } while let Some(next) = chars.next() { if next.is_alphanumeric() || next == '-' { matched.push(next); } else { break; } } let...
News & Blog Posts
2019-04-23
~54 min read