Skip to content

Commit

Permalink
Use JsCast on function bounds instead of MaybeHasId
Browse files Browse the repository at this point in the history
  • Loading branch information
shanemadden committed Dec 31, 2023
1 parent 408b99a commit 574ce7d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub fn symbols() -> JsHashMap<crate::ResourceType, u32> {
/// [Screeps documentation](http://docs.screeps.com/api/#Game.getObjectById)
pub fn get_object_by_js_id_typed<T>(id: &JsObjectId<T>) -> Option<T>
where
T: MaybeHasId,
T: MaybeHasId + JsCast,
{
Game::get_object_by_id(&id.raw).map(JsCast::unchecked_into)
}
Expand All @@ -183,7 +183,7 @@ where
/// [Screeps documentation](http://docs.screeps.com/api/#Game.getObjectById)
pub fn get_object_by_id_typed<T>(id: &ObjectId<T>) -> Option<T>
where
T: MaybeHasId,
T: MaybeHasId + JsCast,
{
// construct a reference to a javascript string using the id data
let js_str = JsString::from(id.to_string());
Expand Down
2 changes: 1 addition & 1 deletion src/js_collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl<T> JsObjectId<T> {
/// don't have vision for.
pub fn resolve(&self) -> Option<T>
where
T: MaybeHasId,
T: MaybeHasId + JsCast,
{
game::get_object_by_js_id_typed(self)
}
Expand Down
4 changes: 2 additions & 2 deletions src/local/object_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl<T> ObjectId<T> {
/// we don't have vision for.
pub fn try_resolve(self) -> Result<Option<T>, RoomObject>
where
T: MaybeHasId,
T: MaybeHasId + JsCast,
{
match game::get_object_by_id_erased(&self.raw) {
Some(v) => v.dyn_into().map(|v| Some(v)),
Expand All @@ -186,7 +186,7 @@ impl<T> ObjectId<T> {
/// don't have vision for.
pub fn resolve(self) -> Option<T>
where
T: MaybeHasId,
T: MaybeHasId + JsCast,
{
game::get_object_by_id_typed(&self)
}
Expand Down
4 changes: 2 additions & 2 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub trait HasId: MaybeHasId {

/// Trait for all game objects which may (or may not) have an associated unique
/// identifier.
pub trait MaybeHasId: JsCast {
pub trait MaybeHasId {
/// Object ID of the object, which can be used to efficiently fetch a
/// fresh reference to the object on subsequent ticks, or `None` if the
/// object doesn't currently have an ID.
Expand Down Expand Up @@ -123,7 +123,7 @@ pub trait MaybeHasId: JsCast {

impl<T> MaybeHasId for T
where
T: HasId + JsCast,
T: HasId,
{
fn try_js_raw_id(&self) -> Option<JsString> {
Some(self.js_raw_id())
Expand Down

0 comments on commit 574ce7d

Please sign in to comment.