Skip to main content

Characteristic

Struct Characteristic 

Source
pub struct Characteristic {
    pub uuid: BluetoothUuid,
    pub properties: u32,
    pub permissions: u32,
    pub value: Option<Vec<u8>>,
    pub descriptors: Vec<Descriptor>,
}
Expand description

A characteristic to publish.

Fields§

§uuid: BluetoothUuid

Which characteristic this is.

§properties: u32

crate::CharacteristicProperties bits: what a central may do.

§permissions: u32

Permissions bits: what a central must have done to be allowed to.

§value: Option<Vec<u8>>

A fixed value, answered by the stack without waking the application.

CoreBluetooth requires a characteristic with one to be read-only, because a cached value can never change; the other platforms do not, and the check is applied where Apple publishes.

§descriptors: Vec<Descriptor>

Descriptors published alongside it.

Implementations§

Source§

impl Characteristic

Source

pub fn new(uuid: impl IntoUuid) -> Result<Self>

Begin defining a characteristic. It has no properties until you add some.

Source

pub fn read(self) -> Self

Allow reads. Answered by Request::Read unless a fixed Characteristic::value is set.

Source

pub fn write(self) -> Self

Allow acknowledged writes.

Source

pub fn write_without_response(self) -> Self

Allow unacknowledged writes.

Source

pub fn notify(self) -> Self

Allow subscription. CoreBluetooth adds the Client Characteristic Configuration descriptor for you.

Source

pub fn indicate(self) -> Self

Allow acknowledged subscription.

Source

pub fn require_encryption(self) -> Self

Require an encrypted link for reads and writes.

Source

pub fn value(self, value: impl Into<Vec<u8>>) -> Self

Serve a fixed value from CoreBluetooth’s cache, with no read requests reaching your code.

Forces read-only: Peripheral::publish rejects a characteristic that combines a fixed value with write, notify or indicate, because CoreBluetooth raises on that.

Source

pub fn descriptor(self, descriptor: Descriptor) -> Self

Attach a descriptor. Publish a descriptor alongside this characteristic.

Source

pub fn validate(&self) -> Result<()>

The rules every platform enforces on a characteristic, and on the descriptors under it. A platform may add its own where it publishes.

Trait Implementations§

Source§

impl Clone for Characteristic

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Characteristic

Source§

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

Formats the value using the given formatter. 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> 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 = !

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.