Skip to main content

PodPool

Struct PodPool 

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

组件状态槽位池。 由于 View 状态允许包含 !Send / !Sync 类型(如 Rc、Cell),PodPool 显式标记为 !Send 与 !Sync。

Implementations§

Source§

impl PodPool

Source

pub fn render_pod_in_arena<'a>( &self, id: PodId, frame: &'a mut FrameScope, ) -> Option<(&'a Element<'a>, &'a ScratchArena)>

调用指定 PodId 的 View::render 生成瞬态 Element<'a> 树(自动递归展开所有嵌套 SubView(PodId)),并返回根引用与 ScratchArena。

注意:接收 &self 而非 &mut self,配合 UnsafeCell 与 Cell<bool> 借用锁,确保渲染期间 frame.pool_ptr 与方法调用严格满足 Stacked Borrows 共享只读起源规则。

Source§

impl PodPool

Source

pub const fn new() -> Self

创建空的状态槽位池。

Source

pub fn try_insert<V: View>(&mut self, view: V) -> Option<Handle<V>>

尝试在状态池中无 panic 分配并初始化一个有状态视图 V。

Source

pub fn insert<V: View>(&mut self, view: V) -> Handle<V>

在状态池中分配并初始化一个有状态视图 V,返回强类型句柄 Handle<V>(携带槽位代号防止 ABA 悬垂引用)。

Source

pub fn remove<V: View>(&mut self, handle: Handle<V>) -> bool

销毁并移除指定句柄对应的视图(调用其 Drop、递增槽位代号并回收槽位)。

Source

pub fn contains_pod(&self, id: PodId) -> bool

判断给定 PodId 当前是否仍驻留在状态池中。

Source

pub fn get_mut<V: View>(&mut self, handle: Handle<V>) -> Option<&mut V>

获取指定句柄对应的可变视图引用(校验代号 generation;若该槽位正被借用或已释放则返回 None)。

Source

pub fn update<V: View, R>( &mut self, handle: Handle<V>, f: impl FnOnce(&mut V) -> R, ) -> Option<R>

通过闭包更新视图状态并自动标记该视图为脏(消除对未初始化结构体对齐字节的裸扫描 UB,同时正确捕获 Vec/String 等堆内修改)。

Source

pub fn get<V: View>(&self, handle: Handle<V>) -> Option<&V>

获取指定句柄对应的只读视图引用(校验代号 generation;若该槽位正被可变借用或已释放则返回 None)。

Source

pub fn read_guarded<V: View>( &self, handle: Handle<V>, ) -> Option<PodReadGuard<'_, V>>

获取指定句柄对应的受控只读借用守卫 PodReadGuard(递增 active_readers 计数,析构时自动释放)。

Source

pub fn flush_signal_dirty_pods(&mut self)

将响应式 Signal 触发的待标记脏 PodId 批量刷入 PodPool。

Source

pub fn mark_dirty(&mut self, id: PodId)

将指定 PodId 标记为脏并压入脏队列(去重,同时级联标记所有通过 cx.read 依赖该视图的观察者视图)。

Source

pub fn invalidate_all_cached_elements(&self)

失效所有槽位中缓存的 Element 树与 LayoutNode 指针(当 ScratchArena 发生 rewind 或扩容切换时调用)。

Source

pub fn mark_all_dirty(&mut self)

将所有在用槽位标记为脏并失效其 Element 与 LayoutNode 缓存(当视口尺寸、主题或安全区域变更时调用)。

Source

pub fn render_count(&self, id: PodId) -> u32

获取指定句柄对应视图累计执行 View::render 的次数。

Source

pub fn skipped_render_count(&self) -> u32

获取自创建以来因未脏而直接复用缓存 Element 跳过 View::render 的子视图次数。

Source

pub fn relayout_boundary_hits(&self) -> u32

获取自创建以来命中子视图布局隔离边界(Relayout Boundary / 跳过子树 Pass 1~3 或原地局部重排)的次数。

Source

pub fn is_dirty(&self, id: PodId) -> bool

判断指定 PodId 是否处于脏状态。

Source

pub fn has_dirty(&self) -> bool

是否存在任何待重绘的脏视图(包含外部变更与 cx.request_frame() 预约的下一帧动画)。

Source

pub fn has_external_dirty(&self) -> bool

是否存在尚未被当前帧消化的外部状态脏标记(不含仅为下一帧预约的 cx.request_frame())。

Source

pub fn has_any_clean_occupied(&self) -> bool

是否存在至少一个未脏且已缓存了 Element 树的在用视图槽位。

Source

pub fn dirty_pods(&self) -> &[PodId]

获取当前脏视图队列切片。

Source

pub fn cached_bounds(&self, id: PodId) -> Region

读取指定 PodId 上一帧缓存的几何边界框。

Source

pub fn set_cached_bounds(&mut self, id: PodId, bounds: Region)

更新指定 PodId 的缓存几何边界框。

Source

pub fn clear_dirty(&mut self)

清空当前帧已完成渲染的脏标记(若某个视图在渲染期间调用了 cx.request_frame(),则自动保留其下一帧脏标记)。

Trait Implementations§

Source§

impl Default for PodPool

Source§

fn default() -> Self

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

impl Drop for PodPool

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> FluentBuilder for T

Source§

fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self

当 condition 为 true 时执行闭包修饰自身,否则原样返回。
Source§

fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self

根据 condition 在两个修饰分支之间二选一。
Source§

fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self

当 option 为 Some(value) 时执行闭包修饰自身,否则原样返回。
Source§

fn when_none<O>( self, option: &Option<O>, then: impl FnOnce(Self) -> Self, ) -> Self

当 option 为 None 时执行闭包修饰自身,否则原样返回。
Source§

fn apply<U>(self, f: impl FnOnce(Self) -> U) -> U

通用管道映射变换(避免与 Iterator::map / Option::map 重名)。
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.