Skip to content

Commit

Permalink
avoid destructuring enums
Browse files Browse the repository at this point in the history
  • Loading branch information
joseluis committed Sep 4, 2023
1 parent eb2f944 commit 676bef7
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 77 deletions.
18 changes: 8 additions & 10 deletions src/color/alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ mod core_impls {

impl fmt::Display for Alpha {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Alpha::*;
write!(
f,
"{}",
match self {
Opaque => "Opaque",
Transparent => "Transparent",
Blend => "Blend",
HighContrast => "HighContrast",
Alpha::Opaque => "Opaque",
Alpha::Transparent => "Transparent",
Alpha::Blend => "Blend",
Alpha::HighContrast => "HighContrast",
}
)
}
Expand Down Expand Up @@ -92,12 +91,11 @@ mod core_impls {
impl Alpha {
/// Displays the short name identifier of the alpha value.
pub fn display_short(&self) -> &str {
use Alpha::*;
match self {
Blend => "B",
HighContrast => "H",
Opaque => "O",
Transparent => "T",
Alpha::Blend => "B",
Alpha::HighContrast => "H",
Alpha::Opaque => "O",
Alpha::Transparent => "T",
}
}
}
7 changes: 3 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ mod core_impls {

impl fmt::Display for NotcursesError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use NotcursesError::*;
match self {
NcError(e) => e.fmt(f),
IoError(e) => e.fmt(f),
Message(string) => write!(f, "Message: {}", string),
NotcursesError::NcError(e) => e.fmt(f),
NotcursesError::IoError(e) => e.fmt(f),
NotcursesError::Message(string) => write!(f, "Message: {}", string),
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/input/input_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ mod core_impls {

impl fmt::Display for InputType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use InputType::*;
write!(
f,
"{}",
match self {
Unknown => "Unknown",
Press => "Press",
Repeat => "Repeat",
Release => "Release",
InputType::Unknown => "Unknown",
InputType::Press => "Press",
InputType::Repeat => "Repeat",
InputType::Release => "Release",
}
)
}
Expand Down
14 changes: 6 additions & 8 deletions src/input/received.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,20 @@ mod core_impls {

impl fmt::Display for Received {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Received::*;
let string = match self {
Key(k) => format!["{k}"],
Char(c) => format!["{c:?}"],
NoInput => "NoInput".to_string(),
Received::Key(k) => format!["{k}"],
Received::Char(c) => format!["{c:?}"],
Received::NoInput => "NoInput".to_string(),
};
write!(f, "{}", string)
}
}
impl fmt::Debug for Received {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Received::*;
let string = match self {
Key(k) => format!["Key({k})"],
Char(c) => format!["Char({c:?})"],
NoInput => "NoInput".to_string(),
Received::Key(k) => format!["Key({k})"],
Received::Char(c) => format!["Char({c:?})"],
Received::NoInput => "NoInput".to_string(),
};
write!(f, "Received::{}", string)
}
Expand Down
19 changes: 9 additions & 10 deletions src/notcurses/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,16 @@ impl Capabilities {

/// Returns `true` if the provided [`Blitter`] is among the capabilities.
pub fn can_blitter(&self, blitter: Blitter) -> bool {
use Blitter::*;
match blitter {
Default => true,
Ascii => true,
Half => self.halfblock,
Quadrant => self.quadrant,
Sextant => self.sextant,
Braille => self.braille,
Pixel => self.pixel,
_4x1 => self.utf8,
_8x1 => self.utf8,
Blitter::Default => true,
Blitter::Ascii => true,
Blitter::Half => self.halfblock,
Blitter::Quadrant => self.quadrant,
Blitter::Sextant => self.sextant,
Blitter::Braille => self.braille,
Blitter::Pixel => self.pixel,
Blitter::_4x1 => self.utf8,
Blitter::_8x1 => self.utf8,
}
}

Expand Down
19 changes: 9 additions & 10 deletions src/notcurses/log_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,19 @@ mod core_impls {

impl fmt::Display for LogLevel {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use LogLevel::*;
write!(
f,
"{}",
match self {
Silent => "Silent",
Panic => "Panic",
Fatal => "Fatal",
Error => "Error",
Warning => "Warning",
Info => "Info",
Verbose => "Verbose",
Debug => "Debug",
Trace => "Trace",
LogLevel::Silent => "Silent",
LogLevel::Panic => "Panic",
LogLevel::Fatal => "Fatal",
LogLevel::Error => "Error",
LogLevel::Warning => "Warning",
LogLevel::Info => "Info",
LogLevel::Verbose => "Verbose",
LogLevel::Debug => "Debug",
LogLevel::Trace => "Trace",
}
)
}
Expand Down
9 changes: 4 additions & 5 deletions src/plane/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ mod core_impls {

impl fmt::Display for Align {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Align::*;
write!(
f,
"{}",
match self {
Left => "Left",
Center => "Center",
Right => "Right",
Unaligned => "Unaligned",
Align::Left => "Left",
Align::Center => "Center",
Align::Right => "Right",
Align::Unaligned => "Unaligned",
}
)
}
Expand Down
34 changes: 16 additions & 18 deletions src/visual/blitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,19 @@ mod core_impls {

impl fmt::Display for Blitter {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Blitter::*;
write!(
f,
"{}",
match self {
Default => "Default",
Ascii => "Ascii",
Half => "Half",
Quadrant => "Quadrant",
Sextant => "Sextant",
Braille => "Braille",
Pixel => "Pixel",
_4x1 => "4x1",
_8x1 => "8x1",
Blitter::Default => "Default",
Blitter::Ascii => "Ascii",
Blitter::Half => "Half",
Blitter::Quadrant => "Quadrant",
Blitter::Sextant => "Sextant",
Blitter::Braille => "Braille",
Blitter::Pixel => "Pixel",
Blitter::_4x1 => "4x1",
Blitter::_8x1 => "8x1",
}
)
}
Expand Down Expand Up @@ -195,15 +194,14 @@ impl Blitter {
///
/// Default & Pixel returns `None`.
pub const fn cell_size(&self) -> Option<(u8, u8)> {
use Blitter::*;
match self {
Ascii => Some((1, 1)),
Half => Some((1, 2)),
Quadrant => Some((2, 2)),
Sextant => Some((2, 3)),
Braille => Some((2, 4)),
_4x1 => Some((1, 4)),
_8x1 => Some((1, 8)),
Blitter::Ascii => Some((1, 1)),
Blitter::Half => Some((1, 2)),
Blitter::Quadrant => Some((2, 2)),
Blitter::Sextant => Some((2, 3)),
Blitter::Braille => Some((2, 4)),
Blitter::_4x1 => Some((1, 4)),
Blitter::_8x1 => Some((1, 8)),
_ => None, // Default, Pixel, …
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/visual/pixel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,17 @@ mod core_impls {

impl fmt::Display for PixelImplementation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use PixelImplementation::*;
write!(
f,
"{}",
match self {
PixelImplementation::None => "None",
Sixel => "Sixel",
LinuxFb => "LinuxFb",
Iterm2 => "Iterm2",
KittyStatic => "KittyStatic",
KittyAnimated => "KittyAnimated",
KittySelfRef => "KittySelfRef",
PixelImplementation::Sixel => "Sixel",
PixelImplementation::LinuxFb => "LinuxFb",
PixelImplementation::Iterm2 => "Iterm2",
PixelImplementation::KittyStatic => "KittyStatic",
PixelImplementation::KittyAnimated => "KittyAnimated",
PixelImplementation::KittySelfRef => "KittySelfRef",
}
)
}
Expand Down

0 comments on commit 676bef7

Please sign in to comment.