blog.rust.careers
...Pattern matching: The filtered variable is created by using pattern
matching to filter out any negative numbers from the input vector.
Collecting into a new vector: The squared variable is created by collecting
the results of the map function into a new vector.
Returning a tuple: The function returns a...
Observations/Thoughts
2024-10-30
~17 min read
kamalmarhubi.com
...codemap,
};
visitor.visit_mod(&krate.module, krate.span, 0);
visitor.arg_counts
}
Rust’s pattern matching really shines when working with ASTs. You can get a small glimpse of it here: we match on the FnKind to see if the function is a method, a free function (ItemFn), or a...
News & Blog Posts
2016-06-06
~6 min read
diziet.dreamwidth.org
...In particular, although you can specify a pattern to match the arguments to your macro, the pattern matching system has serious limitations (for example, it has a very hard time with Rust’s generic type parameters). Also, you can’t feed existing pieces of your program to a macro without...
Project/Tooling Updates
2023-02-08
~5 min read
www.sea-ql.org
...DatabaseConnection| { assert!(db.ping().await.is_ok()); db.clone().close().await; assert!(matches!(db.ping().await, Err(DbErr::ConnectionAcquire)));}
#1708 Added TryInsert that does not panic on empty inserts
// now, you can do:let res = Bakery::insert_many(std::iter::empty()) .on_empty_do_nothing() .exec(db) .await;assert!(matches...
Project/Tooling Updates
2023-08-16
~5 min read
doc.rust-lang.org
...A match expression is made up of arms. An arm consists of a pattern to match against, and the code that should be run if the value given to match fits that arm’s pattern. Rust takes the value given to match and looks through each arm’s pattern in...
The Rust Programming Language
Book
2024-02-01
~27 min read
llogiq.github.io
...We can get rid of those if we encode our atoms as empty
enums by relying on the fact that an empty match {} matches all possible
values of an empty enum. So if we have
enum Foo {}
we can write
impl<B: Bar> Add<B> for Foo {
type Output = ...;
fn...
News & Blog Posts
2016-02-29
~2 min read
dev.to
...After seeing '*', we try to match the rules, and find that it can be matched with First rule of Factor, knowing that '2' is an Factor, we can reduce '2*3' as '6', which is classified as an Factor again. After seeing '/' we try to find the rule, match with...
Learn Simple Rust
2020-10-14
~7 min read
hacks.mozilla.org
...Here’s a more elaborate look at what happens in the pattern-matching phase of our fizzbuzz example:
...
// For pattern matching, we build a tuple, containing
// the remainders for integer division of num by 3 and 5
match (num%3, num%5) {
// When "num" is divisible by 3 AND 5...
Notable Links
2015-05-18
~15 min read
hashrust.com
...let browser = match Browser::new(options) {
Ok(browser) => browser,
Err(e) => {
eprintln!("Failed to create browser: {}", e);
return;
}
};
let tab = match browser.wait_for_initial_tab() {
Ok(tab) => tab,
Err(e) => {
eprintln!("Failed to wait for initial tab: {}", e);
return;
}
};
Nothing much to explain here. Then we navigate to the...
Miscellaneous
2022-01-19
~11 min read
mainmatter.com
...message
}]
});
let client = Client::new();
let result = client
.post("https://api.sendgrid.com/v3/mail/send")
.header("Authorization", format!("Bearer {}", api_key))
.header("Content-Type", "application/json")
.body(data)
.send()
.await;
match result {
Ok(response) => match response.status() {
202 => Response::ok(""),
_ => Response::error("Bad Gateway", 502),
},
Err(_) => Response::error("Internal...
Rust Walkthroughs
2022-12-14
~8 min read
serokell.io
...ADTs usually come in a package with pattern matching.
Pattern matching
Pattern matching is also called “destructuring assignment” in some contexts — usually in languages that don’t have proper sum types, and thus pattern matching essentially boils down to syntactic sugar for extracting fields out of records.
There’s also...
Miscellaneous
2025-01-22
~20 min read
blog.servo.org
...emilio replaced many ad-hoc checks in the CSS selector matching with more structured and consistent logic.
rlhunt added support for tiling gradients in WebRender.
mrobinson improved the logic for deciding when to clip content.
stshine made text correctly inherit overflow properties from its parent element.
nox shared more code...
News & Blog Posts
2017-04-11
~1 min read
blog.nodebb.org
...let mut res = Vec::new();
let mut index = 0; while index < input.len() { match sep.parse(input.slice(index..)) { Err(nom::Err::Error(_)) => { // do-while while { index += 1; !input.is_char_boundary(index) } {} } Err(e) => return Err(e), Ok((rest, mat)) => { // if this match was escaped, skip it if input...
Observations/Thoughts
2020-11-25
~16 min read
dev.to
...The body syntax is similar to match guard, the Rust equivalent to switch-case statement. This guard is slightly different since it is matching against Rust code. It has one arm in parenthesis ( $( $x:expr),* ) which represents a pattern. If the pattern matches, the code after => will be executed.
In...
Learn More Rust
2020-09-23
~9 min read
www.riskpeep.com
...18 - Match on the distance from the player.
19-38 - Arms for each of the distances that an object can be. Respond appropriately for each.
39-42 - This arm should never be matched. Unknown objects will be matched on 25, and other known objects will be matched on 32.
Contents...
Rust Walkthroughs
2023-02-22
~25 min read
fathy.fr
...Google recommending me Chrome, lolfor &key in input {
sequence = match sequence {
Sequence::Char => match key {
0x1b => Sequence::Escape,
0x03 => emit!(Event::Exit),
key => emit!(Event::KeyPress { key }),
},
Sequence::Escape => match key {
b'[' => Sequence::Control,
b'P' => Sequence::DeviceControl(DeviceControl::new()),
0x1b =>
emit!(Event::KeyPress { key: 0x1b }; continue),
key => {
emit!(Event...
Observations/Thoughts
2023-02-01
~12 min read
kamalmarhubi.com
...Rust has a pattern matching syntax for easily checking which variant an enum value is. If we have a variable fork_result, we can pattern match on it like this:
match fork_result {
ForkResult::Parent { child } => {
// stuff to do if we're in the parent
}
ForkResult::Child => {
// stuff do do...
Notable New Crates & Project Updates
2016-04-25
~9 min read
doc.rust-lang.org
...Fields of tuples are named using increasing numeric names matching their position in the list of types. The first field is 0. The second field is 1. And so on. The type of each field is the type of the same position in the tuple's list of types.
For...
The Rust Reference
Book
2024-01-01
~1 min read
osblog.stephenmarz.com
...That is why with print, we specify the plus '+', so that we match ONE or more. To match ZERO or more, we would use the asterisk '*'.
The second arm has $fmt:expr, which Rust will match if we provide at least one argument. In this case, this is the format...
News & Blog Posts
2019-10-15
~26 min read
dev.to
...HttpRequest) -> impl Responder {
let name = req.match_info().get("name").unwrap();
let resp = format!("hello {}", name);
HttpResponse::Ok().body(resp)
}
Enter fullscreen mode
Exit fullscreen mode
We get the name value from req's match info, then format the return string and return the response.
Now visit http://127.0...
Learn More Rust
2020-08-26
~4 min read