Struct rust_sc2::units::Units[][src]

pub struct Units(_);
Expand description

Convinient Units collection.

Implementations

impl Units[src]

pub fn new() -> Self[src]

Constrructs new empty units collection.

pub fn with_capacity(n: usize) -> Self[src]

Constructs new units collection with given capacity.

pub fn capacity(&self) -> usize[src]

Returns current capacity of the collection.

pub fn reserve(&mut self, additional: usize)[src]

Reserves additional capacity in the collection.

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity as much as possible.

pub fn first(&self) -> Option<&Unit>[src]

Returns first unit in the collection.

pub fn push(&mut self, u: Unit) -> Option<Unit>[src]

Inserts unit in the collection.

If collection already contains unit with the same tag, replaces it and returns previous unit.

pub fn pop(&mut self) -> Option<Unit>[src]

Removes and returns last unit from the collection.

Returns None if the collection is empty.

pub fn remove(&mut self, u: u64) -> Option<Unit>[src]

Removes and returns unit with given tag.

Returns None if there’s no unit with such tag in the collection.

pub fn iter(&self) -> Values<'_, u64, Unit>[src]

Returns an iterator over the units of the collection.

pub fn iter_mut(&mut self) -> ValuesMut<'_, u64, Unit>[src]

Returns mutable iterator over the units of the collection.

pub fn pairs(&self) -> Iter<'_, u64, Unit>[src]

Returns an iterator over (tag, unit) pairs of the collection.

pub fn pairs_mut(&mut self) -> IterMut<'_, u64, Unit>[src]

Returns mutable iterator over (tag, unit) pairs of the collection.

pub fn tags(&self) -> Keys<'_, u64, Unit>[src]

Returns an iterator over unit tags of the collection.

pub fn is_empty(&self) -> bool[src]

Returns true if collection contains no units.

pub fn len(&self) -> usize[src]

Returns the current number of units in the collection.

pub fn clear(&mut self)[src]

Removes all units from the collection, while preserving its capacity.

pub fn contains_tag(&self, tag: u64) -> bool[src]

Checks if the collection contains unit with given tag.

pub fn get(&self, tag: u64) -> Option<&Unit>[src]

Returns a reference to unit with given tag or None if there’s no unit with such tag.

pub fn get_mut(&mut self, tag: u64) -> Option<&mut Unit>[src]

Returns a mutable reference to unit with given tag or None if there’s no unit with such tag.

pub fn find_tags<'a, T: IntoIterator<Item = &'a u64>>(&self, tags: T) -> Self[src]

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.

pub fn of_type(&self, unit_type: UnitTypeId) -> Self[src]

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.

pub fn exclude_type(&self, unit_type: UnitTypeId) -> Self[src]

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.

pub fn center(&self) -> Option<Point2>[src]

Returns central position of all units in the collection or None if collection is empty.

pub fn ground(&self) -> Self[src]

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.

pub fn flying(&self) -> Self[src]

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.

pub fn ready(&self) -> Self[src]

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.

pub fn not_ready(&self) -> Self[src]

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.

pub fn idle(&self) -> Self[src]

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.

pub fn almost_idle(&self) -> Self[src]

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.

pub fn unused(&self) -> Self[src]

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.

pub fn almost_unused(&self) -> Self[src]

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.

pub fn in_range_of(&self, unit: &Unit, gap: f32) -> Self[src]

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.

pub fn in_range(&self, unit: &Unit, gap: f32) -> Self[src]

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.

pub fn in_real_range_of(&self, unit: &Unit, gap: f32) -> Self[src]

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.

pub fn in_real_range(&self, unit: &Unit, gap: f32) -> Self[src]

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.

pub fn visible(&self) -> Self[src]

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.

pub fn sort<T, F>(&mut self, f: F) where
    T: PartialOrd,
    F: Fn(&Unit) -> T, 
[src]

Sorts the collection by given function.

pub fn sorted<T, F>(&self, f: F) -> Self where
    T: PartialOrd,
    F: Fn(&Unit) -> T, 
[src]

Makes new collection sorted by given function. Leaves original collection untouched.

impl Units[src]

pub fn filter<F>(&self, f: F) -> Self where
    F: Fn(&&Unit) -> bool
[src]

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.

pub fn of_types<T: Container<UnitTypeId>>(&self, types: &T) -> Self[src]

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.

pub fn exclude_types<T: Container<UnitTypeId>>(&self, types: &T) -> Self[src]

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.

pub fn closer<P: Into<Point2> + Copy>(&self, distance: f32, target: P) -> Self[src]

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.

pub fn further<P: Into<Point2> + Copy>(&self, distance: f32, target: P) -> Self[src]

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.

