Comments (2)
Heya @aWeinzierl,
I'm about to release a new version that improves error messages but the way to know what went wrong will be the same. Essentially a resolver/group of resolvers returns a resolution stream. When resolving a single address, any error a resolver returns is ignored and it attempts the next resolver. If you want to see what's going wrong then you'll need to pickup each error that happens from the stream. Enough text, now for an example:
use futures_util::{future, StreamExt, TryStreamExt};
use public_ip::{dns, http, Version};
#[tokio::main]
async fn main() {
// List of resolvers to try and get an IP address from.
let resolver = &[
http::HTTP_WHATISMYIPADDRESS_COM_RESOLVER,
dns::GOOGLE_DNS_TXT_RESOLVER,
];
let addr = public_ip::resolve(resolver, Version::Any)
// For each error in the stream we print it out to STDERR (console).
.inspect_err(|err| eprintln!("resolver error: {}", err))
// We filter out the errors and leave just the resolved addresses in the stream.
.filter_map(|result| future::ready(result.ok()))
// We get the first resolved address in the stream.
.next()
// Wait for the future to finish.
.await
// We remove the details of the resolution if we don't care about them.
.map(|(addr, _details)| addr);
dbg!(addr);
}
from rust-public-ip.
You can try this example now at https://github.com/avitex/rust-public-ip/blob/master/examples/errors.rs
from rust-public-ip.
Related Issues (9)
- an unknown tool name found in scoped lint: `rustdoc::all` HOT 2
- Panic due to missing Tokio reactor HOT 1
- Add Cloudflare as backend DNS
- Choose resolvers at random instead of always taking the first resolver
- Filter resolvers to compatible address type instead of trying resolvers until a compatible address type comes out HOT 1
- icanhazip.com as a HTTP backend
- ident.me as backend
- Picking IPv4 & IPv6 addresses 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-public-ip.