rename and relocate iter methods
Co-authored-by: backwardspy <backwardspy@gmail.com> Co-authored-by: Carsten Kragelund <carsten@kragelund.dev>
This commit is contained in:
parent
309790a80f
commit
41035e40cd
4 changed files with 20 additions and 15 deletions
|
@ -1,12 +1,13 @@
|
|||
use catppuccin::flavours_iter;
|
||||
use catppuccin::Flavour;
|
||||
|
||||
|
||||
fn main() {
|
||||
// iterate over the four Catppuccin flavours.
|
||||
for flavour in flavours_iter() {
|
||||
for flavour in Flavour::into_iter() {
|
||||
println!("{}", flavour.name());
|
||||
|
||||
// iterate over the 26 colours in the flavour.
|
||||
for (i, colour) in flavour.palette().iter().enumerate() {
|
||||
for (i, colour) in flavour.palette().into_iter().enumerate() {
|
||||
print!("{}", colour.ansi_paint("██"));
|
||||
|
||||
// the 14 analogous colours go on one line,
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
use crate::{Colour, Palette};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
|
@ -132,9 +131,19 @@ impl Flavour {
|
|||
base: Colour(30, 30, 46),
|
||||
mantle: Colour(24, 24, 37),
|
||||
crust: Colour(17, 17, 27),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
/// Returns an iterator over the four delicious Catppuccin flavours.
|
||||
pub fn into_iter() -> std::array::IntoIter<Flavour, 4> {
|
||||
[
|
||||
Self::Latte,
|
||||
Self::Frappe,
|
||||
Self::Macchiato,
|
||||
Self::Mocha,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
|
@ -61,19 +61,14 @@ pub use palette::Palette;
|
|||
mod flavour;
|
||||
pub use flavour::Flavour;
|
||||
|
||||
/// Returns an iterator over the four delicious Catppuccin flavours.
|
||||
pub fn flavours_iter() -> std::array::IntoIter<Flavour, 4> {
|
||||
[Flavour::Latte, Flavour::Frappe, Flavour::Macchiato, Flavour::Mocha].into_iter()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{flavours_iter, Flavour};
|
||||
use super::Flavour;
|
||||
|
||||
/// Ensures flavours are iterated in the correct order.
|
||||
#[test]
|
||||
fn test_flavours_iter() {
|
||||
let mut flavours = flavours_iter();
|
||||
let mut flavours = Flavour::into_iter();
|
||||
assert_eq!(flavours.next(), Some(Flavour::Latte));
|
||||
assert_eq!(flavours.next(), Some(Flavour::Frappe));
|
||||
assert_eq!(flavours.next(), Some(Flavour::Macchiato));
|
||||
|
@ -84,9 +79,9 @@ mod tests {
|
|||
/// Ensures colours within each flavour are iterated in the correct order.
|
||||
#[test]
|
||||
fn test_colours_iter() {
|
||||
for flavour in flavours_iter() {
|
||||
for flavour in Flavour::into_iter() {
|
||||
let palette = flavour.palette();
|
||||
let mut colours = palette.iter();
|
||||
let mut colours = palette.into_iter();
|
||||
assert_eq!(colours.next(), Some(&palette.rosewater));
|
||||
assert_eq!(colours.next(), Some(&palette.flamingo));
|
||||
assert_eq!(colours.next(), Some(&palette.pink));
|
||||
|
|
|
@ -33,7 +33,7 @@ pub struct Palette {
|
|||
|
||||
impl Palette {
|
||||
/// Returns an iterator over the colours in the flavour.
|
||||
pub fn iter(&self) -> std::array::IntoIter<&Colour, 26> {
|
||||
pub fn into_iter(&self) -> std::array::IntoIter<&Colour, 26> {
|
||||
[
|
||||
&self.rosewater,
|
||||
&self.flamingo,
|
||||
|
|
Loading…
Reference in a new issue