pub trait AppContext {
type Result<T>;
// Required methods
fn new<T: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Self::Result<Entity<T>>;
fn reserve_entity<T: 'static>(&mut self) -> Self::Result<Reservation<T>>;
fn insert_entity<T: 'static>(
&mut self,
reservation: Reservation<T>,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Self::Result<Entity<T>>;
fn update_entity<T, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
) -> Self::Result<R>
where T: 'static;
fn as_mut<'a, T>(
&'a mut self,
handle: &Entity<T>,
) -> Self::Result<GpuiBorrow<'a, T>>
where T: 'static;
fn read_entity<T, R>(
&self,
handle: &Entity<T>,
read: impl FnOnce(&T, &App) -> R,
) -> Self::Result<R>
where T: 'static;
fn update_window<T, F>(
&mut self,
window: AnyWindowHandle,
f: F,
) -> Result<T>
where F: FnOnce(AnyView, &mut Window, &mut App) -> T;
fn read_window<T, R>(
&self,
window: &WindowHandle<T>,
read: impl FnOnce(Entity<T>, &App) -> R,
) -> Result<R>
where T: 'static;
fn background_spawn<R>(
&self,
future: impl Future<Output = R> + Send + 'static,
) -> Task<R> ⓘ
where R: Send + 'static;
fn read_global<G, R>(
&self,
callback: impl FnOnce(&G, &App) -> R,
) -> Self::Result<R>
where G: Global;
}Expand description
The context trait, allows the different contexts in GPUI to be used interchangeably for certain operations.
Required Associated Types§
Required Methods§
Sourcefn new<T: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Self::Result<Entity<T>>
fn new<T: 'static>( &mut self, build_entity: impl FnOnce(&mut Context<'_, T>) -> T, ) -> Self::Result<Entity<T>>
Create a new entity in the app context.
Sourcefn reserve_entity<T: 'static>(&mut self) -> Self::Result<Reservation<T>>
fn reserve_entity<T: 'static>(&mut self) -> Self::Result<Reservation<T>>
Reserve a slot for a entity to be inserted later. The returned Reservation allows you to obtain the EntityId for the future entity.
Sourcefn insert_entity<T: 'static>(
&mut self,
reservation: Reservation<T>,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Self::Result<Entity<T>>
fn insert_entity<T: 'static>( &mut self, reservation: Reservation<T>, build_entity: impl FnOnce(&mut Context<'_, T>) -> T, ) -> Self::Result<Entity<T>>
Insert a new entity in the app context based on a Reservation previously obtained from reserve_entity.
Sourcefn update_entity<T, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
) -> Self::Result<R>where
T: 'static,
fn update_entity<T, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
) -> Self::Result<R>where
T: 'static,
Update a entity in the app context.
Sourcefn as_mut<'a, T>(
&'a mut self,
handle: &Entity<T>,
) -> Self::Result<GpuiBorrow<'a, T>>where
T: 'static,
fn as_mut<'a, T>(
&'a mut self,
handle: &Entity<T>,
) -> Self::Result<GpuiBorrow<'a, T>>where
T: 'static,
Update a entity in the app context.
Sourcefn read_entity<T, R>(
&self,
handle: &Entity<T>,
read: impl FnOnce(&T, &App) -> R,
) -> Self::Result<R>where
T: 'static,
fn read_entity<T, R>(
&self,
handle: &Entity<T>,
read: impl FnOnce(&T, &App) -> R,
) -> Self::Result<R>where
T: 'static,
Read a entity from the app context.
Sourcefn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
Update a window for the given handle.
Sourcefn read_window<T, R>(
&self,
window: &WindowHandle<T>,
read: impl FnOnce(Entity<T>, &App) -> R,
) -> Result<R>where
T: 'static,
fn read_window<T, R>(
&self,
window: &WindowHandle<T>,
read: impl FnOnce(Entity<T>, &App) -> R,
) -> Result<R>where
T: 'static,
Read a window off of the application context.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.