[][src]Enum screeps::objects::Structure

pub enum Structure {
    Container(StructureContainer),
    Controller(StructureController),
    Extension(StructureExtension),
    Extractor(StructureExtractor),
    Factory(StructureFactory),
    InvaderCore(StructureInvaderCore),
    KeeperLair(StructureKeeperLair),
    Lab(StructureLab),
    Link(StructureLink),
    Nuker(StructureNuker),
    Observer(StructureObserver),
    PowerBank(StructurePowerBank),
    PowerSpawn(StructurePowerSpawn),
    Portal(StructurePortal),
    Rampart(StructureRampart),
    Road(StructureRoad),
    Spawn(StructureSpawn),
    Storage(StructureStorage),
    Terminal(StructureTerminal),
    Tower(StructureTower),
    Wall(StructureWall),
}

Wrapper which can be any of the game Structures.

This is somewhat useful by itself, but has additional utility methods. Some tricks:

To get a particular type, match on the structure:

use screeps::Structure;

match my_struct {
    Structure::Container(cont) => {
        // cont here is StructureContainer
    }
    _ => {
        // other structure
    }
}

To use structures of a particular type, like something that can be attacked, or something that can be transferred to, use helper methods:

use screeps::Structure;

match my_struct.as_transferable() {
    Some(transf) => {
        // transf is a reference to `dyn Transferable`, and you can transfer to it.
    }
    None => {
        // my_struct is not transferable
    }
}

See method documentation for a full list of possible helpers.

Variants

Implementations

impl Structure[src]

pub fn as_transferable(&self) -> Option<&dyn Transferable>[src]

Cast this structure as something Transferable, or return None if it isn't.

Example usage:

use screeps::{Creep, ResourceType, Structure};

match my_struct.as_transferable() {
    Some(transf) => {
        // transf is a reference to `dyn Transferable`, and you can transfer to it.
        my_creep.transfer_all(transf, ResourceType::Energy);
    }
    None => {
        // my_struct cannot be transferred to
    }
}

pub fn as_withdrawable(&self) -> Option<&dyn Withdrawable>[src]

Cast this as something which can be withdrawn from

pub fn as_attackable(&self) -> Option<&dyn Attackable>[src]

Cast this as something which can be attacked and has hit points.

The only Structure which cannot be attacked is StructureController.

pub fn as_owned(&self) -> Option<&dyn OwnedStructureProperties>[src]

Cast this as something which can be owned.

Example:

use screeps::Structure;

let is_my = my_struct.as_owned().map(|os| os.my()).unwrap_or(false);

pub fn as_can_decay(&self) -> Option<&dyn CanDecay>[src]

pub fn as_has_cooldown(&self) -> Option<&dyn HasCooldown>[src]

pub fn as_has_energy_for_spawn(&self) -> Option<&dyn HasEnergyForSpawn>[src]

pub fn as_has_store(&self) -> Option<&dyn HasStore>[src]

Trait Implementations

impl AsRef<Reference> for Structure[src]

impl Clone for Structure[src]

impl Eq for Structure[src]

impl From<Structure> for Reference[src]

impl FromExpectedType<Reference> for Structure[src]

impl HasId for Structure[src]

impl InstanceOf for Structure[src]

impl PartialEq<Structure> for Structure[src]

impl ReferenceType for Structure[src]

impl RoomObjectProperties for Structure[src]

impl StructureProperties for Structure[src]

impl TryFrom<Reference> for Structure[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl TryFrom<Value> for Structure[src]

type Error = ConversionError

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

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

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

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

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

impl<T> FromExpectedType<Value> for T where
    T: FromExpectedType<Reference>, 
[src]

impl<T> HasPosition for T where
    T: RoomObjectProperties
[src]

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

impl<T, U> IntoExpectedType<U> for T where
    U: FromExpectedType<T>, 
[src]

impl<T> SizedRoomObject for T where
    T: Into<Reference> + ReferenceType<Error = ConversionError, Error = ConversionError> + TryFrom<Value> + TryFrom<Reference> + RoomObjectProperties
[src]

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

type Owned = T

The resulting type after obtaining ownership.

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.

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.

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.