Skip to content

Commit 4e9aa73

Browse files
authored
Make clap styles const (#639)
make clap styles const instead of computing in runtime on every place.
1 parent 8f5f37b commit 4e9aa73

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

src/main.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,28 @@ static SPONSOR_MESSAGE: &str = cstr!(
9292
);
9393

9494
#[mutants::skip] // only visual effects, not worth testing
95-
fn clap_styles() -> Styles {
96-
styling::Styles::styled()
97-
.header(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
98-
.usage(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
99-
.literal(styling::AnsiColor::Blue.on_default() | styling::Effects::BOLD)
100-
.placeholder(styling::AnsiColor::Cyan.on_default())
101-
}
95+
const CLAP_STYLES: Styles = Styles::styled()
96+
.header(
97+
styling::AnsiColor::Green
98+
.on_default()
99+
.effects(styling::Effects::BOLD),
100+
)
101+
.usage(
102+
styling::AnsiColor::Green
103+
.on_default()
104+
.effects(styling::Effects::BOLD),
105+
)
106+
.literal(
107+
styling::AnsiColor::Blue
108+
.on_default()
109+
.effects(styling::Effects::BOLD),
110+
)
111+
.placeholder(styling::AnsiColor::Cyan.on_default());
102112

103113
#[derive(Parser)]
104-
#[command(name = "cargo", bin_name = "cargo", styles(clap_styles()))]
114+
#[command(name = "cargo", bin_name = "cargo", styles(CLAP_STYLES))]
105115
enum Cargo {
106-
#[command(name = "mutants", styles(clap_styles()))]
116+
#[command(name = "mutants", styles(CLAP_STYLES))]
107117
Mutants(Args),
108118
}
109119

@@ -132,7 +142,7 @@ pub enum SchemaType {
132142
author,
133143
about,
134144
after_help = SPONSOR_MESSAGE,
135-
styles(clap_styles())
145+
styles(CLAP_STYLES)
136146
)]
137147
pub struct Args {
138148
// Note: Please keep args grouped within the source by their "help_heading", with the headings

0 commit comments

Comments
 (0)