Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: reduce proc-macro dep strum #169

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ integration_test = []
[dependencies]
ansi-str = { version = "0.8", optional = true }
console = { version = "0.15", optional = true }
strum = "0.26"
strum_macros = "0.26"
unicode-width = "0.2"

[dev-dependencies]
Expand Down
34 changes: 31 additions & 3 deletions src/style/table.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use strum_macros::EnumIter;

/// Specify how comfy_table should arrange the content in your table.
///
/// ```
Expand Down Expand Up @@ -46,7 +44,7 @@ pub enum ContentArrangement {
/// | | | | The inner "+" chars are MiddleIntersections
/// +---+---+---+
/// ```
#[derive(Debug, PartialEq, Eq, Hash, EnumIter, Clone, Copy)]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum TableComponent {
LeftBorder,
RightBorder,
Expand All @@ -68,3 +66,33 @@ pub enum TableComponent {
BottomLeftCorner,
BottomRightCorner,
}

impl TableComponent {
const fn components() -> [TableComponent; 19] {
[
TableComponent::LeftBorder,
TableComponent::RightBorder,
TableComponent::TopBorder,
TableComponent::BottomBorder,
TableComponent::LeftHeaderIntersection,
TableComponent::HeaderLines,
TableComponent::MiddleHeaderIntersections,
TableComponent::RightHeaderIntersection,
TableComponent::VerticalLines,
TableComponent::HorizontalLines,
TableComponent::MiddleIntersections,
TableComponent::LeftBorderIntersections,
TableComponent::RightBorderIntersections,
TableComponent::TopBorderIntersections,
TableComponent::BottomBorderIntersections,
TableComponent::TopLeftCorner,
TableComponent::TopRightCorner,
TableComponent::BottomLeftCorner,
TableComponent::BottomRightCorner,
]
}

Comment on lines +71 to +93
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually implemented iterators for enums are usually a bad idea as it's really easy to forget to adjust them if new variants are added. And there's no way to throw a lint error for stuff like this.

Yes. This is the original reason we use a macro to generate.

I try to use an internal method return [TableComponent; 19] so that the compiler can help a bit.

pub fn iter() -> impl Iterator<Item = TableComponent> {
TableComponent::components().into_iter()
}
}
1 change: 0 additions & 1 deletion src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::slice::{Iter, IterMut};
use crossterm::terminal;
#[cfg(feature = "tty")]
use crossterm::tty::IsTty;
use strum::IntoEnumIterator;

use crate::cell::Cell;
use crate::column::Column;
Expand Down
Loading