Struct OnionTuple

Source
pub struct OnionTuple { /* private fields */ }
Expand description

Onion 元组类型。

封装有序对象集合,支持高效的索引访问与属性查找。

§字段

  • elements: 元组元素的有序对象数组

Implementations§

Source§

impl OnionTuple

Source

pub fn new(elements: Vec<OnionObject>) -> Self

创建新的元组。

§参数
  • elements: 元组元素对象列表
§返回

新的元组实例

Source

pub fn new_static(elements: Vec<&OnionStaticObject>) -> OnionStaticObject

创建静态元组对象(元素为静态对象)。

§参数
  • elements: 静态对象引用列表
§返回

稳定化后的静态元组对象

Source

pub fn new_static_no_ref(elements: &Vec<OnionStaticObject>) -> OnionStaticObject

创建静态元组对象(元素为静态对象,参数为 Vec 所有权)。

§参数
  • elements: 静态对象列表
§返回

稳定化后的静态元组对象

Source

pub fn new_from_slice(elements: &[OnionStaticObject]) -> OnionStaticObject

创建静态元组对象(元素为静态对象,参数为切片)。

§参数
  • elements: 静态对象切片
§返回

稳定化后的静态元组对象

Source

pub fn get_elements(&self) -> &[OnionObject]

获取元组元素的引用。

Source

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

升级元组中所有元素的对象引用。

用于 GC 跟踪,防止元素被提前回收。

Source

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

获取元组长度。

§返回

元组长度的静态整数对象

Source

pub fn at(&self, index: i64) -> Result<OnionStaticObject, RuntimeError>

按索引访问元组元素。

§参数
  • index: 元组索引(从 0 开始)
§返回

对应索引的静态对象

§错误
  • InvalidOperation: 索引越界
Source

pub fn with_index<F, R>(&self, index: i64, f: &F) -> Result<R, RuntimeError>
where F: Fn(&OnionObject) -> Result<R, RuntimeError>,

按索引借用元组元素并应用函数。

§参数
  • index: 元组索引
  • f: 处理函数
§返回

处理函数的返回值

§错误
  • InvalidOperation: 索引越界
Source

pub fn with_attribute<F, R>( &self, key: &OnionObject, f: &F, ) -> Result<R, RuntimeError>
where F: Fn(&OnionObject) -> Result<R, RuntimeError>,

按属性名查找元组中的键值对元素。

§参数
  • key: 属性名对象
  • f: 处理函数,对应值作为参数
§返回
  • Ok(R): 查找成功,返回处理函数结果
  • Err(RuntimeError): 未找到属性
Source

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

元组拼接(二元加法)。

§参数
  • other: 另一个元组对象
§返回

拼接后的新元组对象

Source

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

判断元组是否包含指定对象。

§参数
  • other: 要查找的对象
§返回
  • true: 包含
  • false: 不包含
Source§

impl OnionTuple

Source

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

Trait Implementations§

Source§

impl Clone for OnionTuple

Source§

fn clone(&self) -> OnionTuple

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OnionTuple

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl GCTraceable<OnionObjectCell> for OnionTuple

Source§

fn collect(&self, queue: &mut VecDeque<GCArcWeak<OnionObjectCell>>)

collects all reachable objects and adds them to the provided queue.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.