Skip to content

Commit

Permalink
Move the Typed trait bound to SeedableEntropySource.
Browse files Browse the repository at this point in the history
This trait already holds the majority of trait requirements, so we might as well add it there as well.
  • Loading branch information
andriyDev committed Nov 10, 2024
1 parent 96325a2 commit 60a515c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
8 changes: 5 additions & 3 deletions bevy_prng/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -46,7 +46,7 @@ pub use xoshiro::*;
#[cfg(feature = "serialize")]
pub trait SeedableEntropySource:
RngCore
+ SeedableRng
+ SeedableRng<Seed: Typed>
+ Clone
+ Debug
+ PartialEq
Expand All @@ -56,6 +56,7 @@ pub trait SeedableEntropySource:
+ TypePath
+ FromReflect
+ GetTypeRegistration
+ Typed
+ Serialize
+ for<'a> Deserialize<'a>
+ private::SealedSeedable
Expand Down Expand Up @@ -106,7 +107,7 @@ impl<
#[cfg(not(feature = "serialize"))]
pub trait SeedableEntropySource:
RngCore
+ SeedableRng
+ SeedableRng<Seed: Typed>
+ Clone
+ Debug
+ PartialEq
Expand All @@ -115,6 +116,7 @@ pub trait SeedableEntropySource:
+ TypePath
+ FromReflect
+ GetTypeRegistration
+ Typed
+ Sync
+ Send
+ private::SealedSeedable
Expand Down
9 changes: 3 additions & 6 deletions src/plugin.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -63,9 +60,9 @@ where
}
}

impl<R: SeedableEntropySource + Typed + 'static> Plugin for EntropyPlugin<R>
impl<R: SeedableEntropySource + 'static> Plugin for EntropyPlugin<R>
where
R::Seed: EntropySeed + Typed,
R::Seed: EntropySeed,
{
fn build(&self, app: &mut App) {
app.register_type::<GlobalEntropy<R>>()
Expand Down
9 changes: 3 additions & 6 deletions src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<R: SeedableEntropySource + 'static> {
seed: R::Seed,
rng: R,
Expand Down

0 comments on commit 60a515c

Please sign in to comment.