From c1cd49d734fe00ba0dde52fd7e8ed06966adc858 Mon Sep 17 00:00:00 2001 From: Shane Madden Date: Thu, 5 Sep 2024 09:04:19 -0600 Subject: [PATCH] Fix return type of Structure::destroy (#539) --- CHANGELOG.md | 4 ++++ src/objects/impls/structure.rs | 16 ++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 976e1b41..84b5bab8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Unreleased ========== +### Breaking: + +- Change return type of `Structure::destroy` from `i8` to `Result<(), ErrorCode>`. + 0.22.0 (2024-08-27) =================== diff --git a/src/objects/impls/structure.rs b/src/objects/impls/structure.rs index aacf7ef7..b37e7274 100644 --- a/src/objects/impls/structure.rs +++ b/src/objects/impls/structure.rs @@ -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. /// @@ -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 HasId for T @@ -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 {