use crate as rune;
use crate::alloc::clone::TryClone;
use crate::alloc::fmt::TryWrite;
use crate::runtime::object::{RuneIter, RuneIterKeys, RuneValues};
use crate::runtime::{EnvProtocolCaller, Formatter, Object, Protocol, Value, VmResult};
use crate::{ContextError, Module};
#[rune::module(::std::object)]
pub fn module() -> Result<Module, ContextError> {
let mut m = Module::from_meta(self::module_meta)?;
m.ty::<Object>()?;
m.function_meta(Object::new__meta)?;
m.function_meta(Object::rune_with_capacity)?;
m.function_meta(Object::len__meta)?;
m.function_meta(Object::is_empty__meta)?;
m.function_meta(Object::rune_insert)?;
m.function_meta(remove__meta)?;
m.function_meta(Object::clear__meta)?;
m.function_meta(contains_key__meta)?;
m.function_meta(get__meta)?;
m.function_meta(partial_eq__meta)?;
m.implement_trait::<Object>(rune::item!(::std::cmp::PartialEq))?;
m.function_meta(eq__meta)?;
m.implement_trait::<Object>(rune::item!(::std::cmp::Eq))?;
m.function_meta(clone__meta)?;
m.implement_trait::<Object>(rune::item!(::std::clone::Clone))?;
m.function_meta(debug_fmt__meta)?;
m.function_meta(Object::rune_iter__meta)?;
m.function_meta(Object::rune_keys__meta)?;
m.function_meta(Object::rune_values__meta)?;
m.associated_function(&Protocol::INTO_ITER, Object::rune_iter)?;
m.ty::<RuneIter>()?;
m.function_meta(RuneIter::next__meta)?;
m.function_meta(RuneIter::size_hint__meta)?;
m.implement_trait::<RuneIter>(rune::item!(::std::iter::Iterator))?;
m.function_meta(RuneIter::len__meta)?;
m.implement_trait::<RuneIter>(rune::item!(::std::iter::ExactSizeIterator))?;
m.ty::<RuneIterKeys>()?;
m.function_meta(RuneIterKeys::next__meta)?;
m.function_meta(RuneIterKeys::size_hint__meta)?;
m.implement_trait::<RuneIterKeys>(rune::item!(::std::iter::Iterator))?;
m.function_meta(RuneIterKeys::len__meta)?;
m.implement_trait::<RuneIterKeys>(rune::item!(::std::iter::ExactSizeIterator))?;
m.ty::<RuneValues>()?;
m.function_meta(RuneValues::next__meta)?;
m.function_meta(RuneValues::size_hint__meta)?;
m.implement_trait::<RuneValues>(rune::item!(::std::iter::Iterator))?;
m.function_meta(RuneValues::len__meta)?;
m.implement_trait::<RuneValues>(rune::item!(::std::iter::ExactSizeIterator))?;
Ok(m)
}
#[rune::function(keep, instance)]
#[inline]
fn contains_key(object: &Object, key: &str) -> bool {
object.contains_key(key)
}
#[rune::function(keep, instance)]
#[inline]
fn remove(object: &mut Object, key: &str) -> Option<Value> {
object.remove(key)
}
#[rune::function(keep, instance)]
#[inline]
fn get(object: &Object, key: &str) -> Option<Value> {
object.get(key).cloned()
}
#[rune::function(keep, instance, protocol = PARTIAL_EQ)]
fn partial_eq(this: &Object, other: &Object) -> VmResult<bool> {
Object::partial_eq_with(this, other, &mut EnvProtocolCaller)
}
#[rune::function(keep, instance, protocol = EQ)]
fn eq(this: &Object, other: &Object) -> VmResult<bool> {
Object::eq_with(this, other, Value::eq_with, &mut EnvProtocolCaller)
}
#[rune::function(keep, instance, protocol = CLONE)]
fn clone(this: &Object) -> VmResult<Object> {
VmResult::Ok(vm_try!(this.try_clone()))
}
#[rune::function(keep, instance, protocol = DEBUG_FMT)]
#[inline]
fn debug_fmt(this: &Object, f: &mut Formatter) -> VmResult<()> {
vm_write!(f, "{this:?}")
}