Make a macro for less boilerplate when moving variables (#12182)

Also: 
- Simplify open listener implementation
- Add set_global API to global traits

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2024-05-22 22:07:29 -07:00 committed by GitHub
parent 8b57d6d4c6
commit 3eb0418bda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 164 additions and 31 deletions

View file

@ -49,6 +49,11 @@ pub trait UpdateGlobal {
where
C: BorrowAppContext,
F: FnOnce(&mut Self, &mut C) -> R;
/// Set the global instance of the implementing type.
fn set_global<C>(cx: &mut C, global: Self)
where
C: BorrowAppContext;
}
impl<T: Global> UpdateGlobal for T {
@ -59,4 +64,11 @@ impl<T: Global> UpdateGlobal for T {
{
cx.update_global(update)
}
fn set_global<C>(cx: &mut C, global: Self)
where
C: BorrowAppContext,
{
cx.set_global(global)
}
}