Rust: impl IntoIterator for FlavourColours

This moves the `into_iter` method into the `IntoIterator` trait
implementation and switches to using values instead of references

Closes #28
This commit is contained in:
Carsten Kragelund 2022-10-26 22:55:10 +02:00 committed by Hamothy
parent b27829caea
commit 1684c22392

View file

@ -31,36 +31,39 @@ pub struct FlavourColours {
pub crust: Colour, pub crust: Colour,
} }
impl FlavourColours { impl IntoIterator for FlavourColours {
type Item = Colour;
type IntoIter = std::array::IntoIter<Self::Item, 26>;
/// Returns an iterator over the colours in the flavour. /// Returns an iterator over the colours in the flavour.
pub fn into_iter(&self) -> std::array::IntoIter<&Colour, 26> { fn into_iter(self) -> std::array::IntoIter<Colour, 26> {
[ [
&self.rosewater, self.rosewater,
&self.flamingo, self.flamingo,
&self.pink, self.pink,
&self.mauve, self.mauve,
&self.red, self.red,
&self.maroon, self.maroon,
&self.peach, self.peach,
&self.yellow, self.yellow,
&self.green, self.green,
&self.teal, self.teal,
&self.sky, self.sky,
&self.sapphire, self.sapphire,
&self.blue, self.blue,
&self.lavender, self.lavender,
&self.text, self.text,
&self.subtext1, self.subtext1,
&self.subtext0, self.subtext0,
&self.overlay2, self.overlay2,
&self.overlay1, self.overlay1,
&self.overlay0, self.overlay0,
&self.surface2, self.surface2,
&self.surface1, self.surface1,
&self.surface0, self.surface0,
&self.base, self.base,
&self.mantle, self.mantle,
&self.crust, self.crust,
] ]
.into_iter() .into_iter()
} }