1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
use serde::{ Deserialize, Serialize, }; use std::collections::HashMap; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Advice { #[serde(skip_serializing_if = "Option::is_none")] pub timeout: Option<u64>, #[serde(skip_serializing_if = "Option::is_none")] pub reconnect: Option<Reconnect>, #[serde(skip_serializing_if = "Option::is_none")] pub interval: Option<i64>, #[serde(rename = "maxInterval", skip_serializing_if = "Option::is_none")] pub max_interval: Option<i64>, #[serde(flatten)] pub extra: HashMap<String, serde_json::Value>, } impl Advice { pub fn new() -> Self { Self { timeout: None, reconnect: None, interval: None, max_interval: None, extra: Default::default(), } } pub fn timeout(mut self, timeout: u64) -> Self { self.timeout = Some(timeout); self } pub fn interval(mut self, interval: i64) -> Self { self.interval = Some(interval); self } } impl Default for Advice { fn default() -> Self { Self::new() } } #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)] pub enum Reconnect { #[serde(rename = "retry")] Retry, #[serde(rename = "handshake")] Handshake, #[serde(rename = "none")] None, }