From abf8878b39ea613b37d1a0c4f72bbe4a6ca9e68e Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Thu, 21 Feb 2019 15:29:26 +0200 Subject: [PATCH] add set_id() method in Component trait --- ui/src/components.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ui/src/components.rs b/ui/src/components.rs index 644cc1fa..d72378a0 100644 --- a/ui/src/components.rs +++ b/ui/src/components.rs @@ -83,9 +83,11 @@ pub struct Entity { } impl From> for Entity { - fn from(kind: Box) -> Entity { + fn from(mut kind: Box) -> Entity { + let id = Uuid::new_v4(); + kind.set_id(id); Entity { - id: Uuid::new_v4(), + id: id, component: kind, } } @@ -95,9 +97,11 @@ impl From> for Entity where C: Component, { - fn from(kind: Box) -> Entity { + fn from(mut kind: Box) -> Entity { + let id = Uuid::new_v4(); + kind.set_id(id); Entity { - id: Uuid::new_v4(), + id: id, component: kind, } } @@ -143,7 +147,8 @@ pub trait Component: Display + Debug { true } fn set_dirty(&mut self); - fn kill(&mut self, _uuid: Uuid) {} + fn kill(&mut self, uuid: Uuid) {} + fn set_id(&mut self, uuid: Uuid) {} } /*