Skip to main content

Advertising

Struct Advertising 

Source
pub struct Advertising {
    pub local_name: Option<String>,
    pub services: Vec<BluetoothUuid>,
    pub interval: Option<(Duration, Duration)>,
}
Expand description

What to put in the advertisement.

Apple honours only a local name and a service UUID list in the peripheral role — no manufacturer data, no service data. The packet holds 28 bytes for everything; service UUIDs that do not fit go to the overflow area, where only an Apple device scanning for them explicitly will see them.

Fields§

§local_name: Option<String>

The name to advertise, if any.

§services: Vec<BluetoothUuid>

Service UUIDs to advertise, which is what a central filters on.

§interval: Option<(Duration, Duration)>

The preferred range between advertising events; None leaves it to the platform. See Advertising::interval.

Implementations§

Source§

impl Advertising

Source

pub fn new() -> Self

Advertise nothing in particular. Add a name or a service.

Source

pub fn local_name(self, name: impl Into<String>) -> Self

The name centrals will show.

Source

pub fn service(self, uuid: impl IntoUuid) -> Result<Self>

Advertise a service UUID, so centrals filtering for it find this device.

Source

pub fn interval(self, min: Duration, max: Duration) -> Result<Self>

Prefer advertising every min to max: shorter is found sooner, at the cost of power and airtime. Each scan window a central opens only catches the events that fall inside it, so at BlueZ’s default of about 1.28 s a scanner — especially one next to a radio shared with Wi-Fi, which drops some events — can miss a device for several windows in a row.

A preference, honoured where the platform exposes one:

  • Linux: BlueZ’s MinInterval / MaxInterval, applied as given by BlueZ 5.82 (checked with btmon). Older releases treated them as experimental and ignore them unless bluetoothd runs with Experimental = true in /etc/bluetooth/main.conf (or -E). The system-wide default is [LE] MinAdvertisementInterval / MaxAdvertisementInterval in the same file.
  • Android: the closest AdvertiseSettings mode — low latency (~100 ms) up to 175 ms, balanced (~250 ms) up to 500 ms, low power (~1 s) beyond. Without a preference Android uses low latency.
  • Apple and Windows expose no interval; CoreBluetooth advertises quickly while the app is in the foreground.

Fails if either bound is outside 20 ms–10.24 s or min > max.

Trait Implementations§

Source§

impl Clone for Advertising

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 Advertising

Source§

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

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

impl Default for Advertising

Source§

fn default() -> Self

Returns the “default value” for a type. 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.