Skip to content

Commit

Permalink
Cleanup FromResources (#2601)
Browse files Browse the repository at this point in the history
## Objective

- Clean up remaining references to the trait `FromResources`, which was replaced in favor of `FromWorld` during the ECS rework.

## Solution

- Remove the derive macro for `FromResources`
- Change doc references of `FromResources` to `FromWorld`

(this is the first item in #2576)
  • Loading branch information
Davier committed Aug 13, 2021
1 parent 5eeba15 commit 6aedb25
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 51 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl App {
/// A resource in Bevy represents globally unique data. Resources must be added to Bevy Apps
/// before using them. This happens with [`App::insert_resource`].
///
/// See also `init_resource` for resources that implement `Default` or [`FromResources`].
/// See also `init_resource` for resources that implement `Default` or [`FromWorld`].
///
/// ## Example
/// ```
Expand Down Expand Up @@ -390,7 +390,7 @@ impl App {

/// Initialize a resource in the current [App], if it does not exist yet
///
/// Adds a resource that implements `Default` or [`FromResources`] trait.
/// Adds a resource that implements `Default` or [`FromWorld`] trait.
/// If the resource already exists, `init_resource` does nothing.
///
/// ## Example
Expand Down
8 changes: 0 additions & 8 deletions crates/bevy_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@ mod enum_variant_meta;
mod modules;
mod render_resource;
mod render_resources;
mod resource;
mod shader_defs;

use proc_macro::TokenStream;

/// 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.
#[proc_macro_derive(FromResources)]
pub fn derive_from_resources(input: TokenStream) -> TokenStream {
resource::derive_from_resources(input)
}

/// Derives the Bytes trait. Each field must also implements Bytes or this will fail.
#[proc_macro_derive(Bytes)]
pub fn derive_bytes(input: TokenStream) -> TokenStream {
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_derive/src/modules.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub const BEVY_APP: &str = "bevy_app";
pub const BEVY_ASSET: &str = "bevy_asset";
pub const BEVY_CORE: &str = "bevy_core";
pub const BEVY_RENDER: &str = "bevy_render";
Expand Down
33 changes: 0 additions & 33 deletions crates/bevy_derive/src/resource.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/bevy_transform/src/components/parent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl MapEntities for PreviousParent {
}
}

// TODO: Better handle this case see `impl FromResources for Parent`
// TODO: Better handle this case see `impl FromWorld for Parent`
impl FromWorld for PreviousParent {
fn from_world(_world: &mut World) -> Self {
PreviousParent(Entity::new(u32::MAX))
Expand Down
2 changes: 1 addition & 1 deletion examples/ecs/ecs_guide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ fn main() {
// that :) The plugin below runs our app's "system schedule" once every 5 seconds
// (configured above).
.add_plugin(ScheduleRunnerPlugin::default())
// Resources that implement the Default or FromResources trait can be added like this:
// Resources that implement the Default or FromWorld trait can be added like this:
.init_resource::<GameState>()
// Startup systems run exactly once BEFORE all other systems. These are generally used for
// app initialization code (ex: adding entities and resources)
Expand Down
10 changes: 5 additions & 5 deletions examples/scene/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ fn main() {
.run();
}

// Registered components must implement the `Reflect` and `FromResources` traits.
// Registered components must implement the `Reflect` and `FromWorld` traits.
// The `Reflect` trait enables serialization, deserialization, and dynamic property access.
// `Reflect` enable a bunch of cool behaviors, so its worth checking out the dedicated `reflect.rs`
// example. The `FromResources` trait determines how your component is constructed when it loads.
// example. The `FromWorld` trait determines how your component is constructed when it loads.
// For simple use cases you can just implement the `Default` trait (which automatically implements
// FromResources). The simplest registered component just needs these two derives:
// FromWorld). The simplest registered component just needs these two derives:
#[derive(Reflect, Default)]
#[reflect(Component)] // this tells the reflect derive to also reflect component behaviors
struct ComponentA {
Expand All @@ -27,8 +27,8 @@ struct ComponentA {
}

// Some components have fields that cannot (or should not) be written to scene files. These can be
// ignored with the #[reflect(ignore)] attribute. This is also generally where the `FromResources`
// trait comes into play. `FromResources` gives you access to your App's current ECS `Resources`
// ignored with the #[reflect(ignore)] attribute. This is also generally where the `FromWorld`
// trait comes into play. `FromWorld` gives you access to your App's current ECS `Resources`
// when you construct your component.
#[derive(Reflect)]
#[reflect(Component)]
Expand Down

0 comments on commit 6aedb25

Please sign in to comment.