App

Struct App 

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

App is the primary API for writing user applications. It automates the setup of a standard lifecycle and provides interface glue for plugins.

A single App can contain multiple SubApp instances, but App methods only affect the “main” one. To access a particular SubApp, use get_sub_app or get_sub_app_mut.

§Examples

Here is a simple “Hello World” Bevy app:

fn main() {
   App::new()
       .add_systems(Update, hello_world_system)
       .run();
}

fn hello_world_system() {
   println!("hello world");
}

Implementations§

Source§

impl App

Source

pub fn new() -> App

Creates a new App with some default structure to enable core engine features. This is the preferred constructor for most use cases.

Examples found in repository?
examples/app/empty.rs (line 6)
5fn main() {
6    App::new().run();
7}
More examples
Hide additional examples
examples/app/empty_defaults.rs (line 6)
5fn main() {
6    App::new().add_plugins(DefaultPlugins).run();
7}
examples/2d/mesh2d_alpha_mode.rs (line 11)
10fn main() {
11    App::new()
12        .add_plugins(DefaultPlugins)
13        .add_systems(Startup, setup)
14        .run();
15}
examples/3d/vertex_colors.rs (line 6)
5fn main() {
6    App::new()
7        .add_plugins(DefaultPlugins)
8        .add_systems(Startup, setup)
9        .run();
10}
examples/asset/hot_asset_reloading.rs (line 11)
10fn main() {
11    App::new()
12        .add_plugins(DefaultPlugins)
13        .add_systems(Startup, setup)
14        .run();
15}
examples/audio/audio.rs (line 7)
6fn main() {
7    App::new()
8        .add_plugins(DefaultPlugins)
9        .add_systems(Startup, setup)
10        .run();
11}
Source

pub fn empty() -> App

Creates a new empty App with minimal default configuration.

Use this constructor if you want to customize scheduling, exit handling, cleanup, etc.

Source

pub fn update(&mut self)

Runs the default schedules of all sub-apps (starting with the “main” app) once.

Examples found in repository?
examples/ecs/system_stepping.rs (line 38)
7fn main() {
8    let mut app = App::new();
9
10    app
11        // to display log messages from Stepping resource
12        .add_plugins(LogPlugin::default())
13        .add_systems(
14            Update,
15            (
16                update_system_one,
17                // establish a dependency here to simplify descriptions below
18                update_system_two.after(update_system_one),
19                update_system_three.after(update_system_two),
20                update_system_four,
21            ),
22        )
23        .add_systems(PreUpdate, pre_update_system);
24
25    // For the simplicity of this example, we directly modify the `Stepping`
26    // resource here and run the systems with `App::update()`.  Each call to
27    // `App::update()` is the equivalent of a single frame render when using
28    // `App::run()`.
29    //
30    // In a real-world situation, the `Stepping` resource would be modified by
31    // a system based on input from the user.  A full demonstration of this can
32    // be found in the breakout example.
33    println!(
34        r#"
35    Actions: call app.update()
36     Result: All systems run normally"#
37    );
38    app.update();
39
40    println!(
41        r#"
42    Actions: Add the Stepping resource then call app.update()
43     Result: All systems run normally.  Stepping has no effect unless explicitly
44             configured for a Schedule, and Stepping has been enabled."#
45    );
46    app.insert_resource(Stepping::new());
47    app.update();
48
49    println!(
50        r#"
51    Actions: Add the Update Schedule to Stepping; enable Stepping; call
52             app.update()
53     Result: Only the systems in PreUpdate run.  When Stepping is enabled,
54             systems in the configured schedules will not run unless:
55             * Stepping::step_frame() is called
56             * Stepping::continue_frame() is called
57             * System has been configured to always run"#
58    );
59    let mut stepping = app.world_mut().resource_mut::<Stepping>();
60    stepping.add_schedule(Update).enable();
61    app.update();
62
63    println!(
64        r#"
65    Actions: call Stepping.step_frame(); call app.update()
66     Result: The PreUpdate systems run, and one Update system will run.  In
67             Stepping, step means run the next system across all the schedules 
68             that have been added to the Stepping resource."#
69    );
70    let mut stepping = app.world_mut().resource_mut::<Stepping>();
71    stepping.step_frame();
72    app.update();
73
74    println!(
75        r#"
76    Actions: call app.update()
77     Result: Only the PreUpdate systems run.  The previous call to
78             Stepping::step_frame() only applies for the next call to
79             app.update()/the next frame rendered.
80    "#
81    );
82    app.update();
83
84    println!(
85        r#"
86    Actions: call Stepping::continue_frame(); call app.update()
87     Result: PreUpdate system will run, and all remaining Update systems will
88             run.  Stepping::continue_frame() tells stepping to run all systems
89             starting after the last run system until it hits the end of the
90             frame, or it encounters a system with a breakpoint set.  In this
91             case, we previously performed a step, running one system in Update.
92             This continue will cause all remaining systems in Update to run."#
93    );
94    let mut stepping = app.world_mut().resource_mut::<Stepping>();
95    stepping.continue_frame();
96    app.update();
97
98    println!(
99        r#"
100    Actions: call Stepping::step_frame() & app.update() four times in a row
101     Result: PreUpdate system runs every time we call app.update(), along with
102             one system from the Update schedule each time.  This shows what
103             execution would look like to step through an entire frame of 
104             systems."#
105    );
106    for _ in 0..4 {
107        let mut stepping = app.world_mut().resource_mut::<Stepping>();
108        stepping.step_frame();
109        app.update();
110    }
111
112    println!(
113        r#"
114    Actions: Stepping::always_run(Update, update_system_two); step through all
115             systems
116     Result: PreUpdate system and update_system_two() will run every time we
117             call app.update().  We'll also only need to step three times to
118             execute all systems in the frame.  Stepping::always_run() allows
119             us to granularly allow systems to run when stepping is enabled."#
120    );
121    let mut stepping = app.world_mut().resource_mut::<Stepping>();
122    stepping.always_run(Update, update_system_two);
123    for _ in 0..3 {
124        let mut stepping = app.world_mut().resource_mut::<Stepping>();
125        stepping.step_frame();
126        app.update();
127    }
128
129    println!(
130        r#"
131    Actions: Stepping::never_run(Update, update_system_two); continue through
132             all systems
133     Result: All systems except update_system_two() will execute.
134             Stepping::never_run() allows us to disable systems while Stepping
135             is enabled."#
136    );
137    let mut stepping = app.world_mut().resource_mut::<Stepping>();
138    stepping.never_run(Update, update_system_two);
139    stepping.continue_frame();
140    app.update();
141
142    println!(
143        r#"
144    Actions: Stepping::set_breakpoint(Update, update_system_two); continue,
145             step, continue
146     Result: During the first continue, pre_update_system() and
147             update_system_one() will run.  update_system_four() may also run
148             as it has no dependency on update_system_two() or
149             update_system_three().  Nether update_system_two() nor
150             update_system_three() will run in the first app.update() call as
151             they form a chained dependency on update_system_one() and run
152             in order of one, two, three.  Stepping stops system execution in
153             the Update schedule when it encounters the breakpoint for
154             update_system_two().
155             During the step we run update_system_two() along with the
156             pre_update_system().
157             During the final continue pre_update_system() and
158             update_system_three() run."#
159    );
160    let mut stepping = app.world_mut().resource_mut::<Stepping>();
161    stepping.set_breakpoint(Update, update_system_two);
162    stepping.continue_frame();
163    app.update();
164    let mut stepping = app.world_mut().resource_mut::<Stepping>();
165    stepping.step_frame();
166    app.update();
167    let mut stepping = app.world_mut().resource_mut::<Stepping>();
168    stepping.continue_frame();
169    app.update();
170
171    println!(
172        r#"
173    Actions: Stepping::clear_breakpoint(Update, update_system_two); continue
174             through all systems
175     Result: All systems will run"#
176    );
177    let mut stepping = app.world_mut().resource_mut::<Stepping>();
178    stepping.clear_breakpoint(Update, update_system_two);
179    stepping.continue_frame();
180    app.update();
181
182    println!(
183        r#"
184    Actions: Stepping::disable(); app.update()
185     Result: All systems will run.  With Stepping disabled, there's no need to
186             call Stepping::step_frame() or Stepping::continue_frame() to run
187             systems in the Update schedule."#
188    );
189    let mut stepping = app.world_mut().resource_mut::<Stepping>();
190    stepping.disable();
191    app.update();
192}
Source

