bluejay_visibility/
input_fields_definition.rs

1use crate::{Cache, InputValueDefinition, Warden};
2use bluejay_core::definition::{self, SchemaDefinition};
3use bluejay_core::AsIter;
4use once_cell::unsync::OnceCell;
5
6pub struct InputFieldsDefinition<'a, S: SchemaDefinition, W: Warden<SchemaDefinition = S>> {
7    inner: &'a S::InputFieldsDefinition,
8    cache: &'a Cache<'a, S, W>,
9    input_fields_definition: OnceCell<Vec<InputValueDefinition<'a, S, W>>>,
10}
11
12impl<'a, S: SchemaDefinition, W: Warden<SchemaDefinition = S>> InputFieldsDefinition<'a, S, W> {
13    pub(crate) fn new(inner: &'a S::InputFieldsDefinition, cache: &'a Cache<'a, S, W>) -> Self {
14        Self {
15            inner,
16            cache,
17            input_fields_definition: OnceCell::new(),
18        }
19    }
20}
21
22impl<'a, S: SchemaDefinition + 'a, W: Warden<SchemaDefinition = S>> AsIter
23    for InputFieldsDefinition<'a, S, W>
24{
25    type Item = InputValueDefinition<'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.input_fields_definition
33            .get_or_init(|| {
34                self.inner
35                    .iter()
36                    .filter_map(|ivd| InputValueDefinition::new(ivd, self.cache))
37                    .collect()
38            })
39            .iter()
40    }
41}
42
43impl<'a, S: SchemaDefinition + 'a, W: Warden<SchemaDefinition = S>>
44    definition::InputFieldsDefinition for InputFieldsDefinition<'a, S, W>
45{
46    type InputValueDefinition = InputValueDefinition<'a, S, W>;
47}