From 0b5e9a5f442205a7c5bec3a24ae2c1d2b3672b99 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 19 Apr 2025 10:42:30 +0300 Subject: [PATCH] add Function to Value --- src/types.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/types.rs b/src/types.rs index 2b46b99..57493ab 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,4 +1,4 @@ -use std::{cell::RefCell, collections::HashMap, hash::Hash, rc::Rc}; +use std::{cell::RefCell, collections::HashMap, fmt::Debug, hash::Hash, rc::Rc}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum ValueInner { @@ -6,6 +6,7 @@ pub enum ValueInner { Number(i64), String(String), Table(Table), + Function(Function), } macro_rules! impl_from { @@ -75,3 +76,29 @@ impl Table { } } } + +#[derive(Clone)] +pub struct Function { + name: &'static str, + inner: Rc Value>, +} + +impl Debug for Function { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "", self.name) + } +} + +impl PartialEq for Function { + fn eq(&self, other: &Self) -> bool { + std::ptr::eq(self.inner.as_ref(), other.inner.as_ref()) + } +} + +impl Eq for Function {} + +impl Hash for Function { + fn hash(&self, state: &mut H) { + std::ptr::hash(self.inner.as_ref(), state) + } +}