Comments (5)
Can we change the Resolver trait to use https://docs.rs/async_trait?
from domain.
I’m wondering if Resolver::Query
should perhaps be Send
? I am also running into a situation where it seems to me a Send
future there would make the trait more generally usable?
For example, here is another program that would compile if Resolver::Query
were Send
:
use async_trait::async_trait;
use domain::resolv::StubResolver;
use std::net::IpAddr;
#[async_trait]
trait Lookup {
async fn lookup_ptrs(&self, ip: IpAddr) -> Vec<String>;
}
struct Resolver {
delegate: StubResolver,
}
#[async_trait]
impl Lookup for Resolver {
async fn lookup_ptrs(&self, ip: IpAddr) -> Vec<String> {
self.delegate
.lookup_addr(ip)
.await
.unwrap()
.into_iter()
.map(|p| p.to_string())
.collect()
}
}
#[tokio::main]
async fn main() {
let resolver = Resolver {
delegate: StubResolver::new(),
};
let addrs = resolver.lookup_ptrs(IpAddr::from([8, 8, 8, 8])).await;
println!("{:?}", addrs);
}
from domain.
Apologies for the ridiculously late answer!
Requiring Resolver::Query
to be Send + 'static
is a good idea, indeed. It should be easy to achieve this for stub::Query
by placing the data of a StubResolver
behind an arc and keep that in Query
.
I’ll draft a PR for it and see if it really is all that simple.
from domain.
Can we change the Resolver trait to use https://docs.rs/async_trait?
The trait is already what I imagine async trait would turn it into. Resolver::query
is basically an async function in anything but the name. It returns a future which you can await
.
from domain.
Turns out that resolv::stub::Query
is already Send
, so requiring the trait in Resolver::Query
is enough.
However, I now wonder if it might be worthwhile to turn this whole concept on its head by making the lookups implement a trait and ditch the Resolver
trait. I think the lookups can be made in such a way that they don’t need to be aware of how the underlying querying mechanism works and whether it is synchronous or asynchronous atop Tokio or async-std or something else entirely.
from domain.
Related Issues (20)
- Change `qr` bit HOT 3
- domain::zonefile::inplace::Zonefile adds two extra bytes to the public key of a DNSKEY record HOT 2
- Rename variants of `base::name::FromStrError`.
- `FoundSrvs::into_srvs` missing from v0.8.0
- function dname_from_addr HOT 3
- Difference between domain::base::name::Dname and domain::rdata::dname::Dname? HOT 2
- Make it easier to manipulate messages. HOT 4
- Ns record extraction HOT 2
- The TXT record concatenates and outputs all character strings HOT 4
- Reject empty TXT record data.
- Update the README
- Mistake in Dname::from_slice doc example HOT 1
- Stable/core RRSet type HOT 6
- serde_json round-trip of TXT record fails with spaces HOT 2
- ZoneRecordData should include CAA records HOT 1
- Change IANA types from an enum into a struct wrapping an integer.
- Switch `ToDname` et al. to have a `try_to_dname`/`to_dname` pair.
- idns: report redundant statistics
- Using pre-release version HOT 4
- Latest version of domain 0.10.0 is not compatible with triomphe v0.1.12 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from domain.