From 706b51ec478bd9046a310a9afd6820774cb59f1e Mon Sep 17 00:00:00 2001 From: Freja Roberts Date: Tue, 20 Feb 2024 14:14:10 +0100 Subject: [PATCH] feat: implement RandomFetch for NthRelation --- src/fetch/relations.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/fetch/relations.rs b/src/fetch/relations.rs index 26f1432..1106c40 100644 --- a/src/fetch/relations.rs +++ b/src/fetch/relations.rs @@ -14,7 +14,7 @@ use crate::{ Entity, Fetch, FetchItem, }; -use super::{FetchAccessData, FetchPrepareData, PreparedFetch}; +use super::{FetchAccessData, FetchPrepareData, PreparedFetch, RandomFetch}; /// Returns a list of relations of a specified type #[derive(Debug, Clone)] @@ -194,6 +194,19 @@ where } } +impl<'q, T: ComponentValue> RandomFetch<'q> for PreparedNthRelation<'q, T> { + unsafe fn fetch_shared(&'q self, slot: Slot) -> Self::Item { + let value = &self.borrow.1.get()[slot]; + (self.borrow.0, value) + } + + unsafe fn fetch_shared_chunk(chunk: &Self::Chunk, slot: Slot) -> Self::Item { + let (id, borrow) = &*chunk.borrow; + + (*id, &borrow.get()[slot]) + } +} + impl<'q, T: ComponentValue> FetchItem<'q> for NthRelation { type Item = (Entity, &'q T); }