pub struct AsyncApp { /* private fields */ }Expand description
An async-friendly version of App with a static lifetime so it can be held across await points in async code.
You’re provided with an instance when calling App::spawn, and you can also create one with App::to_async.
Internally, this holds a weak reference to an App. Methods will panic if the app has been dropped,
but this should not happen in practice when using foreground tasks spawned via cx.spawn(),
as the executor checks if the app is alive before running each task.
Implementations§
Source§impl AsyncApp
impl AsyncApp
Sourcepub fn background_executor(&self) -> &BackgroundExecutor
pub fn background_executor(&self) -> &BackgroundExecutor
Get an executor which can be used to spawn futures in the background.
Sourcepub fn foreground_executor(&self) -> &ForegroundExecutor
pub fn foreground_executor(&self) -> &ForegroundExecutor
Get an executor which can be used to spawn futures in the foreground.
Sourcepub fn update<R>(&self, f: impl FnOnce(&mut App) -> R) -> R
pub fn update<R>(&self, f: impl FnOnce(&mut App) -> R) -> R
Invoke the given function in the context of the app, then flush any effects produced during its invocation.
Sourcepub fn subscribe<T, Event>(
&mut self,
entity: &Entity<T>,
on_event: impl FnMut(Entity<T>, &Event, &mut App) + 'static,
) -> Subscriptionwhere
T: 'static + EventEmitter<Event>,
Event: 'static,
pub fn subscribe<T, Event>(
&mut self,
entity: &Entity<T>,
on_event: impl FnMut(Entity<T>, &Event, &mut App) + 'static,
) -> Subscriptionwhere
T: 'static + EventEmitter<Event>,
Event: 'static,
Arrange for the given callback to be invoked whenever the given entity emits an event of a given type. The callback is provided a handle to the emitting entity and a reference to the emitted event.
Sourcepub fn open_window<V>(
&self,
options: WindowOptions,
build_root_view: impl FnOnce(&mut Window, &mut App) -> Entity<V>,
) -> Result<WindowHandle<V>>where
V: 'static + Render,
pub fn open_window<V>(
&self,
options: WindowOptions,
build_root_view: impl FnOnce(&mut Window, &mut App) -> Entity<V>,
) -> Result<WindowHandle<V>>where
V: 'static + Render,
Open a window with the given options based on the root view returned by the given function.
Sourcepub fn spawn<AsyncFn, R>(&self, f: AsyncFn) -> Task<R> ⓘwhere
AsyncFn: AsyncFnOnce(&mut AsyncApp) -> R + 'static,
R: 'static,
pub fn spawn<AsyncFn, R>(&self, f: AsyncFn) -> Task<R> ⓘwhere
AsyncFn: AsyncFnOnce(&mut AsyncApp) -> R + 'static,
R: 'static,
Schedule a future to be polled in the foreground.
Sourcepub fn has_global<G: Global>(&self) -> bool
pub fn has_global<G: Global>(&self) -> bool
Determine whether global state of the specified type has been assigned.
Sourcepub fn read_global<G: Global, R>(&self, read: impl FnOnce(&G, &App) -> R) -> R
pub fn read_global<G: Global, R>(&self, read: impl FnOnce(&G, &App) -> R) -> R
Reads the global state of the specified type, passing it to the given callback.
Panics if no global state of the specified type has been assigned.
Sourcepub fn try_read_global<G: Global, R>(
&self,
read: impl FnOnce(&G, &App) -> R,
) -> Option<R>
pub fn try_read_global<G: Global, R>( &self, read: impl FnOnce(&G, &App) -> R, ) -> Option<R>
Reads the global state of the specified type, passing it to the given callback.
Similar to AsyncApp::read_global, but returns an error instead of panicking
Sourcepub fn read_default_global<G: Global + Default, R>(
&self,
read: impl FnOnce(&G, &App) -> R,
) -> R
pub fn read_default_global<G: Global + Default, R>( &self, read: impl FnOnce(&G, &App) -> R, ) -> R
Reads the global state of the specified type, passing it to the given callback. A default value is assigned if a global of this type has not yet been assigned.
Sourcepub fn update_global<G: Global, R>(
&self,
update: impl FnOnce(&mut G, &mut App) -> R,
) -> R
pub fn update_global<G: Global, R>( &self, update: impl FnOnce(&mut G, &mut App) -> R, ) -> R
A convenience method for App::update_global
for updating the global state of the specified type.
Trait Implementations§
Source§impl AppContext for AsyncApp
impl AppContext for AsyncApp
Source§fn new<T: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Entity<T>
fn new<T: 'static>( &mut self, build_entity: impl FnOnce(&mut Context<'_, T>) -> T, ) -> Entity<T>
Source§fn reserve_entity<T: 'static>(&mut self) -> Reservation<T>
fn reserve_entity<T: 'static>(&mut self) -> Reservation<T>
Source§fn insert_entity<T: 'static>(
&mut self,
reservation: Reservation<T>,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Entity<T>
fn insert_entity<T: 'static>( &mut self, reservation: Reservation<T>, build_entity: impl FnOnce(&mut Context<'_, T>) -> T, ) -> Entity<T>
reserve_entity.Source§fn update_entity<T: 'static, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
) -> R
fn update_entity<T: 'static, R>( &mut self, handle: &Entity<T>, update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R, ) -> R
Source§fn as_mut<'a, T>(&'a mut self, _handle: &Entity<T>) -> GpuiBorrow<'a, T>where
T: 'static,
fn as_mut<'a, T>(&'a mut self, _handle: &Entity<T>) -> GpuiBorrow<'a, T>where
T: 'static,
Source§fn read_entity<T, R>(
&self,
handle: &Entity<T>,
callback: impl FnOnce(&T, &App) -> R,
) -> Rwhere
T: 'static,
fn read_entity<T, R>(
&self,
handle: &Entity<T>,
callback: impl FnOnce(&T, &App) -> R,
) -> Rwhere
T: 'static,
Source§fn 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>
Source§fn with_window<R>(
&mut self,
entity_id: EntityId,
f: impl FnOnce(&mut Window, &mut App) -> R,
) -> Option<R>
fn with_window<R>( &mut self, entity_id: EntityId, f: impl FnOnce(&mut Window, &mut App) -> R, ) -> Option<R>
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,
fn read_window<T, R>(
&self,
window: &WindowHandle<T>,
read: impl FnOnce(Entity<T>, &App) -> R,
) -> Result<R>where
T: 'static,
Auto Trait Implementations§
impl Freeze for AsyncApp
impl !RefUnwindSafe for AsyncApp
impl !Send for AsyncApp
impl !Sync for AsyncApp
impl Unpin for AsyncApp
impl UnsafeUnpin for AsyncApp
impl !UnwindSafe for AsyncApp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more