use core::{fmt, iter::FusedIterator};
pub use codegen::*;
mod codegen;
pub fn from_str(name: &str) -> Option<crate::Srgb<u8>> {
COLORS.get(name).copied()
}
pub fn entries() -> Entries {
Entries {
iter: COLORS.entries(),
}
}
pub fn names() -> Names {
Names {
iter: COLORS.keys(),
}
}
pub fn colors() -> Colors {
Colors {
iter: COLORS.values(),
}
}
#[derive(Clone)]
pub struct Entries {
iter: phf::map::Entries<'static, &'static str, crate::Srgb<u8>>,
}
impl fmt::Debug for Entries {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.iter.fmt(f)
}
}
impl Iterator for Entries {
type Item = (&'static str, crate::Srgb<u8>);
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(&name, &color)| (name, color))
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}
impl DoubleEndedIterator for Entries {
fn next_back(&mut self) -> Option<Self::Item> {
self.iter.next_back().map(|(&name, &color)| (name, color))
}
}
impl ExactSizeIterator for Entries {}
impl FusedIterator for Entries {}
#[derive(Clone)]
pub struct Names {
iter: phf::map::Keys<'static, &'static str, crate::Srgb<u8>>,
}
impl fmt::Debug for Names {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.iter.fmt(f)
}
}
impl Iterator for Names {
type Item = &'static str;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().copied()
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}
impl DoubleEndedIterator for Names {
fn next_back(&mut self) -> Option<Self::Item> {
self.iter.next_back().copied()
}
}
impl ExactSizeIterator for Names {}
impl FusedIterator for Names {}
#[derive(Clone)]
pub struct Colors {
iter: phf::map::Values<'static, &'static str, crate::Srgb<u8>>,
}
impl fmt::Debug for Colors {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.iter.fmt(f)
}
}
impl Iterator for Colors {
type Item = crate::Srgb<u8>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().copied()
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}
impl DoubleEndedIterator for Colors {
fn next_back(&mut self) -> Option<Self::Item> {
self.iter.next_back().copied()
}
}
impl ExactSizeIterator for Colors {}
impl FusedIterator for Colors {}