Enum LambdaParameter

Source
pub enum LambdaParameter {
    Single((Box<str>, OnionObject)),
    Multiple(Box<[LambdaParameter]>),
}
Expand description

Lambda 参数定义。

支持单参数和多参数的递归结构:

  • Single: 单个参数,包含参数名和约束对象
  • Multiple: 多个参数,支持嵌套结构

§示例

// 单参数: x : Int
LambdaParameter::Single(("x".into(), OnionObject::Integer(0)))

// 多参数: (a : String, (b : Int, c : Bool))
LambdaParameter::Multiple(box [
    LambdaParameter::Single(("a".into(), OnionObject::String(...))),
    LambdaParameter::Multiple(box [...])
])

Variants§

§

Single((Box<str>, OnionObject))

单个参数:(参数名, 约束对象)

§

Multiple(Box<[LambdaParameter]>)

多个参数:递归参数列表

Implementations§

Source§

impl LambdaParameter

Source

pub fn top(key: &str) -> Self

创建 top 参数(约束为 true,顶类型)。

Source

pub fn bottom(key: &str) -> Self

创建 bottom 参数(约束为 false,底类型)。

Source§

impl LambdaParameter

Source

pub fn len(&self) -> usize

获取参数的总数量(扁平化后)。

递归计算所有嵌套参数的数量总和。

Source

pub fn constraint_at(&self, index: usize) -> Option<&OnionObject>

按扁平化顺序获取指定索引的参数约束定义。

§参数
  • index: 扁平化后的参数索引
§返回
  • Some(&OnionObject): 对应位置的约束对象
  • None: 索引超出范围
Source

pub fn key_at(&self, index: usize) -> Option<&str>

按扁平化顺序获取指定索引的参数名。

Source

pub fn at(&self, index: usize) -> Option<(&str, &OnionObject)>

按扁平化顺序获取指定索引的参数名和约束。

Source

pub fn to_onion(&self) -> OnionStaticObject

将参数结构打包为 Onion 对象。

  • 单参数打包为 Pair 对象
  • 多参数打包为 Tuple 对象,递归处理嵌套结构
§返回

稳定化的 Onion 对象,可用于序列化或传输

Source

pub fn from_onion(obj: &OnionObject) -> Result<LambdaParameter, RuntimeError>

从 Onion 对象解析参数结构。

支持从 Pair、Tuple、String 等对象解析参数:

  • Pair: 解析为单参数
  • Tuple: 解析为多参数,递归处理
  • String: 解析为简单参数(约束为 true)
§错误

当对象格式不符合预期时返回 RuntimeError::InvalidType

Source§

impl LambdaParameter

Source

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

升级参数中的弱引用为强引用。

遍历参数结构,将所有对象的弱引用升级为强引用, 防止在垃圾回收过程中被意外回收。

Source§

impl LambdaParameter

Source

pub fn unpack_arguments( &self, argument: &OnionObject, ) -> Result<Vec<OnionObject>, RuntimeError>

根据参数结构解包实际参数。

将传入的参数对象按照当前参数结构进行解包:

  • 单参数:直接接受任意对象
  • 多参数:要求传入 Tuple,且元素数量匹配
§参数
  • argument: 待解包的参数对象
§返回

解包后的参数列表,按扁平化顺序排列

§错误
  • Arity Mismatch: 参数数量不匹配
  • InvalidType: 期望 Tuple 但传入其他类型
Source§

impl LambdaParameter

Source

pub fn flatten_keys(&self) -> Box<[Box<str>]>

递归扁平化参数结构,生成参数名列表。

将嵌套的参数结构展开为一维的参数名列表。 例如:(a, (b, c)) 会返回 ["a", "b", "c"]

§返回

按深度优先顺序排列的参数名列表

Source

pub fn flatten_constraints(&self) -> Box<[OnionObject]>

递归扁平化参数结构,生成约束对象列表。

将嵌套的参数结构展开为一维的约束对象列表。 例如:(a: Int, (b: String, c: Bool)) 会返回 [Int, String, Bool]

§返回

按深度优先顺序排列的约束对象列表

Trait Implementations§

Source§

impl Clone for LambdaParameter

Source§

fn clone(&self) -> LambdaParameter

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 LambdaParameter

Source§

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

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

impl Display for LambdaParameter

Source§

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

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

impl GCTraceable<OnionObjectCell> for LambdaParameter

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.