Trait RelationshipSourceCollection

Source
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§

Source

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§

Source

fn new() -> Self

Creates a new empty instance.

Source

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.

Source

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.

Source

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).

Source

fn remove(&mut self, entity: Entity) -> bool

Removes the given entity from the collection.

Returns whether the collection actually contained the entity.

Source

fn iter(&self) -> Self::SourceIter<'_>

Iterates all entities in the collection.

Source

fn len(&self) -> usize

Returns the current length of the collection.

Source

fn clear(&mut self)

Clears the collection.

Source

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§

Source

fn is_empty(&self) -> bool

Returns true if the collection contains no entities.

Source

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.

Implementations on Foreign Types§

Source§

impl<const N: usize> RelationshipSourceCollection for SmallVec<[Entity; N]>

Source§

type SourceIter<'a> = Copied<Iter<'a, Entity>>

Source§

fn new() -> SmallVec<[Entity; N]>

Source§

fn reserve(&mut self, additional: usize)

Source§

fn with_capacity(capacity: usize) -> SmallVec<[Entity; N]>

Source§

fn add(&mut self, entity: Entity) -> bool

Source§

fn remove(&mut self, entity: Entity) -> bool

Source§

fn iter( &self, ) -> <SmallVec<[Entity; N]> as RelationshipSourceCollection>::SourceIter<'_>

Source§

fn len(&self) -> usize

Source§

fn clear(&mut self)

Source§

fn shrink_to_fit(&mut self)

Source§

fn extend_from_iter(&mut self, entities: impl IntoIterator<Item = Entity>)

Implementors§