dioxus/packages/core/src/bump_frame.rs

30 lines
676 B
Rust
Raw Normal View History

2022-12-03 00:24:49 +00:00
use crate::nodes::RenderReturn;
2022-11-20 01:07:29 +00:00
use bumpalo::Bump;
2022-11-22 01:00:34 +00:00
use std::cell::Cell;
2022-11-29 21:31:04 +00:00
pub(crate) struct BumpFrame {
pub bump: Bump,
2022-11-29 21:31:04 +00:00
pub node: Cell<*const RenderReturn<'static>>,
}
2022-11-20 01:07:29 +00:00
impl BumpFrame {
2022-12-03 00:24:49 +00:00
pub(crate) fn new(capacity: usize) -> Self {
let bump = Bump::with_capacity(capacity);
Self {
bump,
2022-11-29 21:31:04 +00:00
node: Cell::new(std::ptr::null()),
}
}
2022-11-20 01:07:29 +00:00
/// Creates a new lifetime out of thin air
2022-12-03 00:24:49 +00:00
pub(crate) unsafe fn try_load_node<'b>(&self) -> Option<&'b RenderReturn<'b>> {
2022-11-29 21:31:04 +00:00
let node = self.node.get();
if node.is_null() {
return None;
}
unsafe { std::mem::transmute(&*node) }
2022-11-12 02:29:27 +00:00
}
}