agnostic_mdns/
worksteal.rs

1use mdns_proto::proto::{Label, ResourceRecord, ResourceType};
2
3pub use agnostic_net as net;
4pub use async_channel as channel;
5pub use client::*;
6pub use server::*;
7
8mod client;
9mod server;
10
11#[cfg(test)]
12mod tests;
13
14/// The interface used to integrate with the server and
15/// to serve records dynamically
16pub trait Zone: core::fmt::Debug + Send + Sync + 'static {
17  /// The error type of the zone
18  type Error: core::error::Error + Send + Sync + 'static;
19
20  /// Returns the answers for a DNS question.
21  fn answers<'a>(
22    &'a self,
23    name: Label<'a>,
24    rt: ResourceType,
25  ) -> impl Future<Output = Result<impl Iterator<Item = ResourceRecord<'a>> + 'a, Self::Error>> + Send + 'a;
26
27  /// Returns the additional records for a DNS question.
28  fn additionals<'a>(
29    &'a self,
30    name: Label<'a>,
31    rt: ResourceType,
32  ) -> impl Future<Output = Result<impl Iterator<Item = ResourceRecord<'a>> + 'a, Self::Error>> + Send + 'a;
33}
34
35impl Zone for super::service::Service {
36  type Error = core::convert::Infallible;
37
38  async fn answers<'a>(
39    &'a self,
40    name: Label<'a>,
41    rt: ResourceType,
42  ) -> Result<impl Iterator<Item = ResourceRecord<'a>> + 'a, Self::Error> {
43    Ok(self.fetch_answers(name, rt))
44  }
45
46  async fn additionals<'a>(
47    &'a self,
48    _: Label<'a>,
49    _: ResourceType,
50  ) -> Result<impl Iterator<Item = ResourceRecord<'a>> + 'a, Self::Error> {
51    Ok(core::iter::empty())
52  }
53}