gpui: Add Global marker trait (#7095)
This should prevent a class of bugs where one queries the wrong type of global, which results in oddities at runtime. Release Notes: - N/A --------- Co-authored-by: Marshall <marshall@zed.dev> Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
parent
7bfa584eb6
commit
e6ebe7974d
59 changed files with 449 additions and 237 deletions
|
@ -258,14 +258,14 @@ pub trait EventEmitter<E: Any>: 'static {}
|
|||
/// can be used interchangeably.
|
||||
pub trait BorrowAppContext {
|
||||
/// Set a global value on the context.
|
||||
fn set_global<T: 'static>(&mut self, global: T);
|
||||
fn set_global<T: Global>(&mut self, global: T);
|
||||
}
|
||||
|
||||
impl<C> BorrowAppContext for C
|
||||
where
|
||||
C: BorrowMut<AppContext>,
|
||||
{
|
||||
fn set_global<G: 'static>(&mut self, global: G) {
|
||||
fn set_global<G: Global>(&mut self, global: G) {
|
||||
self.borrow_mut().set_global(global)
|
||||
}
|
||||
}
|
||||
|
@ -287,3 +287,8 @@ impl<T> Flatten<T> for Result<T> {
|
|||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// A marker trait for types that can be stored in GPUI's global state.
|
||||
///
|
||||
/// Implement this on types you want to store in the context as a global.
|
||||
pub trait Global: 'static {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue