cynic_parser_deser/value/
scalars.rs1use core::fmt;
2
3use cynic_parser::Span;
4
5#[derive(Clone, Copy)]
6pub struct IntValue {
7 pub(crate) value: i64,
8 pub(crate) span: Option<Span>,
9}
10
11impl IntValue {
12 pub fn as_i64(&self) -> i64 {
13 self.value
14 }
15
16 pub fn as_i32(&self) -> i32 {
17 self.value as i32
18 }
19
20 fn value(&self) -> i64 {
21 self.value
22 }
23
24 pub fn span(&self) -> Option<Span> {
25 self.span
26 }
27}
28
29impl PartialEq for IntValue {
30 fn eq(&self, other: &Self) -> bool {
31 self.value() == other.value()
32 }
33}
34
35impl Eq for IntValue {}
36
37impl std::fmt::Debug for IntValue {
38 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39 write!(f, "{}", self.value())
40 }
41}
42
43impl std::fmt::Display for IntValue {
44 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45 write!(f, "{}", self.value())
46 }
47}
48
49#[derive(Clone, Copy)]
50pub struct FloatValue {
51 pub(crate) value: f64,
52 pub(crate) span: Option<Span>,
53}
54
55impl FloatValue {
56 pub fn value(&self) -> f64 {
57 self.value
58 }
59
60 pub fn as_f64(&self) -> f64 {
61 self.value()
62 }
63
64 pub fn span(&self) -> Option<Span> {
65 self.span
66 }
67}
68
69impl PartialEq for FloatValue {
70 fn eq(&self, other: &Self) -> bool {
71 self.value() == other.value()
72 }
73}
74
75impl fmt::Debug for FloatValue {
76 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
77 write!(f, "{}", self.value())
78 }
79}
80
81impl fmt::Display for FloatValue {
82 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
83 write!(f, "{}", self.value())
84 }
85}
86
87#[derive(Clone, Copy)]
88pub struct StringValue<'a> {
89 pub(crate) value: &'a str,
90 pub(crate) span: Option<Span>,
91}
92
93impl<'a> StringValue<'a> {
94 pub fn value(&self) -> &'a str {
95 self.value
96 }
97
98 pub fn as_str(&self) -> &'a str {
99 self.value()
100 }
101
102 pub fn span(&self) -> Option<Span> {
103 self.span
104 }
105}
106
107impl PartialEq for StringValue<'_> {
108 fn eq(&self, other: &Self) -> bool {
109 self.value() == other.value()
110 }
111}
112
113impl Eq for StringValue<'_> {}
114
115impl fmt::Debug for StringValue<'_> {
116 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
117 write!(f, "{}", self.value())
118 }
119}
120
121impl fmt::Display for StringValue<'_> {
122 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
123 write!(f, "{}", self.value())
124 }
125}
126
127#[derive(Clone, Copy)]
128pub struct BooleanValue {
129 pub(crate) value: bool,
130 pub(crate) span: Option<Span>,
131}
132
133impl BooleanValue {
134 pub fn value(&self) -> bool {
135 self.value
136 }
137
138 pub fn as_bool(&self) -> bool {
139 self.value()
140 }
141
142 pub fn span(&self) -> Option<Span> {
143 self.span
144 }
145}
146
147impl PartialEq for BooleanValue {
148 fn eq(&self, other: &Self) -> bool {
149 self.value() == other.value()
150 }
151}
152
153impl Eq for BooleanValue {}
154
155impl fmt::Debug for BooleanValue {
156 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
157 write!(f, "{}", self.value())
158 }
159}
160
161impl fmt::Display for BooleanValue {
162 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
163 write!(f, "{}", self.value())
164 }
165}
166
167#[derive(Clone, Copy)]
168pub struct NullValue {
169 pub(crate) span: Option<Span>,
170}
171
172impl NullValue {
173 pub fn span(&self) -> Option<Span> {
174 self.span
175 }
176}
177
178impl PartialEq for NullValue {
179 fn eq(&self, _: &Self) -> bool {
180 true
181 }
182}
183
184impl Eq for NullValue {}
185
186impl fmt::Debug for NullValue {
187 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
188 write!(f, "null")
189 }
190}
191
192impl fmt::Display for NullValue {
193 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
194 write!(f, "null")
195 }
196}