pub trait Connection {
type Error: Error + From<DecodeError> + From<Cdc2Ack> + From<FixedStringSizeError>;
// Required methods
fn connection_type(&self) -> ConnectionType;
fn send(
&mut self,
packet: impl Encode,
) -> impl Future<Output = Result<(), Self::Error>>;
fn recv<P: Decode + CheckHeader>(
&mut self,
timeout: Duration,
) -> impl Future<Output = Result<P, Self::Error>>;
fn read_user(
&mut self,
buf: &mut [u8],
) -> impl Future<Output = Result<usize, Self::Error>>;
fn write_user(
&mut self,
buf: &[u8],
) -> impl Future<Output = Result<usize, Self::Error>>;
// Provided methods
fn execute_command<C: Command>(
&mut self,
command: C,
) -> impl Future<Output = Result<C::Output, Self::Error>> { ... }
async fn handshake<D: Decode + CheckHeader>(
&mut self,
timeout: Duration,
retries: usize,
packet: impl Encode + Clone,
) -> Result<D, Self::Error> { ... }
}
Expand description
Represents an open connection to a V5 peripheral.
Required Associated Types§
type Error: Error + From<DecodeError> + From<Cdc2Ack> + From<FixedStringSizeError>
Required Methods§
fn connection_type(&self) -> ConnectionType
Sourcefn send(
&mut self,
packet: impl Encode,
) -> impl Future<Output = Result<(), Self::Error>>
fn send( &mut self, packet: impl Encode, ) -> impl Future<Output = Result<(), Self::Error>>
Sends a packet.
Sourcefn recv<P: Decode + CheckHeader>(
&mut self,
timeout: Duration,
) -> impl Future<Output = Result<P, Self::Error>>
fn recv<P: Decode + CheckHeader>( &mut self, timeout: Duration, ) -> impl Future<Output = Result<P, Self::Error>>
Receives a packet.
Provided Methods§
Sourcefn execute_command<C: Command>(
&mut self,
command: C,
) -> impl Future<Output = Result<C::Output, Self::Error>>
fn execute_command<C: Command>( &mut self, command: C, ) -> impl Future<Output = Result<C::Output, Self::Error>>
Executes a Command
.
Sourceasync fn handshake<D: Decode + CheckHeader>(
&mut self,
timeout: Duration,
retries: usize,
packet: impl Encode + Clone,
) -> Result<D, Self::Error>
async fn handshake<D: Decode + CheckHeader>( &mut self, timeout: Duration, retries: usize, packet: impl Encode + Clone, ) -> Result<D, Self::Error>
Sends a packet and waits for a response.
This function will retry the handshake retries
times
before giving up and erroring with the error thrown on the last retry.
§Note
This function will fail immediately if the given packet fails to encode.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.