Skip to content

Commit

Permalink
Replace a number of forced JsString -> String conversions with JsString
Browse files Browse the repository at this point in the history
  • Loading branch information
shanemadden committed Jan 9, 2024
1 parent 4f0bb15 commit 7618101
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 30 deletions.
16 changes: 8 additions & 8 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,30 @@ pub fn construction_sites() -> JsHashMap<RawObjectId, ConstructionSite> {
Game::construction_sites().into()
}

/// Get a [`JsHashMap<String, Creep>`] with all of your creeps, which has creep
/// Get a [`JsHashMap<JsString, Creep>`] with all of your creeps, which has creep
/// names as keys.
///
/// Note that newly spawned creeps are immediately added when spawned, but will
/// not have an id until the following tick.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Game.creeps)
pub fn creeps() -> JsHashMap<String, Creep> {
pub fn creeps() -> JsHashMap<JsString, Creep> {
Game::creeps().into()
}

/// Get a [`JsHashMap<String, Flag>`] with all of your flags, which has flag
/// Get a [`JsHashMap<JsString, Flag>`] with all of your flags, which has flag
/// names as keys.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Game.flags)
pub fn flags() -> JsHashMap<String, Flag> {
pub fn flags() -> JsHashMap<JsString, Flag> {
Game::flags().into()
}

/// Get a [`JsHashMap<String, AccountPowerCreep>`] with all of your power
/// Get a [`JsHashMap<JsString, AccountPowerCreep>`] with all of your power
/// creeps, which has power creep names as keys.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Game.powerCreeps)
pub fn power_creeps() -> JsHashMap<String, AccountPowerCreep> {
pub fn power_creeps() -> JsHashMap<JsString, AccountPowerCreep> {
Game::power_creeps().into()
}

Expand All @@ -126,11 +126,11 @@ pub fn rooms() -> JsHashMap<RoomName, Room> {
Game::rooms().into()
}

/// Get a [`JsHashMap<String, StructureSpawn>`] with all of your spawns, which
/// Get a [`JsHashMap<JsString, StructureSpawn>`] with all of your spawns, which
/// has spawn names as keys.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Game.spawns)
pub fn spawns() -> JsHashMap<String, StructureSpawn> {
pub fn spawns() -> JsHashMap<JsString, StructureSpawn> {
Game::spawns().into()
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn outgoing_transactions() -> Vec<Transaction> {
/// order ID [`JsString`] keys and [`MyOrder`] values.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Game.market.orders)
pub fn orders() -> JsHashMap<String, MyOrder> {
pub fn orders() -> JsHashMap<JsString, MyOrder> {
Market::orders().into()
}

Expand Down
14 changes: 0 additions & 14 deletions src/js_collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,20 +283,6 @@ impl JsCollectionFromValue for JsString {
}
}

impl JsCollectionIntoValue for String {
fn into_value(self) -> JsValue {
self.into()
}
}

impl JsCollectionFromValue for String {
fn from_value(val: JsValue) -> String {
let val: JsString = val.unchecked_into();

val.into()
}
}

impl JsCollectionIntoValue for u8 {
fn into_value(self) -> JsValue {
JsValue::from_f64(self as f64)
Expand Down
4 changes: 2 additions & 2 deletions src/objects/impls/creep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@ impl SharedCreepProperties for Creep {
self.my()
}

fn name(&self) -> String {
self.name_internal().into()
fn name(&self) -> JsString {
self.name_internal()
}

fn owner(&self) -> Owner {
Expand Down
11 changes: 9 additions & 2 deletions src/objects/impls/power_creep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ impl SharedCreepProperties for PowerCreep {
self.my()
}

fn name(&self) -> String {
self.name_internal().into()
fn name(&self) -> JsString {
self.name_internal()
}

fn owner(&self) -> Owner {
Expand Down Expand Up @@ -533,6 +533,13 @@ impl AccountPowerCreep {
self.level_internal()
}

/// Name of the power creep.
///
/// [Screeps documentation](https://docs.screeps.com/api/#PowerCreep.name)
pub fn name(&self) -> JsString {
self.name_internal()
}

/// The levels of this power creep's abilities, with [`PowerType`] keys and
/// values containing power level and cooldown.
///
Expand Down
4 changes: 2 additions & 2 deletions src/raw_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ extern "C" {
fn set_public_segments(segment_ids: &Array);
}

/// Get a [`JsHashMap<u8, String>`] with all of the segments requested on
/// Get a [`JsHashMap<u8, JsString>`] with all of the segments requested on
/// the previous tick, with segment numbers as keys and segment data in
/// [`JsString`] form as values.
///
/// [Screeps documentation](https://docs.screeps.com/api/#RawMemory.segments)
pub fn segments() -> JsHashMap<u8, String> {
pub fn segments() -> JsHashMap<u8, JsString> {
RawMemory::segments().into()
}

Expand Down
2 changes: 1 addition & 1 deletion src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub trait SharedCreepProperties {
/// The creep's name as an owned reference to a [`String`].
///
/// [Screeps documentation](https://docs.screeps.com/api/#Creep.name)
fn name(&self) -> String;
fn name(&self) -> JsString;

/// The [`Owner`] of this creep that contains the owner's username.
fn owner(&self) -> Owner;
Expand Down

0 comments on commit 7618101

Please sign in to comment.