cynic_parser/common/
int_value.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/// An integer value
///
/// The GraphQl Int scalar is an i32, however the GraphQl language doesn't
/// impose specific limits on integers.  Currently cynic-parser represents
/// an IntValue as an i64, but we hide this fact behind a newtype to allow
/// us to change the internal representaiton later if we need to.
#[derive(Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub struct IntValue(pub(crate) i64);

impl IntValue {
    pub fn as_i64(&self) -> i64 {
        self.0
    }

    pub fn as_i32(&self) -> i32 {
        self.0 as i32
    }
}

impl std::fmt::Debug for IntValue {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl std::fmt::Display for IntValue {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}