Comments (3)
I had a go at coming up with the simplest possible example. I wanted to write something like this:
fn main() {
// Perform a query, getting the result as a future.
let mut resolver = SomeResolverObject::new(); // Probably passing in some c_ares::Options
let future_results = resolver.a_query_as_future("apple.com");
// Do some other stuff here while we wait
// ...
// Now we need the resolved adress, so block on it.
print_a_results(future_results.into_inner());
}
Then I realised Future
s aren't possible in the current Rust, so had the query_as_future
return a function instead, which blocks for the result.
Anyway, long story short, I don't think the current API makes this very easy - I think you still need to faff around with file process_fd
, ares_timeout
etc. to get any callbacks from c-ares. I've not got that far yet, but do you agree that it's desirable to have the API abstract away more of the c-ares grunge, or does this go contrary to your intentions?
WIP example at CJTozer/rust-c-ares@8dc4474 in case you're interested...
from rust-c-ares.
I wouldn't want to remove the current API, but I'd be very happy to have a way of using the library without doing so much work.
Suggest: work on something in examples
for now - as you are doing - and if and when you get something that looks nice we'll work out whether we just leave it there, or incorporate something into the API on this crate, or release the nice wrapper as its own crate, or what.
Possibly useful things to look at:
- mioco is built on mio and "allows handling asynchronous and scalable IO inside coroutines, simplifying the handling logic". I've only looked at this briefly and so far completely failed to understand, but the description sounds like something useful.
- eventual comes from the same guy as mio; looks like it provides futures if that's what you want
from rust-c-ares.
Closing.
I might yet write more examples at some point, and I'd surely accept pull requests containing nice examples. But I've nothing currently planned, and the existing examples give pretty good coverage of how I imagine the API being used.
from rust-c-ares.
Related Issues (20)
- Expose hostname in A/AAAA results HOT 2
- Use Box::from_raw and boxed::into_raw HOT 1
- use Unique pointers?! HOT 2
- Remove feature "old-cares" HOT 1
- Retire our implementation of IpAddr HOT 2
- Retire ipv4_as_in_addr, socket_addrv4_as_sockaddr_in etc HOT 4
- Make the README more encouraging HOT 2
- Tidy up docs comments for bitflags
- Consider bundling a c-ares with c-ares-sys HOT 1
- Use Result expect()
- Relicense under dual MIT/Apache-2.0
- Fails to build using MSVC 2015: Unknown value for _NMAKE_VER macro: 14.00.23918.0 HOT 2
- Remove boxing from futures example HOT 2
- Support cross compiling HOT 13
- panic index 34 out of range for slice of length 32 HOT 2
- Unable to resolve api.apaylater.com HOT 2
- Export headers HOT 3
- Revert to 2018 edition HOT 4
- Timeouts cause hang waiting for response HOT 4
- Windows support HOT 1
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 rust-c-ares.