kdwarn

Codeberg Mastodon Feeds

Home > Programming > Blog > Capturing Catchall Test Value

Capturing Catchall Test Value

January 18, 2024

daybook, rust | permalink

I seem to have forgotten that when pattern matching in Rust, you can capture the value of a catchall test (left side of arm). I typically just use _, which will match anything, but isn't captured for further use. By creating a variable instead, it can be used on the right side of the arm, for whatever purpose. Realized this from watching Zoo's Rust Club: Error-handling.