pub struct ScratchArena<const CAP: usize = SCRATCH_CAPACITY> { /* private fields */ }Expand description
基于 bumpalo::Bump 的帧级瞬态内存池,帧末 rewind() 零分配复用。
Implementations§
Source§impl<const CAP: usize> ScratchArena<CAP>
impl<const CAP: usize> ScratchArena<CAP>
Sourcepub fn try_alloc_temp<'a, T>(&'a self, val: T) -> Option<&'a mut T>
pub fn try_alloc_temp<'a, T>(&'a self, val: T) -> Option<&'a mut T>
尝试在帧池中无 panic 分配临时树节点。
Sourcepub fn alloc_temp<'a, T>(&'a self, val: T) -> &'a mut T
pub fn alloc_temp<'a, T>(&'a self, val: T) -> &'a mut T
分配仅在布局求解阶段存活的临时树节点(ElementNode / Element / DivVisual)。
Sourcepub fn alloc_bytes<'a>(&'a self, len: usize) -> &'a mut [u8] ⓘ
pub fn alloc_bytes<'a>(&'a self, len: usize) -> &'a mut [u8] ⓘ
在帧池中分配长度为 len 的对齐字节切片 &'a mut [u8]。
Sourcepub fn alloc_iter<'a, T, I>(&'a self, iter: I) -> &'a mut [T]where
I: IntoIterator<Item = T>,
pub fn alloc_iter<'a, T, I>(&'a self, iter: I) -> &'a mut [T]where
I: IntoIterator<Item = T>,
无需 Vec 中转,直接将任意迭代器原地展开为连续内存切片 &'a mut [T]。
Sourcepub fn alloc_str<'a>(&'a self, s: &str) -> StrRef<'a>
pub fn alloc_str<'a>(&'a self, s: &str) -> StrRef<'a>
将任意临时字符串切片 s 拷贝至当前 ScratchArena,返回 StrRef<'a>。
Sourcepub fn alloc_fmt<'a>(&'a self, args: Arguments<'_>) -> StrRef<'a>
pub fn alloc_fmt<'a>(&'a self, args: Arguments<'_>) -> StrRef<'a>
将 format_args! 字节流直接写入当前 ScratchArena,返回 StrRef<'a>。
Sourcepub fn restore_mark(&mut self, mark: usize)
pub fn restore_mark(&mut self, mark: usize)
恢复竞技场游标至指定水位线(需要可变引用 &mut self,静态保证此前分配的借用生命周期已结束)。
Sourcepub fn used_bytes(&self) -> usize
pub fn used_bytes(&self) -> usize
返回当前帧已使用的逻辑字节数。
Sourcepub fn can_alloc_slice<T>(&self, count: usize) -> bool
pub fn can_alloc_slice<T>(&self, count: usize) -> bool
检查当前竞技场剩余空间是否足以容纳 count 个连续的 T 元素。
Sourcepub fn can_alloc_temp_slice<T>(&self, count: usize) -> bool
pub fn can_alloc_temp_slice<T>(&self, count: usize) -> bool
检查当前竞技场临时区是否足以分配 count 个 T 元素。
Sourcepub fn alloc_temp_iter_exact<'a, T, I>(
&'a self,
count: usize,
iter: I,
) -> &'a mut [T]where
I: IntoIterator<Item = T>,
pub fn alloc_temp_iter_exact<'a, T, I>(
&'a self,
count: usize,
iter: I,
) -> &'a mut [T]where
I: IntoIterator<Item = T>,
批量分配由固定长度迭代器产生的连续切片 &'a mut [T](供布局求解器构建 LayoutNode 子树使用)。
Trait Implementations§
Auto Trait Implementations§
impl<const CAP: usize = SCRATCH_CAPACITY> !Freeze for ScratchArena<CAP>
impl<const CAP: usize = SCRATCH_CAPACITY> !RefUnwindSafe for ScratchArena<CAP>
impl<const CAP: usize = SCRATCH_CAPACITY> !Sync for ScratchArena<CAP>
impl<const CAP: usize = SCRATCH_CAPACITY> !UnwindSafe for ScratchArena<CAP>
impl<const CAP: usize> Forget for ScratchArena<CAP>
impl<const CAP: usize> Move for ScratchArena<CAP>
impl<const CAP: usize> Send for ScratchArena<CAP>
impl<const CAP: usize> Unpin for ScratchArena<CAP>
impl<const CAP: usize> UnsafeUnpin for ScratchArena<CAP>
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
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) 时执行闭包修饰自身,否则原样返回。