From 60a515c45041908f4a9726e6ce68bbed23c0c227 Mon Sep 17 00:00:00 2001 From: andriyDev Date: Sun, 10 Nov 2024 10:13:36 -0800 Subject: [PATCH] Move the `Typed` trait bound to `SeedableEntropySource`. This trait already holds the majority of trait requirements, so we might as well add it there as well. --- bevy_prng/src/lib.rs | 8 +++++--- src/plugin.rs | 9 +++------ src/resource.rs | 9 +++------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/bevy_prng/src/lib.rs b/bevy_prng/src/lib.rs index 51922b8..de27122 100644 --- a/bevy_prng/src/lib.rs +++ b/bevy_prng/src/lib.rs @@ -23,7 +23,7 @@ use std::fmt::Debug; use bevy::{ prelude::{FromReflect, Reflect}, - reflect::{GetTypeRegistration, TypePath}, + reflect::{GetTypeRegistration, TypePath, Typed}, }; use rand_core::{RngCore, SeedableRng}; #[cfg(feature = "serialize")] @@ -46,7 +46,7 @@ pub use xoshiro::*; #[cfg(feature = "serialize")] pub trait SeedableEntropySource: RngCore - + SeedableRng + + SeedableRng + Clone + Debug + PartialEq @@ -56,6 +56,7 @@ pub trait SeedableEntropySource: + TypePath + FromReflect + GetTypeRegistration + + Typed + Serialize + for<'a> Deserialize<'a> + private::SealedSeedable @@ -106,7 +107,7 @@ impl< #[cfg(not(feature = "serialize"))] pub trait SeedableEntropySource: RngCore - + SeedableRng + + SeedableRng + Clone + Debug + PartialEq @@ -115,6 +116,7 @@ pub trait SeedableEntropySource: + TypePath + FromReflect + GetTypeRegistration + + Typed + Sync + Send + private::SealedSeedable diff --git a/src/plugin.rs b/src/plugin.rs index d6f2cae..9e11af1 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1,8 +1,5 @@ use crate::{component::EntropyComponent, resource::GlobalEntropy, seed::RngSeed}; -use bevy::{ - prelude::{App, Plugin}, - reflect::Typed, -}; +use bevy::prelude::{App, Plugin}; use bevy_prng::{EntropySeed, SeedableEntropySource}; use rand_core::SeedableRng; @@ -63,9 +60,9 @@ where } } -impl Plugin for EntropyPlugin +impl Plugin for EntropyPlugin where - R::Seed: EntropySeed + Typed, + R::Seed: EntropySeed, { fn build(&self, app: &mut App) { app.register_type::>() diff --git a/src/resource.rs b/src/resource.rs index e4228ea..c6a0b43 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -8,10 +8,7 @@ use crate::{ ForkableRng, ForkableSeed, }, }; -use bevy::{ - prelude::{Reflect, ReflectFromReflect, ReflectFromWorld, ReflectResource, Resource}, - reflect::Typed, -}; +use bevy::prelude::{Reflect, ReflectFromReflect, ReflectFromWorld, ReflectResource, Resource}; use bevy_prng::SeedableEntropySource; use rand_core::{RngCore, SeedableRng}; @@ -65,8 +62,8 @@ use serde::{Deserialize, Serialize}; feature = "serialize", serde(bound(deserialize = "R: for<'a> Deserialize<'a>, R::Seed: for<'a> Deserialize<'a>")) )] -#[cfg_attr(feature = "serialize", reflect(where R::Seed: PartialEq + Debug + Sync + Send + Clone + Serialize + Typed + for<'a> Deserialize<'a>))] -#[cfg_attr(not(feature = "serialize"), reflect(where R::Seed: PartialEq + Debug + Sync + Send + Clone + Typed))] +#[cfg_attr(feature = "serialize", reflect(where R::Seed: PartialEq + Debug + Sync + Send + Clone + Serialize + for<'a> Deserialize<'a>))] +#[cfg_attr(not(feature = "serialize"), reflect(where R::Seed: PartialEq + Debug + Sync + Send + Clone))] pub struct GlobalEntropy { seed: R::Seed, rng: R,