mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-25 05:22:52 +00:00
35 lines
898 B
Rust
35 lines
898 B
Rust
use super::{Iface, IfaceChecker};
|
|
use crate::ty::def::*;
|
|
|
|
pub trait SelectChecker: TyCtx {
|
|
fn select(&mut self, sig: Iface, key: &Interned<str>, pol: bool);
|
|
}
|
|
|
|
impl Ty {
|
|
/// Select the given type with the given key.
|
|
pub fn select(&self, key: &Interned<str>, pol: bool, checker: &mut impl SelectChecker) {
|
|
SelectKeyChecker(checker, key).ty(self, pol);
|
|
}
|
|
}
|
|
|
|
#[derive(BindTyCtx)]
|
|
#[bind(0)]
|
|
pub struct SelectKeyChecker<'a, T: TyCtx>(&'a mut T, &'a Interned<str>);
|
|
|
|
impl<T: SelectChecker> SelectKeyChecker<'_, T> {
|
|
fn ty(&mut self, ty: &Ty, pol: bool) {
|
|
ty.iface_surface(pol, self)
|
|
}
|
|
}
|
|
|
|
impl<T: SelectChecker> IfaceChecker for SelectKeyChecker<'_, T> {
|
|
fn check(
|
|
&mut self,
|
|
iface: Iface,
|
|
_ctx: &mut super::IfaceCheckContext,
|
|
pol: bool,
|
|
) -> Option<()> {
|
|
self.0.select(iface, self.1, pol);
|
|
Some(())
|
|
}
|
|
}
|