AppContext

Trait AppContext 

Source
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§

Source

type Result<T>

The result type for this context, used for async contexts that can’t hold a direct reference to the application context.

Required Methods§

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

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 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, ) -> Self::Result<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", so this trait is not object safe.

Implementors§