Skip to main content

cynic_parser/executable/generated/
fragment.rs

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