Skip to main content

Connection

Struct Connection 

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

A GATT connection to one peer.

Implementations§

Source§

impl Connection

Source

pub fn open( address: &str, random_address: bool, sink: Arc<dyn NotificationSink>, ) -> Result<Self, Error>

Open an ATT connection to address.

random_address must match how the peer advertised — connecting to a random address as though it were public simply times out.

Source

pub fn peer(&self) -> &str

Source

pub fn mtu(&self) -> u16

The negotiated ATT MTU. A write carries mtu - 3 bytes.

Source

pub fn is_connected(&self) -> bool

Source

pub fn close(&self)

Source

pub fn discover_services(&self) -> Result<Vec<Service>, Error>

Every primary service on the peer.

Repeats Read By Group Type from where the last reply stopped until the peer answers ATTRIBUTE_NOT_FOUND, which is how it says “no more”.

Source

pub fn discover_included_services( &self, service: &Service, ) -> Result<Vec<Service>, Error>

Every characteristic within a service’s handle range. The services this one includes.

An Include declaration whose included service has a 128-bit UUID does not carry it, so the UUID is read from the included service’s own declaration — otherwise the caller would have a handle range it cannot name.

Source

pub fn discover_characteristics( &self, service: &Service, ) -> Result<Vec<Characteristic>, Error>

Source

pub fn discover_descriptors( &self, start: u16, end: u16, ) -> Result<Vec<Descriptor>, Error>

The descriptors of one characteristic — everything between its value handle and the next characteristic (or the end of the service).

Source

pub fn read(&self, handle: u16) -> Result<Vec<u8>, Error>

Read an attribute, following on with Read Blob if the value filled the MTU — which is the only signal that there is more of it.

Source

pub fn write(&self, handle: u16, value: &[u8]) -> Result<(), Error>

Write and wait for the peer to acknowledge.

Source

pub fn write_command(&self, handle: u16, value: &[u8]) -> Result<(), Error>

Write without acknowledgement. Nothing comes back, so nothing is waited for and a dropped write is invisible.

Source

pub fn set_notify( &self, cccd_handle: u16, notify: bool, indicate: bool, ) -> Result<(), Error>

Subscribe by writing the Client Characteristic Configuration descriptor.

There is no “subscribe” in ATT — 0x0001 asks for notifications, 0x0002 for indications, 0x0000 stops both.

Trait Implementations§

Source§

impl Drop for Connection

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.