Skip to main content

AppContext

Trait AppContext 

Source
pub trait AppContext {
    // Required methods
    fn new<T: 'static>(
        &mut self,
        build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
    ) -> Entity<T>;
    fn reserve_entity<T: 'static>(&mut self) -> Reservation<T>;
    fn insert_entity<T: 'static>(
        &mut self,
        reservation: Reservation<T>,
        build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
    ) -> Entity<T>;
    fn update_entity<T, R>(
        &mut self,
        handle: &Entity<T>,
        update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
    ) -> R
       where T: 'static;
    fn as_mut<'a, T>(&'a mut self, handle: &Entity<T>) -> GpuiBorrow<'a, T>
       where T: 'static;
    fn read_entity<T, R>(
        &self,
        handle: &Entity<T>,
        read: impl FnOnce(&T, &App) -> R,
    ) -> 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 with_window<R>(
        &mut self,
        entity_id: EntityId,
        f: impl FnOnce(&mut Window, &mut App) -> R,
    ) -> Option<R>;
    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) -> R
       where G: Global;
}
Expand description

The context trait, allows the different contexts in GPUI to be used interchangeably for certain operations.

Required Methods§

Source

fn new<T: 'static>( &mut self, build_entity: impl FnOnce(&mut Context<'_, T>) -> T, ) -> Entity<T>

Create a new entity in the app context.

Source

fn reserve_entity<T: 'static>(&mut self) -> 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.

Source

fn insert_entity<T: 'static>( &mut self, reservation: Reservation<T>, build_entity: impl FnOnce(&mut Context<'_, T>) -> T, ) -> Entity<T>

Insert a new entity in the app context based on a Reservation previously obtained from reserve_entity.

Source

fn update_entity<T, R>( &mut self, handle: &Entity<T>, update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R, ) -> R
where T: 'static,

Update a entity in the app context.

Source

fn as_mut<'a, T>(&'a mut self, handle: &Entity<T>) -> GpuiBorrow<'a, T>
where T: 'static,

Update a entity in the app context.

Source

fn read_entity<T, R>( &self, handle: &Entity<T>, read: impl FnOnce(&T, &App) -> R, ) -> R
where T: 'static,

Read a entity from the app context.

Source

fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
where F: FnOnce(AnyView, &mut Window, &mut App) -> T,

Update a window for the given handle.

Source

fn with_window<R>( &mut self, entity_id: EntityId, f: impl FnOnce(&mut Window, &mut App) -> R, ) -> Option<R>

Run f against the entity’s current window — the most recently rendered window that referenced the entity. Returns None if the entity has no current window or that window is unavailable. See App::with_window for the underlying lookup.

Source

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.

Source

fn background_spawn<R>( &self, future: impl Future<Output = R> + Send + 'static, ) -> Task<R>
where R: Send + 'static,

Spawn a future on a background thread

Source

fn read_global<G, R>(&self, callback: impl FnOnce(&G, &App) -> R) -> R
where G: Global,

Read a global from this app context

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§