Skip to main content

SendScdcTransport

Trait SendScdcTransport 

Source
pub trait SendScdcTransport: Send + Sync {
    type Error: DdcError + Send;

    // Required methods
    fn read(
        &self,
        reg: u8,
    ) -> impl Future<Output = Result<u8, Self::Error>> + Send;
    fn write(
        &mut self,
        reg: u8,
        value: u8,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send;
    fn read_block(
        &self,
        reg: u8,
        buf: &mut [u8],
    ) -> impl Future<Output = Result<(), Self::Error>> + Send;
}
Available on crate feature culvert-async only.
Expand description

The transport’s Send twin, re-exported from hdmi-hal-async: bound generic code by it to spawn work through Scdc<T> on a multi-threaded executor. ScdcTransport with Send futures, for code that spawns link training on a multi-threaded executor.

ScdcTransport’s async fns promise nothing about their futures, so code generic over T: ScdcTransport cannot spawn a future that calls them, however T is bounded. This trait has the same methods and contract, each returning a future that is Send, and errors that are Send too: a spawned task returns them. Implementations still write async fn; the compiler checks that each future is Send.

The transport is Sync as well as Send: read takes &self, and a future holding &self is only Send when Self is Sync. A transport that keeps interior state for reads uses a Sync type for it (an atomic or a lock rather than a Cell).

Every SendScdcTransport is an ScdcTransport, through a blanket implementation, so it works with everything written against ScdcTransport as well (its read_block included); a type implements one of the two (implementing both conflicts with the blanket implementation). A SendScdcTransport type has both traits’ methods, so with both traits in scope a method call on it is ambiguous: import only the trait the code is bounded by, or call SendScdcTransport::read(…).

Bound generic code by SendScdcTransport alone. Adding + ScdcTransport, which it implies anyway, makes the compiler use that bound instead of the blanket implementation, and the futures are no longer known to be Send.

Required Associated Types§

Source

type Error: DdcError + Send

Error type returned by transport operations, classified by DdcError::kind. Over a SendDdcBus, SendScdcOverDdc is the transport.

Required Methods§

Source

fn read(&self, reg: u8) -> impl Future<Output = Result<u8, Self::Error>> + Send

Source

fn write( &mut self, reg: u8, value: u8, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Source

fn read_block( &self, reg: u8, buf: &mut [u8], ) -> impl Future<Output = Result<(), Self::Error>> + Send

See ScdcTransport::read_block, whose contract it has. A transport that cannot burst-read implements it with read_block_bytewise:

use hdmi_hal_async::scdc::{SendScdcTransport, read_block_bytewise};
async fn read_block(&self, reg: u8, buf: &mut [u8]) -> Result<(), ()> {
    read_block_bytewise(self, reg, buf).await
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§