Struct bevy_defer::access::AsyncWorld

source ·
pub struct AsyncWorld;
Expand description

Async version of World or Commands.

This type only works inside a bevy_defer future, calling any function outside of a bevy_defer future or inside a world access function (a closure with World as a parameter) will likely panic.

If you need the functionalities defined here in sync code, see non-send resources AsyncExecutor and QueryQueue.

Implementations§

source§

impl AsyncWorld

source

pub fn asset<A: Asset>(&self, handle: Handle<A>) -> AsyncAsset<A>

Obtain an AsyncAsset from a Handle.

§Example
let square = AsyncWorld.load_asset::<Image>("square.png");
AsyncWorld.asset(square.into_handle());
source

pub fn load_asset<A: Asset>( &self, path: impl Into<AssetPath<'static>> + Send + 'static ) -> AsyncAsset<A>

Load an asset from an AssetPath, equivalent to AssetServer::load. Does not wait for Asset to be loaded.

§Panics

If AssetServer does not exist in the world.

§Example
let square = AsyncWorld.load_asset::<Image>("square.png");
source

pub fn load_asset_with_settings<A: Asset, S: Settings>( &self, path: impl Into<AssetPath<'static>> + Send + 'static, f: impl Fn(&mut S) + Send + Sync + 'static ) -> AsyncAsset<A>

Begins loading an Asset of type A stored at path. The given settings function will override the asset’s AssetLoader settings.

source

pub fn add_asset<A: Asset + 'static>(&self, item: A) -> AccessResult<Handle<A>>

Add an asset and obtain its handle.

source§

impl AsyncWorld

source

pub fn send_event<E: Event>(&self, event: E) -> AccessResult<EventId<E>>

Send an Event.

source

pub fn event_stream<E: Event + Clone>(&self) -> EventStream<E>

Create a stream to an Event, requires the corresponding react_to_event system.

This requires Clone and duplicates all events sent in bevy.

source§

impl AsyncWorld

source

pub fn new() -> Self

Acquire an AsyncWorld, checks if in a bevy_defer future.

§Panics

When used outside a bevy_defer future.

§Note

You can construct AsyncWorld directly without this error.

source

pub fn entity(&self, entity: Entity) -> AsyncEntityMut

Obtain an AsyncEntityMut of the entity.

§Note

This does not mean the entity exists in the world.

source

pub fn resource<R: Resource>(&self) -> AsyncResource<R>

Obtain an AsyncResource.

§Note

This does not mean the resource exists in the world.

source

pub fn non_send_resource<R: 'static>(&self) -> AsyncNonSend<R>

Obtain an AsyncNonSend.

§Note

This does not mean the resource exists in the world.

source

pub fn query<Q: QueryData>(&self) -> AsyncQuery<Q>

Obtain an AsyncQuery.

source

pub fn query_filtered<Q: QueryData, F: QueryFilter>(&self) -> AsyncQuery<Q, F>

Obtain an AsyncQuery.

source

pub fn now(&self) -> Duration

Obtain duration from init, according to the executor.

source

pub fn frame_count(&self) -> u32

Obtain frame count since init, according to the executor.

source§

impl AsyncWorld

source

pub fn apply_command(&self, command: impl Command)

Apply a command.

Use AsyncWorld::run to obtain a result instead.

§Example
AsyncWorld.apply_command(|w: &mut World| println!("{:?}", w))
source

pub fn apply_command_queue(&self, commands: CommandQueue)

Apply a CommandQueue.

§Example
let queue = CommandQueue::default();
AsyncWorld.apply_command_queue(queue);
source

pub fn run<T>(&self, f: impl FnOnce(&mut World) -> T) -> T

Apply a function on the World and obtain the result.

§Example
AsyncWorld.run(|w: &mut World| w.resource::<Int>().0)
source

pub fn watch<T: 'static>( &self, f: impl FnMut(&mut World) -> Option<T> + 'static ) -> ChannelOut<T>

Apply a function on the World, repeat until it returns Some.

§Note

Dropping the future will stop the task.

§Example
AsyncWorld.watch(|w: &mut World| w.get_resource::<Int>().map(|r| r.0))
source

pub fn run_schedule(&self, schedule: impl ScheduleLabel) -> AccessResult

Runs a schedule a single time.

§Example
AsyncWorld.run_schedule(Update)
source

pub fn register_system<I: 'static, O: 'static, M, S: IntoSystem<I, O, M> + 'static>( &self, system: S ) -> SystemId<I, O>

Register a system and return a SystemId so it can later be called by run_system.

§Example
AsyncWorld.register_system(|time: Res<Time>| println!("{}", time.delta_seconds()))
source

pub fn run_system<O: 'static>(&self, system: SystemId<(), O>) -> AccessResult<O>

Run a stored system by their SystemId.

§Example
let id = AsyncWorld.register_system(|time: Res<Time>| println!("{}", time.delta_seconds()));
AsyncWorld.run_system(id).unwrap();
source

pub fn run_system_with_input<I: 'static, O: 'static>( &self, system: SystemId<I, O>, input: I ) -> AccessResult<O>

Run a stored system by their SystemId with input.

§Example
let id = AsyncWorld.register_system(|input: In<f32>, time: Res<Time>| time.delta_seconds() + *input);
AsyncWorld.run_system_with_input(id, 4.0).unwrap();
source

pub fn run_cached_system<O: 'static, M, S: IntoSystem<(), O, M> + 'static>( &self, system: S ) -> AccessResult<O>

Run a system that will be stored and reused upon repeated usage.

§Note

The system is disambiguated by the type ID of the closure. Be careful not to pass in a fn.

§Example
AsyncWorld.run_cached_system(|time: Res<Time>| println!("{}", time.delta_seconds())).unwrap();
source

