bluejay_visibility/
interface_implementations.rs1use crate::{Cache, InterfaceImplementation, Warden};
2use bluejay_core::definition::{self, SchemaDefinition};
3use bluejay_core::AsIter;
4use once_cell::unsync::OnceCell;
5
6pub struct InterfaceImplementations<'a, S: SchemaDefinition, W: Warden<SchemaDefinition = S>> {
7 inner: &'a S::InterfaceImplementations,
8 cache: &'a Cache<'a, S, W>,
9 interface_implementations: OnceCell<Vec<InterfaceImplementation<'a, S, W>>>,
10}
11
12impl<'a, S: SchemaDefinition, W: Warden<SchemaDefinition = S>> InterfaceImplementations<'a, S, W> {
13 pub(crate) fn new(inner: &'a S::InterfaceImplementations, cache: &'a Cache<'a, S, W>) -> Self {
14 Self {
15 inner,
16 cache,
17 interface_implementations: OnceCell::new(),
18 }
19 }
20}
21
22impl<'a, S: SchemaDefinition + 'a, W: Warden<SchemaDefinition = S>> AsIter
23 for InterfaceImplementations<'a, S, W>
24{
25 type Item = InterfaceImplementation<'a, S, W>;
26 type Iterator<'b>
27 = std::slice::Iter<'b, Self::Item>
28 where
29 'a: 'b;
30
31 fn iter(&self) -> Self::Iterator<'_> {
32 self.interface_implementations
33 .get_or_init(|| {
34 self.inner
35 .iter()
36 .filter_map(|ii| InterfaceImplementation::new(ii, self.cache))
37 .collect()
38 })
39 .iter()
40 }
41}
42
43impl<'a, S: SchemaDefinition + 'a, W: Warden<SchemaDefinition = S>>
44 definition::InterfaceImplementations for InterfaceImplementations<'a, S, W>
45{
46 type InterfaceImplementation = InterfaceImplementation<'a, S, W>;
47}