From 76181011dbb7f62e0d0301a1f636684f10e64d36 Mon Sep 17 00:00:00 2001 From: Shane Madden Date: Mon, 8 Jan 2024 21:24:18 -0700 Subject: [PATCH] Replace a number of forced JsString -> String conversions with JsString --- src/game.rs | 16 ++++++++-------- src/game/market.rs | 2 +- src/js_collections.rs | 14 -------------- src/objects/impls/creep.rs | 4 ++-- src/objects/impls/power_creep.rs | 11 +++++++++-- src/raw_memory.rs | 4 ++-- src/traits.rs | 2 +- 7 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/game.rs b/src/game.rs index 33ce5bed..8690f482 100644 --- a/src/game.rs +++ b/src/game.rs @@ -83,30 +83,30 @@ pub fn construction_sites() -> JsHashMap { Game::construction_sites().into() } -/// Get a [`JsHashMap`] with all of your creeps, which has creep +/// Get a [`JsHashMap`] 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 { +pub fn creeps() -> JsHashMap { Game::creeps().into() } -/// Get a [`JsHashMap`] with all of your flags, which has flag +/// Get a [`JsHashMap`] with all of your flags, which has flag /// names as keys. /// /// [Screeps documentation](https://docs.screeps.com/api/#Game.flags) -pub fn flags() -> JsHashMap { +pub fn flags() -> JsHashMap { Game::flags().into() } -/// Get a [`JsHashMap`] with all of your power +/// Get a [`JsHashMap`] 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 { +pub fn power_creeps() -> JsHashMap { Game::power_creeps().into() } @@ -126,11 +126,11 @@ pub fn rooms() -> JsHashMap { Game::rooms().into() } -/// Get a [`JsHashMap`] with all of your spawns, which +/// Get a [`JsHashMap`] with all of your spawns, which /// has spawn names as keys. /// /// [Screeps documentation](https://docs.screeps.com/api/#Game.spawns) -pub fn spawns() -> JsHashMap { +pub fn spawns() -> JsHashMap { Game::spawns().into() } diff --git a/src/game/market.rs b/src/game/market.rs index 6edf7dee..b863d2ea 100644 --- a/src/game/market.rs +++ b/src/game/market.rs @@ -86,7 +86,7 @@ pub fn outgoing_transactions() -> Vec { /// order ID [`JsString`] keys and [`MyOrder`] values. /// /// [Screeps documentation](https://docs.screeps.com/api/#Game.market.orders) -pub fn orders() -> JsHashMap { +pub fn orders() -> JsHashMap { Market::orders().into() } diff --git a/src/js_collections.rs b/src/js_collections.rs index 5357ef9c..27a828fd 100644 --- a/src/js_collections.rs +++ b/src/js_collections.rs @@ -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) diff --git a/src/objects/impls/creep.rs b/src/objects/impls/creep.rs index 692b7f0d..f473ca98 100644 --- a/src/objects/impls/creep.rs +++ b/src/objects/impls/creep.rs @@ -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 { diff --git a/src/objects/impls/power_creep.rs b/src/objects/impls/power_creep.rs index 85b11828..cf6f5e44 100644 --- a/src/objects/impls/power_creep.rs +++ b/src/objects/impls/power_creep.rs @@ -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 { @@ -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. /// diff --git a/src/raw_memory.rs b/src/raw_memory.rs index 2fa2206c..4641d421 100644 --- a/src/raw_memory.rs +++ b/src/raw_memory.rs @@ -46,12 +46,12 @@ extern "C" { fn set_public_segments(segment_ids: &Array); } -/// Get a [`JsHashMap`] with all of the segments requested on +/// Get a [`JsHashMap`] 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 { +pub fn segments() -> JsHashMap { RawMemory::segments().into() } diff --git a/src/traits.rs b/src/traits.rs index 2c023d9f..c5db9c59 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -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;