cynic_parser/values/
enums.rs1use crate::{AstLookup, Span};
2
3use super::{ids::ValueId, Cursor};
4
5#[derive(Clone, Copy)]
6pub struct EnumValue<'a>(pub(super) Cursor<'a, ValueId>);
7
8impl<'a> EnumValue<'a> {
9 pub fn name(&self) -> &'a str {
10 let store = self.0.store;
11 store.lookup(store.lookup(self.0.id).kind.as_enum_value().unwrap())
12 }
13
14 pub fn as_str(&self) -> &'a str {
15 self.name()
16 }
17
18 pub fn span(&self) -> Span {
19 let store = self.0.store;
20 store.lookup(self.0.id).span
21 }
22}
23
24impl EnumValue<'_> {
25 pub fn id(&self) -> ValueId {
26 self.0.id
27 }
28}
29
30impl PartialEq for EnumValue<'_> {
31 fn eq(&self, other: &Self) -> bool {
32 self.name() == other.name()
33 }
34}
35
36impl Eq for EnumValue<'_> {}
37
38impl std::fmt::Debug for EnumValue<'_> {
39 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40 write!(f, "{}", self.name())
41 }
42}
43
44impl std::fmt::Display for EnumValue<'_> {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 write!(f, "{}", self.name())
47 }
48}