use crate::format::{LangItemEntry, LangItemKind, TyDefId};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RawLangItem {
pub kind: LangItemKind,
pub ty_def: TyDefId,
pub def_index: Option<u32>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct LangItemView {
pub kind: LangItemKind,
pub ty_def: TyDefId,
pub def_index: Option<u32>,
}
impl LangItemView {
#[inline]
pub const fn from_raw(raw: LangItemEntry) -> Self {
Self { kind: raw.lang_kind(), ty_def: raw.ty_def_id(), def_index: raw.def_index() }
}
}
#[derive(Debug, Clone, Copy)]
pub struct LangItemIter<'a> {
entries: &'a [LangItemEntry],
}
impl<'a> LangItemIter<'a> {
#[inline]
pub const fn new(entries: &'a [LangItemEntry]) -> Self {
Self { entries }
}
#[inline]
pub const fn len(&self) -> usize {
self.entries.len()
}
#[inline]
pub const fn is_empty(&self) -> bool {
self.entries.is_empty()
}
}
impl Iterator for LangItemIter<'_> {
type Item = LangItemView;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
let (&first, rest) = self.entries.split_first()?;
self.entries = rest;
Some(LangItemView::from_raw(first))
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(self.entries.len(), Some(self.entries.len()))
}
}
impl ExactSizeIterator for LangItemIter<'_> {}