Struct AsyncWorld

Source
pub struct AsyncWorld(/* private fields */);
Expand description

Exposes asynchronous access to the Bevy ECS World.

The easiest way to get an AsyncWorld is with AsyncWorld::from_world().

§Commands

Apply any Command asynchronously with AsyncWorld::apply_command.

§Systems

Just like their synchronous variants, asynchronous Systems must be registered before they can be used. Systems can optionally accept and return values asynchronously if they are registered with AsyncWorld::register_io_system.

§Entities

Spawn entities with the AsyncWorld::spawn_* family.

§Resources

Insert, remove, and wait for resources to exist.

Implementations§

Source§

impl AsyncWorld

Source

pub fn sender(&self) -> CommandQueueSender

Returns a copy of the underlying CommandQueueSender.

Source

pub async fn apply<C: Command>(&self, command: C)

Applies the given Command to the world.

Source

pub fn start_queue(&self) -> CommandQueueBuilder

Starts building a CommandQueue.

Source

pub async fn run_system<M>( self, system: impl IntoSystem<(), (), M> + Send + 'static, )

Run a System once.

Source

pub async fn register_system<M>( &self, system: impl IntoSystem<(), (), M> + Send, ) -> AsyncSystem

Registers a System and returns an AsyncSystem that can be used to run the system on demand.

Source

pub async fn register_io_system<I: Send + 'static, O: Send + 'static, M>( &self, system: impl IntoSystem<In<I>, O, M> + Send, ) -> AsyncIOSystem<I, O>

Registers a System and returns an AsyncIOSystem that can be used to run the system on demand while supplying an input value and receiving an output value.

Source

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

Constructs an AsyncEntity for the given Entity. If the entity does not exist, any operation performed on it will panic.

Source

pub async fn spawn_empty(&self) -> AsyncEntity

Spawns a new Entity and returns an AsyncEntity that represents it, which can be used to further manipulate the entity.

Source

pub async fn spawn<B: Bundle>(&self, bundle: B) -> AsyncEntity

Spawns a new Entity with the given Bundle and returns an AsyncEntity that represents it, which can be used to further manipulate the entity.

Source

pub async fn spawn_named( &self, name: impl Into<Cow<'static, str>> + Send, ) -> AsyncEntity

Spawns a new Entity and returns an AsyncEntity that represents it, which can be used to further manipulate the entity. This function attaches a bevy Name component with the given value.

Source

pub async fn insert_resource<R: Resource>(&self, resource: R)

Inserts a new resource or updates an existing resource with the given value.

Source

pub async fn remove_resource<R: Resource>(&self)

Removes the resource of a given type, if it exists.

Source

pub async fn start_waiting_for_resource<R: Resource + Clone>( &self, ) -> AsyncResource<R>

Start waiting for the Resource of a given type. Returns an AsyncResource which can be further waited to receive the value of the resource.

AsyncWorld::wait_for_resource().await is equivalent to AsyncWorld::start_waiting_for_resource().await.wait().await.

Source

pub async fn wait_for_resource<R: Resource + Clone>(&self) -> R

Wait for the Resource of a given type. Returns the value of the resource, once it exists.

AsyncWorld::wait_for_resource().await is equivalent to AsyncWorld::start_waiting_for_resource().await.wait().await.

Source

pub async fn send_event<E: Event>(&self, event: E)

Send an Event to the bevy world.

Source

pub async fn start_waiting_for_events<E: Event + Clone>(&self) -> AsyncEvents<E>

Start listening for Events coming from the main bevy world. Returns an AsyncEvents which can be further waited to receive these events.

AsyncWorld::wait_for_event().await is equivalent to AsyncWorld::start_waiting_for_events().await.wait().await.

Source

pub async fn wait_for_event<E: Event + Clone>(&self) -> E

Wait for the Event of a given type. Returns the value of the event, once it is received.

AsyncWorld::wait_for_event().await is equivalent to AsyncWorld::start_waiting_for_events().await.wait().await.

Source

pub async fn trigger<E: Event>(&self, event: E)

Triggers the given Event, which will run any Observers watching for it.

Source

pub async fn trigger_targets<E: Event, T: TriggerTargets + Send + Sync + 'static>( &self, event: E, targets: T, )

Triggers the given Event for the given targets, which will run any Observers watching for it.

Trait Implementations§

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 From<CommandQueueSender> for AsyncWorld

Source§

fn from(sender: CommandQueueSender) -> Self

Converts to this type from the input type.
Source§

impl FromWorld for AsyncWorld

Source§

fn from_world(world: &mut World) -> Self

Creates Self using data from the given World.

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>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

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

Converts &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> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<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,

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

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> ConditionalSend for T
where T: Send,