Beatsaber Rust Utilities: A Beatsaber V3 parsing library.
beatsaber beatmap
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added `Deref` and `DerefMut` implementations for `FxEventContainer`.

Also includes various documentation fixes and test simplification.

+25 -15
+25 -15
src/difficulty/lightshow/group/fx.rs
··· 1 - //! Events that animations unique to each environment. 1 + //! Events that control animations unique to each environment. 2 2 //! 3 3 //! Unlike the other V3 group event types, FX events use a template-like JSON syntax. 4 4 //! In order to have standardized structure across all V3 events, custom serialization has been written in [`FxEventContainer`]. 5 - //! Because of this, neither [`FxEventBox`] nor [`FxEventGroup`] implement [`Serialize`] nor [`Deserialize`]. 5 + //! Because of this, neither [`FxEventBox`] nor [`FxEventGroup`] implement [`Serialize`] nor [`Deserialize`] directly. 6 6 7 7 use crate::difficulty::lightshow::DistributionType; 8 8 use crate::difficulty::lightshow::easing::Easing; ··· 13 13 use ordered_float::OrderedFloat; 14 14 use serde::ser::SerializeStruct; 15 15 use serde::{Deserialize, Deserializer, Serialize, Serializer}; 16 + use std::ops::{Deref, DerefMut}; 16 17 17 18 /// Contains a list of [`FxEventBox`] as well as the [`Serialize`] and [`Deserialize`] implementations for FX events. 18 19 #[derive(Debug, Clone, PartialEq, Default)] ··· 23 24 )] 24 25 pub struct FxEventContainer { 25 26 pub event_boxes: Vec<FxEventBox>, 27 + } 28 + 29 + impl Deref for FxEventContainer { 30 + type Target = Vec<FxEventBox>; 31 + 32 + fn deref(&self) -> &Self::Target { 33 + &self.event_boxes 34 + } 35 + } 36 + 37 + impl DerefMut for FxEventContainer { 38 + fn deref_mut(&mut self) -> &mut Self::Target { 39 + &mut self.event_boxes 40 + } 26 41 } 27 42 28 43 /// The format that is actually stored in JSON. ··· 176 191 pub groups: Vec<FxEventGroup>, 177 192 } 178 193 179 - /// The raw JSON structure that uses [data IDs](self::data_ids) rather than actual [event data](FxEventData). 194 + /// The raw JSON structure that uses [data IDs](FxEventGroupRaw::data_ids) rather than actual [event data](FxEventData). 180 195 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] 181 196 struct FxEventBoxRaw { 182 197 #[serde(rename = "b")] ··· 461 476 462 477 #[test] 463 478 fn test_deserialize() { 464 - let container: FxEventContainer = 465 - serde_json::from_value(get_test_json()).expect("Failed to deserialize"); 479 + let container: FxEventContainer = serde_json::from_value(get_test_json()).unwrap(); 466 480 467 481 assert_eq!(container, get_test_container()); 468 482 } 469 483 470 484 #[test] 471 485 fn test_serialize() { 472 - let out_json = serde_json::to_value(&get_test_container()).expect("Failed to serialize"); 486 + let out_json = serde_json::to_value(&get_test_container()).unwrap(); 473 487 474 488 assert_eq!(out_json, get_test_json()); 475 489 } 476 490 477 491 #[test] 478 - fn test_roundtrip() { 479 - let container: FxEventContainer = 480 - serde_json::from_value(get_test_json()).expect("Failed to deserialize"); 492 + fn test_round_trip() { 493 + let container: FxEventContainer = serde_json::from_value(get_test_json()).unwrap(); 481 494 482 - let out_json = serde_json::to_string_pretty(&container).expect("Failed to serialize"); 495 + let out_json = serde_json::to_string_pretty(&container).unwrap(); 483 496 484 - let roundtrip: FxEventContainer = 485 - serde_json::from_str(&out_json).expect("Re-deserialization failed"); 497 + let round_trip: FxEventContainer = serde_json::from_str(&out_json).unwrap(); 486 498 487 - assert_eq!(container, roundtrip, "Round-trip did not match"); 488 - 489 - println!("Round-trip serialization succeeded."); 499 + assert_eq!(container, round_trip); 490 500 } 491 501 }