Omit throttled if not true

This commit is contained in:
Joscha 2022-06-22 21:16:54 +02:00
parent 956cb51231
commit 2f5b4b1c2f

View file

@ -9,8 +9,7 @@ pub struct Packet {
pub r#type: PacketType, pub r#type: PacketType,
pub data: Option<Value>, pub data: Option<Value>,
pub error: Option<String>, pub error: Option<String>,
#[serde(default)] pub throttled: Option<bool>,
pub throttled: bool,
pub throttled_reason: Option<String>, pub throttled_reason: Option<String>,
} }
@ -174,7 +173,7 @@ impl ParsedPacket {
Ok(Data::from_value(r#type, data)?) Ok(Data::from_value(r#type, data)?)
}; };
let throttled = if packet.throttled { let throttled = if packet.throttled == Some(true) {
let reason = packet let reason = packet
.throttled_reason .throttled_reason
.unwrap_or_else(|| "no reason given".to_string()); .unwrap_or_else(|| "no reason given".to_string());
@ -194,7 +193,7 @@ impl ParsedPacket {
pub fn to_packet(self) -> serde_json::Result<Packet> { pub fn to_packet(self) -> serde_json::Result<Packet> {
let id = self.id; let id = self.id;
let r#type = self.r#type; let r#type = self.r#type;
let throttled = self.throttled.is_some(); let throttled = self.throttled.as_ref().map(|_| true);
let throttled_reason = self.throttled; let throttled_reason = self.throttled;
Ok(match self.content { Ok(match self.content {