Skip to main content

day_part_zeroconf/
day_part_zeroconf.rs

1use day_part_zeroconf::{BrowseOptions, Event, browse};
2use std::time::{Duration, Instant};
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let kind = std::env::args().nth(1);
5    let options = kind.map_or_else(BrowseOptions::all, BrowseOptions::service);
6    let mut browser = browse(options)?;
7    let until = Instant::now() + Duration::from_secs(10);
8    while Instant::now() < until {
9        if let Some(e) = browser.recv_timeout(Duration::from_millis(250)) {
10            println!("{e:?}");
11            if matches!(e, Event::Error(_)) {
12                break;
13            }
14        }
15    }
16    browser.stop();
17    Ok(())
18}