pub fn closest<P: Into<Point2> + Copy>(&self, target: P) -> Option<&Unit>[src]

Returns closest from the collection unit to given target.

pub fn furthest<P: Into<Point2> + Copy>(&self, target: P) -> Option<&Unit>[src]

Returns furthest from the collection unit to given target.

pub fn closest_distance<P: Into<Point2> + Copy>(&self, target: P) -> Option<f32>[src]

Returns distance from closest unit in the collection to given target.

pub fn furthest_distance<P: Into<Point2> + Copy>(
    &self,
    target: P
) -> Option<f32>
[src]

Returns distance from furthest unit in the collection to given target.

pub fn closest_distance_squared<P: Into<Point2> + Copy>(
    &self,
    target: P
) -> Option<f32>
[src]

Returns squared distance from closest unit in the collection to given target.

pub fn furthest_distance_squared<P: Into<Point2> + Copy>(
    &self,
    target: P
) -> Option<f32>
[src]

Returns squared distance from furthest unit in the collection to given target.

pub fn sum<T, F>(&self, f: F) -> T where
    T: Sum,
    F: Fn(&Unit) -> T, 
[src]

Returns sum of given unit values.

pub fn min<T, F>(&self, f: F) -> Option<&Unit> where
    T: PartialOrd,
    F: Fn(&Unit) -> T, 
[src]

Returns unit with minimum given predicate.

pub fn min_value<T, F>(&self, f: F) -> Option<T> where
    T: PartialOrd,
    F: Fn(&Unit) -> T, 
[src]

Returns minimum of given unit values.

pub fn max<T, F>(&self, f: F) -> Option<&Unit> where
    T: PartialOrd,
    F: Fn(&Unit) -> T, 
[src]

Returns unit with maximum given predicate.

pub fn max_value<T, F>(&self, f: F) -> Option<T> where
    T: PartialOrd,
    F: Fn(&Unit) -> T, 
[src]

Returns maximum of given unit values.

Trait Implementations

impl Clone for Units[src]

fn clone(&self) -> Units[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Default for Units[src]

fn default() -> Units[src]

Returns the “default value” for a type. Read more

impl Extend<(u64, Unit)> for Units[src]

fn extend<T: IntoIterator<Item = (u64, Unit)>>(&mut self, iter: T)[src]

Extends a collection with the contents of an iterator. Read more

fn extend_one(&mut self, item: A)[src]

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

fn extend_reserve(&mut self, additional: usize)[src]

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

impl Extend<Unit> for Units[src]

fn extend<T: IntoIterator<Item = Unit>>(&mut self, iter: T)[src]

Extends a collection with the contents of an iterator. Read more

fn extend_one(&mut self, item: A)[src]

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

fn extend_reserve(&mut self, additional: usize)[src]

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

impl FromIterator<(u64, Unit)> for Units[src]

fn from_iter<I: IntoIterator<Item = (u64, Unit)>>(iter: I) -> Self[src]

Creates a value from an iterator. Read more

impl FromIterator<Unit> for Units[src]

fn from_iter<I: IntoIterator<Item = Unit>>(iter: I) -> Self[src]

Creates a value from an iterator. Read more

impl Index<u64> for Units[src]

type Output = Unit

The returned type after indexing.

fn index(&self, tag: u64) -> &Self::Output[src]

Performs the indexing (container[index]) operation. Read more

impl Index<usize> for Units[src]

type Output = Unit

The returned type after indexing.

fn index(&self, i: usize) -> &Self::Output[src]

Performs the indexing (container[index]) operation. Read more

impl IndexMut<u64> for Units[src]

fn index_mut(&mut self, tag: u64) -> &mut Self::Output[src]

Performs the mutable indexing (container[index]) operation. Read more

impl IndexMut<usize> for Units[src]

fn index_mut(&mut self, i: usize) -> &mut Self::Output[src]

Performs the mutable indexing (container[index]) operation. Read more

impl IntoIterator for Units[src]

type Item = Unit

The type of the elements being iterated over.

type IntoIter = IntoUnits

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

impl<'a> IntoIterator for &'a Units[src]

type Item = &'a Unit

The type of the elements being iterated over.

type IntoIter = Values<'a, u64, Unit>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

impl<'a> IntoIterator for &'a mut Units[src]

type Item = &'a mut Unit

The type of the elements being iterated over.

type IntoIter = ValuesMut<'a, u64, Unit>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

Auto Trait Implementations

impl !RefUnwindSafe for Units

impl !Send for Units

impl !Sync for Units

impl Unpin for Units

impl !UnwindSafe for Units

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V