pub fn run(&mut self) -> AppExit

Runs the App by calling its runner.

This will (re)build the App first. For general usage, see the example on the item level documentation.

§Caveats

Calls to App::run() will never return on iOS and Web.

Headless apps can generally expect this method to return control to the caller when it completes, but that is not the case for windowed apps. Windowed apps are typically driven by an event loop and some platforms expect the program to terminate when the event loop ends.

By default, Bevy uses the winit crate for window creation.

§Panics

Panics if not all plugins have been built.

Examples found in repository?
examples/app/empty.rs (line 6)
5fn main() {
6    App::new().run();
7}
More examples
Hide additional examples
examples/app/empty_defaults.rs (line 6)
5fn main() {
6    App::new().add_plugins(DefaultPlugins).run();
7}
examples/2d/mesh2d_alpha_mode.rs (line 14)
10fn main() {
11    App::new()
12        .add_plugins(DefaultPlugins)
13        .add_systems(Startup, setup)
14        .run();
15}
examples/3d/vertex_colors.rs (line 9)
5fn main() {
6    App::new()
7        .add_plugins(DefaultPlugins)
8        .add_systems(Startup, setup)
9        .run();
10}
examples/asset/hot_asset_reloading.rs (line 14)
10fn main() {
11    App::new()
12        .add_plugins(DefaultPlugins)
13        .add_systems(Startup, setup)
14        .run();
15}
examples/audio/audio.rs (line 10)
6fn main() {
7    App::new()
8        .add_plugins(DefaultPlugins)
9        .add_systems(Startup, setup)
10        .run();
11}
Source

