NLnetLabs / domain

A DNS library for Rust.
https://nlnetlabs.nl/projects/domain/about/
BSD 3-Clause "New" or "Revised" License
341 stars 57 forks source link

Proposal for adding `run()` and `query()` style helper interfaces. #283

Closed ximon18 closed 5 months ago

ximon18 commented 6 months ago

This PR explores the idea of extending the transport interfaces, where applicable, with run() and query() style interfaces.

run simplifies usage in the most common case by spawning transport::run() onto a new Tokio task, as new() returns both a transport and a connection and the caller is responsible for spawning transport::run() onto a new tokio task, or running it and awaiting it while passing the connection or a clone of it to another task/thread. When using run() one cannot await the join handle of the spawned task, but there isn't anything one can usefully do with the join handle anyway.

query simplifies usage in the one-shot case, which is unsuitable for sending many queries but maybe useful in demonstration, test or simple client scenarios.

examples/client-transport.rs is extended to show the new interfaces, but in particular if we like run() we might want to simplify the example to use it everywhere and leave new() for advanced scenarios.