use futures::StreamExt as _;
extern crate erbium;
use erbium::lldp;
enum Error {
ConfigError(std::path::PathBuf, erbium::config::Error),
ServiceError(String),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
Error::ConfigError(ref path, ref e) => write!(
f,
"Failed to load config from {}: {}",
path.to_string_lossy(),
e
),
Error::ServiceError(ref e) => write!(f, "{}", e),
}
}
}
async fn go() -> Result<(), Error> {
let mut services = futures::stream::FuturesUnordered::new();
let lldp = std::sync::Arc::new(
lldp::LldpService::new().unwrap(), );
services.push(tokio::spawn(async move { lldp.run().await }));
while let Some(x) = services.next().await {
println!("Service complete: {:?}", x)
}
Ok(())
}
#[tokio::main]
async fn main() {
match go().await {
Ok(()) => (),
Err(x) => {
println!("Error: {}", x);
std::process::exit(1);
}
}
}