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:
parent
8b57d6d4c6
commit
3eb0418bda
5 changed files with 164 additions and 31 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue