rust_sc2::units

Struct Units

Source
pub struct Units(/* private fields */);
Expand description

Convinient Units collection.

Implementations§

Source§

impl Units

Source

pub fn new() -> Self

Constrructs new empty units collection.

Source

pub fn with_capacity(n: usize) -> Self

Constructs new units collection with given capacity.

Source

pub fn capacity(&self) -> usize

Returns current capacity of the collection.

Source

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

Reserves additional capacity in the collection.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity as much as possible.

Source

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

Returns first unit in the collection.

Source

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.

Source

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

Removes and returns last unit from the collection.

Returns None if the collection is empty.

Source

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.

Source

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

Returns an iterator over the units of the collection.

Source

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

Returns mutable iterator over the units of the collection.

Source

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

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

Source

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

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

Source

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

Returns an iterator over unit tags of the collection.

Source

pub fn is_empty(&self) -> bool

Returns true if collection contains no units.

Source

pub fn len(&self) -> usize

Returns the current number of units in the collection.

Source

pub fn clear(&mut self)

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

Source

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

Checks if the collection contains unit with given tag.

Source

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.

Source

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.

Source

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

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.

Source

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.

Source

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.

Source

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

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

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

Sorts the collection by given function.

Source

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

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

Source§

impl Units

Source

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

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Returns closest from the collection unit to given target.

Source

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

Returns furthest from the collection unit to given target.

Source

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

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

Source

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

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

Source

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.

Source

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.

Source

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

Returns sum of given unit values.

Source

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

Returns unit with minimum given predicate.

Source

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

Returns minimum of given unit values.

Source

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

Returns unit with maximum given predicate.

Source

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

Returns maximum of given unit values.

Trait Implementations§

Source§

impl Clone for Units

Source§

fn clone(&self) -> Units

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Units

Source§

fn default() -> Units

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

impl Extend<(u64, Unit)> for Units

Source§

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

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

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<Unit> for Units

Source§

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

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

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl FromIterator<(u64, Unit)> for Units

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromIterator<Unit> for Units

Source§

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

Creates a value from an iterator. Read more
Source§

impl Index<u64> for Units

Source§

type Output = Unit

The returned type after indexing.
Source§

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

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

impl Index<usize> for Units

Source§

type Output = Unit

The returned type after indexing.
Source§

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

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

impl IndexMut<u64> for Units

Source§

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

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

impl IndexMut<usize> for Units

Source§

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

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

impl<'a> IntoIterator for &'a Units

Source§

type Item = &'a Unit

The type of the elements being iterated over.
Source§

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

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut Units

Source§

type Item = &'a mut Unit

The type of the elements being iterated over.
Source§

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

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Units

Source§

type Item = Unit

The type of the elements being iterated over.
Source§

type IntoIter = IntoUnits

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl Freeze for Units

§

impl !RefUnwindSafe for Units

§

impl !Send for Units

§

impl !Sync for Units

§

impl Unpin for Units

§

impl !UnwindSafe for Units

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V