cynic_parser/executable/generated/
fragment.rs

1use super::prelude::*;
2use super::{
3    directive::Directive,
4    ids::{DirectiveId, FragmentDefinitionId, SelectionId},
5    selections::Selection,
6    ExecutableId,
7};
8#[allow(unused_imports)]
9use std::fmt::{self, Write};
10
11pub struct FragmentDefinitionRecord {
12    pub name: StringId,
13    pub name_span: Span,
14    pub type_condition: StringId,
15    pub type_condition_span: Span,
16    pub directives: IdRange<DirectiveId>,
17    pub selection_set: IdRange<SelectionId>,
18    pub selection_set_span: Span,
19}
20
21#[derive(Clone, Copy)]
22pub struct FragmentDefinition<'a>(pub(in super::super) ReadContext<'a, FragmentDefinitionId>);
23
24impl<'a> FragmentDefinition<'a> {
25    pub fn name(&self) -> &'a str {
26        let document = &self.0.document;
27        document.lookup(document.lookup(self.0.id).name)
28    }
29    pub fn name_span(&self) -> Span {
30        let document = self.0.document;
31        document.lookup(self.0.id).name_span
32    }
33    pub fn type_condition(&self) -> &'a str {
34        let document = &self.0.document;
35        document.lookup(document.lookup(self.0.id).type_condition)
36    }
37    pub fn type_condition_span(&self) -> Span {
38        let document = self.0.document;
39        document.lookup(self.0.id).type_condition_span
40    }
41    pub fn directives(&self) -> Iter<'a, Directive<'a>> {
42        let document = self.0.document;
43        super::Iter::new(document.lookup(self.0.id).directives, document)
44    }
45    pub fn selection_set(&self) -> Iter<'a, Selection<'a>> {
46        let document = self.0.document;
47        super::Iter::new(document.lookup(self.0.id).selection_set, document)
48    }
49    pub fn selection_set_span(&self) -> Span {
50        let document = self.0.document;
51        document.lookup(self.0.id).selection_set_span
52    }
53}
54
55impl FragmentDefinition<'_> {
56    pub fn id(&self) -> FragmentDefinitionId {
57        self.0.id
58    }
59}
60
61impl fmt::Debug for FragmentDefinition<'_> {
62    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63        f.debug_struct("FragmentDefinition")
64            .field("name", &self.name())
65            .field("type_condition", &self.type_condition())
66            .field("directives", &self.directives())
67            .field("selection_set", &self.selection_set())
68            .finish()
69    }
70}
71
72impl ExecutableId for FragmentDefinitionId {
73    type Reader<'a> = FragmentDefinition<'a>;
74    fn read(self, document: &ExecutableDocument) -> Self::Reader<'_> {
75        FragmentDefinition(ReadContext { id: self, document })
76    }
77}
78
79impl IdReader for FragmentDefinition<'_> {
80    type Id = FragmentDefinitionId;
81    type Reader<'a> = FragmentDefinition<'a>;
82    fn new(id: Self::Id, document: &'_ ExecutableDocument) -> Self::Reader<'_> {
83        document.read(id)
84    }
85}