AsyncApp

Struct AsyncApp 

Source
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

Source

pub fn refresh(&self) -> Result<()>

Schedules all windows in the application to be redrawn.

Source

pub fn background_executor(&self) -> &BackgroundExecutor

Get an executor which can be used to spawn futures in the background.

Source

pub fn foreground_executor(&self) -> &ForegroundExecutor

Get an executor which can be used to spawn futures in the foreground.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn on_drop<T: 'static, Callback: FnOnce(&mut T, &mut Context<'_, T>) + 'static>( &self, entity: &WeakEntity<T>, f: Callback, ) -> Deferred<impl FnOnce() + use<T, Callback>>

Run something using this entity and cx, when the returned struct is dropped

Trait Implementations§

Source§

impl AppContext for AsyncApp

Source§

type Result<T> = Result<T, Error>

The result type for this context, used for async contexts that can’t hold a direct reference to the application context.
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) -> 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, ) -> 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: 'static, R>( &mut self, handle: &Entity<T>, update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R, ) -> Self::Result<R>

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>, callback: 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
Source§

impl Clone for AsyncApp

Source§

fn clone(&self) -> AsyncApp

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more