From 7300d0c9712eb13194b7ff26af9a209440806d0d Mon Sep 17 00:00:00 2001 From: Shane Madden Date: Wed, 14 Aug 2024 17:54:26 -0600 Subject: [PATCH 1/4] Stop using __Nonexhaustive for market type conversion (#527) --- CHANGELOG.md | 4 ++++ src/constants/types.rs | 36 +++++++++++++++--------------------- src/lib.rs | 4 ++++ 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4382c13..a2a66692 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Unreleased ========== +### Bugfixes: + +- Update for new string enum implementation's implementation in wasm-bindgen 0.2.93 + ### Misc: - Move crate constant `ROOM_AREA` to extra constants module and make public diff --git a/src/constants/types.rs b/src/constants/types.rs index 934a5e7b..394ff2f4 100644 --- a/src/constants/types.rs +++ b/src/constants/types.rs @@ -674,7 +674,7 @@ impl wasm_bindgen::convert::FromWasmAbi for MarketResourceType { // try with IntershardResourceType match IntershardResourceType::from_js_value(&s) { Some(r) => Self::IntershardResource(r), - None => Self::Resource(ResourceType::__Nonexhaustive), + None => unreachable!("should have come from IntoWasmAbi"), } } } @@ -834,7 +834,7 @@ mod test { #[test] fn resources_rust_to_serde_json_from_serde_json_roundtrip() { for resource in enum_iterator::all::() { - if resource != ResourceType::__Nonexhaustive { + if resource != ResourceType::__Invalid { let serialized = serde_json::to_string(&resource).unwrap(); let parsed: ResourceType = serde_json::from_str(&serialized).unwrap(); assert_eq!(resource, parsed); @@ -845,7 +845,7 @@ mod test { #[test] fn resources_rust_to_display_from_str_roundtrip() { for resource in enum_iterator::all::() { - if resource != ResourceType::__Nonexhaustive { + if resource != ResourceType::__Invalid { let string = format!("{}", resource); let parsed = ResourceType::from_str(&string).unwrap(); assert_eq!(resource, parsed); @@ -857,7 +857,7 @@ mod test { fn resources_rust_vec_to_serde_json_from_serde_json_roundtrip() { let mut resources = vec![]; for resource in enum_iterator::all::() { - if resource != ResourceType::__Nonexhaustive { + if resource != ResourceType::__Invalid { resources.push(resource); } } @@ -870,7 +870,7 @@ mod test { fn resources_rust_vec_to_serde_json_from_serde_json_roundtrip_via_values() { let mut resources = vec![]; for resource in enum_iterator::all::() { - if resource != ResourceType::__Nonexhaustive { + if resource != ResourceType::__Invalid { resources.push(resource); } } @@ -887,7 +887,7 @@ mod test { #[test] fn intershard_resources_rust_to_serde_json_from_serde_json_roundtrip() { for resource in enum_iterator::all::() { - if resource != IntershardResourceType::__Nonexhaustive { + if resource != IntershardResourceType::__Invalid { let serialized = serde_json::to_string(&resource).unwrap(); let parsed: IntershardResourceType = serde_json::from_str(&serialized).unwrap(); assert_eq!(resource, parsed); @@ -898,7 +898,7 @@ mod test { #[test] fn intershard_resources_rust_to_display_from_str_roundtrip() { for resource in enum_iterator::all::() { - if resource != IntershardResourceType::__Nonexhaustive { + if resource != IntershardResourceType::__Invalid { let string = format!("{}", resource); let parsed = IntershardResourceType::from_str(&string).unwrap(); assert_eq!(resource, parsed); @@ -910,7 +910,7 @@ mod test { fn intershard_resources_rust_vec_to_serde_json_from_serde_json_roundtrip() { let mut resources = vec![]; for resource in enum_iterator::all::() { - if resource != IntershardResourceType::__Nonexhaustive { + if resource != IntershardResourceType::__Invalid { resources.push(resource); } } @@ -924,7 +924,7 @@ mod test { fn intershard_resources_rust_vec_to_serde_json_from_serde_json_roundtrip_via_values() { let mut resources = vec![]; for resource in enum_iterator::all::() { - if resource != IntershardResourceType::__Nonexhaustive { + if resource != IntershardResourceType::__Invalid { resources.push(resource); } } @@ -941,11 +941,9 @@ mod test { #[test] fn market_resources_rust_to_serde_json_from_serde_json_roundtrip() { for resource in enum_iterator::all::() { - if resource != MarketResourceType::Resource(ResourceType::__Nonexhaustive) + if resource != MarketResourceType::Resource(ResourceType::__Invalid) && resource - != MarketResourceType::IntershardResource( - IntershardResourceType::__Nonexhaustive, - ) + != MarketResourceType::IntershardResource(IntershardResourceType::__Invalid) { let serialized = serde_json::to_string(&resource).unwrap(); let parsed: MarketResourceType = serde_json::from_str(&serialized).unwrap(); @@ -958,11 +956,9 @@ mod test { fn market_resources_rust_vec_to_serde_json_from_serde_json_roundtrip() { let mut resources = vec![]; for resource in enum_iterator::all::() { - if resource != MarketResourceType::Resource(ResourceType::__Nonexhaustive) + if resource != MarketResourceType::Resource(ResourceType::__Invalid) && resource - != MarketResourceType::IntershardResource( - IntershardResourceType::__Nonexhaustive, - ) + != MarketResourceType::IntershardResource(IntershardResourceType::__Invalid) { resources.push(resource); } @@ -977,11 +973,9 @@ mod test { fn market_resources_rust_vec_to_serde_json_from_serde_json_roundtrip_via_values() { let mut resources = vec![]; for resource in enum_iterator::all::() { - if resource != MarketResourceType::Resource(ResourceType::__Nonexhaustive) + if resource != MarketResourceType::Resource(ResourceType::__Invalid) && resource - != MarketResourceType::IntershardResource( - IntershardResourceType::__Nonexhaustive, - ) + != MarketResourceType::IntershardResource(IntershardResourceType::__Invalid) { resources.push(resource); } diff --git a/src/lib.rs b/src/lib.rs index 6117ad0f..0b87246b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,6 +94,10 @@ // #![warn(clippy::missing_const_for_fn)] +// disable deprecation warnings - TODO need to figure out how to get wasm_bindgen's new thread_local +// attribute working +#![allow(deprecated)] + pub mod console; pub mod constants; pub mod enums; From 144691472dc987da7e07bc975d851f3b570a9f4a Mon Sep 17 00:00:00 2001 From: Shane Madden Date: Wed, 14 Aug 2024 18:09:37 -0600 Subject: [PATCH 2/4] Prep 0.21.2 release (#528) --- CHANGELOG.md | 3 +++ Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2a66692..0c8ca6f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ Unreleased ========== +0.21.2 (2024-08-14) +=================== + ### Bugfixes: - Update for new string enum implementation's implementation in wasm-bindgen 0.2.93 diff --git a/Cargo.toml b/Cargo.toml index 3acdb927..0be27864 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "screeps-game-api" -version = "0.21.1" +version = "0.21.2" authors = ["David Ross "] documentation = "https://docs.rs/screeps-game-api/" edition = "2021" From 95dec58a259b020c0e84b5719cf07af909a5e957 Mon Sep 17 00:00:00 2001 From: Shane Madden Date: Wed, 14 Aug 2024 20:16:27 -0600 Subject: [PATCH 3/4] Prep 0.21.3 release, downgrading wasm-bindgen to compatible version (#530) --- CHANGELOG.md | 6 +++++- Cargo.toml | 4 ++-- src/constants/types.rs | 34 ++++++++++++++++++++-------------- src/lib.rs | 4 ---- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c8ca6f7..b92ace41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,16 @@ Unreleased ========== +### Bugfixes: + +- Temporarily pin to wasm-bindgen 0.2.92 due to incompatible generated javascript + 0.21.2 (2024-08-14) =================== ### Bugfixes: -- Update for new string enum implementation's implementation in wasm-bindgen 0.2.93 +- Update for new string enum implementation in wasm-bindgen 0.2.93 ### Misc: diff --git a/Cargo.toml b/Cargo.toml index 0be27864..5784c9d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "screeps-game-api" -version = "0.21.2" +version = "0.21.3" authors = ["David Ross "] documentation = "https://docs.rs/screeps-game-api/" edition = "2021" @@ -39,7 +39,7 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" serde_repr = "0.1" serde-wasm-bindgen = "0.6" -wasm-bindgen = "0.2" +wasm-bindgen = "=0.2.92" [dev-dependencies] bincode = "1.3" diff --git a/src/constants/types.rs b/src/constants/types.rs index 394ff2f4..743ddfe2 100644 --- a/src/constants/types.rs +++ b/src/constants/types.rs @@ -834,7 +834,7 @@ mod test { #[test] fn resources_rust_to_serde_json_from_serde_json_roundtrip() { for resource in enum_iterator::all::() { - if resource != ResourceType::__Invalid { + if resource != ResourceType::__Nonexhaustive { let serialized = serde_json::to_string(&resource).unwrap(); let parsed: ResourceType = serde_json::from_str(&serialized).unwrap(); assert_eq!(resource, parsed); @@ -845,7 +845,7 @@ mod test { #[test] fn resources_rust_to_display_from_str_roundtrip() { for resource in enum_iterator::all::() { - if resource != ResourceType::__Invalid { + if resource != ResourceType::__Nonexhaustive { let string = format!("{}", resource); let parsed = ResourceType::from_str(&string).unwrap(); assert_eq!(resource, parsed); @@ -857,7 +857,7 @@ mod test { fn resources_rust_vec_to_serde_json_from_serde_json_roundtrip() { let mut resources = vec![]; for resource in enum_iterator::all::() { - if resource != ResourceType::__Invalid { + if resource != ResourceType::__Nonexhaustive { resources.push(resource); } } @@ -870,7 +870,7 @@ mod test { fn resources_rust_vec_to_serde_json_from_serde_json_roundtrip_via_values() { let mut resources = vec![]; for resource in enum_iterator::all::() { - if resource != ResourceType::__Invalid { + if resource != ResourceType::__Nonexhaustive { resources.push(resource); } } @@ -887,7 +887,7 @@ mod test { #[test] fn intershard_resources_rust_to_serde_json_from_serde_json_roundtrip() { for resource in enum_iterator::all::() { - if resource != IntershardResourceType::__Invalid { + if resource != IntershardResourceType::__Nonexhaustive { let serialized = serde_json::to_string(&resource).unwrap(); let parsed: IntershardResourceType = serde_json::from_str(&serialized).unwrap(); assert_eq!(resource, parsed); @@ -898,7 +898,7 @@ mod test { #[test] fn intershard_resources_rust_to_display_from_str_roundtrip() { for resource in enum_iterator::all::() { - if resource != IntershardResourceType::__Invalid { + if resource != IntershardResourceType::__Nonexhaustive { let string = format!("{}", resource); let parsed = IntershardResourceType::from_str(&string).unwrap(); assert_eq!(resource, parsed); @@ -910,7 +910,7 @@ mod test { fn intershard_resources_rust_vec_to_serde_json_from_serde_json_roundtrip() { let mut resources = vec![]; for resource in enum_iterator::all::() { - if resource != IntershardResourceType::__Invalid { + if resource != IntershardResourceType::__Nonexhaustive { resources.push(resource); } } @@ -924,7 +924,7 @@ mod test { fn intershard_resources_rust_vec_to_serde_json_from_serde_json_roundtrip_via_values() { let mut resources = vec![]; for resource in enum_iterator::all::() { - if resource != IntershardResourceType::__Invalid { + if resource != IntershardResourceType::__Nonexhaustive { resources.push(resource); } } @@ -941,9 +941,11 @@ mod test { #[test] fn market_resources_rust_to_serde_json_from_serde_json_roundtrip() { for resource in enum_iterator::all::() { - if resource != MarketResourceType::Resource(ResourceType::__Invalid) + if resource != MarketResourceType::Resource(ResourceType::__Nonexhaustive) && resource - != MarketResourceType::IntershardResource(IntershardResourceType::__Invalid) + != MarketResourceType::IntershardResource( + IntershardResourceType::__Nonexhaustive, + ) { let serialized = serde_json::to_string(&resource).unwrap(); let parsed: MarketResourceType = serde_json::from_str(&serialized).unwrap(); @@ -956,9 +958,11 @@ mod test { fn market_resources_rust_vec_to_serde_json_from_serde_json_roundtrip() { let mut resources = vec![]; for resource in enum_iterator::all::() { - if resource != MarketResourceType::Resource(ResourceType::__Invalid) + if resource != MarketResourceType::Resource(ResourceType::__Nonexhaustive) && resource - != MarketResourceType::IntershardResource(IntershardResourceType::__Invalid) + != MarketResourceType::IntershardResource( + IntershardResourceType::__Nonexhaustive, + ) { resources.push(resource); } @@ -973,9 +977,11 @@ mod test { fn market_resources_rust_vec_to_serde_json_from_serde_json_roundtrip_via_values() { let mut resources = vec![]; for resource in enum_iterator::all::() { - if resource != MarketResourceType::Resource(ResourceType::__Invalid) + if resource != MarketResourceType::Resource(ResourceType::__Nonexhaustive) && resource - != MarketResourceType::IntershardResource(IntershardResourceType::__Invalid) + != MarketResourceType::IntershardResource( + IntershardResourceType::__Nonexhaustive, + ) { resources.push(resource); } diff --git a/src/lib.rs b/src/lib.rs index 0b87246b..6117ad0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,10 +94,6 @@ // #![warn(clippy::missing_const_for_fn)] -// disable deprecation warnings - TODO need to figure out how to get wasm_bindgen's new thread_local -// attribute working -#![allow(deprecated)] - pub mod console; pub mod constants; pub mod enums; From 9e63c8d8efe21437f858276e0248067cad0fd653 Mon Sep 17 00:00:00 2001 From: Shane Madden Date: Sat, 17 Aug 2024 08:12:53 -0600 Subject: [PATCH 4/4] Make `RoomName::from_packed` and `RoomName::packed_repr` public (#531) --- CHANGELOG.md | 5 +++++ src/local/room_name.rs | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b92ace41..ffd58da2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Unreleased ========== +- Make `RoomName::from_packed` and `RoomName::packed_repr` public + +0.21.3 (2024-08-14) +=================== + ### Bugfixes: - Temporarily pin to wasm-bindgen 0.2.92 due to incompatible generated javascript diff --git a/src/local/room_name.rs b/src/local/room_name.rs index ab2cdc6e..7e299f99 100644 --- a/src/local/room_name.rs +++ b/src/local/room_name.rs @@ -111,8 +111,9 @@ impl RoomName { x.as_ref().parse() } + /// Get the [`RoomName`] represented by a packed integer #[inline] - pub(crate) const fn from_packed(packed: u16) -> Self { + pub const fn from_packed(packed: u16) -> Self { RoomName { packed } } @@ -156,8 +157,12 @@ impl RoomName { (self.packed & 0xFF) as i32 - HALF_WORLD_SIZE } + /// Get the inner packed representation of the room name. + /// + /// This data structure matches the implementation of the upper 16 bits of + /// the js Position type. #[inline] - pub(super) const fn packed_repr(&self) -> u16 { + pub const fn packed_repr(&self) -> u16 { self.packed }