ed_journals/modules/logs/content/log_event_content/
module_swap_event.rsuse serde::{Deserialize, Deserializer, Serialize};
use std::str::FromStr;
use crate::modules::ship::{ShipSlot, ShipType};
use crate::ship::ShipModule;
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct ModuleSwapEvent {
#[serde(rename = "MarketID")]
pub market_id: u64,
pub from_slot: ShipSlot,
pub to_slot: ShipSlot,
pub from_item: ShipModule,
#[serde(rename = "FromItem_Localised")]
pub from_item_localized: Option<String>,
#[serde(deserialize_with = "deserialize_to_item")]
pub to_item: Option<ShipModule>,
#[serde(rename = "ToItem_Localised")]
pub to_item_localized: Option<String>,
pub ship: ShipType,
#[serde(rename = "ShipID")]
pub ship_id: u64,
}
fn deserialize_to_item<'de, D>(deserializer: D) -> Result<Option<ShipModule>, D::Error>
where
D: Deserializer<'de>,
{
let string = String::deserialize(deserializer)?;
if &string == "Null" {
Ok(None)
} else {
ShipModule::from_str(&string)
.map(Some)
.map_err(serde::de::Error::custom)
}
}