`characteristics()` and `services()` of `Peripheral` returning a `HashMap` instead of a `BTreeSet`
hansmbakker opened this issue · comments
Feature Description
Would it be possible to have characteristics()
and services()
of Peripheral
return a HashMap
instead of a BTreeSet
?
That way, looping over the characteristics or calling iter().find()
to find the characteristic you need is not needed anymore as below:
Lines 63 to 66 in 76fd795
Instead you could do something like
let cmd_char = light.characteristics()[&LIGHT_CHARACTERISTIC_UUID];
One thing to consider here is that bluetooth le peripherals may advertise multiple instances of a service or characteristic with the same Uuid (differentiated by their underlying AT handle) which couldn't be supported by btleplug if they were only exposed via a HashMap
, indexed by uuid.
Their on-device order may also be significant, which would be lost with a HashMap
.
let cmd_char = light.characteristics()[&LIGHT_CHARACTERISTIC_UUID];
If it is just about API ergonomics, then a new type around the returned BTreeSet
plus an imlementation of Index
would also allow this API.