Skip to content

Commit

Permalink
feat: implement RandomFetch for NthRelation
Browse files Browse the repository at this point in the history
  • Loading branch information
ten3roberts committed Feb 20, 2024
1 parent 81e9afc commit 706b51e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/fetch/relations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<T> {
type Item = (Entity, &'q T);
}
Expand Down

0 comments on commit 706b51e

Please sign in to comment.