Skip to main content

BtleplugTransport

Struct BtleplugTransport 

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

Source

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.

Source

pub const fn peripheral(&self) -> &P

Returns a shared reference to the wrapped peripheral.

Source

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.

Source

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>

Source§

type Error = Error

Error returned by Bluetooth or adapter operations.
Source§

async fn subscribe( &mut self, source: NotificationSource, ) -> Result<(), Self::Error>

Enables notifications for one protocol source. Read more
Source§

async fn unsubscribe( &mut self, source: NotificationSource, ) -> Result<(), Self::Error>

Disables notifications for one protocol source. Read more
Source§

async fn write_command(&mut self, command: &Command) -> Result<(), Self::Error>

Writes an encoded command using its required write kind. Read more
Source§

async fn next_notification<'a>( &'a mut self, buffer: &'a mut [u8], ) -> Result<Notification<'a>, Self::Error>

Receives the next notification into the supplied buffer. Read more
Source§

async fn close(&mut self) -> Result<(), Self::Error>

Closes transport-owned resources after subscriptions are disabled. Read more
Source§

impl<P: Peripheral + 'static> TokioTransport for BtleplugTransport<P>

Available on crate feature tokio only.
Source§

type Error = Error

Error returned by Bluetooth or adapter operations.
Source§

async fn subscribe( &mut self, source: NotificationSource, ) -> Result<(), Self::Error>

Enables notifications for one protocol source. Read more
Source§

async fn unsubscribe( &mut self, source: NotificationSource, ) -> Result<(), Self::Error>

Disables notifications for one protocol source. Read more
Source§

async fn write_command(&mut self, command: &Command) -> Result<(), Self::Error>

Writes an encoded command using its required write kind. Read more
Source§

async fn next_notification<'a>( &'a mut self, buffer: &'a mut [u8], ) -> Result<Notification<'a>, Self::Error>

Receives the next notification into the supplied buffer. Read more
Source§

fn close(&mut self) -> impl Future<Output = Result<(), Self::Error>> + Send + '_

Closes transport-owned resources after subscriptions are disabled. Read more

Auto Trait Implementations§

§

impl<P> !RefUnwindSafe for BtleplugTransport<P>

§

impl<P> !Sync for BtleplugTransport<P>

§

impl<P> !UnwindSafe for BtleplugTransport<P>

§

impl<P> Freeze for BtleplugTransport<P>
where P: Freeze,

§

impl<P> Send for BtleplugTransport<P>
where P: Send,

§

impl<P> Unpin for BtleplugTransport<P>
where P: Unpin,

§

impl<P> UnsafeUnpin for BtleplugTransport<P>
where P: UnsafeUnpin,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more