pub struct Bindings<const N: usize> { /* private fields */ }Expand description
Shared registry of Binding entries across every endpoint and
fabric. Persisted as a single TLV blob under BINDINGS_KEY.
N bounds the total number of entries the device can hold. Per
Matter Core spec, device-type definitions may prescribe a
minimum-per-fabric; the spec also says the total must be
min_per_fabric × supported_fabrics — pick N accordingly.
Implementations§
Source§impl<const N: usize> Bindings<N>
impl<const N: usize> Bindings<N>
Sourcepub const fn new() -> Bindings<N>
pub const fn new() -> Bindings<N>
Create an empty registry. Prefer Self::init for non-trivial
N so the storage is initialised in BSS.
Sourcepub async fn load_persist<S>(
&self,
store: S,
buf: &mut [u8],
) -> Result<(), Error>where
S: KvBlobStore,
pub async fn load_persist<S>(
&self,
store: S,
buf: &mut [u8],
) -> Result<(), Error>where
S: KvBlobStore,
Re-hydrate the registry from store under BINDINGS_KEY.
Call once at startup, before exposing the data model.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
The total number of Binding entries in the registry, across all
local endpoints and fabrics. See Bindings::get.
Sourcepub fn get(&self, index: usize) -> Option<Binding>
pub fn get(&self, index: usize) -> Option<Binding>
The index-th Binding in the registry (across all endpoints and
fabrics), cloned out so the registry lock is not held by the caller, or
None if index is out of range.
This flat, index-based accessor lets application code iterate the bindings
and perform async work (e.g. a remote invoke) per entry without holding
the lock across the await. Each Binding carries its local_endpoint
and fab_idx, so the caller filters on those itself:
for i in 0..bindings.len() {
let Some(b) = bindings.get(i) else { break };
if b.local_endpoint != MY_ENDPOINT { continue; }
if let (Some(node), Some(ep)) = (b.node, b.endpoint) {
// lock already released here - safe to await
let exchange = Exchange::initiate(matter, &crypto, b.fab_idx, node).await?;
exchange.on_off().toggle(ep).await?;
}
}Trait Implementations§
Auto Trait Implementations§
impl<const N: usize> !Freeze for Bindings<N>
impl<const N: usize> !RefUnwindSafe for Bindings<N>
impl<const N: usize> !Sync for Bindings<N>
impl<const N: usize> Send for Bindings<N>
impl<const N: usize> Unpin for Bindings<N>
impl<const N: usize> UnsafeUnpin for Bindings<N>
impl<const N: usize> UnwindSafe for Bindings<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more