diff --git a/examples/term.rs b/examples/term.rs index d53986a..f592f5b 100644 --- a/examples/term.rs +++ b/examples/term.rs @@ -2,7 +2,7 @@ use catppuccin::Flavour; fn main() { // iterate over the four Catppuccin flavours. - for flavour in Flavour::into_iter() { + for flavour in Flavour::all() { println!("{}", flavour.name()); // iterate over the 26 colours in the flavour. diff --git a/src/flavour.rs b/src/flavour.rs index f1790cd..8a8bc5d 100644 --- a/src/flavour.rs +++ b/src/flavour.rs @@ -11,12 +11,12 @@ pub enum Flavour { macro_rules! impl_colour_method { ($x:ident) => ( - pub fn $x(self) -> $crate::Colour { + pub const fn $x(self) -> $crate::Colour { self.colours().$x } ); ($x:ident, $($y:ident),+ $(,)?) => ( - pub fn $x(self) -> $crate::Colour { + pub const fn $x(self) -> $crate::Colour { self.colours().$x } @@ -26,7 +26,7 @@ macro_rules! impl_colour_method { impl Flavour { /// Returns the name of the flavour in lowercase. - pub fn name(self) -> &'static str { + pub const fn name(self) -> &'static str { match self { Self::Latte => "latte", Self::Frappe => "frappe", @@ -35,7 +35,7 @@ impl Flavour { } } - pub fn colours(self) -> FlavourColours { + pub const fn colours(self) -> FlavourColours { match self { Self::Latte => FlavourColours { rosewater: Colour(220, 138, 120), @@ -153,8 +153,13 @@ impl Flavour { } /// Returns an iterator over the four delicious Catppuccin flavours. - pub fn into_iter() -> std::array::IntoIter { - [Self::Latte, Self::Frappe, Self::Macchiato, Self::Mocha].into_iter() + pub fn into_iter() -> std::array::IntoIter { + Self::all().into_iter() + } + + /// Returns an array of the four delicious Catppuccin flavours. + pub const fn all() -> [Self; 4] { + [Self::Latte, Self::Frappe, Self::Macchiato, Self::Mocha] } } diff --git a/src/lib.rs b/src/lib.rs index cbb37b7..6702e0a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,7 +77,7 @@ mod tests { /// Ensures flavours are iterated in the correct order. #[test] fn test_flavours_iter() { - let mut flavours = Flavour::into_iter(); + let mut flavours = Flavour::all().into_iter(); assert_eq!(flavours.next(), Some(Flavour::Latte)); assert_eq!(flavours.next(), Some(Flavour::Frappe)); assert_eq!(flavours.next(), Some(Flavour::Macchiato)); @@ -88,7 +88,7 @@ mod tests { /// Ensures colours within each flavour are iterated in the correct order. #[test] fn test_colours_iter() { - for flavour in Flavour::into_iter() { + for flavour in Flavour::all() { let colours = flavour.colours(); let mut colours_iter = colours.into_iter(); assert_eq!(colours_iter.next(), Some(colours.rosewater));