Learn how to use Rust to build ATProto powered applications
1use atrium_identity::handle::DnsTxtResolver;
2use hickory_resolver::TokioAsyncResolver;
3
4/// Setup for dns resolver for the handle resolver
5pub struct HickoryDnsTxtResolver {
6 resolver: hickory_resolver::TokioAsyncResolver,
7}
8
9impl Default for HickoryDnsTxtResolver {
10 fn default() -> Self {
11 Self {
12 resolver: TokioAsyncResolver::tokio_from_system_conf()
13 .expect("failed to create resolver"),
14 }
15 }
16}
17
18impl DnsTxtResolver for HickoryDnsTxtResolver {
19 async fn resolve(
20 &self,
21 query: &str,
22 ) -> core::result::Result<Vec<String>, Box<dyn std::error::Error + Send + Sync + 'static>> {
23 println!("Resolving TXT for: {}", query);
24 Ok(self
25 .resolver
26 .txt_lookup(query)
27 .await?
28 .iter()
29 .map(|txt| txt.to_string())
30 .collect())
31 }
32}