From 88d98cac2da1c337cdf9bf7d7f7d25444dbd435c Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Mon, 23 Aug 2021 17:18:14 -0700 Subject: [PATCH 1/7] Ergonomics tweaks, remove allocation during sub app get, RenderApp rename --- crates/bevy_app/src/app.rs | 13 ++++++++----- pipelined/bevy_core_pipeline/src/lib.rs | 4 ++-- pipelined/bevy_pbr2/src/lib.rs | 4 ++-- pipelined/bevy_render2/src/camera/mod.rs | 5 ++--- pipelined/bevy_render2/src/lib.rs | 4 ++-- pipelined/bevy_render2/src/render_asset.rs | 5 ++--- pipelined/bevy_render2/src/texture/mod.rs | 5 ++--- pipelined/bevy_render2/src/view/mod.rs | 4 ++-- pipelined/bevy_render2/src/view/window.rs | 5 ++--- pipelined/bevy_sprite2/src/lib.rs | 7 +++---- 10 files changed, 27 insertions(+), 29 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index faf7a4cc1590c..096f470ba69db 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -16,7 +16,6 @@ pub use bevy_app_macros::SubAppLabel; use bevy_utils::tracing::info_span; bevy_utils::define_label!(SubAppLabel); -type BoxedSubAppLabel = Box; #[allow(clippy::needless_doctest_main)] /// Containers of app logic and data @@ -45,7 +44,7 @@ pub struct App { pub world: World, pub runner: Box, pub schedule: Schedule, - sub_apps: HashMap, + sub_apps: HashMap, SubApp>, } struct SubApp { @@ -608,10 +607,14 @@ impl App { self } - pub fn sub_app_mut(&mut self, label: impl SubAppLabel) -> Option<&mut App> { - let label = Box::new(label) as BoxedSubAppLabel; + pub fn sub_app(&mut self, label: impl SubAppLabel) -> &mut App { + self.get_sub_app(label) + .expect("SubApp with the given label does not exist") + } + + pub fn get_sub_app(&mut self, label: impl SubAppLabel) -> Option<&mut App> { self.sub_apps - .get_mut(&label) + .get_mut((&label) as &dyn SubAppLabel) .map(|sub_app| &mut sub_app.app) } } diff --git a/pipelined/bevy_core_pipeline/src/lib.rs b/pipelined/bevy_core_pipeline/src/lib.rs index 6f7d447ac5fb7..c9187adf39daa 100644 --- a/pipelined/bevy_core_pipeline/src/lib.rs +++ b/pipelined/bevy_core_pipeline/src/lib.rs @@ -20,7 +20,7 @@ use bevy_render2::{ renderer::RenderDevice, texture::TextureCache, view::{ExtractedView, ViewPlugin}, - RenderStage, RenderSubApp, RenderWorld, + RenderApp, RenderStage, RenderWorld, }; /// Resource that configures the clear color @@ -74,7 +74,7 @@ impl Plugin for CorePipelinePlugin { fn build(&self, app: &mut App) { app.init_resource::(); - let render_app = app.sub_app_mut(RenderSubApp).unwrap(); + let render_app = app.sub_app(RenderApp); render_app .add_system_to_stage(RenderStage::Extract, extract_clear_color) .add_system_to_stage(RenderStage::Extract, extract_core_pipeline_camera_phases) diff --git a/pipelined/bevy_pbr2/src/lib.rs b/pipelined/bevy_pbr2/src/lib.rs index 4490e660b6514..8e1a0dc8f5b48 100644 --- a/pipelined/bevy_pbr2/src/lib.rs +++ b/pipelined/bevy_pbr2/src/lib.rs @@ -13,7 +13,7 @@ use bevy_ecs::prelude::*; use bevy_render2::{ render_graph::RenderGraph, render_phase::{sort_phase_system, DrawFunctions}, - RenderStage, RenderSubApp, + RenderApp, RenderStage, }; pub mod draw_3d_graph { @@ -30,7 +30,7 @@ impl Plugin for PbrPlugin { app.add_plugin(StandardMaterialPlugin) .init_resource::(); - let render_app = app.sub_app_mut(RenderSubApp).unwrap(); + let render_app = app.sub_app(RenderApp); render_app .add_system_to_stage(RenderStage::Extract, render::extract_meshes) .add_system_to_stage(RenderStage::Extract, render::extract_lights) diff --git a/pipelined/bevy_render2/src/camera/mod.rs b/pipelined/bevy_render2/src/camera/mod.rs index cade9c514962b..597e54c98c26d 100644 --- a/pipelined/bevy_render2/src/camera/mod.rs +++ b/pipelined/bevy_render2/src/camera/mod.rs @@ -12,7 +12,7 @@ pub use bundle::*; pub use camera::*; pub use projection::*; -use crate::{view::ExtractedView, RenderStage, RenderSubApp}; +use crate::{view::ExtractedView, RenderApp, RenderStage}; use bevy_app::{App, CoreStage, Plugin}; use bevy_ecs::prelude::*; @@ -40,8 +40,7 @@ impl Plugin for CameraPlugin { CoreStage::PostUpdate, crate::camera::camera_system::, ); - let render_app = app.sub_app_mut(RenderSubApp).unwrap(); - render_app + app.sub_app(RenderApp) .init_resource::() .add_system_to_stage(RenderStage::Extract, extract_cameras); } diff --git a/pipelined/bevy_render2/src/lib.rs b/pipelined/bevy_render2/src/lib.rs index 49d73e97e43a8..c3fe5fa265beb 100644 --- a/pipelined/bevy_render2/src/lib.rs +++ b/pipelined/bevy_render2/src/lib.rs @@ -75,7 +75,7 @@ impl DerefMut for RenderWorld { /// Label for the rendering sub-app #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, SubAppLabel)] -pub struct RenderSubApp; +pub struct RenderApp; /// A "scratch" world used to avoid allocating new worlds every frame when // swapping out the Render World. @@ -118,7 +118,7 @@ impl Plugin for RenderPlugin { .init_resource::() .init_resource::(); - app.add_sub_app(RenderSubApp, render_app, move |app_world, render_app| { + app.add_sub_app(RenderApp, render_app, move |app_world, render_app| { // reserve all existing app entities for use in render_app // they can only be spawned using `get_or_spawn()` let meta_len = app_world.entities().meta.len(); diff --git a/pipelined/bevy_render2/src/render_asset.rs b/pipelined/bevy_render2/src/render_asset.rs index 66fd9f2dabdbc..4185c93cc09c2 100644 --- a/pipelined/bevy_render2/src/render_asset.rs +++ b/pipelined/bevy_render2/src/render_asset.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use crate::{ renderer::{RenderDevice, RenderQueue}, - RenderStage, RenderSubApp, + RenderApp, RenderStage, }; use bevy_app::{App, Plugin}; use bevy_asset::{Asset, AssetEvent, Assets, Handle}; @@ -31,8 +31,7 @@ impl Default for RenderAssetPlugin { impl Plugin for RenderAssetPlugin { fn build(&self, app: &mut App) { - let render_app = app.sub_app_mut(RenderSubApp).unwrap(); - render_app + app.sub_app(RenderApp) .init_resource::>() .init_resource::>() .add_system_to_stage(RenderStage::Extract, extract_render_asset::) diff --git a/pipelined/bevy_render2/src/texture/mod.rs b/pipelined/bevy_render2/src/texture/mod.rs index efe05dc5616f4..cd25dd57387ae 100644 --- a/pipelined/bevy_render2/src/texture/mod.rs +++ b/pipelined/bevy_render2/src/texture/mod.rs @@ -13,7 +13,7 @@ pub use hdr_texture_loader::*; pub use image_texture_loader::*; pub use texture_cache::*; -use crate::{render_asset::RenderAssetPlugin, RenderStage, RenderSubApp}; +use crate::{render_asset::RenderAssetPlugin, RenderApp, RenderStage}; use bevy_app::{App, Plugin}; use bevy_asset::AddAsset; @@ -30,8 +30,7 @@ impl Plugin for ImagePlugin { app.add_plugin(RenderAssetPlugin::::default()) .add_asset::(); - let render_app = app.sub_app_mut(RenderSubApp).unwrap(); - render_app + app.sub_app(RenderApp) .init_resource::() .add_system_to_stage(RenderStage::Cleanup, update_texture_cache_system); } diff --git a/pipelined/bevy_render2/src/view/mod.rs b/pipelined/bevy_render2/src/view/mod.rs index 911148116b3c7..e00a3bdcdc5bc 100644 --- a/pipelined/bevy_render2/src/view/mod.rs +++ b/pipelined/bevy_render2/src/view/mod.rs @@ -7,7 +7,7 @@ use crate::{ render_graph::{Node, NodeRunError, RenderGraph, RenderGraphContext}, render_resource::DynamicUniformVec, renderer::{RenderContext, RenderDevice}, - RenderStage, RenderSubApp, + RenderApp, RenderStage, }; use bevy_app::{App, Plugin}; use bevy_ecs::prelude::*; @@ -22,7 +22,7 @@ impl ViewPlugin { impl Plugin for ViewPlugin { fn build(&self, app: &mut App) { - let render_app = app.sub_app_mut(RenderSubApp).unwrap(); + let render_app = app.sub_app(RenderApp); render_app .init_resource::() .add_system_to_stage(RenderStage::Prepare, prepare_views); diff --git a/pipelined/bevy_render2/src/view/window.rs b/pipelined/bevy_render2/src/view/window.rs index dbcf46f4c3010..cb71008f572b3 100644 --- a/pipelined/bevy_render2/src/view/window.rs +++ b/pipelined/bevy_render2/src/view/window.rs @@ -2,7 +2,7 @@ use crate::{ render_resource::TextureView, renderer::{RenderDevice, RenderInstance}, texture::BevyDefault, - RenderStage, RenderSubApp, + RenderApp, RenderStage, }; use bevy_app::{App, Plugin}; use bevy_ecs::prelude::*; @@ -19,8 +19,7 @@ pub struct WindowRenderPlugin; impl Plugin for WindowRenderPlugin { fn build(&self, app: &mut App) { - let render_app = app.sub_app_mut(RenderSubApp).unwrap(); - render_app + app.sub_app(RenderApp) .init_resource::() .init_resource::() .add_system_to_stage(RenderStage::Extract, extract_windows) diff --git a/pipelined/bevy_sprite2/src/lib.rs b/pipelined/bevy_sprite2/src/lib.rs index a1a7643ea69d3..5c77bf0714765 100644 --- a/pipelined/bevy_sprite2/src/lib.rs +++ b/pipelined/bevy_sprite2/src/lib.rs @@ -17,7 +17,7 @@ pub use texture_atlas_builder::*; use bevy_app::prelude::*; use bevy_render2::{ - render_graph::RenderGraph, render_phase::DrawFunctions, RenderStage, RenderSubApp, + render_graph::RenderGraph, render_phase::DrawFunctions, RenderApp, RenderStage, }; #[derive(Default)] @@ -28,7 +28,7 @@ impl Plugin for SpritePlugin { app.add_asset::() .register_type::() .add_system_to_stage(CoreStage::PostUpdate, sprite_auto_resize_system); - let render_app = app.sub_app_mut(RenderSubApp).unwrap(); + let render_app = app.sub_app(RenderApp); render_app .init_resource::() .add_system_to_stage(RenderStage::Extract, render::extract_atlases) @@ -44,8 +44,7 @@ impl Plugin for SpritePlugin { .unwrap() .write() .add(draw_sprite); - let render_world = app.sub_app_mut(RenderSubApp).unwrap().world.cell(); - let mut graph = render_world.get_resource_mut::().unwrap(); + let mut graph = render_app.world.get_resource_mut::().unwrap(); graph.add_node("sprite", SpriteNode); graph .add_node_edge("sprite", bevy_core_pipeline::node::MAIN_PASS_DEPENDENCIES) From 4f4982318ee75359ad5f724f00584f442ca46659 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Mon, 23 Aug 2021 17:20:55 -0700 Subject: [PATCH 2/7] SubAppLabel -> AppLabel --- crates/bevy_app/macros/src/lib.rs | 6 +++--- crates/bevy_app/src/app.rs | 14 +++++++------- pipelined/bevy_render2/src/lib.rs | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/bevy_app/macros/src/lib.rs b/crates/bevy_app/macros/src/lib.rs index eafa3dde55cda..05bffa37bc1e5 100644 --- a/crates/bevy_app/macros/src/lib.rs +++ b/crates/bevy_app/macros/src/lib.rs @@ -4,13 +4,13 @@ use bevy_macro_utils::{derive_label, BevyManifest}; use proc_macro::TokenStream; use quote::format_ident; -#[proc_macro_derive(SubAppLabel)] -pub fn derive_sub_app_label(input: TokenStream) -> TokenStream { +#[proc_macro_derive(AppLabel)] +pub fn derive_app_label(input: TokenStream) -> TokenStream { let input = syn::parse_macro_input!(input as syn::DeriveInput); let mut trait_path = bevy_app_path(); trait_path .segments - .push(format_ident!("SubAppLabel").into()); + .push(format_ident!("AppLabel").into()); derive_label(input, trait_path) } diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 096f470ba69db..0ecd09f6073e4 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -10,12 +10,12 @@ use bevy_ecs::{ use bevy_utils::{tracing::debug, HashMap}; use std::{fmt::Debug, hash::Hash}; -pub use bevy_app_macros::SubAppLabel; +pub use bevy_app_macros::AppLabel; #[cfg(feature = "trace")] use bevy_utils::tracing::info_span; -bevy_utils::define_label!(SubAppLabel); +bevy_utils::define_label!(AppLabel); #[allow(clippy::needless_doctest_main)] /// Containers of app logic and data @@ -44,7 +44,7 @@ pub struct App { pub world: World, pub runner: Box, pub schedule: Schedule, - sub_apps: HashMap, SubApp>, + sub_apps: HashMap, SubApp>, } struct SubApp { @@ -593,7 +593,7 @@ impl App { pub fn add_sub_app( &mut self, - label: impl SubAppLabel, + label: impl AppLabel, app: App, f: impl Fn(&mut World, &mut App) + 'static, ) -> &mut Self { @@ -607,14 +607,14 @@ impl App { self } - pub fn sub_app(&mut self, label: impl SubAppLabel) -> &mut App { + pub fn sub_app(&mut self, label: impl AppLabel) -> &mut App { self.get_sub_app(label) .expect("SubApp with the given label does not exist") } - pub fn get_sub_app(&mut self, label: impl SubAppLabel) -> Option<&mut App> { + pub fn get_sub_app(&mut self, label: impl AppLabel) -> Option<&mut App> { self.sub_apps - .get_mut((&label) as &dyn SubAppLabel) + .get_mut((&label) as &dyn AppLabel) .map(|sub_app| &mut sub_app.app) } } diff --git a/pipelined/bevy_render2/src/lib.rs b/pipelined/bevy_render2/src/lib.rs index c3fe5fa265beb..4531c435243b6 100644 --- a/pipelined/bevy_render2/src/lib.rs +++ b/pipelined/bevy_render2/src/lib.rs @@ -24,7 +24,7 @@ use crate::{ texture::ImagePlugin, view::{ViewPlugin, WindowRenderPlugin}, }; -use bevy_app::{App, Plugin, SubAppLabel}; +use bevy_app::{App, Plugin, AppLabel}; use bevy_ecs::prelude::*; #[derive(Default)] @@ -74,7 +74,7 @@ impl DerefMut for RenderWorld { } /// Label for the rendering sub-app -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, SubAppLabel)] +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, AppLabel)] pub struct RenderApp; /// A "scratch" world used to avoid allocating new worlds every frame when From 79b33cc8fa03c5fa4440f562dedc3399647ce339 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Mon, 23 Aug 2021 17:26:59 -0700 Subject: [PATCH 3/7] Remove new app macros crate in favor of bevy_derive --- crates/bevy_app/Cargo.toml | 1 - crates/bevy_app/macros/Cargo.toml | 16 ---------------- crates/bevy_app/macros/src/lib.rs | 19 ------------------- crates/bevy_app/src/app.rs | 4 ++-- crates/bevy_derive/src/lib.rs | 10 ++++++++++ pipelined/bevy_render2/src/lib.rs | 2 +- 6 files changed, 13 insertions(+), 39 deletions(-) delete mode 100644 crates/bevy_app/macros/Cargo.toml delete mode 100644 crates/bevy_app/macros/src/lib.rs diff --git a/crates/bevy_app/Cargo.toml b/crates/bevy_app/Cargo.toml index f73f333392e1e..58e8ac243e79c 100644 --- a/crates/bevy_app/Cargo.toml +++ b/crates/bevy_app/Cargo.toml @@ -23,7 +23,6 @@ bevy_derive = { path = "../bevy_derive", version = "0.5.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } bevy_reflect = { path = "../bevy_reflect", version = "0.5.0", optional = true } bevy_utils = { path = "../bevy_utils", version = "0.5.0" } -bevy_app_macros = { path = "./macros", version = "0.5.0" } # other serde = { version = "1.0", features = ["derive"], optional = true } diff --git a/crates/bevy_app/macros/Cargo.toml b/crates/bevy_app/macros/Cargo.toml deleted file mode 100644 index 505c27068b690..0000000000000 --- a/crates/bevy_app/macros/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "bevy_app_macros" -version = "0.5.0" -description = "Bevy App Macros" -edition = "2018" -license = "MIT OR Apache-2.0" - -[lib] -proc-macro = true - -[dependencies] -bevy_macro_utils = { path = "../../bevy_macro_utils", version = "0.5.0" } - -syn = "1.0" -quote = "1.0" -proc-macro2 = "1.0" diff --git a/crates/bevy_app/macros/src/lib.rs b/crates/bevy_app/macros/src/lib.rs deleted file mode 100644 index 05bffa37bc1e5..0000000000000 --- a/crates/bevy_app/macros/src/lib.rs +++ /dev/null @@ -1,19 +0,0 @@ -extern crate proc_macro; - -use bevy_macro_utils::{derive_label, BevyManifest}; -use proc_macro::TokenStream; -use quote::format_ident; - -#[proc_macro_derive(AppLabel)] -pub fn derive_app_label(input: TokenStream) -> TokenStream { - let input = syn::parse_macro_input!(input as syn::DeriveInput); - let mut trait_path = bevy_app_path(); - trait_path - .segments - .push(format_ident!("AppLabel").into()); - derive_label(input, trait_path) -} - -fn bevy_app_path() -> syn::Path { - BevyManifest::default().get_path("bevy_app") -} diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 0ecd09f6073e4..3f253be8ef7c5 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -1,3 +1,5 @@ +pub use bevy_derive::AppLabel; + use crate::{CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupStage}; use bevy_ecs::{ component::{Component, ComponentDescriptor}, @@ -10,8 +12,6 @@ use bevy_ecs::{ use bevy_utils::{tracing::debug, HashMap}; use std::{fmt::Debug, hash::Hash}; -pub use bevy_app_macros::AppLabel; - #[cfg(feature = "trace")] use bevy_utils::tracing::info_span; diff --git a/crates/bevy_derive/src/lib.rs b/crates/bevy_derive/src/lib.rs index a73093ed2aa7e..7f21428fc2a7a 100644 --- a/crates/bevy_derive/src/lib.rs +++ b/crates/bevy_derive/src/lib.rs @@ -10,7 +10,9 @@ mod render_resources; mod resource; mod shader_defs; +use bevy_macro_utils::{derive_label, BevyManifest}; use proc_macro::TokenStream; +use quote::format_ident; /// Derives the FromResources trait. Each field must also implement the FromResources trait or this /// will fail. FromResources is automatically implemented for types that implement Default. @@ -60,3 +62,11 @@ pub fn bevy_main(attr: TokenStream, item: TokenStream) -> TokenStream { pub fn derive_enum_variant_meta(input: TokenStream) -> TokenStream { enum_variant_meta::derive_enum_variant_meta(input) } + +#[proc_macro_derive(AppLabel)] +pub fn derive_app_label(input: TokenStream) -> TokenStream { + let input = syn::parse_macro_input!(input as syn::DeriveInput); + let mut trait_path = BevyManifest::default().get_path("bevy_app"); + trait_path.segments.push(format_ident!("AppLabel").into()); + derive_label(input, trait_path) +} diff --git a/pipelined/bevy_render2/src/lib.rs b/pipelined/bevy_render2/src/lib.rs index 4531c435243b6..b4f8467fce75c 100644 --- a/pipelined/bevy_render2/src/lib.rs +++ b/pipelined/bevy_render2/src/lib.rs @@ -24,7 +24,7 @@ use crate::{ texture::ImagePlugin, view::{ViewPlugin, WindowRenderPlugin}, }; -use bevy_app::{App, Plugin, AppLabel}; +use bevy_app::{App, AppLabel, Plugin}; use bevy_ecs::prelude::*; #[derive(Default)] From be5ba900d3d0795fc920439746c14782682a52aa Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Mon, 23 Aug 2021 17:27:26 -0700 Subject: [PATCH 4/7] add doc comments --- crates/bevy_app/src/app.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 3f253be8ef7c5..c5c5d6640bd39 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -607,11 +607,13 @@ impl App { self } + /// Retrieves a "sub app" stored inside this [App]. This will panic if the sub app does not exist. pub fn sub_app(&mut self, label: impl AppLabel) -> &mut App { self.get_sub_app(label) .expect("SubApp with the given label does not exist") } + /// Retrieves a "sub app" inside this [App]. Returns None if the sub app does not exist. pub fn get_sub_app(&mut self, label: impl AppLabel) -> Option<&mut App> { self.sub_apps .get_mut((&label) as &dyn AppLabel) From 3d3d757d9505a2c39fad10d7e11ecdb04a2dc3ac Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Mon, 23 Aug 2021 17:29:03 -0700 Subject: [PATCH 5/7] remove bevy_app/macros from publish.sh --- tools/publish.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/publish.sh b/tools/publish.sh index 62b7181c9014a..ca35a3e327c09 100644 --- a/tools/publish.sh +++ b/tools/publish.sh @@ -7,7 +7,6 @@ crates=( bevy_tasks bevy_ecs/macros bevy_ecs - bevy_app/macros bevy_app bevy_log bevy_dynamic_plugin From 8941116d69e80f3ad2475960c14a4e16156529af Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Mon, 23 Aug 2021 18:21:09 -0700 Subject: [PATCH 6/7] better sub-app error handling --- crates/bevy_app/src/app.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index c5c5d6640bd39..76211767296b5 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -609,15 +609,19 @@ impl App { /// Retrieves a "sub app" stored inside this [App]. This will panic if the sub app does not exist. pub fn sub_app(&mut self, label: impl AppLabel) -> &mut App { - self.get_sub_app(label) - .expect("SubApp with the given label does not exist") + match self.get_sub_app(label) { + Ok(app) => app, + Err(label) => panic!("Sub-App with label '{:?}' does not exist", label), + } } - /// Retrieves a "sub app" inside this [App]. Returns None if the sub app does not exist. - pub fn get_sub_app(&mut self, label: impl AppLabel) -> Option<&mut App> { + /// Retrieves a "sub app" inside this [App] with the given label, if it exists. Otherwise returns + /// an [Err] containing the given label. + pub fn get_sub_app(&mut self, label: impl AppLabel) -> Result<&mut App, impl AppLabel> { self.sub_apps .get_mut((&label) as &dyn AppLabel) .map(|sub_app| &mut sub_app.app) + .ok_or_else(|| label) } } From 9a4789d48c02fa6393c4084ad6e652133f6007ea Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Mon, 23 Aug 2021 19:06:54 -0700 Subject: [PATCH 7/7] clippy --- crates/bevy_app/src/app.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 76211767296b5..c7f28970a5e98 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -621,7 +621,7 @@ impl App { self.sub_apps .get_mut((&label) as &dyn AppLabel) .map(|sub_app| &mut sub_app.app) - .ok_or_else(|| label) + .ok_or(label) } }