pub struct Units(/* private fields */);
Expand description
Convinient Unit
s collection.
Implementations§
Source§impl Units
impl Units
Sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Constructs new units collection with given capacity.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity as much as possible.
Sourcepub fn push(&mut self, u: Unit) -> Option<Unit>
pub fn push(&mut self, u: Unit) -> Option<Unit>
Inserts unit in the collection.
If collection already contains unit with the same tag, replaces it and returns previous unit.
Sourcepub fn pop(&mut self) -> Option<Unit>
pub fn pop(&mut self) -> Option<Unit>
Removes and returns last unit from the collection.
Returns None
if the collection is empty.
Sourcepub fn remove(&mut self, u: u64) -> Option<Unit>
pub fn remove(&mut self, u: u64) -> Option<Unit>
Removes and returns unit with given tag.
Returns None
if there’s no unit with such tag in the collection.
Sourcepub fn iter(&self) -> Values<'_, u64, Unit>
pub fn iter(&self) -> Values<'_, u64, Unit>
Returns an iterator over the units of the collection.
Sourcepub fn iter_mut(&mut self) -> ValuesMut<'_, u64, Unit>
pub fn iter_mut(&mut self) -> ValuesMut<'_, u64, Unit>
Returns mutable iterator over the units of the collection.
Sourcepub fn pairs(&self) -> Iter<'_, u64, Unit>
pub fn pairs(&self) -> Iter<'_, u64, Unit>
Returns an iterator over (tag, unit) pairs of the collection.
Sourcepub fn pairs_mut(&mut self) -> IterMut<'_, u64, Unit>
pub fn pairs_mut(&mut self) -> IterMut<'_, u64, Unit>
Returns mutable iterator over (tag, unit) pairs of the collection.
Returns an iterator over unit tags of the collection.
Sourcepub fn contains_tag(&self, tag: u64) -> bool
pub fn contains_tag(&self, tag: u64) -> bool
Checks if the collection contains unit with given tag.
Sourcepub fn get(&self, tag: u64) -> Option<&Unit>
pub fn get(&self, tag: u64) -> Option<&Unit>
Returns a reference to unit with given tag or None
if there’s no unit with such tag.
Sourcepub fn get_mut(&mut self, tag: u64) -> Option<&mut Unit>
pub fn get_mut(&mut self, tag: u64) -> Option<&mut Unit>
Returns a mutable reference to unit with given tag or None
if there’s no unit with such tag.
Searches for units with given tags and makes new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using find_tags
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn of_type(&self, unit_type: UnitTypeId) -> Self
pub fn of_type(&self, unit_type: UnitTypeId) -> Self
Leaves only units of given type and makes a new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using of_type
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn exclude_type(&self, unit_type: UnitTypeId) -> Self
pub fn exclude_type(&self, unit_type: UnitTypeId) -> Self
Excludes all units of given type and makes a new collection of remaining units.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using exclude_type
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn center(&self) -> Option<Point2>
pub fn center(&self) -> Option<Point2>
Returns central position of all units in the collection or None
if collection is empty.
Sourcepub fn ground(&self) -> Self
pub fn ground(&self) -> Self
Leaves only non-flying units and makes new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using ground
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn flying(&self) -> Self
pub fn flying(&self) -> Self
Leaves only flying units and makes new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using flying
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn ready(&self) -> Self
pub fn ready(&self) -> Self
Leaves only ready structures and makes new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using ready
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn not_ready(&self) -> Self
pub fn not_ready(&self) -> Self
Leaves only structures in-progress and makes new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using not_ready
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn idle(&self) -> Self
pub fn idle(&self) -> Self
Leaves only units with no orders and makes new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using idle
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn almost_idle(&self) -> Self
pub fn almost_idle(&self) -> Self
Leaves only units with no orders or that almost finished their orders and makes new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using almost_idle
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn unused(&self) -> Self
pub fn unused(&self) -> Self
Leaves only units with no orders and makes new collection of them.
Unlike idle
this takes reactor on terran buildings into account.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using unused
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn almost_unused(&self) -> Self
pub fn almost_unused(&self) -> Self
Leaves only units with no orders or that almost finished their orders and makes new collection of them.
Unlike almost_idle
this takes reactor on terran buildings into account.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using almost_unused
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn in_range_of(&self, unit: &Unit, gap: f32) -> Self
pub fn in_range_of(&self, unit: &Unit, gap: f32) -> Self
Leaves only units in attack range of given unit and makes new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using in_range_of
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn in_range(&self, unit: &Unit, gap: f32) -> Self
pub fn in_range(&self, unit: &Unit, gap: f32) -> Self
Leaves only units that are close enough to attack given unit and makes new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using in_range
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn in_real_range_of(&self, unit: &Unit, gap: f32) -> Self
pub fn in_real_range_of(&self, unit: &Unit, gap: f32) -> Self
Leaves only units in attack range of given unit and makes new collection of them.
Unlike in_range_of
this takes range upgrades into account.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using in_real_range_of
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn in_real_range(&self, unit: &Unit, gap: f32) -> Self
pub fn in_real_range(&self, unit: &Unit, gap: f32) -> Self
Leaves only units that are close enough to attack given unit and makes new collection of them.
Unlike in_range
this takes range upgrades into account.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using in_real_range
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn visible(&self) -> Self
pub fn visible(&self) -> Self
Leaves only units visible on current step and makes new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using visible
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Source§impl Units
impl Units
Sourcepub fn filter<F>(&self, f: F) -> Self
pub fn filter<F>(&self, f: F) -> Self
Leaves only units that match given predicate and makes new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using filter
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn of_types<T: Container<UnitTypeId>>(&self, types: &T) -> Self
pub fn of_types<T: Container<UnitTypeId>>(&self, types: &T) -> Self
Leaves only units of given types and makes a new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using of_types
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn exclude_types<T: Container<UnitTypeId>>(&self, types: &T) -> Self
pub fn exclude_types<T: Container<UnitTypeId>>(&self, types: &T) -> Self
Excludes units of given types and makes a new collection of remaining units.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using exclude_types
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn closer<P: Into<Point2> + Copy>(&self, distance: f32, target: P) -> Self
pub fn closer<P: Into<Point2> + Copy>(&self, distance: f32, target: P) -> Self
Leaves only units closer than given distance to target and makes new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using closer
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn further<P: Into<Point2> + Copy>(&self, distance: f32, target: P) -> Self
pub fn further<P: Into<Point2> + Copy>(&self, distance: f32, target: P) -> Self
Leaves only units further than given distance to target and makes new collection of them.
Warning: This method will clone units in order to create a new collection
and will be evaluated initially. When applicable prefer using further
on the iterator over units, since it’s lazily evaluated and doesn’t do any cloning operations.
Sourcepub fn closest<P: Into<Point2> + Copy>(&self, target: P) -> Option<&Unit>
pub fn closest<P: Into<Point2> + Copy>(&self, target: P) -> Option<&Unit>
Returns closest from the collection unit to given target.
Sourcepub fn furthest<P: Into<Point2> + Copy>(&self, target: P) -> Option<&Unit>
pub fn furthest<P: Into<Point2> + Copy>(&self, target: P) -> Option<&Unit>
Returns furthest from the collection unit to given target.
Sourcepub fn closest_distance<P: Into<Point2> + Copy>(&self, target: P) -> Option<f32>
pub fn closest_distance<P: Into<Point2> + Copy>(&self, target: P) -> Option<f32>
Returns distance from closest unit in the collection to given target.
Sourcepub fn furthest_distance<P: Into<Point2> + Copy>(
&self,
target: P,
) -> Option<f32>
pub fn furthest_distance<P: Into<Point2> + Copy>( &self, target: P, ) -> Option<f32>
Returns distance from furthest unit in the collection to given target.
Sourcepub fn closest_distance_squared<P: Into<Point2> + Copy>(
&self,
target: P,
) -> Option<f32>
pub fn closest_distance_squared<P: Into<Point2> + Copy>( &self, target: P, ) -> Option<f32>
Returns squared distance from closest unit in the collection to given target.
Sourcepub fn furthest_distance_squared<P: Into<Point2> + Copy>(
&self,
target: P,
) -> Option<f32>
pub fn furthest_distance_squared<P: Into<Point2> + Copy>( &self, target: P, ) -> Option<f32>
Returns squared distance from furthest unit in the collection to given target.
Trait Implementations§
Source§impl Extend<(u64, Unit)> for Units
impl Extend<(u64, Unit)> for Units
Source§fn extend<T: IntoIterator<Item = (u64, Unit)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (u64, Unit)>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl Extend<Unit> for Units
impl Extend<Unit> for Units
Source§fn extend<T: IntoIterator<Item = Unit>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Unit>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)