1use alloc::vec::Vec;
2
3use crate::{
4 geometry::Geometry,
5 link::{LinkError, RxMessage, TxMessage},
6};
7
8pub trait AsyncLink: Send {
10 fn open(
12 &mut self,
13 geometry: &Geometry,
14 ) -> impl core::future::Future<Output = Result<(), LinkError>>;
15
16 fn close(&mut self) -> impl core::future::Future<Output = Result<(), LinkError>>;
18
19 #[doc(hidden)]
20 fn update(
21 &mut self,
22 _: &Geometry,
23 ) -> impl core::future::Future<Output = Result<(), LinkError>> {
24 async { Ok(()) }
25 }
26
27 fn alloc_tx_buffer(
29 &mut self,
30 ) -> impl core::future::Future<Output = Result<Vec<TxMessage>, LinkError>>;
31
32 fn send(
34 &mut self,
35 tx: Vec<TxMessage>,
36 ) -> impl core::future::Future<Output = Result<(), LinkError>>;
37
38 fn receive(
40 &mut self,
41 rx: &mut [RxMessage],
42 ) -> impl core::future::Future<Output = Result<(), LinkError>>;
43
44 #[must_use]
46 fn is_open(&self) -> bool;
47
48 fn ensure_is_open(&self) -> Result<(), LinkError> {
50 if self.is_open() {
51 Ok(())
52 } else {
53 Err(LinkError::closed())
54 }
55 }
56}