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
31
32
use gc_derive::{Finalize, Trace};
use std::fmt::{Display, Formatter, Result};

#[derive(Clone, Debug, Trace, Finalize, PartialEq)]
/// A Javascript Constant
pub enum Const {
    /// A UTF-8 string, such as `"Hello, world"`
    String(String),
    // A 64-bit floating-point number, such as `3.1415`
    Num(f64),
    // A 32-bit integer, such as `42`
    Int(i32),
    // A boolean, which is either `true` or `false` and is used to check if criteria are met
    Bool(bool),
    // The `null` value, which represents a non-existant value
    Null,
    // The `undefined` value, which represents a field or index that doesn't exist
    Undefined,
}

impl Display for Const {
    fn fmt(&self, f: &mut Formatter) -> Result {
        match *self {
            Const::String(ref st) => write!(f, "\"{}\"", st),
            Const::Num(num) => write!(f, "{}", num),
            Const::Int(num) => write!(f, "{}", num),
            Const::Bool(v) => write!(f, "{}", v),
            Const::Null => write!(f, "null"),
            Const::Undefined => write!(f, "undefined"),
        }
    }
}