use crate as rune;
use crate::alloc::fmt::TryWrite;
use crate::alloc::String;
use crate::runtime::{Formatter, Type, Value, VmResult};
use crate::{ContextError, Hash, Module};
#[rune::module(::std::any)]
pub fn module() -> Result<Module, ContextError> {
let mut m = Module::from_meta(self::module_meta)?;
m.ty::<Type>()?.docs(docstring! {
})?;
m.ty::<Hash>()?.docs(docstring! {
})?;
m.function_meta(type_of_val)?;
m.function_meta(type_name_of_val)?;
m.function_meta(format_type)?;
Ok(m)
}
#[rune::function(free, path = Type::of_val)]
#[inline]
fn type_of_val(value: Value) -> Type {
Type::new(value.type_hash())
}
#[rune::function(instance, protocol = DISPLAY_FMT)]
fn format_type(ty: Type, f: &mut Formatter) -> VmResult<()> {
vm_write!(f, "{:?}", ty)
}
#[rune::function]
#[inline]
pub fn type_name_of_val(value: Value) -> VmResult<String> {
value.into_type_name()
}