Skip to content

Commit

Permalink
Change typesafe_*_constants macro syntax
Browse files Browse the repository at this point in the history
This essentially just adds `pub struct` to the syntax, and makes it
slightly more clear what values are used specially by the macro. If
nothing else, it should be more obvious to newcomers that this macro
constructs a number of new structs.
  • Loading branch information
daboross committed Aug 21, 2019
1 parent 72a256b commit 3427b3e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 43 deletions.
78 changes: 39 additions & 39 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,32 +252,32 @@ pub mod find {
}

typesafe_find_constants! {
CREEPS, 101, Creep;
MY_CREEPS, 102, Creep;
HOSTILE_CREEPS, 103, Creep;
SOURCES_ACTIVE, 104, Source;
SOURCES, 105, Source;
DROPPED_RESOURCES, 106, Resource;
STRUCTURES, 107, Structure;
MY_STRUCTURES, 108, OwnedStructure;
HOSTILE_STRUCTURES, 109, OwnedStructure;
FLAGS, 110, Flag;
CONSTRUCTION_SITES, 111, ConstructionSite;
MY_SPAWNS, 112, StructureSpawn;
HOSTILE_SPAWNS, 113, StructureSpawn;
MY_CONSTRUCTION_SITES, 114, ConstructionSite;
HOSTILE_CONSTRUCTION_SITES, 115, ConstructionSite;
MINERALS, 116, Mineral;
NUKES, 117, Nuke;
TOMBSTONES, 118, Tombstone;
POWER_CREEPS, 119, PowerCreep;
MY_POWER_CREEPS, 120, PowerCreep;
HOSTILE_POWER_CREEPS, 121, PowerCreep;
EXIT_TOP, Exit::Top as i16, Position;
EXIT_RIGHT, Exit::Right as i16, Position;
EXIT_BOTTOM, Exit::Bottom as i16, Position;
EXIT_LEFT, Exit::Left as i16, Position;
EXIT, Exit::All as i16, Position;
pub struct CREEPS = (101, Creep);
pub struct MY_CREEPS = (102, Creep);
pub struct HOSTILE_CREEPS = (103, Creep);
pub struct SOURCES_ACTIVE = (104, Source);
pub struct SOURCES = (105, Source);
pub struct DROPPED_RESOURCES = (106, Resource);
pub struct STRUCTURES = (107, Structure);
pub struct MY_STRUCTURES = (108, OwnedStructure);
pub struct HOSTILE_STRUCTURES = (109, OwnedStructure);
pub struct FLAGS = (110, Flag);
pub struct CONSTRUCTION_SITES = (111, ConstructionSite);
pub struct MY_SPAWNS = (112, StructureSpawn);
pub struct HOSTILE_SPAWNS = (113, StructureSpawn);
pub struct MY_CONSTRUCTION_SITES = (114, ConstructionSite);
pub struct HOSTILE_CONSTRUCTION_SITES = (115, ConstructionSite);
pub struct MINERALS = (116, Mineral);
pub struct NUKES = (117, Nuke);
pub struct TOMBSTONES = (118, Tombstone);
pub struct POWER_CREEPS = (119, PowerCreep);
pub struct MY_POWER_CREEPS = (120, PowerCreep);
pub struct HOSTILE_POWER_CREEPS = (121, PowerCreep);
pub struct EXIT_TOP = (Exit::Top as i16, Position);
pub struct EXIT_RIGHT = (Exit::Right as i16, Position);
pub struct EXIT_BOTTOM = (Exit::Bottom as i16, Position);
pub struct EXIT_LEFT = (Exit::Left as i16, Position);
pub struct EXIT = (Exit::All as i16, Position);
}
}

Expand Down Expand Up @@ -529,19 +529,19 @@ pub mod look {
};

typesafe_look_constants! {
CREEPS, Look::Creeps, Creep, IntoExpectedType::into_expected_type;
ENERGY, Look::Energy, Resource, IntoExpectedType::into_expected_type;
RESOURCES, Look::Resources, Resource, IntoExpectedType::into_expected_type;
SOURCES, Look::Sources, Source, IntoExpectedType::into_expected_type;
MINERALS, Look::Minerals, Mineral, IntoExpectedType::into_expected_type;
STRUCTURES, Look::Structures, Structure, IntoExpectedType::into_expected_type;
FLAGS, Look::Flags, Flag, IntoExpectedType::into_expected_type;
CONSTRUCTION_SITES, Look::ConstructionSites, ConstructionSite,
IntoExpectedType::into_expected_type;
NUKES, Look::Nukes, Nuke, IntoExpectedType::into_expected_type;
TERRAIN, Look::Terrain, Terrain, TryInto::try_into;
TOMBSTONES, Look::Tombstones, Tombstone, IntoExpectedType::into_expected_type;
POWER_CREEPS, Look::PowerCreeps, PowerCreep, IntoExpectedType::into_expected_type;
pub struct CREEPS = (Look::Creeps, Creep, IntoExpectedType::into_expected_type);
pub struct ENERGY = (Look::Energy, Resource, IntoExpectedType::into_expected_type);
pub struct RESOURCES = (Look::Resources, Resource, IntoExpectedType::into_expected_type);
pub struct SOURCES = (Look::Sources, Source, IntoExpectedType::into_expected_type);
pub struct MINERALS = (Look::Minerals, Mineral, IntoExpectedType::into_expected_type);
pub struct STRUCTURES = (Look::Structures, Structure, IntoExpectedType::into_expected_type);
pub struct FLAGS = (Look::Flags, Flag, IntoExpectedType::into_expected_type);
pub struct CONSTRUCTION_SITES = (Look::ConstructionSites, ConstructionSite,
IntoExpectedType::into_expected_type);
pub struct NUKES = (Look::Nukes, Nuke, IntoExpectedType::into_expected_type);
pub struct TERRAIN = (Look::Terrain, Terrain, TryInto::try_into);
pub struct TOMBSTONES = (Look::Tombstones, Tombstone, IntoExpectedType::into_expected_type);
pub struct POWER_CREEPS = (Look::PowerCreeps, PowerCreep, IntoExpectedType::into_expected_type);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ macro_rules! calculated_doc {
macro_rules! typesafe_find_constants {
(
$(
$constant_name:ident, $value:expr, $result:path;
$vis:vis struct $constant_name:ident = ($value:expr, $result:path);
)*
) => (
$(
Expand All @@ -394,7 +394,7 @@ macro_rules! typesafe_find_constants {
)]
#[allow(bad_style)]
#[derive(Copy, Clone, Debug, Default)]
pub struct $constant_name;
$vis struct $constant_name;
}
unsafe impl FindConstant for $constant_name {
type Item = $result;
Expand All @@ -410,11 +410,13 @@ macro_rules! typesafe_find_constants {

macro_rules! typesafe_look_constants {
(
$($constant_name:ident, $value:expr, $result:path, $conversion_method:expr;)*
$(
$vis:vis struct $constant_name:ident = ($value:expr, $result:path, $conversion_method:expr);
)*
) => (
$(
#[allow(bad_style)]
pub struct $constant_name;
$vis struct $constant_name;
unsafe impl LookConstant for $constant_name {
type Item = $result;

Expand Down

0 comments on commit 3427b3e

Please sign in to comment.