use std::convert::Into;
use std::fmt;
use std::string::String;
#[derive(Debug, Clone, PartialEq)]
pub enum PingFailedReason {
Busy,
NoAnswer,
}
#[derive(Debug, Clone)]
pub struct PingAck {
peer: String,
snr: u16,
decode_quality: u16,
}
impl PingAck {
pub(crate) fn new<S>(peer: S, snr: u16, decode_quality: u16) -> Self
where
S: Into<String>,
{
Self {
peer: peer.into(),
snr,
decode_quality,
}
}
pub fn peer(&self) -> &String {
&self.peer
}
pub fn snr(&self) -> u16 {
self.snr
}
pub fn decode_quality(&self) -> u16 {
self.decode_quality
}
}
impl fmt::Display for PingAck {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"Ping {}: SNR {} dB - Quality {}",
&self.peer, self.snr, self.decode_quality
)
}
}
impl fmt::Display for PingFailedReason {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
PingFailedReason::Busy => write!(f, "busy channel"),
PingFailedReason::NoAnswer => write!(f, "no answer from peer"),
}
}
}