pub struct BtleplugTransport<P> { /* private fields */ }Expand description
An AsyncTransport adapter around a connected btleplug peripheral.
Device discovery and connection remain with the application. Construction discovers the peripheral’s services, validates the three required characteristics, and opens its notification stream.
The adapter implements AsyncTransport and, with the tokio feature,
TokioTransport.
See TokioTransport for the actor-compatible transport contract.
Implementations§
Source§impl<P: Peripheral> BtleplugTransport<P>
impl<P: Peripheral> BtleplugTransport<P>
Sourcepub async fn new(peripheral: P) -> Result<Self, Error>
pub async fn new(peripheral: P) -> Result<Self, Error>
Creates an adapter around an already connected peripheral.
Call
Peripheral::connect
before this method. This method performs service discovery but does not
establish the Bluetooth connection.
§Examples
use btleplug::api::Peripheral;
use chessnut_move::transport::btleplug::{BtleplugTransport, Error};
BtleplugTransport::new(peripheral).await§Errors
Returns Error::Backend when service discovery or notification-stream
creation fails. Returns Error::MissingCharacteristic when the
connected peripheral does not expose a required Move characteristic.
Sourcepub const fn peripheral(&self) -> &P
pub const fn peripheral(&self) -> &P
Returns a shared reference to the wrapped peripheral.
Sourcepub fn peripheral_mut(&mut self) -> &mut P
pub fn peripheral_mut(&mut self) -> &mut P
Returns a mutable reference to the wrapped peripheral.
Direct operations can change connection or subscription state expected by the adapter.
Sourcepub fn into_peripheral(self) -> P
pub fn into_peripheral(self) -> P
Consumes the adapter and returns the wrapped peripheral.
This method does not unsubscribe or disconnect the peripheral.
Trait Implementations§
Source§impl<P: Peripheral> AsyncTransport for BtleplugTransport<P>
impl<P: Peripheral> AsyncTransport for BtleplugTransport<P>
Source§async fn subscribe(
&mut self,
source: NotificationSource,
) -> Result<(), Self::Error>
async fn subscribe( &mut self, source: NotificationSource, ) -> Result<(), Self::Error>
Source§async fn unsubscribe(
&mut self,
source: NotificationSource,
) -> Result<(), Self::Error>
async fn unsubscribe( &mut self, source: NotificationSource, ) -> Result<(), Self::Error>
Source§async fn write_command(&mut self, command: &Command) -> Result<(), Self::Error>
async fn write_command(&mut self, command: &Command) -> Result<(), Self::Error>
Source§async fn next_notification<'a>(
&'a mut self,
buffer: &'a mut [u8],
) -> Result<Notification<'a>, Self::Error>
async fn next_notification<'a>( &'a mut self, buffer: &'a mut [u8], ) -> Result<Notification<'a>, Self::Error>
Source§impl<P: Peripheral + 'static> TokioTransport for BtleplugTransport<P>
Available on crate feature tokio only.
impl<P: Peripheral + 'static> TokioTransport for BtleplugTransport<P>
tokio only.