Trait OnionObjectExt

Source
pub trait OnionObjectExt:
    GCTraceable<OnionObjectCell>
    + Debug
    + Send
    + Sync
    + 'static {
Show 33 methods // Required methods fn as_any(&self) -> &dyn Any; fn upgrade(&self, collected: &mut Vec<GCArc<OnionObjectCell>>); fn equals(&self, other: &OnionObject) -> Result<bool, RuntimeError>; // Provided methods fn to_integer(&self) -> Result<i64, RuntimeError> { ... } fn to_float(&self) -> Result<f64, RuntimeError> { ... } fn to_string( &self, ptrs: &Vec<*const OnionObject>, ) -> Result<String, RuntimeError> { ... } fn to_bytes(&self) -> Result<Box<[u8]>, RuntimeError> { ... } fn to_boolean(&self) -> Result<bool, RuntimeError> { ... } fn repr( &self, ptrs: &Vec<*const OnionObject>, ) -> Result<String, RuntimeError> { ... } fn type_of(&self) -> Result<String, RuntimeError> { ... } fn len(&self) -> Result<OnionStaticObject, RuntimeError> { ... } fn contains(&self, other: &OnionObject) -> Result<bool, RuntimeError> { ... } fn apply( &self, value: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError> { ... } fn key_of(&self) -> Result<OnionStaticObject, RuntimeError> { ... } fn value_of(&self) -> Result<OnionStaticObject, RuntimeError> { ... } fn with_attribute( &self, key: &OnionObject, f: &mut dyn FnMut(&OnionObject) -> Result<(), RuntimeError>, ) -> Result<(), RuntimeError> { ... } fn binary_eq(&self, other: &OnionObject) -> Result<bool, RuntimeError> { ... } fn binary_lt(&self, other: &OnionObject) -> Result<bool, RuntimeError> { ... } fn binary_gt(&self, other: &OnionObject) -> Result<bool, RuntimeError> { ... } fn binary_add( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError> { ... } fn binary_sub( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError> { ... } fn binary_mul( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError> { ... } fn binary_div( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError> { ... } fn binary_mod( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError> { ... } fn binary_pow( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError> { ... } fn binary_and( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError> { ... } fn binary_or( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError> { ... } fn binary_xor( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError> { ... } fn binary_shl( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError> { ... } fn binary_shr( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError> { ... } fn unary_neg(&self) -> Result<OnionStaticObject, RuntimeError> { ... } fn unary_plus(&self) -> Result<OnionStaticObject, RuntimeError> { ... } fn unary_not(&self) -> Result<OnionStaticObject, RuntimeError> { ... }
}
Expand description

Onion 对象扩展 trait。

定义了所有自定义对象类型必须实现的接口,提供完整的对象行为规范。 支持类型内省、GC 管理、类型转换、运算操作等功能。

§核心功能分类

§类型内省与 GC 管理

  • as_any(): 类型向下转换支持
  • upgrade(): GC 弱引用升级

§基础类型转换

  • to_integer(), to_float(), to_string()
  • to_boolean(): 布尔值转换
  • repr(): 调试表示
  • type_of(): 类型名称

§容器操作

  • len(): 长度获取
  • contains(): 包含关系检查
  • apply(): 函数应用

§键值操作

  • key_of(), value_of(): 键值提取
  • with_attribute(): 属性访问

§比较操作

  • equals(): 值相等性比较(必须实现)
  • is_same(): 引用相等性比较(必须实现)
  • binary_eq(), binary_lt(), binary_gt(): 二元比较

§算术运算

  • binary_add(), binary_sub(), binary_mul(), binary_div(): 四则运算
  • binary_mod(), binary_pow(): 取模与幂运算

§逻辑运算

  • binary_and(), binary_or(), binary_xor(): 位运算
  • binary_shl(), binary_shr(): 位移运算

§一元运算

  • unary_neg(): 负号运算
  • unary_not(): 逻辑非运算

§实现注意事项

  • 所有方法都有默认的错误实现
  • 只需要重写适用于特定类型的方法
  • 必须实现 equals()is_same() 方法
  • 所有实现都应该是线程安全的

§错误处理

大部分方法默认返回 InvalidTypeInvalidOperation 错误, 具体类型应该重写相关方法提供正确的实现。

Required Methods§

Source

fn as_any(&self) -> &dyn Any

Source

fn upgrade(&self, collected: &mut Vec<GCArc<OnionObjectCell>>)

Source

fn equals(&self, other: &OnionObject) -> Result<bool, RuntimeError>

Provided Methods§

Source

fn to_integer(&self) -> Result<i64, RuntimeError>

Source

fn to_float(&self) -> Result<f64, RuntimeError>

Source

fn to_string( &self, ptrs: &Vec<*const OnionObject>, ) -> Result<String, RuntimeError>

Source

fn to_bytes(&self) -> Result<Box<[u8]>, RuntimeError>

Source

fn to_boolean(&self) -> Result<bool, RuntimeError>

Source

fn repr(&self, ptrs: &Vec<*const OnionObject>) -> Result<String, RuntimeError>

Source

fn type_of(&self) -> Result<String, RuntimeError>

Source

fn len(&self) -> Result<OnionStaticObject, RuntimeError>

Source

fn contains(&self, other: &OnionObject) -> Result<bool, RuntimeError>

Source

fn apply(&self, value: &OnionObject) -> Result<OnionStaticObject, RuntimeError>

Source

fn key_of(&self) -> Result<OnionStaticObject, RuntimeError>

Source

fn value_of(&self) -> Result<OnionStaticObject, RuntimeError>

Source

fn with_attribute( &self, key: &OnionObject, f: &mut dyn FnMut(&OnionObject) -> Result<(), RuntimeError>, ) -> Result<(), RuntimeError>

Source

fn binary_eq(&self, other: &OnionObject) -> Result<bool, RuntimeError>

Source

fn binary_lt(&self, other: &OnionObject) -> Result<bool, RuntimeError>

Source

fn binary_gt(&self, other: &OnionObject) -> Result<bool, RuntimeError>

Source

fn binary_add( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError>

Source

fn binary_sub( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError>

Source

fn binary_mul( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError>

Source

fn binary_div( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError>

Source

fn binary_mod( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError>

Source

fn binary_pow( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError>

Source

fn binary_and( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError>

Source

fn binary_or( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError>

Source

fn binary_xor( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError>

Source

fn binary_shl( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError>

Source

fn binary_shr( &self, other: &OnionObject, ) -> Result<OnionStaticObject, RuntimeError>

Source

fn unary_neg(&self) -> Result<OnionStaticObject, RuntimeError>

Source

fn unary_plus(&self) -> Result<OnionStaticObject, RuntimeError>

Source

fn unary_not(&self) -> Result<OnionStaticObject, RuntimeError>

Implementors§