pub struct Client { /* private fields */ }Expand description
Fetches RDAP records.
Build one and keep it. It holds the bootstrap registries and a connection pool, and both are wasted when a client is built for one lookup.
The client connects to public addresses only, unless it is built with
Destinations::Any. A record and a redirect come from outside the process, and
this keeps either from sending the client to a service inside your network.
use abuse_contact::{Client, Scope, rank};
let client = Client::new().await?;
if let Some(record) = client.lookup_ip("8.8.8.8".parse().unwrap()).await? {
for contact in rank(record.abuse_contacts(Scope::Network)) {
println!("{} ({:?})", contact.email, contact.scope);
}
}Implementations§
Source§impl Client
impl Client
Sourcepub async fn new() -> Result<Self, Error>
pub async fn new() -> Result<Self, Error>
Fetches the three bootstrap registries and returns a client.
This makes three requests to IANA. Build the client one time. The client connects to public addresses only.
§Errors
Returns Error::Transport when a registry cannot be fetched,
Error::TooLarge when one is past MAX_BOOTSTRAP_BYTES, and
Error::Decode when one is not a bootstrap file.
Sourcepub fn with_bootstrap(
bootstrap: Bootstrap,
destinations: Destinations,
) -> Result<Self, Error>
pub fn with_bootstrap( bootstrap: Bootstrap, destinations: Destinations, ) -> Result<Self, Error>
Returns a client that uses registries you already hold.
Use this to keep the registries between runs, so a short-lived process does
not fetch them again. Give Destinations::Public unless every server in the
registries is one you run.
§Errors
Returns Error::Transport when the HTTP client cannot be built.
Sourcepub async fn lookup(
&self,
query: impl Into<Query>,
) -> Result<Option<Record>, Error>
pub async fn lookup( &self, query: impl Into<Query>, ) -> Result<Option<Record>, Error>
Fetches the record for an address or a name.
Returns None when the registry holds no record for it.
§Errors
Returns Error::NotPublic for a private or reserved address,
Error::NoServer when no registry answers for the target, and the errors of
Client::fetch.
Sourcepub async fn lookup_domain(
&self,
domain: &DomainName,
) -> Result<Option<Record>, Error>
pub async fn lookup_domain( &self, domain: &DomainName, ) -> Result<Option<Record>, Error>
Fetches the record for a name.
The record names the registrar and carries its abuse address. Follow
Response::related_href on Record::response with Client::fetch only
when you want what the registry leaves out.
§Errors
The same errors as Client::lookup.
Sourcepub async fn fetch(
&self,
url: &str,
target: &str,
) -> Result<Option<Record>, Error>
pub async fn fetch( &self, url: &str, target: &str, ) -> Result<Option<Record>, Error>
Fetches one RDAP record by its URL.
Use it to follow a link out of a record you already hold. The URL is used as it is given, so it must come from a record and not from outside input.
§Errors
Returns Error::Refused when the URL, or a redirect from it, goes where the
client does not connect, Error::Transport when the request does not
complete, Error::Status when the server refuses, Error::TooLarge when the
body is past MAX_RECORD_BYTES, and Error::Decode when the body is not
RDAP.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Client
impl !UnwindSafe for Client
impl Freeze for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more