From d0cac9159e6ddfe5dbb9b32036e7258f6e51d47e Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 18 Jan 2026 17:46:02 +0100 Subject: refactor(ecs): remove Actions & Sole weak ref structs --- ecs/src/actions.rs | 68 ------------------------------------------------------ 1 file changed, 68 deletions(-) (limited to 'ecs/src/actions.rs') diff --git a/ecs/src/actions.rs b/ecs/src/actions.rs index 549e341..3d8afe6 100644 --- a/ecs/src/actions.rs +++ b/ecs/src/actions.rs @@ -1,7 +1,3 @@ -use std::any::type_name; -use std::marker::PhantomData; -use std::rc::{Rc, Weak}; - use crate::component::{Parts as ComponentParts, Sequence as ComponentSequence}; use crate::event::component::Removed; use crate::pair::Pair; @@ -151,28 +147,6 @@ impl Actions<'_> { self.action_queue.push(Action::Stop); } - - /// Returns a struct which holds a weak reference to the [`World`] that `Actions` - /// references and that can be used to aquire a new `Actions` instance if the - /// referenced [`World`] is still alive. - /// - /// # Panics - /// This function will panic if `self` was retrieved from a [`WeakRef`]. - #[must_use] - pub fn to_weak_ref(&self) -> WeakRef - { - let world = self.world.unwrap_or_else(|| { - panic!( - "This function cannot be called if the {} was retrieved from a {}", - type_name::(), - type_name::() - ) - }); - - WeakRef { - action_queue: Rc::downgrade(&world.data.action_queue), - } - } } impl<'world> SystemParam<'world> for Actions<'world> @@ -188,48 +162,6 @@ impl<'world> SystemParam<'world> for Actions<'world> } } -#[derive(Debug, Clone)] -pub struct WeakRef -{ - action_queue: Weak, -} - -impl WeakRef -{ - /// Returns a struct which can be used to retrieve a [`Actions`]. - /// - /// Returns [`None`] if the referenced [`World`] has been dropped. - #[must_use] - pub fn access(&self) -> Option> - { - Some(Ref { - action_queue: self.action_queue.upgrade()?, - _pd: PhantomData, - }) - } -} - -/// Intermediate between [`Actions`] and [`WeakRef`]. Contains a strong reference to -/// a world which is not allowed direct access to. -#[derive(Debug, Clone)] -pub struct Ref<'weak_ref> -{ - action_queue: Rc, - _pd: PhantomData<&'weak_ref ()>, -} - -impl Ref<'_> -{ - #[must_use] - pub fn to_actions(&self) -> Actions<'_> - { - Actions { - action_queue: &self.action_queue, - world: None, - } - } -} - /// A action for a [`System`] to perform. #[derive(Debug)] pub(crate) enum Action -- cgit v1.2.3-18-g5258