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
use crate::expressions::Expression;
use crate::CodeBuffer;

/// Represents a literal expression.
pub struct LiteralExpression {
    literal: String,
}

impl From<String> for LiteralExpression {
    fn from(literal: String) -> Self {
        Self { literal }
    }
}

impl From<&str> for LiteralExpression {
    fn from(literal: &str) -> Self {
        Self {
            literal: literal.to_string(),
        }
    }
}

impl Expression for LiteralExpression {
    fn write(&self, b: &mut CodeBuffer) {
        b.write(self.literal.as_str());
    }
}