Polish a few things (#67)

* Improve some match statements using macros

* Use `thiserror` instead of manually impl'ing Error
This commit is contained in:
T0mstone
2021-04-10 16:27:44 +02:00
committed by GitHub
parent c98bc770da
commit 53b34a9ad0
7 changed files with 145 additions and 75 deletions
+27 -23
View File
@@ -124,29 +124,33 @@ pub enum ToolType {
impl fmt::Display for ToolType {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match self {
ToolType::Select => write!(formatter, "Select"),
ToolType::Crop => write!(formatter, "Crop"),
ToolType::Navigate => write!(formatter, "Navigate"),
ToolType::Sample => write!(formatter, "Sample"),
ToolType::Text => write!(formatter, "Text"),
ToolType::Fill => write!(formatter, "Fill"),
ToolType::Gradient => write!(formatter, "Gradient"),
ToolType::Brush => write!(formatter, "Brush"),
ToolType::Heal => write!(formatter, "Heal"),
ToolType::Clone => write!(formatter, "Clone"),
ToolType::Patch => write!(formatter, "Patch"),
ToolType::BlurSharpen => write!(formatter, "BlurSharpen"),
ToolType::Relight => write!(formatter, "Relight"),
ToolType::Path => write!(formatter, "Path"),
ToolType::Pen => write!(formatter, "Pen"),
ToolType::Freehand => write!(formatter, "Freehand"),
ToolType::Spline => write!(formatter, "Spline"),
ToolType::Line => write!(formatter, "Line"),
ToolType::Rectangle => write!(formatter, "Rectangle"),
ToolType::Ellipse => write!(formatter, "Ellipse"),
ToolType::Shape => write!(formatter, "Shape"),
}
use ToolType::*;
let name = match_variant_name!(match (self) {
Select,
Crop,
Navigate,
Sample,
Text,
Fill,
Gradient,
Brush,
Heal,
Clone,
Patch,
BlurSharpen,
Relight,
Path,
Pen,
Freehand,
Spline,
Line,
Rectangle,
Ellipse,
Shape
});
formatter.write_str(name)
}
}