From 26733820f88bc8b94d9977538f2663bde62b00cb Mon Sep 17 00:00:00 2001 From: quak Date: Tue, 17 Dec 2024 23:34:10 +0100 Subject: [PATCH] experimenting with various ideas to avoid repeating code in config.rs --- src/config.rs | 15 +++++++++++++++ src/format.rs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 1c23282..083db9e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,6 +10,21 @@ use std::fs; use std::io::{Error, Result}; use std::path::PathBuf; +// macro_rules! generate_field_names { +// ($(#[$attr:meta])* struct $name:ident { $($fname:ident : $ftype:ty),* }) => { +// $(#[$attr])* struct $name { +// $($fname : $ftype),* +// } + +// impl $name { +// fn field_names() -> &'static [&'static str] { +// static NAMES: &'static [&'static str] = &[$(stringify!($fname)),*]; +// NAMES +// } +// } +// } +// } + #[derive(Debug, Clone)] pub struct Config { conf_file: PathBuf, diff --git a/src/format.rs b/src/format.rs index 6581a0c..f2345aa 100644 --- a/src/format.rs +++ b/src/format.rs @@ -193,7 +193,7 @@ pub fn make_padding_string(len: usize) -> String { /// convert color setting to ansi escape sequence pub fn parse_color(color: String) -> Result { // check for numbered color - if let Ok(numbered) = color.parse::() { + if let Ok(numbered) = color.parse::() { // TODO: only accept numbers between 16 and 256 return Ok(generate_256color_sequence( ColorContext::Foreground, numbered,