Skip to main content

AsyncDeviceStream

Struct AsyncDeviceStream 

Source
pub struct AsyncDeviceStream { /* private fields */ }
Expand description

An async connected device stream for bidirectional communication.

Implementations§

Source§

impl AsyncDeviceStream

Source

pub async fn connect( addr: SocketAddr, bus_id: u32, dev_id: &str, password: Option<&str>, ) -> Result<Self, ViiperError>

Source

pub async fn send<T: DeviceInput>(&self, input: &T) -> Result<(), ViiperError>

Send a device input to the device.

Source

pub async fn send_timeout<T: DeviceInput>( &self, input: &T, timeout: Duration, ) -> Result<(), ViiperError>

Send a device input to the device with a timeout.

§Arguments
  • input - The device input to send
  • timeout - Timeout duration for the operation
Source

pub fn on_output<F, Fut>(&mut self, callback: F) -> Result<(), ViiperError>
where F: Fn(Arc<Mutex<AsyncReadWrapper>>) -> Fut + Send + 'static, Fut: Future<Output = Result<()>> + Send + 'static,

Register a callback to receive device output asynchronously. The callback receives a shared reference to the read half and must read the exact number of bytes expected. The callback will be invoked repeatedly on a tokio task until it returns an error. Only one callback can be registered at a time.

Source

pub fn on_disconnect<F>(&mut self, callback: F) -> Result<(), ViiperError>
where F: FnOnce() + Send + 'static,

Source

pub async fn send_raw(&self, data: &[u8]) -> Result<(), ViiperError>

Send raw bytes to the device.

Source

pub async fn read_raw(&self, buf: &mut [u8]) -> Result<usize, ViiperError>

Read raw bytes from the device.

Source

pub async fn read_exact(&self, buf: &mut [u8]) -> Result<(), ViiperError>

Read exact number of bytes from the device.

Trait Implementations§

Source§

impl Drop for AsyncDeviceStream

Available on crate feature async only.
Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,