Skip to main content

Adapter

Struct Adapter 

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

The system’s Bluetooth adapter interface.

Implementations§

Source§

impl Adapter

Source

pub async fn default() -> Option<Self>

Creates an interface to a Bluetooth adapter using the default config.

Source

pub async fn with_config(config: AdapterConfig) -> Result<Self>

Creates an interface to a Bluetooth adapter. The vm pointer will be ignored if this has been called previously.

Source

pub async fn events( &self, ) -> Result<impl Stream<Item = Result<AdapterEvent>> + Send + Unpin + '_>

A stream of AdapterEvent which allows the application to identify when the adapter is enabled or disabled.

Source

pub async fn wait_available(&self) -> Result<()>

Asynchronously blocks until the adapter is available.

Source

pub async fn is_available(&self) -> Result<bool>

Check if the adapter is available.

Source

pub async fn open_device(&self, id: &DeviceId) -> Result<Device>

Attempts to create the device identified by id.

Source

pub async fn connected_devices(&self) -> Result<Vec<Device>>

Finds all connected Bluetooth LE devices.

NOTE: there might be BLE devices connected outside this library. If AdapterConfig::allow_multiple_connections is set to true, this method will call BluetoothManager.getConnectedDevices() and ensure GATT connections are created for them in this library instance.

Source

pub async fn connected_devices_with_services( &self, service_ids: &[Uuid], ) -> Result<Vec<Device>>

Finds all connected devices providing any service in service_ids.

Source

pub async fn scan<'a>( &'a self, service_ids: &'a [Uuid], ) -> Result<impl Stream<Item = AdvertisingDevice> + Send + Unpin + 'a>

Starts scanning for Bluetooth advertising packets.

Returns a stream of AdvertisingDevice structs which contain the data from the advertising packet and the Device which sent it. Scanning is automatically stopped when the stream is dropped. Inclusion of duplicate packets is a platform-specific implementation detail.

If service_ids is not empty, returns advertisements including at least one GATT service with a UUID in services. Otherwise returns all advertisements.

Source

pub async fn discover_devices<'a>( &'a self, services: &'a [Uuid], ) -> Result<impl Stream<Item = Result<Device>> + Send + Unpin + 'a>

Finds Bluetooth devices providing any service in services.

Returns a stream of Device structs with matching connected devices returned first. If the stream is not dropped before all matching connected devices are consumed then scanning will begin for devices advertising any of the services. Scanning will continue until the stream is dropped. Inclusion of duplicate devices is a platform-specific implementation detail.

Source

pub async fn connect_device(&self, device: &Device) -> Result<()>

Connects to the Device.

Source

pub async fn disconnect_device(&self, device: &Device) -> Result<()>

Disconnects from the Device.

XXX: manage to call this internally when all API wrapper objects for the device are dropped.

Source

pub async fn device_connection_events<'a>( &'a self, device: &'a Device, ) -> Result<impl Stream<Item = ConnectionEvent> + Send + Unpin + 'a>

Monitors a device for connection/disconnection events.

This monitors only devices connected/disconnected in this library instance, even if AdapterConfig::allow_multiple_connections is set to true.

This does not work with random address devices.

Trait Implementations§

Source§

impl Clone for Adapter

Source§

fn clone(&self) -> Adapter

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Adapter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Adapter

Source§

fn hash<H: Hasher>(&self, _state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Adapter

Source§

fn eq(&self, _other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Adapter

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.