diff options
Diffstat (limited to 'engine-ecs/src/sole.rs')
| -rw-r--r-- | engine-ecs/src/sole.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/engine-ecs/src/sole.rs b/engine-ecs/src/sole.rs index 9409bcb..21dafc9 100644 --- a/engine-ecs/src/sole.rs +++ b/engine-ecs/src/sole.rs @@ -2,13 +2,15 @@ use std::any::{type_name, Any}; use std::fmt::Debug; use std::ops::{Deref, DerefMut}; -use crate::uid::Uid; -use crate::component::HandleMut as ComponentHandleMut; -use crate::component::IntoParts as IntoComponentParts; +use crate::component::{ + HandleMut as ComponentHandleMut, + IntoParts as IntoComponentParts, +}; use crate::system::{Metadata as SystemMetadata, Param as SystemParam}; +use crate::uid::Uid; use crate::World; -/// A type which has a single instance and is shared globally. +/// A component which has a single instance in the [`World`]. pub trait Sole: Any + IntoComponentParts { fn id() -> Uid @@ -49,14 +51,13 @@ impl Debug for dyn Sole } } -/// Holds a reference to a globally shared singleton value. +/// Holds a reference to a singleton component. #[derive(Debug)] pub struct Single<'world, SoleT: Sole> { sole: ComponentHandleMut<'world, SoleT>, } - impl<'world, SoleT> Single<'world, SoleT> where SoleT: Sole, @@ -79,7 +80,10 @@ where .get_entity(SoleT::id()) .and_then(|ent| ent.get_with_id_mut::<SoleT>(SoleT::id())) .unwrap_or_else(|| { - panic!("Sole component {} was not found in world", type_name::<SoleT>()) + panic!( + "Sole component {} was not found in world", + type_name::<SoleT>() + ) }); Self::new(sole) |
