use super::*;
pub fn with_build_context<F, R>(ctx: BuildContext, operation: F) -> R
where
F: FnOnce() -> R,
{
let previous: Option<BuildContext> = ACTIVE_BUILD_CONTEXT
.with(|slot: &RefCell<Option<BuildContext>>| slot.borrow_mut().replace(ctx));
let _guard: BuildContextGuard = BuildContextGuard::new(previous);
operation()
}
#[must_use]
pub fn current_build_context() -> BuildContext {
ACTIVE_BUILD_CONTEXT.with(|slot: &RefCell<Option<BuildContext>>| {
slot.borrow()
.clone()
.unwrap_or_else(|| BuildContext::new(SceneHandle::new_tree(), PlatformKind::Headless))
})
}
#[must_use]
pub fn has_build_context() -> bool {
ACTIVE_BUILD_CONTEXT.with(|slot: &RefCell<Option<BuildContext>>| slot.borrow().is_some())
}
#[must_use]
pub fn current_platform() -> PlatformKind {
current_build_context().get_platform()
}
pub fn mount_current<M>(mountable: M) -> NodeId
where
M: Mountable,
{
let mut ctx: BuildContext = current_build_context();
mountable.mount(&mut ctx)
}