tinymist_analysis/ty/
select.rs

1use super::{Iface, IfaceChecker};
2use crate::ty::def::*;
3
4/// A trait to check the select of a type.
5pub trait SelectChecker: TyCtx {
6    /// Checks the select of the given type.
7    fn select(&mut self, sig: Iface, key: &Interned<str>, pol: bool);
8}
9
10impl Ty {
11    /// Selects the given type with the given key.
12    pub fn select(&self, key: &Interned<str>, pol: bool, checker: &mut impl SelectChecker) {
13        SelectKeyChecker(checker, key).ty(self, pol);
14    }
15}
16
17/// A checker to check the select of a type.
18#[derive(BindTyCtx)]
19#[bind(0)]
20pub struct SelectKeyChecker<'a, T: TyCtx>(&'a mut T, &'a Interned<str>);
21
22/// A driver to check the select of a type.
23impl<T: SelectChecker> SelectKeyChecker<'_, T> {
24    fn ty(&mut self, ty: &Ty, pol: bool) {
25        ty.iface_surface(pol, self)
26    }
27}
28
29/// A checker to check the select of a type.
30impl<T: SelectChecker> IfaceChecker for SelectKeyChecker<'_, T> {
31    fn check(
32        &mut self,
33        iface: Iface,
34        _ctx: &mut super::IfaceCheckContext,
35        pol: bool,
36    ) -> Option<()> {
37        self.0.select(iface, self.1, pol);
38        Some(())
39    }
40}