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§
Implementations§
Source§impl LambdaParameter
impl LambdaParameter
Sourcepub fn constraint_at(&self, index: usize) -> Option<&OnionObject>
pub fn constraint_at(&self, index: usize) -> Option<&OnionObject>
Sourcepub fn to_onion(&self) -> OnionStaticObject
pub fn to_onion(&self) -> OnionStaticObject
Sourcepub fn from_onion(obj: &OnionObject) -> Result<LambdaParameter, RuntimeError>
pub fn from_onion(obj: &OnionObject) -> Result<LambdaParameter, RuntimeError>
从 Onion 对象解析参数结构。
支持从 Pair、Tuple、String 等对象解析参数:
- Pair: 解析为单参数
- Tuple: 解析为多参数,递归处理
- String: 解析为简单参数(约束为 true)
§错误
当对象格式不符合预期时返回 RuntimeError::InvalidType
Source§impl LambdaParameter
impl LambdaParameter
Sourcepub fn upgrade(&self, collected: &mut Vec<GCArc<OnionObjectCell>>)
pub fn upgrade(&self, collected: &mut Vec<GCArc<OnionObjectCell>>)
升级参数中的弱引用为强引用。
遍历参数结构,将所有对象的弱引用升级为强引用, 防止在垃圾回收过程中被意外回收。
Source§impl LambdaParameter
impl LambdaParameter
Sourcepub fn unpack_arguments(
&self,
argument: &OnionObject,
) -> Result<Vec<OnionObject>, RuntimeError>
pub fn unpack_arguments( &self, argument: &OnionObject, ) -> Result<Vec<OnionObject>, RuntimeError>
Source§impl LambdaParameter
impl LambdaParameter
Sourcepub fn flatten_keys(&self) -> Box<[Box<str>]>
pub fn flatten_keys(&self) -> Box<[Box<str>]>
Sourcepub fn flatten_constraints(&self) -> Box<[OnionObject]>
pub fn flatten_constraints(&self) -> Box<[OnionObject]>
递归扁平化参数结构,生成约束对象列表。
将嵌套的参数结构展开为一维的约束对象列表。
例如:(a: Int, (b: String, c: Bool))
会返回 [Int, String, Bool]
。
§返回
按深度优先顺序排列的约束对象列表
Trait Implementations§
Source§impl Clone for LambdaParameter
impl Clone for LambdaParameter
Source§fn clone(&self) -> LambdaParameter
fn clone(&self) -> LambdaParameter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for LambdaParameter
impl Debug for LambdaParameter
Source§impl Display for LambdaParameter
impl Display for LambdaParameter
Source§impl GCTraceable<OnionObjectCell> for LambdaParameter
impl GCTraceable<OnionObjectCell> for LambdaParameter
Auto Trait Implementations§
impl Freeze for LambdaParameter
impl !RefUnwindSafe for LambdaParameter
impl Send for LambdaParameter
impl Sync for LambdaParameter
impl Unpin for LambdaParameter
impl !UnwindSafe for LambdaParameter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more