Struct rinecs::operators::Ref [−][src]
pub struct Ref<'a, T: NToOneComponent<'a>, R> { /* fields omitted */ }
Applies a component in another entity referenced through a component that Derefs to an Entity:
Entity A Entity C
Component(Entity) ───────────────► AnotherCompoenent
▲
│
Entity B │
Component(Entity) ──────────────────┘
Allows to create NToOne relations between entities components.
When the referenced operator accesses the component mutably, an iterator over Ref will return
a StreamingIterator
which can’t be used in for loops and instead has to be used with
.for_each
or .for_each_mut
. The operations available on this iterators are also limited.
This is to ensure that two or more mutable references to the same data won’t be kept
simultaneously. If you are only using the iterator in a for loop or similar and not keeping the
returned mutable references then any of the unsafe_iter_mut
methods in entities or storages
can be used safely.
In the following example we create 2 entities that share a common geometry then access the geometry for each entity:
#[derive(Debug)] struct Vertex; #[derive(NToOneComponent, Debug)] struct GeometryRef(Entity); #[derive(Component, Debug)] struct Geometry(Vec<Vertex>); #[derive(Component, Debug)] struct Position{x: f32, y: f32}; let mut world = World::new(); let geometry = world.new_entity().add(Geometry(vec![Vertex, Vertex, Vertex])).build(); let a = world.new_entity() .add(GeometryRef(geometry)) .add(Position{x: 0.0, y: 0.0}) .build(); let b = world.new_entity() .add(GeometryRef(geometry)) .add(Position{x: 0.0, y: 0.0}) .build(); let entities = world.entities(); for geometry in entities.iter_for::<Ref<GeometryRef, Read<Geometry>>>() { }
Trait Implementations
impl<'a, T, R> DataAccesses for Ref<'a, T, R> where
T: NToOneComponent<'a>,
R: DataAccesses,
[src]
impl<'a, T, R> DataAccesses for Ref<'a, T, R> where
T: NToOneComponent<'a>,
R: DataAccesses,
[src]impl<'a, T: NToOneComponent<'a>, R: UnorderedData<'a>> Deref for Ref<'a, T, R>
[src]
impl<'a, T: NToOneComponent<'a>, R: UnorderedData<'a>> Deref for Ref<'a, T, R>
[src]impl<'a, T: NToOneComponent<'a>, R: UnorderedData<'a>> DerefMut for Ref<'a, T, R>
[src]
impl<'a, T: NToOneComponent<'a>, R: UnorderedData<'a>> DerefMut for Ref<'a, T, R>
[src]impl<'a, T: NToOneComponent<'a>, R> FromComponent<'a, <R as UnorderedData<'a>>::ComponentsRef> for Ref<'a, T, R> where
R: UnorderedData<'a> + FromComponent<'a, <R as UnorderedData<'a>>::ComponentsRef>,
[src]
impl<'a, T: NToOneComponent<'a>, R> FromComponent<'a, <R as UnorderedData<'a>>::ComponentsRef> for Ref<'a, T, R> where
R: UnorderedData<'a> + FromComponent<'a, <R as UnorderedData<'a>>::ComponentsRef>,
[src]fn from_component(
component: <R as UnorderedData<'a>>::ComponentsRef
) -> Ref<'a, T, R>
[src]
component: <R as UnorderedData<'a>>::ComponentsRef
) -> Ref<'a, T, R>
impl<'a, T, R> UnorderedData<'a> for Ref<'a, T, R> where
<T as Component>::Storage: Storage<'s, T>,
R: UnorderedData<'a>,
T: Deref<Target = Entity> + NToOneComponent<'a>,
<<T as Component>::Storage as Storage<'a, T>>::Get: Borrow<T>,
[src]
impl<'a, T, R> UnorderedData<'a> for Ref<'a, T, R> where
<T as Component>::Storage: Storage<'s, T>,
R: UnorderedData<'a>,
T: Deref<Target = Entity> + NToOneComponent<'a>,
<<T as Component>::Storage as Storage<'a, T>>::Get: Borrow<T>,
[src]type Iter = RefIter<'a, Self::Storage>
type IterMut = RefIterMut<'a, Self::Storage, Self::ComponentsRef>
type Components = <R as UnorderedData<'a>>::Components
type ComponentsRef = <R as UnorderedData<'a>>::ComponentsRef
type Storage = RefStorage<'a, ReadGuardRef<'a, <T as Component>::Storage>, T, <R as UnorderedData<'a>>::Storage, <R as UnorderedData<'a>>::Components, RefData, LazyIndexGuard<'a>>
fn query_mask<E: EntitiesStorage>(entities: &E) -> Bitmask
[src]
fn into_iter<E: EntitiesStorage>(entities: &'a E) -> Self::Iter
[src]
fn into_iter_mut<E: EntitiesStorage>(entities: &'a E) -> Self::IterMut
[src]
fn storage<E: EntitiesStorage>(entities: &'a E) -> Option<Self::Storage>
[src]
impl<'a, T, R> SafeIter<'a> for Ref<'a, T, R> where
T: NToOneComponent<'a>,
R: ReadOnlyOp<'a>,
[src]
T: NToOneComponent<'a>,
R: ReadOnlyOp<'a>,
impl<'a, T: NToOneComponent<'a>, R> SafeStreamingIter<'a> for Ref<'a, T, R>
[src]
Auto Trait Implementations
impl<'a, T, R> RefUnwindSafe for Ref<'a, T, R> where
R: RefUnwindSafe,
T: RefUnwindSafe,
R: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T, R> Send for Ref<'a, T, R> where
R: Send,
T: Send,
R: Send,
T: Send,
impl<'a, T, R> Sync for Ref<'a, T, R> where
R: Sync,
T: Sync,
R: Sync,
T: Sync,
impl<'a, T, R> Unpin for Ref<'a, T, R> where
R: Unpin,
T: Unpin,
R: Unpin,
T: Unpin,
impl<'a, T, R> UnwindSafe for Ref<'a, T, R> where
R: UnwindSafe,
T: UnwindSafe,
R: UnwindSafe,
T: UnwindSafe,