pub struct App { /* private fields */ }Expand description
The central application object: owns the ECS world, resources, and every
registered system, organized into SystemStages.
Built by chaining .add_plugin(...)/.add_system(...)/etc. calls —
every builder method takes self by value and returns Self, so a
typical setup reads as one expression ending in App::run:
App::new()
.add_plugin(GraphicsPlugin)
.add_system(SystemStage::Ready, setup)
.add_system(SystemStage::Update, my_game_logic)
.run();Implementations§
Source§impl App
impl App
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a fresh App with no plugins, systems, or resources beyond
the small set every app needs internally (a command buffer,
AppExit, BackendReady). Nothing is registered automatically
— windowing, the GPU backend, Time are all opt-in via
.add_plugin(...).
Sourcepub fn insert_resource<T: 'static>(self, resource: T) -> Self
pub fn insert_resource<T: 'static>(self, resource: T) -> Self
Inserts a resource, replacing any existing value of the same type.
Sourcepub fn remove_resource<T: 'static>(self) -> Self
pub fn remove_resource<T: 'static>(self) -> Self
Removes a resource, if present. A no-op if it wasn’t there.
Sourcepub fn add_plugin<P: Plugin>(self, plugin: P) -> Self
pub fn add_plugin<P: Plugin>(self, plugin: P) -> Self
Runs a Plugin’s build, which may insert resources, register
systems, or add further plugins of its own.
Sourcepub fn add_system<S, Params>(
self,
stage: SystemStage,
system: impl Into<SystemConfig<S, Params>>,
) -> Selfwhere
Params: 'static,
S: IntoSystem<Params> + 'static,
pub fn add_system<S, Params>(
self,
stage: SystemStage,
system: impl Into<SystemConfig<S, Params>>,
) -> Selfwhere
Params: 'static,
S: IntoSystem<Params> + 'static,
Registers system to run on stage, every tick that stage runs.
See SystemStage for what each stage is for and when it runs.
system may be a bare system, or one wrapped with
.after(...)/.before(...)/.priority(...) to order/prioritize it
relative to another system on the same stage — see
IntoSystemConfig.
Sourcepub fn add_systems(self, stage: SystemStage, chain: SystemChain) -> Self
pub fn add_systems(self, stage: SystemStage, chain: SystemChain) -> Self
Registers every system in chain — built by calling .chain() on a
tuple of systems, see Chain —
to run on stage, in that exact relative order.
Sourcepub fn add_event<T: 'static + Send + Sync>(self) -> Self
pub fn add_event<T: 'static + Send + Sync>(self) -> Self
Registers event type T, making EventReader<T>/
EventWriter<T> usable as system
parameters. Idempotent — calling this twice for the same T (e.g.
from two different plugins that both want it) is a no-op the second
time, not a double registration.
Sourcepub fn add_observer<E: 'static + Send + Sync, Params: 'static>(
self,
observer: impl IntoObserverSystem<E, Params> + 'static,
) -> Self
pub fn add_observer<E: 'static + Send + Sync, Params: 'static>( self, observer: impl IntoObserverSystem<E, Params> + 'static, ) -> Self
Registers observer to run whenever Commands::trigger
sends an E, once the current stage finishes syncing (same tick,
not deferred to the next one). Multiple observers can be registered
for the same E — every one of them runs.
Sourcepub fn set_runner(self, runner: impl FnOnce(App) + 'static) -> Self
pub fn set_runner(self, runner: impl FnOnce(App) + 'static) -> Self
Overrides how the main loop is driven — e.g. a windowing plugin installs one that hands control to its own event loop instead of the default headless polling loop.
Sourcepub fn with_logging(self) -> Self
pub fn with_logging(self) -> Self
Initializes a tracing_subscriber formatter so tracing::info!/
warn!/error! calls made throughout the engine actually print
somewhere.
Sourcepub fn update(&mut self)
pub fn update(&mut self)
Runs every schedule for a single tick: while the GPU backend isn’t
ready yet, only the internal gpu_schedules run; once it is,
SystemStage::Ready runs (if anything is still registered there,
exactly once ever), then every other stage runs in order. Called
automatically by the default loop in App::run — call it
yourself only if you’re driving the loop from somewhere else (e.g.
inside a custom runner installed via App::set_runner).
Sourcepub fn should_exit(&self) -> bool
pub fn should_exit(&self) -> bool
Sourcepub fn run(self)
pub fn run(self)
Consumes the app and runs it. SystemStage::Startup runs first,
exactly once, before anything else. Then, if a runner was installed
(e.g. by a windowing plugin via App::set_runner), control is
handed to it — this call doesn’t return until that runner decides
to stop. Otherwise, falls back to a default headless loop that
calls App::update repeatedly until App::should_exit.
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, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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().