Skip to main content

App

Struct App 

Source
pub struct App { /* private fields */ }
Expand description

The central application object.

App owns the ECS world, resources, plugins, and systems. The typical lifecycle is:

  1. Create with App::new.
  2. Register plugins with add_plugin.
  3. Call build to run all plugin registrations, execute validate required resources, and settle AssetSync/AssetSyncDeps as far as they can go synchronously.
  4. Call run to hand control to the runner.

Implementations§

Source§

impl App

Source

pub fn new() -> Self

Create a new App with an empty world and a default infinite-loop runner.

Source

pub fn add_plugin(&mut self, plugin: impl Plugin) -> &mut Self

Queue a plugin to be built during build.

Source

pub fn add_resource(&mut self, res: impl Component) -> &mut Self

Insert a resource into the world immediately.

Source

pub fn get_resource<'a, T: Component>(&'a self) -> Ref<'a, T>

Borrow resource T, panicking if it is absent.

Source

pub fn get_resource_mut<'a, T: Component>(&'a self) -> RefMut<'a, T>

Mutably borrow resource T, panicking if it is absent.

Source

pub fn try_insert_resource<T: Component>(&mut self, res: T) -> bool

Insert resource T only if it is not already present.

Returns true if the resource was inserted.

Source

pub fn provides<T: 'static>(&mut self) -> &mut Self

Declare that resource type T is expected to be inserted later — possibly asynchronously (a background thread’s result, a hand-rolled lazy resource) rather than up front. A system elsewhere with a hard Res<T>/ResMut<T> requirement on T will then wait quietly for it instead of App treating the absence as a configuration mistake and panicking.

GraphicsPlugin and LazyResourcePlugin already call this for the backend and lazy resource types they manage — reach for this directly only for your own resource types that arrive outside of those.

Source

pub fn add_system<Marker>( &mut self, stage: SystemStage, system: impl IntoSystem<Marker> + 'static, ) -> &mut Self

Register a single system to run at stage.

Source

pub fn add_systems<Marker>( &mut self, stage: SystemStage, systems: impl IntoSystemSet<Marker>, ) -> &mut Self

Register multiple systems to run at stage.

Accepts a tuple of systems via IntoSystemSet.

Source

pub fn build(&mut self) -> &mut Self

Build all plugins and validate required resources.

Plugins may register additional plugins during their build call; this repeats until no new plugins are added, up to a hard limit of 64 passes to catch accidental infinite registration cycles.

Source

pub fn update(&mut self)

Run every stage once per tick, in [TICK_STAGES] order. Before every tick, and again after every stage, reconverge drains AssetSync/AssetSyncDeps — so newly-queued asset or resource work is handled immediately rather than waiting for the next tick’s front pass.

Source

pub fn set_runner<F>(&mut self, runner: F) -> &mut Self
where F: FnOnce(App) + 'static,

Replace the default runner with a custom one.

The runner receives ownership of the App and is responsible for calling update at the appropriate cadence (e.g. driven by a window event loop).

Source

pub fn run(&mut self)

Consume the app and hand it to the configured runner.

Panics if no runner has been set.

Trait Implementations§

Source§

impl Default for App

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !Freeze for App

§

impl !RefUnwindSafe for App

§

impl !Send for App

§

impl !Sync for App

§

impl !UnwindSafe for App

§

impl Unpin for App

§

impl UnsafeUnpin for App

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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