1use std::hash::{Hash, Hasher};
2use std::mem::{discriminant, Discriminant};
3
4use mavlink::Message;
5
6use thiserror::Error;
7
8#[derive(Error, Debug)]
11pub enum AsyncMavlinkError {
12 #[error("connection to MAV lost")]
14 ConnectionLost(#[from] std::io::Error),
15
16 #[error("unable to emit task to event loop")]
18 TaskEmit(#[from] futures::channel::mpsc::SendError),
19
20 #[error("the event loop canceled our send ack channel")]
22 SendAck(#[from] futures::channel::oneshot::Canceled),
23}
24
25pub struct MavMessageType<M: Message>(Discriminant<M>);
27impl<M: mavlink::Message> Eq for MavMessageType<M> {}
28impl<M: mavlink::Message> PartialEq for MavMessageType<M> {
29 fn eq(&self, rhs: &Self) -> bool {
30 self.0.eq(&rhs.0)
31 }
32}
33impl<M: mavlink::Message> Hash for MavMessageType<M> {
34 fn hash<H>(&self, hasher: &mut H)
35 where
36 H: Hasher,
37 {
38 self.0.hash(hasher)
39 }
40}
41
42impl<M: Message> MavMessageType<M> {
43 pub fn new(message: &M) -> MavMessageType<M> {
57 #[allow(clippy::mem_discriminant_non_enum)]
58 Self(discriminant(message))
59 }
60}