Struct OnionStaticObject

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

Onion 静态对象封装。

稳定化的对象封装,用于跨函数调用、长期存储和序列化。 通过持有必要的强引用来确保对象在使用期间不被 GC 回收。

§设计目的

  • 跨边界传递: 在函数调用、模块间传递对象
  • 长期存储: 作为常量、全局变量等存储
  • GC 稳定性: 确保对象在使用期间不被回收
  • 序列化支持: 提供对象的稳定表示

§内部结构

  • obj: 实际的对象数据
  • _arcs: GC 强引用存储,防止对象被回收

§GC 策略

根据对象类型采用不同的 GC 策略:

  • 基础类型: 无需额外引用(如 Integer, String 等)
  • Mut 类型: 持有单个强引用
  • 复杂类型: 持有多个强引用(如 Tuple, Lambda 等)

§关键方法

  • new(): 创建静态对象并自动设置 GC 引用
  • weak(): 获取内部对象的弱引用
  • mutablize(): 转换为可变对象
  • immutablize(): 从可变对象中提取值

Implementations§

Source§

impl OnionStaticObject

Source

pub fn new(obj: OnionObject) -> Self

Source

pub fn weak(&self) -> &OnionObject

Source

pub fn mutablize(self, gc: &mut GC<OnionObjectCell>) -> OnionStaticObject

将值装箱成可变容器,严格遵循幂等律的情况下,Cell里不可能出现Mut对象。 也就是说,mut mut x和mut x是等价的。

Source

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

将值从可变容器中卸载,严格遵循幂等律 也就是说,const const x和const x是等价的。

Trait Implementations§

Source§

impl Clone for OnionStaticObject

Source§

fn clone(&self) -> OnionStaticObject

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 OnionStaticObject

Source§

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

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

impl Default for OnionStaticObject

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for OnionStaticObject

Source§

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

Formats the value using the given formatter. Read more

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.