Connection

Trait Connection 

Source
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§

Required Methods§

Source

fn connection_type(&self) -> ConnectionType

Source

fn send( &mut self, packet: impl Encode, ) -> impl Future<Output = Result<(), Self::Error>>

Sends a packet.

Source

fn recv<P: Decode + CheckHeader>( &mut self, timeout: Duration, ) -> impl Future<Output = Result<P, Self::Error>>

Receives a packet.

Source

fn read_user( &mut self, buf: &mut [u8], ) -> impl Future<Output = Result<usize, Self::Error>>

Read user program output.

Source

fn write_user( &mut self, buf: &[u8], ) -> impl Future<Output = Result<usize, Self::Error>>

Write to user program stdio.

Provided Methods§

Source

fn execute_command<C: Command>( &mut self, command: C, ) -> impl Future<Output = Result<C::Output, Self::Error>>

Executes a Command.

Source

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.

Implementors§