use std::hash::{Hash, Hasher};
use std::mem::{discriminant, Discriminant};
use mavlink::Message;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum AsyncMavlinkError {
#[error("connection to MAV lost")]
ConnectionLost(#[from] std::io::Error),
#[error("unable to emit task to event loop")]
TaskEmit(#[from] futures::channel::mpsc::SendError),
#[error("the event loop canceled our send ack channel")]
SendAck(#[from] futures::channel::oneshot::Canceled),
}
pub struct MavMessageType<M: Message>(Discriminant<M>);
impl<M: mavlink::Message> Eq for MavMessageType<M> {}
impl<M: mavlink::Message> PartialEq for MavMessageType<M> {
fn eq(&self, rhs: &Self) -> bool {
self.0.eq(&rhs.0)
}
}
impl<M: mavlink::Message> Hash for MavMessageType<M> {
fn hash<H>(&self, hasher: &mut H)
where
H: Hasher,
{
self.0.hash(hasher)
}
}
impl<M: Message> MavMessageType<M> {
pub fn new(message: &M) -> MavMessageType<M> {
#[allow(clippy::mem_discriminant_non_enum)]
Self(discriminant(message))
}
}