Skip to main content

SourceWatch

Struct SourceWatch 

Source
pub struct SourceWatch<'finder> { /* private fields */ }
Expand description

One consumer’s cursor over a finder’s source-list changes.

Take snapshots and wait through the same watch, so reports published by concurrent lookups between those operations cannot be missed. A report during a snapshot remains visible to the next wait. Each consumer must create its own watch; a watch can move between threads but is not Sync.

let mut watch = finder.watch();
println!("{:?}", watch.current_sources()?);
while watch.wait_for_change(Duration::from_secs(5))? {
    println!("{:?}", watch.current_sources()?);
}

Implementations§

Source§

impl SourceWatch<'_>

Source

pub fn current_sources(&mut self) -> Result<Vec<Source>>

Copy the currently known sources and record the generation before copying, preserving any report that arrives during the snapshot. A failed snapshot leaves the cursor unchanged.

§Errors

Returns the snapshot errors of Finder::current_sources: Error::UnexpectedSdkResult for a malformed top-level descriptor array, Error::AllocationFailed for failed result or text reservations, or Error::ResourceLimit when a snapshot exceeds its copy budgets.

Source

pub fn wait_for_change(&mut self, timeout: Duration) -> Result<bool>

Wait for a report newer than this consumer’s last snapshot or wait.

Returns true immediately if another lookup already published a report. A zero timeout reads such reports even while another native waiter is active; otherwise it makes one nonblocking native query. Returns false when the timeout expires without a report.

§Errors

Returns Error::InvalidInput if timeout exceeds crate::MAX_TIMEOUT.

Trait Implementations§

Source§

impl Debug for SourceWatch<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'finder> !Freeze for SourceWatch<'finder>

§

impl<'finder> !RefUnwindSafe for SourceWatch<'finder>

§

impl<'finder> !Sync for SourceWatch<'finder>

§

impl<'finder> Send for SourceWatch<'finder>

§

impl<'finder> Unpin for SourceWatch<'finder>

§

impl<'finder> UnsafeUnpin for SourceWatch<'finder>

§

impl<'finder> UnwindSafe for SourceWatch<'finder>

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, 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, 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.