use std::future::{IntoFuture, Ready};
use zenoh_config::wrappers::ZenohId;
use zenoh_core::{Resolvable, Wait};
use zenoh_protocol::core::WhatAmI;
use crate::net::runtime::DynamicRuntime;
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct ZenohIdBuilder<'a> {
runtime: &'a DynamicRuntime,
}
impl<'a> ZenohIdBuilder<'a> {
pub(crate) fn new(runtime: &'a DynamicRuntime) -> Self {
Self { runtime }
}
}
impl Resolvable for ZenohIdBuilder<'_> {
type To = ZenohId;
}
impl Wait for ZenohIdBuilder<'_> {
fn wait(self) -> Self::To {
self.runtime.zid()
}
}
impl IntoFuture for ZenohIdBuilder<'_> {
type Output = <Self as Resolvable>::To;
type IntoFuture = Ready<<Self as Resolvable>::To>;
fn into_future(self) -> Self::IntoFuture {
std::future::ready(self.wait())
}
}
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct RoutersZenohIdBuilder<'a> {
runtime: &'a DynamicRuntime,
}
impl<'a> RoutersZenohIdBuilder<'a> {
pub(crate) fn new(runtime: &'a DynamicRuntime) -> Self {
Self { runtime }
}
}
impl Resolvable for RoutersZenohIdBuilder<'_> {
type To = Box<dyn Iterator<Item = ZenohId> + Send + Sync>;
}
impl Wait for RoutersZenohIdBuilder<'_> {
fn wait(self) -> Self::To {
self.runtime.get_zids(WhatAmI::Router)
}
}
impl IntoFuture for RoutersZenohIdBuilder<'_> {
type Output = <Self as Resolvable>::To;
type IntoFuture = Ready<<Self as Resolvable>::To>;
fn into_future(self) -> Self::IntoFuture {
std::future::ready(self.wait())
}
}
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct PeersZenohIdBuilder<'a> {
runtime: &'a DynamicRuntime,
}
impl<'a> PeersZenohIdBuilder<'a> {
pub(crate) fn new(runtime: &'a DynamicRuntime) -> Self {
Self { runtime }
}
}
impl Resolvable for PeersZenohIdBuilder<'_> {
type To = Box<dyn Iterator<Item = ZenohId> + Send + Sync>;
}
impl Wait for PeersZenohIdBuilder<'_> {
fn wait(self) -> <Self as Resolvable>::To {
self.runtime.get_zids(WhatAmI::Peer)
}
}
impl IntoFuture for PeersZenohIdBuilder<'_> {
type Output = <Self as Resolvable>::To;
type IntoFuture = Ready<<Self as Resolvable>::To>;
fn into_future(self) -> Self::IntoFuture {
std::future::ready(self.wait())
}
}