use core::cmp::Ordering;
use crate as rune;
use crate::runtime::slice::Iter;
use crate::runtime::{
EnvProtocolCaller, Formatter, Hasher, OwnedTuple, Ref, Tuple, Value, Vec, VmResult,
};
use crate::{ContextError, Module};
#[rune::module(::std::tuple)]
pub fn module() -> Result<Module, ContextError> {
let mut m = Module::from_meta(self::module_meta)?;
m.ty::<OwnedTuple>()?.docs(docstring! {
})?;
m.function_meta(len)?;
m.function_meta(is_empty)?;
m.function_meta(get)?;
m.function_meta(iter)?;
m.function_meta(into_iter)?;
m.function_meta(partial_eq__meta)?;
m.implement_trait::<OwnedTuple>(rune::item!(::std::cmp::PartialEq))?;
m.function_meta(eq__meta)?;
m.implement_trait::<OwnedTuple>(rune::item!(::std::cmp::Eq))?;
m.function_meta(partial_cmp__meta)?;
m.implement_trait::<OwnedTuple>(rune::item!(::std::cmp::PartialOrd))?;
m.function_meta(cmp__meta)?;
m.implement_trait::<OwnedTuple>(rune::item!(::std::cmp::Ord))?;
m.function_meta(clone__meta)?;
m.implement_trait::<OwnedTuple>(rune::item!(::std::clone::Clone))?;
m.function_meta(hash__meta)?;
m.function_meta(debug_fmt__meta)?;
Ok(m)
}
#[rune::function(instance)]
fn len(this: &Tuple) -> usize {
this.len()
}
#[rune::function(instance)]
fn is_empty(this: &Tuple) -> bool {
this.is_empty()
}
#[rune::function(instance)]
fn get(this: &Tuple, index: Value) -> VmResult<Option<Value>> {
Vec::index_get(this, index)
}
#[rune::function(instance)]
fn iter(this: Ref<Tuple>) -> Iter {
Iter::new(Ref::map(this, |tuple| &**tuple))
}
#[rune::function(instance, instance, protocol = INTO_ITER)]
fn into_iter(this: Ref<Tuple>) -> Iter {
Iter::new(Ref::map(this, |tuple| &**tuple))
}
#[rune::function(keep, instance, protocol = PARTIAL_EQ)]
fn partial_eq(this: &Tuple, other: Value) -> VmResult<bool> {
Vec::partial_eq_with(this, other, &mut EnvProtocolCaller)
}
#[rune::function(keep, instance, protocol = EQ)]
fn eq(this: &Tuple, other: &Tuple) -> VmResult<bool> {
Vec::eq_with(this, other, Value::eq_with, &mut EnvProtocolCaller)
}
#[rune::function(keep, instance, protocol = PARTIAL_CMP)]
fn partial_cmp(this: &Tuple, other: &Tuple) -> VmResult<Option<Ordering>> {
Vec::partial_cmp_with(this, other, &mut EnvProtocolCaller)
}
#[rune::function(keep, instance, protocol = CMP)]
fn cmp(this: &Tuple, other: &Tuple) -> VmResult<Ordering> {
Vec::cmp_with(this, other, &mut EnvProtocolCaller)
}
#[rune::function(keep, instance, protocol = HASH)]
fn hash(this: &Tuple, hasher: &mut Hasher) -> VmResult<()> {
Tuple::hash_with(this, hasher, &mut EnvProtocolCaller)
}
#[rune::function(keep, instance, protocol = CLONE)]
fn clone(this: &Tuple) -> VmResult<OwnedTuple> {
VmResult::Ok(vm_try!(this.clone_with(&mut EnvProtocolCaller)))
}
#[rune::function(keep, instance, protocol = DEBUG_FMT)]
#[inline]
fn debug_fmt(this: &Tuple, f: &mut Formatter) -> VmResult<()> {
this.debug_fmt_with(f, &mut EnvProtocolCaller)
}