Skip to main content

WatchHandle

Struct WatchHandle 

Source
pub struct WatchHandle<P> { /* private fields */ }
Expand description

RAII handle returned by watch(). Holds a subscription lease and reads the property live from the state store. Dropping the handle starts the grace period — the UPnP subscription persists for 50ms so it can be reacquired cheaply on the next frame.

Not Clone — each handle is one subscription hold.

§The value is live, not a snapshot

Self::value reads the store on every call, so a handle acquired once and held across many events keeps returning the current value. There is no need to re-watch() to refresh it; a handle is a lease on the subscription, and reading through it is the same read get() performs.

The value is therefore returned by clone rather than by reference: the store sits behind an RwLock shared with the event worker, and handing out a borrow into it would either hold that lock for the handle’s whole lifetime or alias a value the worker is free to replace. P is a small Clone property (a u8, a bool, a few Strings at worst), so the copy is cheaper than the lock it would otherwise pin.

§Example

// Watch returns a handle — hold it to keep the subscription alive
let volume = speaker.volume.watch()?;

if let Some(v) = volume.value() {
    println!("Volume: {}%", v.value());
}

// Hold the same handle across events — value() re-reads each time
for _event in system.iter() {
    println!("Volume now: {:?}", volume.value());
}

// Dropping the handle starts the 50ms grace period
drop(volume);

Implementations§

Source§

impl<P> WatchHandle<P>

Source

pub fn mode(&self) -> WatchMode

Returns the watch mode (Events, Polling, or CacheOnly).

Source

pub fn value(&self) -> Option<P>

Returns the property’s current value, read live from the state store.

Costs one read-lock acquisition plus a clone of P — not free, unlike the frozen field this replaced, but it is the same cost as get() and it is what makes the handle a live view instead of a stale snapshot.

Returns None if no value has been observed yet, or if the value has since become unreachable (a speaker that left the topology, or a PerCoordinator property whose group was dissolved).

Source

pub fn has_value(&self) -> bool

Returns true if a value is currently available from the store.

Also a live read: this can go from false to true as the first event arrives, without the handle being re-acquired.

Source

pub fn has_realtime_events(&self) -> bool

Returns true if real-time UPnP events are active.

Trait Implementations§

Source§

impl<P: Debug> Debug for WatchHandle<P>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<P> !RefUnwindSafe for WatchHandle<P>

§

impl<P> !UnwindSafe for WatchHandle<P>

§

impl<P> Freeze for WatchHandle<P>

§

impl<P> Send for WatchHandle<P>

§

impl<P> Sync for WatchHandle<P>

§

impl<P> Unpin for WatchHandle<P>

§

impl<P> UnsafeUnpin for WatchHandle<P>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more