Git Product home page Git Product logo

Comments (3)

CJTozer avatar CJTozer commented on June 14, 2024

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 Futures 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.

dimbleby avatar dimbleby commented on June 14, 2024

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.

dimbleby avatar dimbleby commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.