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>
impl<T: Copy> RegValueMonitor<T>
pub fn new<'a, I>(reg_value_paths: I) -> Result<Self, WMIError>where
I: IntoIterator<Item = (T, &'a RegValuePath<'a>)>,
pub async fn next_change(&mut self) -> Option<Result<T, WMIError>>
Sourcepub fn loop<F, U, E>(
&mut self,
stop_receiver: Option<Receiver<U>>,
callback: F,
) -> Result<U, MonitorLoopError<E>>
pub fn loop<F, U, E>( &mut self, stop_receiver: Option<Receiver<U>>, callback: F, ) -> Result<U, MonitorLoopError<E>>
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> 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
Mutably borrows from an owned value. Read more