use gpui::{App, Global};
struct ContextCell<T>(T);
impl<T: 'static> Global for ContextCell<T> {}
pub fn provide<T: 'static>(cx: &mut App, value: T) {
cx.set_global(ContextCell(value));
}
pub fn use_context<T: 'static + Clone>(cx: &App) -> Option<T> {
cx.try_global::<ContextCell<T>>().map(|cell| cell.0.clone())
}
pub fn use_context_ref<T: 'static>(cx: &App) -> Option<&T> {
cx.try_global::<ContextCell<T>>().map(|cell| &cell.0)
}
pub fn has_context<T: 'static>(cx: &App) -> bool {
cx.has_global::<ContextCell<T>>()
}