use super::*;
pub fn with_context<F, R>(ctx: Context, operation: F) -> R
where
F: FnOnce() -> R,
{
let previous: Option<Context> =
ACTIVE_CONTEXT.with(|slot: &RefCell<Option<Context>>| slot.borrow_mut().replace(ctx));
let _guard: ContextGuard = ContextGuard::new(previous);
operation()
}
#[must_use]
pub fn current_context() -> Context {
ACTIVE_CONTEXT.with(|slot: &RefCell<Option<Context>>| {
slot.borrow()
.clone()
.unwrap_or_else(|| Context::new(SceneHandle::new_tree(), PlatformKind::Headless))
})
}
#[must_use]
pub fn has_context() -> bool {
ACTIVE_CONTEXT.with(|slot: &RefCell<Option<Context>>| slot.borrow().is_some())
}
#[must_use]
pub fn current_platform() -> PlatformKind {
current_context().get_platform()
}
#[must_use]
pub fn into_text<T>(value: T) -> String
where
T: Into<String>,
{
value.into()
}