Skip to content

Commit

Permalink
Fix return type of Structure::destroy (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanemadden authored Sep 5, 2024
1 parent f34e08d commit c1cd49d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Unreleased
==========

### Breaking:

- Change return type of `Structure::destroy` from `i8` to `Result<(), ErrorCode>`.

0.22.0 (2024-08-27)
===================

Expand Down
16 changes: 10 additions & 6 deletions src/objects/impls/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ extern "C" {
#[wasm_bindgen(method, getter = structureType)]
pub fn structure_type(this: &Structure) -> StructureType;

/// Destroy the structure, if possible.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Structure.destroy)
#[wasm_bindgen(method)]
pub fn destroy(this: &Structure) -> i8;
#[wasm_bindgen(method, js_name = destroy)]
fn destroy_internal(this: &Structure) -> i8;

/// Determine if the structure is active and can be used at the current RCL.
///
Expand Down Expand Up @@ -74,6 +71,13 @@ impl Structure {
pub fn hits_max(&self) -> u32 {
self.hits_max_internal().unwrap_or(0)
}

/// Destroy the structure, if possible.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Structure.destroy)
pub fn destroy(&self) -> Result<(), ErrorCode> {
ErrorCode::result_from_i8(self.destroy_internal())
}
}

impl<T> HasId for T
Expand Down Expand Up @@ -107,7 +111,7 @@ where
}

fn destroy(&self) -> Result<(), ErrorCode> {
ErrorCode::result_from_i8(Structure::destroy(self.as_ref()))
Structure::destroy(self.as_ref())
}

fn is_active(&self) -> bool {
Expand Down

0 comments on commit c1cd49d

Please sign in to comment.