cynic_parser/common/
int_value.rs

1/// An integer value
2///
3/// The GraphQl Int scalar is an i32, however the GraphQl language doesn't
4/// impose specific limits on integers.  Currently cynic-parser represents
5/// an IntValue as an i64, but we hide this fact behind a newtype to allow
6/// us to change the internal representaiton later if we need to.
7#[derive(Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
8pub struct IntValue(pub(crate) i64);
9
10impl IntValue {
11    pub fn as_i64(&self) -> i64 {
12        self.0
13    }
14
15    pub fn as_i32(&self) -> i32 {
16        self.0 as i32
17    }
18}
19
20impl std::fmt::Debug for IntValue {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        write!(f, "{}", self.0)
23    }
24}
25
26impl std::fmt::Display for IntValue {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        write!(f, "{}", self.0)
29    }
30}