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, so its methods are fallible to protect against cases where the App is dropped.
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) -> Result<R>
pub fn update<R>(&self, f: impl FnOnce(&mut App) -> R) -> Result<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,
) -> Result<Subscription>where
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,
) -> Result<Subscription>where
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) -> Result<bool>
pub fn has_global<G: Global>(&self) -> Result<bool>
Determine whether global state of the specified type has been assigned.
Returns an error if the App has been dropped.
Sourcepub fn read_global<G: Global, R>(
&self,
read: impl FnOnce(&G, &App) -> R,
) -> Result<R>
pub fn read_global<G: Global, R>( &self, read: impl FnOnce(&G, &App) -> R, ) -> Result<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.
Returns an error if the App has been dropped.
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
if no state of the specified type has been assigned.
Returns an error if no state of the specified type has been assigned the App has been dropped.
Sourcepub fn try_read_default_global<G: Global + Default, R>(
&self,
read: impl FnOnce(&G, &App) -> R,
) -> Result<R>
pub fn try_read_default_global<G: Global + Default, R>( &self, read: impl FnOnce(&G, &App) -> R, ) -> Result<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.
§Errors
If the app has ben dropped this returns an error.
Sourcepub fn update_global<G: Global, R>(
&self,
update: impl FnOnce(&mut G, &mut App) -> R,
) -> Result<R>
pub fn update_global<G: Global, R>( &self, update: impl FnOnce(&mut G, &mut App) -> R, ) -> Result<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§type Result<T> = Result<T, Error>
type Result<T> = Result<T, Error>
Source§fn 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>>
Source§fn reserve_entity<T: 'static>(&mut self) -> Result<Reservation<T>>
fn reserve_entity<T: 'static>(&mut self) -> Result<Reservation<T>>
Source§fn insert_entity<T: 'static>(
&mut self,
reservation: Reservation<T>,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Result<Entity<T>>
fn insert_entity<T: 'static>( &mut self, reservation: Reservation<T>, build_entity: impl FnOnce(&mut Context<'_, T>) -> T, ) -> Result<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,
) -> Self::Result<R>
fn update_entity<T: 'static, R>( &mut self, handle: &Entity<T>, update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R, ) -> Self::Result<R>
Source§fn 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,
Source§fn read_entity<T, R>(
&self,
handle: &Entity<T>,
callback: impl FnOnce(&T, &App) -> R,
) -> Self::Result<R>where
T: 'static,
fn read_entity<T, R>(
&self,
handle: &Entity<T>,
callback: impl FnOnce(&T, &App) -> R,
) -> Self::Result<R>where
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 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 !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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.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