RegValueMonitor

Struct RegValueMonitor 

Source
pub struct RegValueMonitor<T: Copy> { /* private fields */ }
Expand description

Note that, on changes in very quick succession, reading a registry value after receiving a change event for it may yield newer data than from the write that triggered the event.

Implementations§

Source§

impl<T: Copy> RegValueMonitor<T>

Source

pub fn new<'a, I>(reg_value_paths: I) -> Result<Self, WMIError>
where I: IntoIterator<Item = (T, &'a RegValuePath<'a>)>,

Source

pub async fn next_change(&mut self) -> Option<Result<T, WMIError>>

Source

pub fn loop<F, U, E>( &mut self, stop_receiver: Option<Receiver<U>>, callback: F, ) -> Result<U, MonitorLoopError<E>>
where F: FnMut(T) -> Option<Result<U, E>>, U: Default,

Send a signal to the stop_receiver or return Some(...) from the callback to stop the loop.

§Examples
fn main() {
    let (stop_sender, stop_receiver) = oneshot::channel();

    let join_handle = thread::spawn(move || {
        let mut monitor = RegValueMonitor::new([
            (NightLightRegValueId::State, &NIGHT_LIGHT_STATE_REG_VALUE_PATH),
            (NightLightRegValueId::Settings, &NIGHT_LIGHT_SETTINGS_REG_VALUE_PATH),
        ])
        .unwrap();

        monitor.r#loop(Some(stop_receiver), |changed_value_id| {
            println!("{:?}", changed_value_id);
            None
        })
        .unwrap();
    });

    thread::sleep(Duration::from_secs(10));
    stop_sender.send(()).unwrap();
    join_handle.join().unwrap();
}

#[derive(Clone, Copy, Debug)]
enum NightLightRegValueId {
    State,
    Settings,
}

Auto Trait Implementations§

§

impl<T> Freeze for RegValueMonitor<T>

§

impl<T> !RefUnwindSafe for RegValueMonitor<T>

§

impl<T> !Send for RegValueMonitor<T>

§

impl<T> !Sync for RegValueMonitor<T>

§

impl<T> Unpin for RegValueMonitor<T>
where T: Unpin,

§

impl<T> !UnwindSafe for RegValueMonitor<T>

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

Source§

fn map_self<O, T>(self, op: O) -> T
where O: FnOnce(Self) -> T, Self: Sized,

Example: Read more
Source§

fn map_self_or_keep<O>(self, op: O) -> Self
where O: FnOnce(&Self) -> Option<Self>, Self: Sized,

Example: Read more
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.