pub struct App { /* private fields */ }Expand description
The central application object.
App owns the ECS world, resources, plugins, and systems. The typical
lifecycle is:
- Create with
App::new. - Register plugins with
add_plugin. - Call
buildto run all plugin registrations, execute validate required resources, and settleAssetSync/AssetSyncDepsas far as they can go synchronously. - Call
runto hand control to the runner.
Implementations§
Source§impl App
impl App
Sourcepub fn add_plugin(&mut self, plugin: impl Plugin) -> &mut Self
pub fn add_plugin(&mut self, plugin: impl Plugin) -> &mut Self
Queue a plugin to be built during build.
Sourcepub fn add_resource(&mut self, res: impl Component) -> &mut Self
pub fn add_resource(&mut self, res: impl Component) -> &mut Self
Insert a resource into the world immediately.
Sourcepub fn get_resource<'a, T: Component>(&'a self) -> Ref<'a, T>
pub fn get_resource<'a, T: Component>(&'a self) -> Ref<'a, T>
Borrow resource T, panicking if it is absent.
Sourcepub fn get_resource_mut<'a, T: Component>(&'a self) -> RefMut<'a, T>
pub fn get_resource_mut<'a, T: Component>(&'a self) -> RefMut<'a, T>
Mutably borrow resource T, panicking if it is absent.
Sourcepub fn try_insert_resource<T: Component>(&mut self, res: T) -> bool
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.
Sourcepub fn provides<T: 'static>(&mut self) -> &mut Self
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.
Sourcepub fn add_system<Marker>(
&mut self,
stage: SystemStage,
system: impl IntoSystem<Marker> + 'static,
) -> &mut Self
pub fn add_system<Marker>( &mut self, stage: SystemStage, system: impl IntoSystem<Marker> + 'static, ) -> &mut Self
Register a single system to run at stage.
Sourcepub fn add_systems<Marker>(
&mut self,
stage: SystemStage,
systems: impl IntoSystemSet<Marker>,
) -> &mut Self
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.
Sourcepub fn build(&mut self) -> &mut Self
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.
Sourcepub fn update(&mut self)
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.
Sourcepub fn set_runner<F>(&mut self, runner: F) -> &mut Self
pub fn set_runner<F>(&mut self, runner: F) -> &mut Self
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).
Trait Implementations§
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> 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().