pub struct HybridMonitor<F, L, C = SystemClock> { /* private fields */ }Expand description
Hybrid IP address monitor combining API events with polling fallback.
The hybrid monitor uses platform API events (e.g., NotifyIpInterfaceChange)
for immediate notification of IP changes, with periodic polling as a safety net.
§Degradation Behavior
If the API listener fails (returns an error), the monitor automatically degrades to polling-only mode. This degradation is permanent for the lifetime of the stream - no automatic recovery is attempted.
§Type Parameters
F- TheAddressFetcherimplementation for retrieving adapter snapshotsL- TheApiListenerimplementation for platform event notificationsC- TheClockimplementation for timestamps (defaults toSystemClock)
§Example
use ddns_a::monitor::{HybridMonitor, DebouncePolicy};
use ddns_a::monitor::platform::PlatformListener;
use std::time::Duration;
let fetcher = MyFetcher::new();
let listener = PlatformListener::new()?;
let monitor = HybridMonitor::new(fetcher, listener, Duration::from_secs(60))
.with_debounce(DebouncePolicy::default());
let mut stream = monitor.into_stream();
while let Some(changes) = stream.next().await {
for change in changes {
println!("{:?}", change);
}
}Implementations§
Source§impl<F, L> HybridMonitor<F, L, SystemClock>where
F: AddressFetcher,
L: ApiListener,
impl<F, L> HybridMonitor<F, L, SystemClock>where
F: AddressFetcher,
L: ApiListener,
Sourcepub const fn new(fetcher: F, api_listener: L, poll_interval: Duration) -> Self
pub const fn new(fetcher: F, api_listener: L, poll_interval: Duration) -> Self
Creates a new hybrid monitor with system clock.
§Arguments
fetcher- The address fetcher to use for pollingapi_listener- The platform API listener for event notificationspoll_interval- The interval between polls (safety net for missed events)
Source§impl<F, L, C> HybridMonitor<F, L, C>
impl<F, L, C> HybridMonitor<F, L, C>
Sourcepub const fn with_clock(
fetcher: F,
api_listener: L,
clock: C,
poll_interval: Duration,
) -> Self
pub const fn with_clock( fetcher: F, api_listener: L, clock: C, poll_interval: Duration, ) -> Self
Creates a new hybrid monitor with a custom clock.
This constructor allows injecting a mock clock for testing.
§Arguments
fetcher- The address fetcher to use for pollingapi_listener- The platform API listener for event notificationsclock- The clock to use for timestampspoll_interval- The interval between polls
Sourcepub const fn with_debounce(self, policy: DebouncePolicy) -> Self
pub const fn with_debounce(self, policy: DebouncePolicy) -> Self
Configures debounce policy for this monitor.
When debounce is enabled, rapid consecutive changes within the debounce window are merged, with cancelling changes (add then remove of the same IP) being eliminated.
Note: The debounce window is fixed-duration from the first change; subsequent changes within the window do not extend the timer.
§Arguments
policy- The debounce policy to apply
Sourcepub const fn poll_interval(&self) -> Duration
pub const fn poll_interval(&self) -> Duration
Returns the configured polling interval.
Sourcepub const fn debounce(&self) -> Option<&DebouncePolicy>
pub const fn debounce(&self) -> Option<&DebouncePolicy>
Returns the configured debounce policy, if any.
Sourcepub fn into_stream(self) -> HybridStream<F, L::Stream, C>
pub fn into_stream(self) -> HybridStream<F, L::Stream, C>
Converts this monitor into a stream of IP changes.
The returned stream will:
- React to API events for immediate change detection
- Poll at the configured interval as a safety net
- Yield batches of
crate::monitor::IpChangeevents whenever addresses change
If the API listener fails, the stream automatically degrades to polling-only mode without terminating.
The stream never terminates on its own; use take_until with
a shutdown signal to stop it gracefully.