dev-resources.site
for different kinds of informations.
Compact `match` in Rust
Published at
9/17/2023
Categories
rust
optimization
code
formatting
Author
rsk
Main Article
Author
3 person written this
rsk
open
match
often used to work with enums, let's look at this example:
enum NextStep {
TurnLeft,
TurnRight
}
fn main() {
let next_step = NextStep::TurnLeft;
match next_step {
NextStep::TurnLeft => println!("turn left"),
NextStep::TurnRight => println!("turn right"),
}
}
It may not be obvious, but enums in Rust can be brought into the current namespace, allowing for more compact code:
// ...
use NextStep::*;
match next_step {
TurnLeft => println!("turn left"),
TurnRight => println!("turn right"),
}
// ...
And, to limit the effect to just match
, you will have to set boundaries using {}
for an additional scope:
// ...
{
use NextStep::*;
match next_step {
// ...
}
}
// ...
My links
I'm making my perfect todo, note-taking app Heaplist, you can try it here heaplist.app
And I have a twitter @rsk
formatting Article's
30 articles in total
How to Configure VSCode for Auto Formatting and Linting in Python
read article
Clean Code: Open Source Linting & Formatting
read article
A One-Liner `sed` Command to Format SSH Config File
read article
Developing a Custom Gradle Plugin for Formatting and Static Analysis
read article
Why Do I Love Code Formatters?
read article
My opinion about opinionated Prettier: 👎
read article
How to convert XML files to CSV format using Boomi in Docker
read article
Format Time Ago Function - Time Differences in TypeScript
read article
How to use Prettier as a Github Action
read article
My universal code beautification tool
read article
What are formatting tags in HTML?
read article
Compact `match` in Rust
currently reading
Axis Headaches? Examples for Formatting Tick Labels (Matplotlib)
read article
Wednesday Links - Edition 2023-05-17
read article
Formatting External Drives On Linux Using Gparted.
read article
Make Your Code Shine with Prettier Extension for VS Code
read article
Accounting Number Format in Excel – How to Apply it to Selected Cells
read article
How to Clear Formatting in Excel – Remove Format From a Cell
read article
Best Practice #1 : One Function can be accessed many times with Different Values
read article
Hugo.io - Multiline cells in a table
read article
AppVeyor and python formatting
read article
Checking your python code format on Azure Pipelines
read article
Formatting Python – Why and How !
read article
Golang automatic code formatting : Code like a Pro
read article
Clean Code in C# Part 4 Formatting
read article
Formatting numbers in JavaScript
read article
How to format relative dates using native JavaScript
read article
Formatting dates in JavaScript using the user's locale
read article
Set Cell Styles and Formatting in Excel with Java
read article
Code formatting for C# projects: dotnet format + GitHub Actions
read article
Featured ones: