documentation changes
This commit is contained in:
parent
1b1c7708ef
commit
bf17d5abf6
@ -1,3 +1,6 @@
|
||||
//! Jikan.moe api wrapper.
|
||||
|
||||
/// `/anime` endpoints.
|
||||
pub mod anime;
|
||||
mod client;
|
||||
mod endpoint;
|
||||
|
@ -7,7 +7,7 @@ use crate::api::{
|
||||
page::Pageable,
|
||||
};
|
||||
|
||||
/// Retrieves a list of users who have added/updated/removed
|
||||
/// Retrieves a list of users who have added/updated/removed.
|
||||
/// the entry on their list.
|
||||
#[derive(Debug, Clone, Builder)]
|
||||
#[builder(setter(into))]
|
||||
|
@ -12,7 +12,7 @@ use super::error::ApiError;
|
||||
|
||||
/// A parent trait representing a client which can communicate with jikan.moe
|
||||
pub trait RestClient {
|
||||
/// The error that may occur for this client
|
||||
/// The error that may occur for this client.
|
||||
type Error: Error + Send + Sync + 'static;
|
||||
|
||||
/// Get the URL for the endpoint for the client.
|
||||
@ -23,7 +23,7 @@ pub trait RestClient {
|
||||
|
||||
/// A trait representing a blocking client which can communicate with jikan.moe
|
||||
pub trait Client: RestClient {
|
||||
/// Send a REST query
|
||||
/// Send a REST query.
|
||||
fn rest(
|
||||
&self,
|
||||
request: RequestBuilder,
|
||||
@ -31,11 +31,11 @@ pub trait Client: RestClient {
|
||||
) -> Result<Response<Bytes>, ApiError<Self::Error>>;
|
||||
}
|
||||
|
||||
/// A trait representing an asynchronous client which can communicate with
|
||||
/// A trait representing an asynchronous client which can communicate with.
|
||||
/// jikan.moe
|
||||
#[async_trait]
|
||||
pub trait AsyncClient: RestClient {
|
||||
/// Send a REST query asynchronously
|
||||
/// Send a REST query asynchronously.
|
||||
async fn rest_async(
|
||||
&self,
|
||||
request: RequestBuilder,
|
||||
|
@ -2,7 +2,7 @@ use std::error::Error;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
/// Errors from response
|
||||
/// Errors from response.
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ResponseError {
|
||||
#[error("Parsing JSON: {0}")]
|
||||
@ -24,7 +24,7 @@ pub enum ResponseError {
|
||||
#[derive(Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum BodyError {
|
||||
/// Error serializing body data from form paramaters
|
||||
/// Error serializing body data from form paramaters.
|
||||
#[error("URL encode error: {0}")]
|
||||
UrlEncoded(#[from] serde_urlencoded::ser::Error),
|
||||
#[error("JSON encode error: {0}")]
|
||||
@ -38,7 +38,7 @@ pub enum ApiError<E>
|
||||
where
|
||||
E: Error + Send + Sync + 'static,
|
||||
{
|
||||
/// Error creating body data
|
||||
/// Error creating body data.
|
||||
#[error("failed to create form data: {0}")]
|
||||
Body(#[from] BodyError),
|
||||
/// The client encountered an error.
|
||||
@ -47,11 +47,12 @@ where
|
||||
/// The URL failed to parse.
|
||||
#[error("url parse error: {0}")]
|
||||
Parse(#[from] url::ParseError),
|
||||
/// Error in response.
|
||||
#[error("Error in the HTTP response at url [{url}]: source")]
|
||||
Response {
|
||||
/// Source of the error
|
||||
/// Source of the error.
|
||||
source: ResponseError,
|
||||
/// URL of the error
|
||||
/// URL of the error.
|
||||
url: http::Uri,
|
||||
},
|
||||
}
|
||||
@ -60,7 +61,7 @@ impl<E> ApiError<E>
|
||||
where
|
||||
E: Error + Send + Sync + 'static,
|
||||
{
|
||||
/// Create an API error from a client error
|
||||
/// Create an API error from a client error.
|
||||
pub fn client(source: E) -> Self {
|
||||
Self::Client(source)
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ use crate::types::Pagination;
|
||||
/// Marker trait to indicate that an endpoint is pageable.
|
||||
pub trait Pageable {}
|
||||
|
||||
// Adapters specific to [`Pageable`] endpoints.
|
||||
/// Adapters specific to [`Pageable`] endpoints.
|
||||
pub trait PagedEndpointExt<'a, E> {
|
||||
/// Create an Iterator over the results of the paginated endpoint.
|
||||
fn iter<T, C>(&'a self, client: &'a C) -> PagedIter<'a, E, C, T>
|
||||
@ -29,10 +29,12 @@ pub trait PagedEndpointExt<'a, E> {
|
||||
T: DeserializeOwned;
|
||||
}
|
||||
|
||||
/// Asynchronous iterator over paginated endpoints.
|
||||
pub trait AsyncIterator {
|
||||
/// The type of the items in this iterator.
|
||||
type Item;
|
||||
|
||||
// async fn next(&mut self) -> Option<Self::Item>;
|
||||
/// Advance to the next page of results.
|
||||
fn next(&mut self) -> impl Future<Output = Option<Self::Item>> + Send;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Error types for the crate
|
||||
//! Error types for the crate.
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::api;
|
||||
@ -13,7 +13,7 @@ pub enum JikanApiError {
|
||||
/// Error from the jikan.moe API
|
||||
#[error("API error: {0}")]
|
||||
Api(#[from] api::ApiError<RestError>),
|
||||
/// Error parsing URL
|
||||
/// Error parsing URL.
|
||||
#[error("url parse error: {0}")]
|
||||
Parse(#[from] url::ParseError),
|
||||
}
|
||||
@ -22,10 +22,10 @@ pub enum JikanApiError {
|
||||
#[derive(Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum RestError {
|
||||
/// Reqwest client error
|
||||
/// Reqwest client error.
|
||||
#[error("communication: {0}")]
|
||||
Communication(#[from] reqwest::Error),
|
||||
/// HTTP protocol error
|
||||
/// HTTP protocol error.
|
||||
#[error("HTTP error: {0}")]
|
||||
Http(#[from] http::Error),
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Helper types for jikan.moe responses.
|
||||
|
||||
pub mod anime;
|
||||
mod common;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user