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