pub fn set_runner( &mut self, f: impl FnOnce(App) -> AppExit + 'static, ) -> &mut App

Sets the function that will be called when the app is run.

The runner function f is called only once by App::run. If the presence of a main loop in the app is desired, it is the responsibility of the runner function to provide it.

The runner function is usually not set manually, but by Bevy integrated plugins (e.g. WinitPlugin).

§Examples
fn my_runner(mut app: App) -> AppExit {
    loop {
        println!("In main loop");
        app.update();
        if let Some(exit) = app.should_exit() {
            return exit;
        }
    }
}

App::new()
    .set_runner(my_runner);
Source

pub fn plugins_state(&mut self) -> PluginsState

Returns the state of all plugins. This is usually called by the event loop, but can be useful for situations where you want to use App::update.

Source

pub fn finish(&mut self)

Runs Plugin::finish for each plugin. This is usually called by the event loop once all plugins are ready, but can be useful for situations where you want to use App::update.

Source

pub fn cleanup(&mut self)

Runs Plugin::cleanup for each plugin. This is usually called by the event loop after App::finish, but can be useful for situations where you want to use App::update.

Source

pub fn add_systems<M>( &mut self, schedule: impl ScheduleLabel, systems: impl IntoScheduleConfigs<Box<dyn System<In = (), Out = ()>>, M>, ) -> &mut App

Adds one or more systems to the given schedule in this app’s Schedules.

§Examples
app.add_systems(Update, (system_a, system_b, system_c));
app.add_systems(Update, (system_a, system_b).run_if(should_run));
Examples found in repository?
examples/app/plugin_group.rs (line 41)
40    fn build(&self, app: &mut App) {
41        app.add_systems(Update, print_hello_system);
42    }
43}
44
45fn print_hello_system() {
46    info!("hello");
47}
48
49struct PrintWorldPlugin;
50
51impl Plugin for PrintWorldPlugin {
52    fn build(&self, app: &mut App) {
53        app.add_systems(Update, print_world_system);
54    }
More examples
Hide additional examples
examples/2d/mesh2d_alpha_mode.rs (line 13)
10fn main() {
11    App::new()
12        .add_plugins(DefaultPlugins)
13        .add_systems(Startup, setup)
14        .run();
15}
examples/3d/vertex_colors.rs (line 8)
5fn main() {
6    App::new()
7        .add_plugins(DefaultPlugins)
8        .add_systems(Startup, setup)
9        .run();
10}
examples/asset/hot_asset_reloading.rs (line 13)
10fn main() {
11    App::new()
12        .add_plugins(DefaultPlugins)
13        .add_systems(Startup, setup)
14        .run();
15}
examples/audio/audio.rs (line 9)
6fn main() {
7    App::new()
8        .add_plugins(DefaultPlugins)
9        .add_systems(Startup, setup)
10        .run();
11}
examples/reflection/reflection_types.rs (line 14)
11fn main() {
12    App::new()
13        .add_plugins(DefaultPlugins)
14        .add_systems(Startup, setup)
15        .run();
16}
Source

pub fn remove_systems_in_set<M>( &mut self, schedule: impl ScheduleLabel, set: impl IntoSystemSet<M>, policy: ScheduleCleanupPolicy, ) -> Result<usize, ScheduleError>

Removes all systems in a SystemSet. This will cause the schedule to be rebuilt when the schedule is run again and can be slow. A ScheduleError is returned if the schedule needs to be Schedule::initialize’d or the set is not found.

Note that this can remove all systems of a type if you pass the system to this function as systems implicitly create a set based on the system type.

§Example
// add the system
app.add_systems(Update, system_a);

// remove the system
app.remove_systems_in_set(Update, system_a, ScheduleCleanupPolicy::RemoveSystemsOnly);
Source

pub fn register_system<I, O, M>( &mut self, system: impl IntoSystem<I, O, M> + 'static, ) -> SystemId<I, O>
where I: SystemInput + 'static, O: 'static,

Registers a system and returns a SystemId so it can later be called by World::run_system.

It’s possible to register the same systems more than once, they’ll be stored separately.

This is different from adding systems to a Schedule with App::add_systems, because the SystemId that is returned can be used anywhere in the World to run the associated system. This allows for running systems in a push-based fashion. Using a Schedule is still preferred for most cases due to its better performance and ability to run non-conflicting systems simultaneously.

Source

pub fn configure_sets<M>( &mut self, schedule: impl ScheduleLabel, sets: impl IntoScheduleConfigs<Interned<dyn SystemSet>, M>, ) -> &mut App

Configures a collection of system sets in the provided schedule, adding any sets that do not exist.

Source

pub fn add_message<M>(&mut self) -> &mut App
where M: Message,

Initializes Message handling for T by inserting a message queue resource (Messages::<T>) and scheduling an message_update_system in First.

See Messages for information on how to define messages.

§Examples
app.add_message::<MyMessage>();
Source

pub fn insert_resource<R>(&mut self, resource: R) -> &mut App
where R: Resource,

Inserts the Resource into the app, overwriting any existing resource of the same type.

There is also an init_resource for resources that have Default or FromWorld implementations.

§Examples
#[derive(Resource)]
struct MyCounter {
    counter: usize,
}

App::new()
   .insert_resource(MyCounter { counter: 0 });
Examples found in repository?
examples/ui/ui_texture_slice_flip_and_tile.rs (line 12)
9fn main() {
10    App::new()
11        .add_plugins(DefaultPlugins)
12        .insert_resource(UiScale(2.))
13        .add_systems(Startup, setup)
14        .run();
15}
More examples
Hide additional examples
examples/ecs/system_param.rs (line 7)
5fn main() {
6    App::new()
7        .insert_resource(PlayerCount(0))
8        .add_systems(Startup, spawn)
9        .add_systems(Update, count_players)
10        .run();
11}
examples/ui/z_index.rs (line 13)
11fn main() {
12    App::new()
13        .insert_resource(ClearColor(Color::BLACK))
14        .add_plugins(DefaultPlugins)
15        .add_systems(Startup, setup)
16        .run();
17}
examples/ui/virtual_keyboard.rs (line 18)
15fn main() {
16    App::new()
17        .add_plugins((DefaultPlugins, FeathersPlugins))
18        .insert_resource(UiTheme(create_dark_theme()))
19        .add_systems(Startup, setup)
20        .run();
21}
examples/3d/spherical_area_lights.rs (lines 7-10)
5fn main() {
6    App::new()
7        .insert_resource(GlobalAmbientLight {
8            brightness: 60.0,
9            ..default()
10        })
11        .add_plugins(DefaultPlugins)
12        .add_systems(Startup, setup)
13        .run();
14}
examples/gltf/update_gltf_scene.rs (line 8)
6fn main() {
7    App::new()
8        .insert_resource(DirectionalLightShadowMap { size: 4096 })
9        .add_plugins(DefaultPlugins)
10        .add_systems(Startup, setup)
11        .add_systems(Update, move_scene_entities)
12        .run();
13}
Source

pub fn init_resource<R>(&mut self) -> &mut App
where R: Resource + FromWorld,

Inserts the Resource, initialized with its default value, into the app, if there is no existing instance of R.

R must implement FromWorld. If R implements Default, FromWorld will be automatically implemented and initialize the Resource with Default::default.

§Examples
#[derive(Resource)]
struct MyCounter {
    counter: usize,
}

impl Default for MyCounter {
    fn default() -> MyCounter {
        MyCounter {
            counter: 100
        }
    }
}

App::new()
    .init_resource::<MyCounter>();
Examples found in repository?
examples/ui/font_atlas_debug.rs (line 10)
8fn main() {
9    App::new()
10        .init_resource::<State>()
11        .insert_resource(ClearColor(Color::BLACK))
12        .add_plugins(DefaultPlugins)
13        .add_systems(Startup, setup)
14        .add_systems(Update, (text_update_system, atlas_render_system))
15        .run();
16}
Source

pub fn insert_non_send_resource<R>(&mut self, resource: R) -> &mut App
where R: 'static,

Inserts the !Send resource into the app, overwriting any existing resource of the same type.

There is also an init_non_send_resource for resources that implement Default

§Examples
struct MyCounter {
    counter: usize,
}

App::new()
    .insert_non_send_resource(MyCounter { counter: 0 });
Source

pub fn init_non_send_resource<R>(&mut self) -> &mut App
where R: 'static + FromWorld,

Inserts the !Send resource into the app if there is no existing instance of R.

R must implement FromWorld. If R implements Default, FromWorld will be automatically implemented and initialize the Resource with Default::default.

Source

pub fn is_plugin_added<T>(&self) -> bool
where T: Plugin,

Returns true if the Plugin has already been added.

Source

pub fn get_added_plugins<T>(&self) -> Vec<&T>
where T: Plugin,

Returns a vector of references to all plugins of type T that have been added.

This can be used to read the settings of any existing plugins. This vector will be empty if no plugins of that type have been added. If multiple copies of the same plugin are added to the App, they will be listed in insertion order in this vector.

let default_sampler = app.get_added_plugins::<ImagePlugin>()[0].default_sampler;
Source

pub fn add_plugins<M>(&mut self, plugins: impl Plugins<M>) -> &mut App

Installs a Plugin collection.

Bevy prioritizes modularity as a core principle. All engine features are implemented as plugins, even the complex ones like rendering.

Plugins can be grouped into a set by using a PluginGroup.

There are built-in PluginGroups that provide core engine functionality. The PluginGroups available by default are DefaultPlugins and MinimalPlugins.

To customize the plugins in the group (reorder, disable a plugin, add a new plugin before / after another plugin), call build() on the group, which will convert it to a PluginGroupBuilder.

You can also specify a group of Plugins by using a tuple over Plugins and PluginGroups. See Plugins for more details.

§Examples
App::new()
    .add_plugins(MinimalPlugins);
App::new()
    .add_plugins((MinimalPlugins, LogPlugin));
§Panics

Panics if one of the plugins had already been added to the application.

Examples found in repository?
examples/app/empty_defaults.rs (line 6)
5fn main() {
6    App::new().add_plugins(DefaultPlugins).run();
7}
More examples
Hide additional examples
examples/2d/mesh2d_alpha_mode.rs (line 12)
10fn main() {
11    App::new()
12        .add_plugins(DefaultPlugins)
13        .add_systems(Startup, setup)
14        .run();
15}
examples/3d/vertex_colors.rs (line 7)
5fn main() {
6    App::new()
7        .add_plugins(DefaultPlugins)
8        .add_systems(Startup, setup)
9        .run();
10}
examples/asset/hot_asset_reloading.rs (line 12)
10fn main() {
11    App::new()
12        .add_plugins(DefaultPlugins)
13        .add_systems(Startup, setup)
14        .run();
15}
examples/audio/audio.rs (line 8)
6fn main() {
7    App::new()
8        .add_plugins(DefaultPlugins)
9        .add_systems(Startup, setup)
10        .run();
11}
examples/reflection/reflection_types.rs (line 13)
11fn main() {
12    App::new()
13        .add_plugins(DefaultPlugins)
14        .add_systems(Startup, setup)
15        .run();
16}
Source

pub fn register_type<T>(&mut self) -> &mut App

Available on crate feature bevy_reflect only.

Registers the type T in the AppTypeRegistry resource, adding reflect data as specified in the Reflect derive:

#[derive(Component, Serialize, Deserialize, Reflect)]
#[reflect(Component, Serialize, Deserialize)] // will register ReflectComponent, ReflectSerialize, ReflectDeserialize

See bevy_reflect::TypeRegistry::register for more information.

Examples found in repository?
examples/reflection/generic_reflection.rs (line 10)
6fn main() {
7    App::new()
8        .add_plugins(DefaultPlugins)
9        // You must manually register each instance of a generic type
10        .register_type::<MyType<u32>>()
11        .add_systems(Startup, setup)
12        .run();
13}
Source

pub fn register_type_data<T, D>(&mut self) -> &mut App
where T: Reflect + TypePath, D: TypeData + FromType<T>,

Available on crate feature bevy_reflect only.

Associates type data D with type T in the AppTypeRegistry resource.

Most of the time register_type can be used instead to register a type you derived Reflect for. However, in cases where you want to add a piece of type data that was not included in the list of #[reflect(...)] type data in the derive, or where the type is generic and cannot register e.g. ReflectSerialize unconditionally without knowing the specific type parameters, this method can be used to insert additional type data.

§Example
use bevy_app::App;
use bevy_reflect::{ReflectSerialize, ReflectDeserialize};

App::new()
    .register_type::<Option<String>>()
    .register_type_data::<Option<String>, ReflectSerialize>()
    .register_type_data::<Option<String>, ReflectDeserialize>();

See bevy_reflect::TypeRegistry::register_type_data.

Source

pub fn register_function<F, Marker>(&mut self, function: F) -> &mut App
where F: IntoFunction<'static, Marker> + 'static,

Available on crate feature reflect_functions only.

Registers the given function into the AppFunctionRegistry resource.

The given function will internally be stored as a DynamicFunction and mapped according to its name.

Because the function must have a name, anonymous functions (e.g. |a: i32, b: i32| { a + b }) and closures must instead be registered using register_function_with_name or converted to a DynamicFunction and named using DynamicFunction::with_name. Failure to do so will result in a panic.

Only types that implement IntoFunction may be registered via this method.

See FunctionRegistry::register for more information.

§Panics

Panics if a function has already been registered with the given name or if the function is missing a name (such as when it is an anonymous function).

§Examples
use bevy_app::App;

fn add(a: i32, b: i32) -> i32 {
    a + b
}

App::new().register_function(add);

Functions cannot be registered more than once.

use bevy_app::App;

fn add(a: i32, b: i32) -> i32 {
    a + b
}

App::new()
    .register_function(add)
    // Panic! A function has already been registered with the name "my_function"
    .register_function(add);

Anonymous functions and closures should be registered using register_function_with_name or given a name using DynamicFunction::with_name.

use bevy_app::App;

// Panic! Anonymous functions cannot be registered using `register_function`
App::new().register_function(|a: i32, b: i32| a + b);
Source

pub fn register_function_with_name<F, Marker>( &mut self, name: impl Into<Cow<'static, str>>, function: F, ) -> &mut App
where F: IntoFunction<'static, Marker> + 'static,

Available on crate feature reflect_functions only.

Registers the given function or closure into the AppFunctionRegistry resource using the given name.

To avoid conflicts, it’s recommended to use a unique name for the function. This can be achieved by “namespacing” the function with a unique identifier, such as the name of your crate.

For example, to register a function, add, from a crate, my_crate, you could use the name, "my_crate::add".

Another approach could be to use the type name of the function, however, it should be noted that anonymous functions do not have unique type names.

For named functions (e.g. fn add(a: i32, b: i32) -> i32 { a + b }) where a custom name is not needed, it’s recommended to use register_function instead as the generated name is guaranteed to be unique.

Only types that implement IntoFunction may be registered via this method.

See FunctionRegistry::register_with_name for more information.

§Panics

Panics if a function has already been registered with the given name.

§Examples
use bevy_app::App;

fn mul(a: i32, b: i32) -> i32 {
    a * b
}

let div = |a: i32, b: i32| a / b;

App::new()
    // Registering an anonymous function with a unique name
    .register_function_with_name("my_crate::add", |a: i32, b: i32| {
        a + b
    })
    // Registering an existing function with its type name
    .register_function_with_name(std::any::type_name_of_val(&mul), mul)
    // Registering an existing function with a custom name
    .register_function_with_name("my_crate::mul", mul)
    // Be careful not to register anonymous functions with their type name.
    // This code works but registers the function with a non-unique name like `foo::bar::{{closure}}`
    .register_function_with_name(std::any::type_name_of_val(&div), div);

Names must be unique.

use bevy_app::App;

fn one() {}
fn two() {}

App::new()
    .register_function_with_name("my_function", one)
    // Panic! A function has already been registered with the name "my_function"
    .register_function_with_name("my_function", two);
Source

pub fn register_required_components<T, R>(&mut self) -> &mut App
where T: Component, R: Component + Default,

Registers the given component R as a required component for T.

When T is added to an entity, R and its own required components will also be added if R was not already provided. The Default constructor will be used for the creation of R. If a custom constructor is desired, use App::register_required_components_with instead.

For the non-panicking version, see App::try_register_required_components.

Note that requirements must currently be registered before T is inserted into the world for the first time. Commonly, this is done in plugins. This limitation may be fixed in the future.

§Panics

Panics if R is already a directly required component for T, or if T has ever been added on an entity before the registration.

Indirect requirements through other components are allowed. In those cases, any existing requirements will only be overwritten if the new requirement is more specific.

§Example
#[derive(Component)]
struct A;

#[derive(Component, Default, PartialEq, Eq, Debug)]
struct B(usize);

#[derive(Component, Default, PartialEq, Eq, Debug)]
struct C(u32);

// Register B as required by A and C as required by B.
app.register_required_components::<A, B>();
app.register_required_components::<B, C>();

fn setup(mut commands: Commands) {
    // This will implicitly also insert B and C with their Default constructors.
    commands.spawn(A);
}

fn validate(query: Option<Single<(&A, &B, &C)>>) {
    let (a, b, c) = query.unwrap().into_inner();
    assert_eq!(b, &B(0));
    assert_eq!(c, &C(0));
}
Source

pub fn register_required_components_with<T, R>( &mut self, constructor: fn() -> R, ) -> &mut App
where T: Component, R: Component,

Registers the given component R as a required component for T.

When T is added to an entity, R and its own required components will also be added if R was not already provided. The given constructor will be used for the creation of R. If a Default constructor is desired, use App::register_required_components instead.

For the non-panicking version, see App::try_register_required_components_with.

Note that requirements must currently be registered before T is inserted into the world for the first time. Commonly, this is done in plugins. This limitation may be fixed in the future.

§Panics

Panics if R is already a directly required component for T, or if T has ever been added on an entity before the registration.

Indirect requirements through other components are allowed. In those cases, any existing requirements will only be overwritten if the new requirement is more specific.

§Example
#[derive(Component)]
struct A;

#[derive(Component, Default, PartialEq, Eq, Debug)]
struct B(usize);

#[derive(Component, Default, PartialEq, Eq, Debug)]
struct C(u32);

// Register B and C as required by A and C as required by B.
// A requiring C directly will overwrite the indirect requirement through B.
app.register_required_components::<A, B>();
app.register_required_components_with::<B, C>(|| C(1));
app.register_required_components_with::<A, C>(|| C(2));

fn setup(mut commands: Commands) {
    // This will implicitly also insert B with its Default constructor and C
    // with the custom constructor defined by A.
    commands.spawn(A);
}

fn validate(query: Option<Single<(&A, &B, &C)>>) {
    let (a, b, c) = query.unwrap().into_inner();
    assert_eq!(b, &B(0));
    assert_eq!(c, &C(2));
}
Source

pub fn try_register_required_components<T, R>( &mut self, ) -> Result<(), RequiredComponentsError>
where T: Component, R: Component + Default,

Tries to register the given component R as a required component for T.

When T is added to an entity, R and its own required components will also be added if R was not already provided. The Default constructor will be used for the creation of R. If a custom constructor is desired, use App::register_required_components_with instead.

For the panicking version, see App::register_required_components.

Note that requirements must currently be registered before T is inserted into the world for the first time. Commonly, this is done in plugins. This limitation may be fixed in the future.

§Errors

Returns a RequiredComponentsError if R is already a directly required component for T, or if T has ever been added on an entity before the registration.

Indirect requirements through other components are allowed. In those cases, any existing requirements will only be overwritten if the new requirement is more specific.

§Example
#[derive(Component)]
struct A;

#[derive(Component, Default, PartialEq, Eq, Debug)]
struct B(usize);

#[derive(Component, Default, PartialEq, Eq, Debug)]
struct C(u32);

// Register B as required by A and C as required by B.
app.register_required_components::<A, B>();
app.register_required_components::<B, C>();

// Duplicate registration! This will fail.
assert!(app.try_register_required_components::<A, B>().is_err());

fn setup(mut commands: Commands) {
    // This will implicitly also insert B and C with their Default constructors.
    commands.spawn(A);
}

fn validate(query: Option<Single<(&A, &B, &C)>>) {
    let (a, b, c) = query.unwrap().into_inner();
    assert_eq!(b, &B(0));
    assert_eq!(c, &C(0));
}
Source

pub fn try_register_required_components_with<T, R>( &mut self, constructor: fn() -> R, ) -> Result<(), RequiredComponentsError>
where T: Component, R: Component,

Tries to register the given component R as a required component for T.

When T is added to an entity, R and its own required components will also be added if R was not already provided. The given constructor will be used for the creation of R. If a Default constructor is desired, use App::register_required_components instead.

For the panicking version, see App::register_required_components_with.

Note that requirements must currently be registered before T is inserted into the world for the first time. Commonly, this is done in plugins. This limitation may be fixed in the future.

§Errors

Returns a RequiredComponentsError if R is already a directly required component for T, or if T has ever been added on an entity before the registration.

Indirect requirements through other components are allowed. In those cases, any existing requirements will only be overwritten if the new requirement is more specific.

§Example
#[derive(Component)]
struct A;

#[derive(Component, Default, PartialEq, Eq, Debug)]
struct B(usize);

#[derive(Component, Default, PartialEq, Eq, Debug)]
struct C(u32);

// Register B and C as required by A and C as required by B.
// A requiring C directly will overwrite the indirect requirement through B.
app.register_required_components::<A, B>();
app.register_required_components_with::<B, C>(|| C(1));
app.register_required_components_with::<A, C>(|| C(2));

// Duplicate registration! Even if the constructors were different, this would fail.
assert!(app.try_register_required_components_with::<B, C>(|| C(1)).is_err());

fn setup(mut commands: Commands) {
    // This will implicitly also insert B with its Default constructor and C
    // with the custom constructor defined by A.
    commands.spawn(A);
}

fn validate(query: Option<Single<(&A, &B, &C)>>) {
    let (a, b, c) = query.unwrap().into_inner();
    assert_eq!(b, &B(0));
    assert_eq!(c, &C(2));
}
Source

pub fn register_disabling_component<C>(&mut self)
where C: Component,

Registers a component type as “disabling”, using default query filters to exclude entities with the component from queries.

§Warning

As discussed in the module docs, this can have performance implications, as well as create interoperability issues, and should be used with caution.

Source

pub fn world(&self) -> &World

Returns a reference to the main SubApp’s World. This is the same as calling app.main().world().

Source

pub fn world_mut(&mut self) -> &mut World

Returns a mutable reference to the main SubApp’s World. This is the same as calling app.main_mut().world_mut().

Examples found in repository?
examples/shader/shader_material_wesl.rs (line 43)
41    fn build(&self, app: &mut App) {
42        let handle = app
43            .world_mut()
44            .resource_mut::<AssetServer>()
45            .load::<Shader>("shaders/util.wesl");
46        app.insert_resource(UtilityShader(handle));
47    }
More examples
Hide additional examples
examples/ecs/system_stepping.rs (line 59)
7fn main() {
8    let mut app = App::new();
9
10    app
11        // to display log messages from Stepping resource
12        .add_plugins(LogPlugin::default())
13        .add_systems(
14            Update,
15            (
16                update_system_one,
17                // establish a dependency here to simplify descriptions below
18                update_system_two.after(update_system_one),
19                update_system_three.after(update_system_two),
20                update_system_four,
21            ),
22        )
23        .add_systems(PreUpdate, pre_update_system);
24
25    // For the simplicity of this example, we directly modify the `Stepping`
26    // resource here and run the systems with `App::update()`.  Each call to
27    // `App::update()` is the equivalent of a single frame render when using
28    // `App::run()`.
29    //
30    // In a real-world situation, the `Stepping` resource would be modified by
31    // a system based on input from the user.  A full demonstration of this can
32    // be found in the breakout example.
33    println!(
34        r#"
35    Actions: call app.update()
36     Result: All systems run normally"#
37    );
38    app.update();
39
40    println!(
41        r#"
42    Actions: Add the Stepping resource then call app.update()
43     Result: All systems run normally.  Stepping has no effect unless explicitly
44             configured for a Schedule, and Stepping has been enabled."#
45    );
46    app.insert_resource(Stepping::new());
47    app.update();
48
49    println!(
50        r#"
51    Actions: Add the Update Schedule to Stepping; enable Stepping; call
52             app.update()
53     Result: Only the systems in PreUpdate run.  When Stepping is enabled,
54             systems in the configured schedules will not run unless:
55             * Stepping::step_frame() is called
56             * Stepping::continue_frame() is called
57             * System has been configured to always run"#
58    );
59    let mut stepping = app.world_mut().resource_mut::<Stepping>();
60    stepping.add_schedule(Update).enable();
61    app.update();
62
63    println!(
64        r#"
65    Actions: call Stepping.step_frame(); call app.update()
66     Result: The PreUpdate systems run, and one Update system will run.  In
67             Stepping, step means run the next system across all the schedules 
68             that have been added to the Stepping resource."#
69    );
70    let mut stepping = app.world_mut().resource_mut::<Stepping>();
71    stepping.step_frame();
72    app.update();
73
74    println!(
75        r#"
76    Actions: call app.update()
77     Result: Only the PreUpdate systems run.  The previous call to
78             Stepping::step_frame() only applies for the next call to
79             app.update()/the next frame rendered.
80    "#
81    );
82    app.update();
83
84    println!(
85        r#"
86    Actions: call Stepping::continue_frame(); call app.update()
87     Result: PreUpdate system will run, and all remaining Update systems will
88             run.  Stepping::continue_frame() tells stepping to run all systems
89             starting after the last run system until it hits the end of the
90             frame, or it encounters a system with a breakpoint set.  In this
91             case, we previously performed a step, running one system in Update.
92             This continue will cause all remaining systems in Update to run."#
93    );
94    let mut stepping = app.world_mut().resource_mut::<Stepping>();
95    stepping.continue_frame();
96    app.update();
97
98    println!(
99        r#"
100    Actions: call Stepping::step_frame() & app.update() four times in a row
101     Result: PreUpdate system runs every time we call app.update(), along with
102             one system from the Update schedule each time.  This shows what
103             execution would look like to step through an entire frame of 
104             systems."#
105    );
106    for _ in 0..4 {
107        let mut stepping = app.world_mut().resource_mut::<Stepping>();
108        stepping.step_frame();
109        app.update();
110    }
111
112    println!(
113        r#"
114    Actions: Stepping::always_run(Update, update_system_two); step through all
115             systems
116     Result: PreUpdate system and update_system_two() will run every time we
117             call app.update().  We'll also only need to step three times to
118             execute all systems in the frame.  Stepping::always_run() allows
119             us to granularly allow systems to run when stepping is enabled."#
120    );
121    let mut stepping = app.world_mut().resource_mut::<Stepping>();
122    stepping.always_run(Update, update_system_two);
123    for _ in 0..3 {
124        let mut stepping = app.world_mut().resource_mut::<Stepping>();
125        stepping.step_frame();
126        app.update();
127    }
128
129    println!(
130        r#"
131    Actions: Stepping::never_run(Update, update_system_two); continue through
132             all systems
133     Result: All systems except update_system_two() will execute.
134             Stepping::never_run() allows us to disable systems while Stepping
135             is enabled."#
136    );
137    let mut stepping = app.world_mut().resource_mut::<Stepping>();
138    stepping.never_run(Update, update_system_two);
139    stepping.continue_frame();
140    app.update();
141
142    println!(
143        r#"
144    Actions: Stepping::set_breakpoint(Update, update_system_two); continue,
145             step, continue
146     Result: During the first continue, pre_update_system() and
147             update_system_one() will run.  update_system_four() may also run
148             as it has no dependency on update_system_two() or
149             update_system_three().  Nether update_system_two() nor
150             update_system_three() will run in the first app.update() call as
151             they form a chained dependency on update_system_one() and run
152             in order of one, two, three.  Stepping stops system execution in
153             the Update schedule when it encounters the breakpoint for
154             update_system_two().
155             During the step we run update_system_two() along with the
156             pre_update_system().
157             During the final continue pre_update_system() and
158             update_system_three() run."#
159    );
160    let mut stepping = app.world_mut().resource_mut::<Stepping>();
161    stepping.set_breakpoint(Update, update_system_two);
162    stepping.continue_frame();
163    app.update();
164    let mut stepping = app.world_mut().resource_mut::<Stepping>();
165    stepping.step_frame();
166    app.update();
167    let mut stepping = app.world_mut().resource_mut::<Stepping>();
168    stepping.continue_frame();
169    app.update();
170
171    println!(
172        r#"
173    Actions: Stepping::clear_breakpoint(Update, update_system_two); continue
174             through all systems
175     Result: All systems will run"#
176    );
177    let mut stepping = app.world_mut().resource_mut::<Stepping>();
178    stepping.clear_breakpoint(Update, update_system_two);
179    stepping.continue_frame();
180    app.update();
181
182    println!(
183        r#"
184    Actions: Stepping::disable(); app.update()
185     Result: All systems will run.  With Stepping disabled, there's no need to
186             call Stepping::step_frame() or Stepping::continue_frame() to run
187             systems in the Update schedule."#
188    );
189    let mut stepping = app.world_mut().resource_mut::<Stepping>();
190    stepping.disable();
191    app.update();
192}
Source

pub fn main(&self) -> &SubApp

Returns a reference to the main SubApp.

Source

pub fn main_mut(&mut self) -> &mut SubApp

Returns a mutable reference to the main SubApp.

Source

pub fn sub_apps(&self) -> &SubApps

Returns a reference to the SubApps collection.

Source

pub fn sub_apps_mut(&mut self) -> &mut SubApps

Returns a mutable reference to the SubApps collection.

Source

pub fn sub_app(&self, label: impl AppLabel) -> &SubApp

Returns a reference to the SubApp with the given label.

§Panics

Panics if the SubApp doesn’t exist.

Source

pub fn sub_app_mut(&mut self, label: impl AppLabel) -> &mut SubApp

Returns a reference to the SubApp with the given label.

§Panics

Panics if the SubApp doesn’t exist.

Source

pub fn get_sub_app(&self, label: impl AppLabel) -> Option<&SubApp>

Returns a reference to the SubApp with the given label, if it exists.

Source

pub fn get_sub_app_mut(&mut self, label: impl AppLabel) -> Option<&mut SubApp>

Returns a mutable reference to the SubApp with the given label, if it exists.

Source

pub fn insert_sub_app(&mut self, label: impl AppLabel, sub_app: SubApp)

Inserts a SubApp with the given label.

Source

pub fn remove_sub_app(&mut self, label: impl AppLabel) -> Option<SubApp>

Removes the SubApp with the given label, if it exists.

Source

pub fn update_sub_app_by_label(&mut self, label: impl AppLabel)

Extract data from the main world into the SubApp with the given label and perform an update if it exists.

Source

pub fn add_schedule(&mut self, schedule: Schedule) -> &mut App

Inserts a new schedule under the provided label, overwriting any existing schedule with the same label.

Source

pub fn init_schedule(&mut self, label: impl ScheduleLabel) -> &mut App

Initializes an empty schedule under the provided label, if it does not exist.

See add_schedule to insert an existing schedule.

Source

pub fn get_schedule(&self, label: impl ScheduleLabel) -> Option<&Schedule>

Returns a reference to the Schedule with the provided label if it exists.

Source

pub fn get_schedule_mut( &mut self, label: impl ScheduleLabel, ) -> Option<&mut Schedule>

Returns a mutable reference to the Schedule with the provided label if it exists.

Source

pub fn edit_schedule( &mut self, label: impl ScheduleLabel, f: impl FnMut(&mut Schedule), ) -> &mut App

Runs function f with the Schedule associated with label.

Note: This will create the schedule if it does not already exist.

Source

pub fn configure_schedules( &mut self, schedule_build_settings: ScheduleBuildSettings, ) -> &mut App

Applies the provided ScheduleBuildSettings to all schedules.

This mutates all currently present schedules, but does not apply to any custom schedules that might be added in the future.

Source

pub fn allow_ambiguous_component<T>(&mut self) -> &mut App
where T: Component,

When doing ambiguity checking this ignores systems that are ambiguous on Component T.

This settings only applies to the main world. To apply this to other worlds call the corresponding method on World

§Example

#[derive(Component)]
struct A;

// these systems are ambiguous on A
fn system_1(_: Query<&mut A>) {}
fn system_2(_: Query<&A>) {}

let mut app = App::new();
app.configure_schedules(ScheduleBuildSettings {
  ambiguity_detection: LogLevel::Error,
  ..default()
});

app.add_systems(Update, ( system_1, system_2 ));
app.allow_ambiguous_component::<A>();

// running the app does not error.
app.update();
Source

pub fn allow_ambiguous_resource<T>(&mut self) -> &mut App
where T: Resource,

When doing ambiguity checking this ignores systems that are ambiguous on Resource T.

This settings only applies to the main world. To apply this to other worlds call the corresponding method on World

§Example

#[derive(Resource)]
struct R;

// these systems are ambiguous on R
fn system_1(_: ResMut<R>) {}
fn system_2(_: Res<R>) {}

let mut app = App::new();
app.configure_schedules(ScheduleBuildSettings {
  ambiguity_detection: LogLevel::Error,
  ..default()
});
app.insert_resource(R);

app.add_systems(Update, ( system_1, system_2 ));
app.allow_ambiguous_resource::<R>();

// running the app does not error.
app.update();
Source

pub fn ignore_ambiguity<M1, M2, S1, S2>( &mut self, schedule: impl ScheduleLabel, a: S1, b: S2, ) -> &mut App
where S1: IntoSystemSet<M1>, S2: IntoSystemSet<M2>,

Suppress warnings and errors that would result from systems in these sets having ambiguities (conflicting access but indeterminate order) with systems in set.

When possible, do this directly in the .add_systems(Update, a.ambiguous_with(b)) call. However, sometimes two independent plugins A and B are reported as ambiguous, which you can only suppress as the consumer of both.

Source

pub fn should_exit(&self) -> Option<AppExit>

Attempts to determine if an AppExit was raised since the last update.

Will attempt to return the first Error it encounters. This should be called after every update() otherwise you risk dropping possible AppExit events.

Source

pub fn add_observer<E, B, M>( &mut self, observer: impl IntoObserverSystem<E, B, M>, ) -> &mut App
where E: Event, B: Bundle,

Spawns an Observer entity, which will watch for and respond to the given event.

observer can be any system whose first parameter is On.

§Examples

app.add_observer(|event: On<Party>, friends: Query<Entity, With<Friend>>, mut commands: Commands| {
    if event.friends_allowed {
        for entity in friends.iter() {
            commands.trigger(Invite { entity } );
        }
    }
});
Source

pub fn get_error_handler(&self) -> Option<fn(BevyError, ErrorContext)>

Gets the error handler to set for new supapps.

Note that the error handler of existing subapps may differ.

Source

pub fn set_error_handler( &mut self, handler: fn(BevyError, ErrorContext), ) -> &mut App

Set the default error handler for the all subapps (including the main one and future ones) that do not have one.

May only be called once and should be set by the application, not by libraries.

The handler will be called when an error is produced and not otherwise handled.

§Panics

Panics if called multiple times.

§Example
App::new()
    .set_error_handler(warn)
    .add_plugins(MyPlugins)
    .run();

Trait Implementations§

Source§

impl AddAudioSource for App

Source§

fn add_audio_source<T>(&mut self) -> &mut App

Registers an audio source. The type must implement Decodable, so that it can be converted to a rodio::Source type, and Asset, so that it can be registered as an asset. To use this method on App, the audio and asset plugins must be added first.
Source§

impl AddRenderCommand for App

Source§

fn add_render_command<P, C>(&mut self) -> &mut App
where P: PhaseItem, C: RenderCommand<P> + Send + Sync + 'static, <C as RenderCommand<P>>::Param: ReadOnlySystemParam,

Adds the RenderCommand for the specified render phase to the app.
Source§

impl AppExtStates for App

Source§

fn init_state<S>(&mut self) -> &mut App

Initializes a State with standard starting values. Read more
Source§

fn insert_state<S>(&mut self, state: S) -> &mut App

Inserts a specific State to the current App and overrides any State previously added of the same type. Read more
Source§

fn add_computed_state<S>(&mut self) -> &mut App
where S: ComputedStates,

Sets up a type implementing ComputedStates. Read more
Source§

fn add_sub_state<S>(&mut self) -> &mut App
where S: SubStates,

Sets up a type implementing SubStates. Read more
Source§

fn register_type_state<S>(&mut self) -> &mut App

Available on crate feature bevy_reflect only.
Registers the state type T using App::register_type, and adds ReflectState type data to T in the type registry. Read more
Source§

fn register_type_mutable_state<S>(&mut self) -> &mut App

Available on crate feature bevy_reflect only.
Registers the state type T using App::register_type, and adds crate::reflect::ReflectState and crate::reflect::ReflectFreelyMutableState type data to T in the type registry. Read more
Source§

impl AppGizmoBuilder for App

Source§

fn init_gizmo_group<Config>(&mut self) -> &mut App
where Config: GizmoConfigGroup,

Registers GizmoConfigGroup in the app enabling the use of Gizmos<Config>. Read more
Source§

fn insert_gizmo_config<Config>( &mut self, group: Config, config: GizmoConfig, ) -> &mut App
where Config: GizmoConfigGroup,

Insert a GizmoConfig into a specific GizmoConfigGroup. Read more
Source§

impl AssetApp for App

Source§

fn register_asset_loader<L>(&mut self, loader: L) -> &mut App
where L: AssetLoader,

Registers the given loader in the App’s AssetServer.
Source§

fn register_asset_processor<P>(&mut self, processor: P) -> &mut App
where P: Process,

Registers the given processor in the App’s AssetProcessor.
Source§

fn register_asset_source( &mut self, id: impl Into<AssetSourceId<'static>>, source: AssetSourceBuilder, ) -> &mut App

Registers the given AssetSourceBuilder with the given id. Read more
Source§

fn set_default_asset_processor<P>(&mut self, extension: &str) -> &mut App
where P: Process,

Sets the default asset processor for the given extension.
Source§

fn init_asset_loader<L>(&mut self) -> &mut App

Initializes the given loader in the App’s AssetServer.
Source§

fn init_asset<A>(&mut self) -> &mut App
where A: Asset,

Initializes the given Asset in the App by: Read more
Source§

fn register_asset_reflect<A>(&mut self) -> &mut App

Registers the asset type T using [App::register], and adds ReflectAsset type data to T and ReflectHandle type data to Handle<T> in the type registry. Read more
Source§

fn preregister_asset_loader<L>(&mut self, extensions: &[&str]) -> &mut App
where L: AssetLoader,

Preregisters a loader for the given extensions, that will block asset loads until a real loader is registered.
Source§

impl Debug for App

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for App

Source§

fn default() -> App

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

impl GetAssetServer for App

Source§

impl RegisterDiagnostic for App

Source§

fn register_diagnostic(&mut self, diagnostic: Diagnostic) -> &mut App

Register a new Diagnostic with an App. Read more
Source§

impl RenderGraphExt for App

Source§

fn add_render_graph_node<T>( &mut self, sub_graph: impl RenderSubGraph, node_label: impl RenderLabel, ) -> &mut App
where T: Node + FromWorld,

Add a Node to the RenderGraph: Read more
Source§

fn add_render_graph_edge( &mut self, sub_graph: impl RenderSubGraph, output_node: impl RenderLabel, input_node: impl RenderLabel, ) -> &mut App

Add node edge to the specified graph
Source§

fn add_render_graph_edges<const N: usize>( &mut self, sub_graph: impl RenderSubGraph, edges: impl IntoRenderNodeArray<N>, ) -> &mut App

Automatically add the required node edges based on the given ordering
Source§

fn add_render_sub_graph(&mut self, sub_graph: impl RenderSubGraph) -> &mut App

Source§

impl StateScopedMessagesAppExt for App

Source§

fn clear_messages_on_exit<M>(&mut self, state: impl States) -> &mut App
where M: Message,

Clears a Message when exiting the specified state. Read more
Source§

fn clear_messages_on_enter<M>(&mut self, state: impl States) -> &mut App
where M: Message,

Clears a Message when entering the specified state. Read more

Auto Trait Implementations§

§

impl !Freeze for App

§

impl !RefUnwindSafe for App

§

impl !Send for App

§

impl !Sync for App

§

impl Unpin for App

§

impl !UnwindSafe 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, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
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<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &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)

Converts &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 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> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

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> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

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

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,