pub struct PodPool { /* private fields */ }Expand description
组件状态槽位池。
由于 View 状态允许包含 !Send / !Sync 类型(如 Rc、Cell),PodPool 显式标记为 !Send 与 !Sync。
Implementations§
Source§impl PodPool
impl PodPool
Sourcepub fn render_pod_in_arena<'a>(
&self,
id: PodId,
frame: &'a mut FrameScope,
) -> Option<(&'a Element<'a>, &'a ScratchArena)>
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
impl PodPool
Sourcepub fn try_insert<V: View>(&mut self, view: V) -> Option<Handle<V>>
pub fn try_insert<V: View>(&mut self, view: V) -> Option<Handle<V>>
尝试在状态池中无 panic 分配并初始化一个有状态视图 V。
Sourcepub fn insert<V: View>(&mut self, view: V) -> Handle<V>
pub fn insert<V: View>(&mut self, view: V) -> Handle<V>
在状态池中分配并初始化一个有状态视图 V,返回强类型句柄 Handle<V>(携带槽位代号防止 ABA 悬垂引用)。
Sourcepub fn remove<V: View>(&mut self, handle: Handle<V>) -> bool
pub fn remove<V: View>(&mut self, handle: Handle<V>) -> bool
销毁并移除指定句柄对应的视图(调用其 Drop、递增槽位代号并回收槽位)。
Sourcepub fn contains_pod(&self, id: PodId) -> bool
pub fn contains_pod(&self, id: PodId) -> bool
判断给定 PodId 当前是否仍驻留在状态池中。
Sourcepub fn get_mut<V: View>(&mut self, handle: Handle<V>) -> Option<&mut V>
pub fn get_mut<V: View>(&mut self, handle: Handle<V>) -> Option<&mut V>
获取指定句柄对应的可变视图引用(校验代号 generation;若该槽位正被借用或已释放则返回 None)。
Sourcepub fn update<V: View, R>(
&mut self,
handle: Handle<V>,
f: impl FnOnce(&mut V) -> R,
) -> Option<R>
pub fn update<V: View, R>( &mut self, handle: Handle<V>, f: impl FnOnce(&mut V) -> R, ) -> Option<R>
通过闭包更新视图状态并自动标记该视图为脏(消除对未初始化结构体对齐字节的裸扫描 UB,同时正确捕获 Vec/String 等堆内修改)。
Sourcepub fn get<V: View>(&self, handle: Handle<V>) -> Option<&V>
pub fn get<V: View>(&self, handle: Handle<V>) -> Option<&V>
获取指定句柄对应的只读视图引用(校验代号 generation;若该槽位正被可变借用或已释放则返回 None)。
Sourcepub fn read_guarded<V: View>(
&self,
handle: Handle<V>,
) -> Option<PodReadGuard<'_, V>>
pub fn read_guarded<V: View>( &self, handle: Handle<V>, ) -> Option<PodReadGuard<'_, V>>
获取指定句柄对应的受控只读借用守卫 PodReadGuard(递增 active_readers 计数,析构时自动释放)。
Sourcepub fn flush_signal_dirty_pods(&mut self)
pub fn flush_signal_dirty_pods(&mut self)
将响应式 Signal 触发的待标记脏 PodId 批量刷入 PodPool。
Sourcepub fn mark_dirty(&mut self, id: PodId)
pub fn mark_dirty(&mut self, id: PodId)
将指定 PodId 标记为脏并压入脏队列(去重,同时级联标记所有通过 cx.read 依赖该视图的观察者视图)。
Sourcepub fn invalidate_all_cached_elements(&self)
pub fn invalidate_all_cached_elements(&self)
失效所有槽位中缓存的 Element 树与 LayoutNode 指针(当 ScratchArena 发生 rewind 或扩容切换时调用)。
Sourcepub fn mark_all_dirty(&mut self)
pub fn mark_all_dirty(&mut self)
将所有在用槽位标记为脏并失效其 Element 与 LayoutNode 缓存(当视口尺寸、主题或安全区域变更时调用)。
Sourcepub fn render_count(&self, id: PodId) -> u32
pub fn render_count(&self, id: PodId) -> u32
获取指定句柄对应视图累计执行 View::render 的次数。
Sourcepub fn skipped_render_count(&self) -> u32
pub fn skipped_render_count(&self) -> u32
获取自创建以来因未脏而直接复用缓存 Element 跳过 View::render 的子视图次数。
Sourcepub fn relayout_boundary_hits(&self) -> u32
pub fn relayout_boundary_hits(&self) -> u32
获取自创建以来命中子视图布局隔离边界(Relayout Boundary / 跳过子树 Pass 1~3 或原地局部重排)的次数。
Sourcepub fn has_external_dirty(&self) -> bool
pub fn has_external_dirty(&self) -> bool
是否存在尚未被当前帧消化的外部状态脏标记(不含仅为下一帧预约的 cx.request_frame())。
Sourcepub fn has_any_clean_occupied(&self) -> bool
pub fn has_any_clean_occupied(&self) -> bool
是否存在至少一个未脏且已缓存了 Element 树的在用视图槽位。
Sourcepub fn dirty_pods(&self) -> &[PodId]
pub fn dirty_pods(&self) -> &[PodId]
获取当前脏视图队列切片。
Sourcepub fn cached_bounds(&self, id: PodId) -> Region
pub fn cached_bounds(&self, id: PodId) -> Region
读取指定 PodId 上一帧缓存的几何边界框。
Sourcepub fn set_cached_bounds(&mut self, id: PodId, bounds: Region)
pub fn set_cached_bounds(&mut self, id: PodId, bounds: Region)
更新指定 PodId 的缓存几何边界框。
Sourcepub fn clear_dirty(&mut self)
pub fn clear_dirty(&mut self)
清空当前帧已完成渲染的脏标记(若某个视图在渲染期间调用了 cx.request_frame(),则自动保留其下一帧脏标记)。
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for PodPool
impl !RefUnwindSafe for PodPool
impl !Send for PodPool
impl !Sync for PodPool
impl !UnwindSafe for PodPool
impl Forget for PodPool
impl Move for PodPool
impl Unpin for PodPool
impl UnsafeUnpin for PodPool
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FluentBuilder for T
impl<T> FluentBuilder for T
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
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
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
fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self
option 为 Some(value) 时执行闭包修饰自身,否则原样返回。