pub enum Structure {
Show 21 variants 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),
}
Expand description

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

Container(StructureContainer)

Controller(StructureController)

Extension(StructureExtension)

Extractor(StructureExtractor)

Factory(StructureFactory)

InvaderCore(StructureInvaderCore)

KeeperLair(StructureKeeperLair)

Lab(StructureLab)

Nuker(StructureNuker)

Observer(StructureObserver)

PowerBank(StructurePowerBank)

PowerSpawn(StructurePowerSpawn)

Portal(StructurePortal)

Rampart(StructureRampart)

Road(StructureRoad)

Spawn(StructureSpawn)

Storage(StructureStorage)

Terminal(StructureTerminal)

Tower(StructureTower)

Wall(StructureWall)

Implementations

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
    }
}

Cast this as something which can be withdrawn from

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

The only Structure which cannot be attacked is StructureController.

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

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Converts to this type from the input type.

Retrieves this object’s id as an untyped, packed value. Read more

Retrieves this object’s id as a typed, packed value. Read more

Checks whenever a given Reference if of type Self.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Converts a given reference into a concrete reference-like wrapper. Doesn’t do any type checking; highly unsafe to use! Read more

The room that the object is in, or None if an object is a flag or a construction site and is placed in a room that is not visible to you. Read more

Usable on either owned structures or neutral structures in owned rooms, returns ReturnCode::NotOwner otherwise. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Casts this value as the target type, making the assumption that the types are correct. Read more

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.