pub trait RelationshipSourceCollection {
type SourceIter<'a>: Iterator<Item = Entity>
where Self: 'a;
// Required methods
fn new() -> Self;
fn with_capacity(capacity: usize) -> Self;
fn reserve(&mut self, additional: usize);
fn add(&mut self, entity: Entity) -> bool;
fn remove(&mut self, entity: Entity) -> bool;
fn iter(&self) -> Self::SourceIter<'_>;
fn len(&self) -> usize;
fn clear(&mut self);
fn shrink_to_fit(&mut self);
// Provided methods
fn is_empty(&self) -> bool { ... }
fn extend_from_iter(&mut self, entities: impl IntoIterator<Item = Entity>) { ... }
}
Expand description
The internal Entity
collection used by a RelationshipTarget
component.
This is not intended to be modified directly by users, as it could invalidate the correctness of relationships.
Required Associated Types§
Sourcetype SourceIter<'a>: Iterator<Item = Entity>
where
Self: 'a
type SourceIter<'a>: Iterator<Item = Entity> where Self: 'a
The type of iterator returned by the iter
method.
This is an associated type (rather than using a method that returns an opaque return-position impl trait)
to ensure that all methods and traits (like DoubleEndedIterator
) of the underlying collection’s iterator
are available to the user when implemented without unduly restricting the possible collections.
The SourceIter
type alias can be helpful to reduce confusion when working with this associated type.
Required Methods§
Sourcefn with_capacity(capacity: usize) -> Self
fn with_capacity(capacity: usize) -> Self
Returns an instance with the given pre-allocated entity capacity
.
Some collections will ignore the provided capacity
and return a default instance.
Sourcefn reserve(&mut self, additional: usize)
fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more entities to be inserted.
Not all collections support this operation, in which case it is a no-op.
Sourcefn add(&mut self, entity: Entity) -> bool
fn add(&mut self, entity: Entity) -> bool
Adds the given entity
to the collection.
Returns whether the entity was added to the collection.
Mainly useful when dealing with collections that don’t allow
multiple instances of the same entity (EntityHashSet
).
Sourcefn remove(&mut self, entity: Entity) -> bool
fn remove(&mut self, entity: Entity) -> bool
Removes the given entity
from the collection.
Returns whether the collection actually contained the entity.
Sourcefn iter(&self) -> Self::SourceIter<'_>
fn iter(&self) -> Self::SourceIter<'_>
Iterates all entities in the collection.
Sourcefn shrink_to_fit(&mut self)
fn shrink_to_fit(&mut self)
Attempts to save memory by shrinking the capacity to fit the current length.
This operation is a no-op for collections that do not support it.
Provided Methods§
Sourcefn extend_from_iter(&mut self, entities: impl IntoIterator<Item = Entity>)
fn extend_from_iter(&mut self, entities: impl IntoIterator<Item = Entity>)
Add multiple entities to collection at once.
May be faster than repeatedly calling Self::add
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.