rodarmor.com
...for c in text.chars() {
match state {
…
State::Backslash => {
match c {
'n' => cooked.push('\n'),
…
}
…
}
…
}
}
So just asks rustc to insert the result of evaluating the Rust '\n'
character escape. Let's take a look at how rustc handles '\n'.
rustc's escape code handling is in the lexer, in...
Observations/Thoughts
2024-10-02
~2 min read
github.com
...This proposal also includes a `debug_asset_ne`, matching `debug_assert_eq`.
## Motivation
[motivation]: #motivation
This feature, among other reasons, makes testing more readable and consistent as
it complements `asset_eq`. It gives the same style panic message as `assert_eq`,
which eliminates the need to write it yourself.
## Detailed...
RFC 1653
RFC
2016-07-27
~1 min read
loige.co
...select a part, then print it on the standard output.Another interesting example in our code base involved the match expression. This was the code before the refactoring:impl fmt::Display for JWTParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { JWTParseError::MissingSection() => write!(f, "{}", "Missing token...
Observations/Thoughts
2020-10-14
~16 min read
rustc-dev-guide.rust-lang.org
...Note that exactly one of the matchers from the various rules should match the invocation; if there is more than one match, the parse is ambiguous, while if there are no matches at all, there is a syntax error.
Assuming exactly one rule matches, macro expansion will then transcribe the...
Guide to Rustc Development
Book
2024-01-01
~16 min read
worldwithouteng.com
...Handling these error variants is straightforward on the calling side thanks to Rust’s pattern matching. Using the match statement, you can easily run different code for different error variants. Further, the compiler ensures that your match statement is exhaustive. If you ever add a new error variant but forget...
Rust Walkthroughs
2023-11-01
~8 min read
matthewkmayer.github.io
...let credentials = DefaultCredentialsProvider::new()
.expect("Couldn't create AWS credentials provider.");
Knowing when to use expect instead of matching against Result or Option is worth understanding. In our sample code, panicking if we can’t get AWS credentials is probably what we want to do. But what about calls to...
News & Blog Posts
2017-06-06
~7 min read
kerkour.com
...They match routes (URLs). For example, the Login page matches the /login route. The Home page matches the / route.
And finally, Services are auxiliary utilities to wrap low-level features or external services such as an HTTP client, Storage...
The goal of our application is simple: It's a portal...
Rust Walkthroughs
2022-06-15
~5 min read
levpaul.com
...For now I’ve just set this command as a build target for when I need it but I’m sure it will eventually annoy me enough to find a better answer.match match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal...
Learn Rust
2020-10-28
~7 min read
codeandbitters.com
...It allows us to apply a closure to convert the matched string into
something else: in the json_bool case, one of the JsonBool variants. You
will probably smell something funny about that code, though: we already matched
the "true" and "false" strings once in the parser generated by the...
News & Blog Posts
2020-07-14
~33 min read
willcrichton.net
...These mechanisms can ensure that two variadic argument lists share important properties, like the number of format string holes matches the number of printf arguments.
Part of an ongoing series about type-level programming in Rust. Consider reading part one first! All code in this note can be found in...
News & Blog Posts
2020-06-23
~6 min read
willcrichton.net
...These mechanisms can ensure that two variadic argument lists share important properties, like the number of format string holes matches the number of printf arguments.
Part of an ongoing series about type-level programming in Rust. Consider reading part one first! All code in this note can be found in...
Learn More Rust
2020-08-11
~6 min read
rust.code-maven.com
...Vec<(&str, &str)>) -> surrealdb::Result<()> {
for (name, phone) in data {
let response = db
.query("CREATE entry SET name=$name, phone=$phone")
.bind(("name", name))
.bind(("phone", phone))
.await?;
match response.check() {
Ok(_) => {}
Err(err) => {
eprintln!("Could not add entry: '{}'", err);
return Err(err);
}
};
}
Ok(())
}
SELECT to fetch data
This query...
Miscellaneous
2024-01-17
~6 min read
www.chriskrycho.com
...Rust’s match and Swift’s switch and case fill the same role of pattern matching. I’m curious to see how they differ. Does Swift do matching on arbitrary expressions?
Also, I see where the syntax choices came from in both, and while I slightly prefer Rust’s, I...
News & Blog Posts
2015-10-26
~3 min read
agourlay.github.io
...usize = match args_iter.next() {
- None => num_cpus::get_physical(),
- Some(count) => count.parse().unwrap(),
- };
+ let batch_size: usize = args_iter.next().unwrap().parse().unwrap();
+
+ let workers: usize = num_cpus::get_physical();
- match password_finder(&zip_path, dictionary_path, workers) {
+ match password_finder(&zip_path, dictionary_path, workers, batch_size...
Observations/Thoughts
2022-10-05
~26 min read
rust-analyzer.github.io
...include! and other eager macros work in expression position.
#8970 duplicate dependencies that have multiple DepKinds.
#8975 use todo!() as placeholder body for generated match arms.
#8983 fix type mismatch caused by macros.
#8986 add "Go to type definition" for struct fields within struct.
#8989 try to fix type inference...
Project/Tooling Updates
2021-06-02
~1 min read
joelmccracken.github.io
...open(filename));
try!(file.write_all(bytes));
Ok(())
}
fn log_time(filename: &'static str) -> io::Result<()> {
let entry = formatted_time_entry();
let bytes = entry.as_bytes();
try!(record_entry_in_log(filename, &bytes));
Ok(())
}
fn main2() {
match log_time("log.txt") {
Ok(..) => println!("File created!"),
Err(e) => println!("Error: {}", e...
From the Blogosphere
2015-07-06
~10 min read
pliniker.github.io
...When computed gotos and optimized tail calls are unavailable, the fallback standard is to use
switch/match statements. It must be noted that a switch/match compiles to a single computed goto,
but it cannot be used to jump to arbitrary points in a function as with the full Computed...
Observations/Thoughts
2021-09-08
~11 min read
github.com
## Summary
Make the `count` parameter of `SliceExt::splitn`, `StrExt::splitn` and
corresponding reverse variants mean the *maximum number of items
returned*, instead of the *maximum number of times to match the
separator*.
## Motivation
The majority of other languages (see examples below) treat the `count`
parameter as the maximum number of...
RFC 979
RFC
2015-03-15
~2 min read
adventures.michaelfbryan.com
...Axes> System<L, A> for Motion {
fn poll(&mut self, inputs: &L, outputs: &mut A) {
match self.control_mode {
ControlMode::Idle => {}
ControlMode::Home(ref mut home) => match home.poll(inputs, outputs) {
Transition::Complete => {
self.control_mode = ControlMode::Idle
}
Transition::Fault(_) => {
// TODO: we should probably do something about this fault...
self...
News & Blog Posts
2019-10-29
~5 min read
arzg.github.io
...35 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Let’s also extract the parsers for each of the match arms in lhs:fn lhs(p: &mut Parser) -> Option<CompletedMarker> {
let cm = match p.peek() {
Some(SyntaxKind::Number) => literal(p),
Some(SyntaxKind::Ident) => variable_ref(p),
Some(SyntaxKind...
Rust Walkthroughs
2020-12-23
~4 min read