diff options
Diffstat (limited to 'src/eval/class.rs')
| -rw-r--r-- | src/eval/class.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/eval/class.rs b/src/eval/class.rs index 28e49a99..5601fb0b 100644 --- a/src/eval/class.rs +++ b/src/eval/class.rs @@ -1,3 +1,4 @@ +use std::any::TypeId; use std::fmt::{self, Debug, Formatter, Write}; use std::hash::{Hash, Hasher}; @@ -36,6 +37,7 @@ use crate::diag::TypResult; #[derive(Clone)] pub struct Class { name: &'static str, + id: TypeId, construct: fn(&mut Vm, &mut Args) -> TypResult<Value>, set: fn(&mut Args, &mut StyleMap) -> TypResult<()>, } @@ -48,6 +50,7 @@ impl Class { { Self { name, + id: TypeId::of::<T>(), construct: |ctx, args| { let mut styles = StyleMap::new(); T::set(args, &mut styles)?; @@ -63,6 +66,11 @@ impl Class { self.name } + /// The type id of the class. + pub fn id(&self) -> TypeId { + self.id + } + /// Return the class constructor as a function. pub fn constructor(&self) -> Func { Func::native(self.name, self.construct) |
