use crate::{Enum, EnumId, EnumVariant, EnumVariantId, Walker};
pub type EnumWalker<'a> = Walker<'a, EnumId>;
pub type EnumVariantWalker<'a> = Walker<'a, EnumVariantId>;
impl<'a> EnumWalker<'a> {
fn get(self) -> &'a Enum {
&self.schema.enums[self.id.0 as usize]
}
pub fn namespace(self) -> Option<&'a str> {
self.schema
.namespaces
.get(self.get().namespace_id.0 as usize)
.map(|s| s.as_str())
}
pub fn name(self) -> &'a str {
&self.get().name
}
pub fn variants(self) -> impl ExactSizeIterator<Item = EnumVariantWalker<'a>> {
super::range_for_key(&self.schema.enum_variants, self.id, |variant| variant.enum_id)
.map(move |idx| self.walk(EnumVariantId(idx as u32)))
}
pub fn values(self) -> impl ExactSizeIterator<Item = &'a str> {
super::range_for_key(&self.schema.enum_variants, self.id, |variant| variant.enum_id)
.map(move |idx| self.schema.enum_variants[idx].variant_name.as_str())
}
pub fn description(self) -> Option<&'a str> {
self.get().description.as_deref()
}
}
impl<'a> EnumVariantWalker<'a> {
fn get(self) -> &'a EnumVariant {
&self.schema.enum_variants[self.id.0 as usize]
}
pub fn r#enum(self) -> EnumWalker<'a> {
self.walk(self.get().enum_id)
}
pub fn name(self) -> &'a str {
&self.get().variant_name
}
}