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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user