Struct crates_io_api::AsyncClient

source ·
pub struct AsyncClient { /* private fields */ }
Expand description

Asynchronous client for the crates.io API.

Implementations§

source§

impl Client

source

pub fn new( user_agent: &str, rate_limit: Duration ) -> Result<Self, InvalidHeaderValue>

Instantiate a new client.

Returns an Error if the given user agent is invalid.

To respect the offical Crawler Policy, you must specify both a descriptive user agent and a rate limit interval.

At most one request will be executed in the specified duration. The guidelines suggest 1 per second or less. (Only one request is executed concurrenly, even if the given Duration is 0).

Example user agent: "my_bot (my_bot.com/info)" or "my_bot (help@my_bot.com)".

let client = crates_io_api::AsyncClient::new(
  "my_bot (help@my_bot.com)",
  std::time::Duration::from_millis(1000),
).unwrap();
source

pub fn with_http_client(client: HttpClient, rate_limit: Duration) -> Self

Instantiate a new client.

To respect the offical Crawler Policy, you must specify both a descriptive user agent and a rate limit interval.

At most one request will be executed in the specified duration. The guidelines suggest 1 per second or less. (Only one request is executed concurrenly, even if the given Duration is 0).

source

pub async fn summary(&self) -> Result<Summary, Error>

Retrieve a summary containing crates.io wide information.

source

pub async fn get_crate(&self, crate_name: &str) -> Result<CrateResponse, Error>

Retrieve information of a crate.

If you require detailed information, consider using full_crate.

source

pub async fn crate_downloads( &self, crate_name: &str ) -> Result<CrateDownloads, Error>

Retrieve download stats for a crate.

source

pub async fn crate_owners(&self, name: &str) -> Result<Vec<User>, Error>

Retrieve the owners of a crate.

source

pub async fn crate_reverse_dependencies_page( &self, crate_name: &str, page: u64 ) -> Result<ReverseDependencies, Error>

Get a single page of reverse dependencies.

Note: if the page is 0, it is coerced to 1.

source

pub async fn crate_reverse_dependencies( &self, crate_name: &str ) -> Result<ReverseDependencies, Error>

Load all reverse dependencies of a crate.

Note: Since the reverse dependency endpoint requires pagination, this will result in multiple requests if the crate has more than 100 reverse dependencies.

source

pub async fn crate_reverse_dependency_count( &self, crate_name: &str ) -> Result<u64, Error>

Get the total count of reverse dependencies for a given crate.

source

pub async fn crate_authors( &self, crate_name: &str, version: &str ) -> Result<Authors, Error>

Retrieve the authors for a crate version.

source

pub async fn crate_dependencies( &self, crate_name: &str, version: &str ) -> Result<Vec<Dependency>, Error>

Retrieve the dependencies of a crate version.

source

pub async fn full_crate( &self, name: &str, all_versions: bool ) -> Result<FullCrate, Error>

Retrieve all available information for a crate, including download stats, owners and reverse dependencies.

The all_versions argument controls the retrieval of detailed version information. If false, only the data for the latest version will be fetched, if true, detailed information for all versions will be available. Note: Each version requires two extra requests.

source

pub async fn crates(&self, query: CratesQuery) -> Result<CratesPage, Error>

Retrieve a page of crates, optionally constrained by a query.

If you want to get all results without worrying about paging, use [all_crates].

source

pub fn crates_stream(&self, filter: CratesQuery) -> CrateStream

Get a stream over all crates matching the given CratesQuery.

source

pub async fn user(&self, username: &str) -> Result<User, Error>

Retrieves a user by username.

Trait Implementations§

source§

impl Clone for Client

source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more