Lines
0 %
Functions
use std::fmt::{Display, Formatter};
use serde::{Deserialize, Serialize};
use uniplate::derive::Uniplate;
use uniplate::{Biplate, Uniplate};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Uniplate)]
#[uniplate()]
pub enum Constant {
Int(i32),
Bool(bool),
}
impl TryFrom<Constant> for i32 {
type Error = &'static str;
fn try_from(value: Constant) -> Result<Self, Self::Error> {
match value {
Constant::Int(i) => Ok(i),
_ => Err("Cannot convert non-i32 Constant to i32"),
impl TryFrom<Constant> for bool {
Constant::Bool(b) => Ok(b),
_ => Err("Cannot convert non-bool Constant to bool"),
impl From<i32> for Constant {
fn from(i: i32) -> Self {
Constant::Int(i)
impl From<bool> for Constant {
fn from(b: bool) -> Self {
Constant::Bool(b)
impl Display for Constant {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match &self {
Constant::Int(i) => write!(f, "Int({})", i),
Constant::Bool(b) => write!(f, "Bool({})", b),