aboutsummaryrefslogtreecommitdiff
path: root/src/entity.rs
diff options
context:
space:
mode:
authorCharlotte Pabst <charlotte.pabst@stud.tu-darmstadt.de>2024-03-25 02:25:43 +0100
committerCharlotte Pabst <charlotte.pabst@stud.tu-darmstadt.de>2024-03-25 02:25:43 +0100
commit4cc4f8d5e07a4aa85ac52ce3205574e37ffdf780 (patch)
tree4a4a6c864e25ab8df5f6547b490428b23c6c5d14 /src/entity.rs
parent1f92f06d21289019ca8a955b9162da66d98badfe (diff)
downloaddcel-4cc4f8d5e07a4aa85ac52ce3205574e37ffdf780.tar.xz
generational references & documentation
Diffstat (limited to 'src/entity.rs')
-rw-r--r--src/entity.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/entity.rs b/src/entity.rs
index 1c2eb7a..f6003c1 100644
--- a/src/entity.rs
+++ b/src/entity.rs
@@ -73,8 +73,8 @@ macro_rules! entity {
($name:ident : $T:ident $(($init_name:ident : $init_ty:ty))?
$(, $($custom_field:ident : $custom_ty:ty = $custom_expr:expr),* )?
$(;
- $( $field_vis:vis $field:ident
- $([ $list_singular:ident : $list_name:ident $(($list_init:ty))? $($list_back:ident)? ])?
+ $( $(#[$field_attr:meta])* $field_vis:vis $field:ident
+ $([ $(#[$list_attr:meta])* $list_singular:ident : $list_name:ident $(($list_init:ty))? $($list_back:ident)? ])?
: $field_ty:ident ),*
)?
) => { paste! {
@@ -138,6 +138,7 @@ macro_rules! entity {
#[allow(unused)]
impl<'brand, 'arena, V> ptr!($T) {
$($(
+ $(#[$field_attr])*
$field_vis fn $field(self, token: &impl ReflAsRef<GhostToken<'brand>>) -> ptr!($field_ty) {
self.[<maybe_ $field>](token).unwrap()
}
@@ -155,6 +156,7 @@ macro_rules! entity {
}
$(
+ $(#[$list_attr])*
pub fn [<iter_ $field>]<'tok>(
self,
token: &'tok impl ReflAsRef<GhostToken<'brand>>,
@@ -163,7 +165,7 @@ macro_rules! entity {
EntityIterator::new(self.[<maybe_ $field>](token), token)
}
- pub fn [<iter_mut_ $field>]<T: ReflAsMut<GhostToken<'brand>>>(
+ fn [<iter_mut_ $field>]<T: ReflAsMut<GhostToken<'brand>>>(
self,
token: &mut T,
mut f: impl FnMut(ptr!($field_ty), &mut T),
@@ -177,7 +179,10 @@ macro_rules! entity {
let next_item = item.next(token);
f(item, token);
item = next_item;
- matches!(item.maybe_id(token), Some(x) if x != last)
+
+ // hack to ensure killing the item is allowed
+ // bypassing generational references
+ matches!(item.cell.borrow(ReflAsRef::as_ref(token)).maybe_id(), Some(x) if x != last)
} {}
}