arzg.github.io
...Let’s add a todo!() and comment out the rest so we can get on with running our tests:impl Expr {
// snip
pub(crate) fn eval(&self, env: &Env) -> Result<Val, String> {
match self {
Self::Number(Number(n)) => Ok(Val::Number(*n)),
Self::Operation { lhs, rhs, op } => {
todo!();
// let Number...
Learn More Rust
2020-10-14
~25 min read
adventures.michaelfbryan.com
...std::slice::Iter<'src, Operation>,
}
Turning TextObjectParser into an Iterator turned out to be pretty easy
thanks to pattern matching. I know ahead of time exactly which operations
I’m looking for and what their operands will be so each pattern can be its
own branch in a big match...
Rust Walkthroughs
2021-02-03
~13 min read
dev.to
...diesel::result::Error, context: &str) -> AppError {
AppError::new(
format!("{}: {}", context, err.to_string()).as_str(),
match err {
diesel::result::Error::DatabaseError(db_err, _) => {
match db_err {
diesel::result::DatabaseErrorKind::UniqueViolation => ErrorType::BadRequest,
_ => ErrorType::Internal,
}
}
diesel::result::Error::NotFound => ErrorType::NotFound,
// Here we can handle other cases if needed
_ => {
ErrorType::Internal...
Learn More Rust
2020-08-04
~20 min read
matthewkmayer.github.io
...database_instance_name.to_string(),
db_instance_class: "db.t2.micro".to_string(),
// name and login details should match `.env` in rusoto-rocket
master_user_password: Some("TotallySecurePassword501".to_string()),
master_username: Some("masteruser".to_string()),
db_name: Some("rusotodb".to_string()),
engine: "postgres".to_string(),
multi_az: Some(false...
News & Blog Posts
2017-05-23
~9 min read
traxys.me
...We need to be careful when categorizing arguments, as we don't want --foo to match a short argument, nor do we want -- to match a long argument.
The reason for introducing a ShortArgument structure is that short arguments are inherently ambiguous.
-abc could be parsed as either -a -b...
Project/Tooling Updates
2024-10-02
~15 min read
fasterthanli.me
...2
Match arms are patterns
match arms are also patterns, just like if let:
fn print_number(n: Number) {
match n {
Number { odd: true, value } => println!("Odd number: {}", value),
Number { odd: false, value } => println!("Even number: {}", value),
}
}
// this prints the same as before
Exhaustive matches
A match has to be...
News & Blog Posts
2020-03-03
~31 min read
rust-analyzer.github.io
...pattern_analysis to fix a panic on mismatched types.
#16770 fix panic on float numbers without dots in chain calls (x.1e0).
#16779 skip match diagnostics for partially unknown types.
#16690 use four-space indentation in macro expansion.
#16752 don’t allow destructuring of structs with no public fields.
#16766...
Project/Tooling Updates
2024-03-13
~1 min read
zupzup.org
...println!("requests in flight: {}", request_contexts.len());
for ev in &events {
match ev.u64 {
100 => {
match listener.accept() {
Ok((stream, addr)) => {
stream.set_nonblocking(true)?;
println!("new client: {}", addr);
key += 1;
add_interest(epoll_fd, stream.as_raw_fd(), listener_read_event(key))?;
request_contexts.insert(key, RequestContext::new(stream...
Learn More Rust
2020-10-21
~15 min read
wiki.cont.run
...Below is its comment.Desugar `<expr>.await` into:
```rust
match ::std::future::IntoFuture::into_future(<expr>) {
mut pinned => loop {
match unsafe { ::std::future::Future::poll(
<::std::pin::Pin>::new_unchecked(&mut pinned),
::std::future::get_context(task_context),
) } {
::std::task::Poll::Ready(result) => break result,
::std::task::Poll::Pending => {}
}
task...
Rust Walkthroughs
2022-01-26
~14 min read
dev.to
...Environment variables are a good place to store such values and they are fairly easy to change.
# main.rs
fn main(){
match std::env::var("CLIENT_ID1") {
Ok(client_id) => println!("Client ID: {}", client_id),
Err(e) => panic!("Couldn't read CLIENT_ID ({})", e),
};
match std::env::var("CLIENT_SECRET1...
Learn More Rust
2020-08-11
~8 min read
blog.sheerluck.dev
...Arc<PathBuf>) {
let mut buf = vec![0u8; 8192];
// Read data from the socket
let n = match socket.read(&mut buf).await {
Ok(0) => return, // client closed immediately
Ok(n) => n,
Err(_) => return,
};
// Parse the request
let request = match parse_request(&buf[..n]) {
Some(req) => req,
None => {
let response = Response::new...
Rust Walkthroughs
2026-06-24
~30 min read
rust-analyzer.github.io
...trait or impl declarations.
#8510 move cursor position when using item movers.
#8536 (first contribution) slightly improve status messages.
#8543 (first contribution) fix "Fill match arms" issue with single-element tuples.
#8545 fix primitive shadowing with inner items.
#8539 do not propose inherent traits in flyimports and import assists.
#8546...
Project/Tooling Updates
2021-04-21
~1 min read
arthurtw.github.io
...For example, I think Rust’s match syntax:
match key.cmp(&node.key) {
Less => return insert(&mut node.left, key, value),
Greater => return insert(&mut node.right, key, value),
Equal => node.value = value,
}
looks clearer than Nim’s case statement:
case key
of "help", "h": echo usageString
of "ignore-case...
Blog Posts
2015-01-19
~17 min read
limpet.net
...fn get_color(layout_box: &LayoutBox, name: &str) -> Option<Color> {
match layout_box.box_type {
BlockNode(style) | InlineNode(style) => match style.value(name) {
Some(Value::ColorValue(color)) => Some(color),
_ => None
},
AnonymousBlock => None
}
}
The borders are similar, but instead of a single rectangle we draw
four—one for each edge of...
Blog Posts
2014-11-10
~7 min read
tavianator.com
...Bit) -> (Bit, Bit) {
match (a, b) {
(Zero, Zero) => (Zero, Zero),
(Zero, One) => (One, Zero),
(One, Zero) => (One, Zero),
(One, One) => (Zero, One),
}
}
let (s, c) = half_adder(One, One);
println!("One plus One is {:?}, carry the {:?}", s, c);
}
But we want to do all this at compile-time, not runtime...
Observations/Thoughts
2020-10-21
~22 min read
rust-analyzer.github.io
...language clients in Restart server.
#12850 fix error tooltip message for VSCode status bar item.
#12851 don’t add braces to 'if' completion in match guard position.
#12832 don’t try to implement default members.
#12861 include receiver in struct field autocomplete.
#12807 add basic support for completion item details...
Project/Tooling Updates
2022-07-27
~1 min read
mattrighetti.com
...Form<LoginData>
) -> impl IntoResponse {
// dummy function to get a user
let user = match db::user::get(&app.pg_pool, &username, &password).await {
None => return Redirect::to("/signup").into_response()
Some(user) => user
};
// get/create a refresh token for the user
let refresh_token = match db::refresh_tokens::create(user.id...
Rust Walkthroughs
2025-05-07
~15 min read
blog.pnkfx.org
...As another example, one can step through the the instructions corresponding to
the subcomponents of a match pattern. This way, one might discover which parts
matched and which failed to match, and in what order they were evaluated.
Here is a concrete example of the latter:
1
2
3
4...
Observations/Thoughts
2022-01-12
~18 min read
piware.de
...const char **matches = r_grep("ell", "Hello\nworld\ncan you tell?");
for (const char **m = matches; *m; m++)
printf("matched line: %s\n", *m);
free (matches);
However, I am fairly convinced that the strings inside the returned lists get
leaked. There is no CString::as_mut_ptr(), I can’t...
Rust Walkthroughs
2021-09-08
~6 min read
rust-analyzer.github.io
...assist.
#8830 implement built-in concat_idents! macro.
#8831 apply async semantic token modifier to the async/await keywords.
#8840 fix false positive "Missing match arm" when a tuple pattern is shorter than scrutinee type.
#8845 add default type parameters on "Generate Default from new function".
#8848 attach comments to...
Project/Tooling Updates
2021-05-19
~1 min read