Skip to content

Commit d0c6ff5

Browse files
committed
feat: Using ref PaintType in make_styles trait method
1 parent bdd27b4 commit d0c6ff5

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/colors.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub trait Stylify {
2-
fn make_styles(&self, paint_type: Option<PaintType>) -> String;
2+
fn make_styles(&self, paint_type: Option<&PaintType>) -> String;
33
}
44
#[derive(Debug, Clone)]
55
pub enum PaintType {
@@ -16,7 +16,7 @@ pub enum Styles {
1616
}
1717

1818
impl Styles {
19-
fn make_styles(&self, paint_type: Option<PaintType>) -> String {
19+
pub fn make_styles(&self, paint_type: Option<&PaintType>) -> String {
2020
match self {
2121
Styles::StyleBasicColor(c) => c.make_styles(paint_type),
2222
Styles::StylePaintType(c) => c.make_styles(paint_type),
@@ -27,7 +27,7 @@ impl Styles {
2727
}
2828

2929
impl Stylify for PaintType {
30-
fn make_styles(&self, _paint_type: Option<PaintType>) -> String {
30+
fn make_styles(&self, _paint_type: Option<&PaintType>) -> String {
3131
String::new()
3232
}
3333
}
@@ -39,8 +39,8 @@ pub struct BasicColor {
3939

4040
impl Stylify for BasicColor {
4141
/// If the `is_foreground` was None it's assume as foreground
42-
fn make_styles(&self, paint_type: Option<PaintType>) -> String {
43-
let paint_type = paint_type.unwrap_or(PaintType::FG);
42+
fn make_styles(&self, paint_type: Option<&PaintType>) -> String {
43+
let paint_type = paint_type.unwrap_or(&PaintType::FG);
4444
format!("{}", match paint_type {
4545
PaintType::FG => self.fg,
4646
PaintType::BG => self.bg,
@@ -72,8 +72,8 @@ pub struct PaletteColor {
7272
}
7373

7474
impl Stylify for PaletteColor {
75-
fn make_styles(&self, paint_type: Option<PaintType>) -> String {
76-
let paint_type = paint_type.unwrap_or(PaintType::FG);
75+
fn make_styles(&self, paint_type: Option<&PaintType>) -> String {
76+
let paint_type = paint_type.unwrap_or(&PaintType::FG);
7777
format!(
7878
"{};5;{}",
7979
match paint_type {
@@ -92,8 +92,8 @@ pub struct Rgb {
9292
}
9393

9494
impl Stylify for Rgb {
95-
fn make_styles(&self, paint_type: Option<PaintType>) -> String {
96-
let paint_type = paint_type.unwrap_or(PaintType::FG);
95+
fn make_styles(&self, paint_type: Option<&PaintType>) -> String {
96+
let paint_type = paint_type.unwrap_or(&PaintType::FG);
9797
format!(
9898
"{};2;{};{};{}",
9999
match paint_type {
@@ -136,7 +136,7 @@ mod test {
136136

137137
#[test]
138138
fn paint_magenta_background() {
139-
let painted_bg = MAGENTA.make_styles(Some(PaintType::BG));
139+
let painted_bg = MAGENTA.make_styles(Some(&PaintType::BG));
140140

141141
assert_eq!("45", painted_bg)
142142
}
@@ -163,7 +163,7 @@ mod test {
163163
#[test]
164164
fn palette_paint_blue_bg() {
165165
let blue = PaletteColor { index: 33 };
166-
let painted_bg = blue.make_styles(Some(PaintType::BG));
166+
let painted_bg = blue.make_styles(Some(&PaintType::BG));
167167
assert_eq!("48;5;33", painted_bg)
168168
}
169169

@@ -193,7 +193,7 @@ mod test {
193193
#[test]
194194
fn rgb_paint_orange_bg() {
195195
let orange = Rgb { r: 219, g: 132, b: 50 };
196-
let painted_bg = orange.make_styles(Some(PaintType::BG));
196+
let painted_bg = orange.make_styles(Some(&PaintType::BG));
197197
assert_eq!("48;2;219;132;50", painted_bg)
198198
}
199199
}

0 commit comments

Comments
 (0)