use std::fmt::Display; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub enum Error { SignalType(SignalType), } impl std::error::Error for Error { fn cause(&self) -> Option<&dyn std::error::Error> { self.source() } } impl Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Error::SignalType(signal_type) => { write!(f, "Not Expected Signal Type: {}", signal_type) } } } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub enum SignalType { Auth, Offer, Answer, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Signal { signal_type: SignalType, data: String, time: DateTime, } impl Display for SignalType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { SignalType::Auth => write!(f, "Auth"), SignalType::Offer => write!(f, "Offer"), SignalType::Answer => write!(f, "Answer"), } } } impl Signal { pub fn new(signal_type: &SignalType, data: &String) -> Signal { let signal_type = *signal_type; let data = data.to_owned(); Signal { signal_type, data, time: DateTime::default(), } } pub fn get_signal_type(&self) -> SignalType { self.signal_type } pub fn get_data(&self) -> String { self.data.to_owned() } pub fn get_time(&self) -> DateTime { self.time } }