use std::{error::Error, fmt, future::Future, net::IpAddr, pin::Pin};
use super::RawEvent;
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TransportError(String);
impl TransportError {
pub fn new(message: impl Into<String>) -> Self {
Self(message.into())
}
}
impl fmt::Display for TransportError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl Error for TransportError {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AdvertisementUpdate {
pub port: u16,
pub addrs: Vec<IpAddr>,
pub txt: Vec<(String, String)>,
}
pub trait AdvertisementHandle: Send + Sync + 'static {
fn update(&self, update: AdvertisementUpdate) -> BoxFuture<'_, Result<(), TransportError>>;
fn request_close(&self);
fn closed(&self) -> BoxFuture<'_, Result<(), TransportError>>;
}
pub trait BrowseHandle: Send + Sync + 'static {
fn next(&self) -> BoxFuture<'_, Result<Option<RawEvent>, TransportError>>;
fn request_close(&self);
fn closed(&self) -> BoxFuture<'_, Result<(), TransportError>>;
}