pub struct ObserversHolder { /* private fields */ }Expand description
Optional convenience mechanism to aid in managing dynamic Observers instances.
Intended to be used as:
use coap_server::app::{ObservableResource, Observers, ObserversHolder};
struct MyResource {
holder: ObserversHolder
}
#[async_trait::async_trait]
impl ObservableResource for MyResource {
async fn on_active(&self, observers: Observers) -> Observers {
let attached = self.holder.attach(observers).await;
attached.stay_active().await;
attached.detach().await
}
}Implementations§
Source§impl ObserversHolder
impl ObserversHolder
pub fn new() -> Self
Sourcepub async fn attach(&self, observers: Observers) -> Attached<'_>
pub async fn attach(&self, observers: Observers) -> Attached<'_>
Attach a new Observers instance which affects how [notify_change] behaves.
Sourcepub async fn notify_change(&self)
pub async fn notify_change(&self)
Defers to Observers::notify_change when attached; does nothing otherwise.
Sourcepub async fn notify_change_for_path(&self, relative_path: &str)
pub async fn notify_change_for_path(&self, relative_path: &str)
Special variation of [notify_change] that indicates only observe requests grouped
under the provided path should be notified of the change. This optimization can help a lot
when you are observing dynamic resources (i.e. /resources/{resource_name}/) with a very
large number of updates across different resources.
The provided relative_path is used for fuzzy matching of any “relevant” observing path. For
example, if relative_path is "resources/abc" then it will match against observe requests for
"resources/abc/some_property", "resources/abc", or even "resources". It would not
match observe requests for "/resources/xyz".
relative_path is relative to the resource path that the crate::app::ObservableResource
was installed at.
Trait Implementations§
Source§impl Clone for ObserversHolder
impl Clone for ObserversHolder
Source§fn clone(&self) -> ObserversHolder
fn clone(&self) -> ObserversHolder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more