pub fn run_cached_system_with_input<I: 'static, O: 'static, M, S: IntoSystem<I, O, M> + 'static>( &self, system: S, input: I ) -> AccessResult<O>

Run a system with input that will be stored and reused upon repeated usage.

§Note

The system is disambiguated by the type ID of the closure. Be careful not to pass in a fn.

§Example
AsyncWorld.run_cached_system_with_input(|input: In<f32>, time: Res<Time>| time.delta_seconds() + *input, 4.0).unwrap();
source

pub fn spawn_empty(&self) -> AsyncEntityMut

Spawns a new Entity with no components.

§Example
AsyncWorld.spawn_empty()
source

pub fn spawn_bundle(&self, bundle: impl Bundle) -> AsyncEntityMut

Spawn a new Entity with a given Bundle of components.

§Example
AsyncWorld.spawn_bundle(SpriteBundle::default())
source

pub fn set_state<S: States>(&self, state: S) -> AccessResult<()>

Transition to a new States.

§Example
AsyncWorld.set_state(MyState::A)
source

pub fn get_state<S: States>(&self) -> AccessResult<S>

Obtain a States.

§Example
AsyncWorld.get_state::<MyState>()
source

pub fn in_state<S: States>(&self, state: S) -> ChannelOut<()>

👎Deprecated: Use state_stream instead.

Wait until a States is entered.

§Example
AsyncWorld.in_state(MyState::A)
source

pub fn state_stream<S: States + Clone + Default>(&self) -> SignalStream<S>

Obtain a SignalStream that reacts to changes of a States.

Requires system react_to_state.

source

pub fn sleep(&self, duration: impl AsSeconds) -> MaybeChannelOut<()>

Pause the future for the duration, according to the Time resource.

§Example
AsyncWorld.sleep(5.4).await
source

pub fn sleep_frames(&self, frames: u32) -> MaybeChannelOut<()>

Pause the future for some frames, according to the FrameCount resource.

§Example
AsyncWorld.sleep_frames(12).await
source

pub fn yield_now(&self) -> impl Future<Output = ()> + 'static

Yield control back to the bevy_defer executor.

Unlike yield_now from futures_lite, the future will be resumed on the next execution point.

source

pub fn quit(&self)

Shutdown the bevy app.

§Example
AsyncWorld.quit()
source

pub fn typed_signal<T: SignalId>(&self) -> Signal<T::Data>

Obtain or init a signal by SignalId.

§Panics

If used outside a bevy_defer future.

§Example
let signal = AsyncWorld.typed_signal::<MySignal>();
signal.send(3.14);
signal.poll().await;
source

pub fn named_signal<T: SignalId>(&self, name: &str) -> Signal<T::Data>

Obtain or init a signal by name and SignalId.

§Panics

If used outside a bevy_defer future.

§Example
let signal = AsyncWorld.named_signal::<MySignal>("signal 1");
signal.send(3.14);
signal.poll().await;
source

pub fn spawn_scoped<T: 'static>( &self, fut: impl Future<Output = T> + 'static ) -> impl Future<Output = T>

Spawn a bevy_defer compatible future with a handle.

§Handle

The handle can be used to obtain the result, if dropped, the associated future will be dropped by the executor.

§Panics

If used outside a bevy_defer future.

source

pub fn spawn<T: 'static>(&self, fut: impl Future<Output = T> + 'static)

Spawn a bevy_defer compatible future.

The spawned future will not be dropped until finished.

§Panics

If used outside a bevy_defer future.

source

pub fn spawn_log<T: 'static, E: Display + 'static>( &self, fut: impl Future<Output = Result<T, E>> + 'static )

Spawn a bevy_defer compatible future and logs errors.

The spawned future will not be dropped until finished.

§Panics

If used outside a bevy_defer future.

source§

impl AsyncWorld

source

pub async fn spawn_scene(&self, bun: impl Bundle) -> AsyncEntityMut

Spawn a scene and wait for spawning to complete.

Requires react_to_scene_load to function.

source§

impl AsyncWorld

source

pub fn timed_routine<T: 'static>( &self, f: impl FnMut(&mut World, Duration) -> Option<T> + 'static, cancellation: impl Into<TaskCancellation> ) -> ChannelOutOrCancel<T>

Run a repeatable routine on Update, with access to delta time.

Trait Implementations§

source§

impl AsyncWorldParam for AsyncWorld

source§

fn from_async_context(_: &Reactors) -> Option<Self>

Obtain Self from the async context.
source§

fn build_in_async() -> Option<Self>

Construct inside a bevy_defer future.
source§

impl Clone for AsyncWorld

source§

fn clone(&self) -> AsyncWorld

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for AsyncWorld

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Copy for AsyncWorld

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, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
source§

impl<T> AsyncEntityParam for T
where T: AsyncWorldParam,

§

type Signal = ()

Associated signal, or ().
source§

fn fetch_signal(_: &Signals) -> Option<<T as AsyncEntityParam>::Signal>

If not found, log what’s missing and return None.
source§

fn from_async_context( _: Entity, reactors: &Reactors, _: <T as AsyncEntityParam>::Signal, _: &[Entity] ) -> Option<T>

Obtain Self from the async context.
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> DynClone for T
where T: Clone,

source§

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

source§

impl<T> Downcast<T> for T

source§

fn downcast(&self) -> &T

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> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> ToOwned for T
where T: Clone,

§

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

§

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

§

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<T> TypeData for T
where T: 'static + Send + Sync + Clone,

source§

impl<T> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>

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

impl<T> Settings for T
where T: 'static + Send + Sync,

source§

impl<T> WasmNotSend for T
where T: Send,

source§

impl<T> WasmNotSendSync for T

source§

impl<T> WasmNotSync for T
where T: Sync,