use crate::named_entity::TypeEnt;
use crate::{AnyEnt, AnyEntKind, EntRef};
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct FileEnt<'a>(EntRef<'a>);
impl<'a> FileEnt<'a> {
pub fn from_any(ent: EntRef<'a>) -> Option<FileEnt<'a>> {
match ent.kind() {
AnyEntKind::File(_) | AnyEntKind::InterfaceFile(_) => Some(FileEnt(ent)),
_ => None,
}
}
pub fn inner(&self) -> EntRef<'a> {
self.0
}
pub fn type_mark(&self) -> TypeEnt<'a> {
match self.0.kind() {
AnyEntKind::File(subtype) => subtype.type_mark(),
AnyEntKind::InterfaceFile(typ) => *typ,
_ => unreachable!(),
}
}
}
impl<'a> std::ops::Deref for FileEnt<'a> {
type Target = AnyEnt<'a>;
fn deref(&self) -> EntRef<'a> {
self.inner()
}
}