Skip to main content

App

Struct App 

Source
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

Source

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(...).

Source

pub fn insert_resource<T: 'static>(self, resource: T) -> Self

Inserts a resource, replacing any existing value of the same type.

Source

pub fn remove_resource<T: 'static>(self) -> Self

Removes a resource, if present. A no-op if it wasn’t there.

Source

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.

Source

pub fn add_system<S, Params>( self, stage: SystemStage, system: impl Into<SystemConfig<S, Params>>, ) -> Self
where 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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn with_logging(self) -> Self

Initializes a tracing_subscriber formatter so tracing::info!/ warn!/error! calls made throughout the engine actually print somewhere.

Source

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

Source

pub fn should_exit(&self) -> bool

true once AppExit has been set — the default loop in App::run checks this after every tick.

Source

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§

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 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> 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, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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