documentation changes

This commit is contained in:
Dmitriy Kholkin 2025-01-11 21:20:48 +03:00
parent 91f730fd56
commit 530ce3c4bc
Signed by: AtaraxiaDev
GPG Key ID: FD266B810DF48DF2
7 changed files with 25 additions and 17 deletions

View File

@ -1,3 +1,6 @@
//! Jikan.moe api wrapper.
/// `/anime` endpoints.
pub mod anime; pub mod anime;
mod client; mod client;
mod endpoint; mod endpoint;

View File

@ -7,7 +7,7 @@ use crate::api::{
page::Pageable, 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. /// the entry on their list.
#[derive(Debug, Clone, Builder)] #[derive(Debug, Clone, Builder)]
#[builder(setter(into))] #[builder(setter(into))]

View File

@ -12,7 +12,7 @@ use super::error::ApiError;
/// A parent trait representing a client which can communicate with jikan.moe /// A parent trait representing a client which can communicate with jikan.moe
pub trait RestClient { 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; type Error: Error + Send + Sync + 'static;
/// Get the URL for the endpoint for the client. /// 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 /// A trait representing a blocking client which can communicate with jikan.moe
pub trait Client: RestClient { pub trait Client: RestClient {
/// Send a REST query /// Send a REST query.
fn rest( fn rest(
&self, &self,
request: RequestBuilder, request: RequestBuilder,
@ -31,11 +31,11 @@ pub trait Client: RestClient {
) -> Result<Response<Bytes>, ApiError<Self::Error>>; ) -> 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 /// jikan.moe
#[async_trait] #[async_trait]
pub trait AsyncClient: RestClient { pub trait AsyncClient: RestClient {
/// Send a REST query asynchronously /// Send a REST query asynchronously.
async fn rest_async( async fn rest_async(
&self, &self,
request: RequestBuilder, request: RequestBuilder,

View File

@ -2,7 +2,7 @@ use std::error::Error;
use thiserror::Error; use thiserror::Error;
/// Errors from response /// Errors from response.
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum ResponseError { pub enum ResponseError {
#[error("Parsing JSON: {0}")] #[error("Parsing JSON: {0}")]
@ -24,7 +24,7 @@ pub enum ResponseError {
#[derive(Debug, Error)] #[derive(Debug, Error)]
#[non_exhaustive] #[non_exhaustive]
pub enum BodyError { pub enum BodyError {
/// Error serializing body data from form paramaters /// Error serializing body data from form paramaters.
#[error("URL encode error: {0}")] #[error("URL encode error: {0}")]
UrlEncoded(#[from] serde_urlencoded::ser::Error), UrlEncoded(#[from] serde_urlencoded::ser::Error),
#[error("JSON encode error: {0}")] #[error("JSON encode error: {0}")]
@ -38,7 +38,7 @@ pub enum ApiError<E>
where where
E: Error + Send + Sync + 'static, E: Error + Send + Sync + 'static,
{ {
/// Error creating body data /// Error creating body data.
#[error("failed to create form data: {0}")] #[error("failed to create form data: {0}")]
Body(#[from] BodyError), Body(#[from] BodyError),
/// The client encountered an error. /// The client encountered an error.
@ -47,11 +47,12 @@ where
/// The URL failed to parse. /// The URL failed to parse.
#[error("url parse error: {0}")] #[error("url parse error: {0}")]
Parse(#[from] url::ParseError), Parse(#[from] url::ParseError),
/// Error in response.
#[error("Error in the HTTP response at url [{url}]: source")] #[error("Error in the HTTP response at url [{url}]: source")]
Response { Response {
/// Source of the error /// Source of the error.
source: ResponseError, source: ResponseError,
/// URL of the error /// URL of the error.
url: http::Uri, url: http::Uri,
}, },
} }
@ -60,7 +61,7 @@ impl<E> ApiError<E>
where where
E: Error + Send + Sync + 'static, 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 { pub fn client(source: E) -> Self {
Self::Client(source) Self::Client(source)
} }

View File

@ -20,7 +20,7 @@ use crate::types::Pagination;
/// Marker trait to indicate that an endpoint is pageable. /// Marker trait to indicate that an endpoint is pageable.
pub trait Pageable {} pub trait Pageable {}
// Adapters specific to [`Pageable`] endpoints. /// Adapters specific to [`Pageable`] endpoints.
pub trait PagedEndpointExt<'a, E> { pub trait PagedEndpointExt<'a, E> {
/// Create an Iterator over the results of the paginated endpoint. /// Create an Iterator over the results of the paginated endpoint.
fn iter<T, C>(&'a self, client: &'a C) -> PagedIter<'a, E, C, T> 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; T: DeserializeOwned;
} }
/// Asynchronous iterator over paginated endpoints.
pub trait AsyncIterator { pub trait AsyncIterator {
/// The type of the items in this iterator.
type Item; 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; fn next(&mut self) -> impl Future<Output = Option<Self::Item>> + Send;
} }

View File

@ -1,4 +1,4 @@
//! Error types for the crate //! Error types for the crate.
use thiserror::Error; use thiserror::Error;
use crate::api; use crate::api;
@ -13,7 +13,7 @@ pub enum JikanApiError {
/// Error from the jikan.moe API /// Error from the jikan.moe API
#[error("API error: {0}")] #[error("API error: {0}")]
Api(#[from] api::ApiError<RestError>), Api(#[from] api::ApiError<RestError>),
/// Error parsing URL /// Error parsing URL.
#[error("url parse error: {0}")] #[error("url parse error: {0}")]
Parse(#[from] url::ParseError), Parse(#[from] url::ParseError),
} }
@ -22,10 +22,10 @@ pub enum JikanApiError {
#[derive(Debug, Error)] #[derive(Debug, Error)]
#[non_exhaustive] #[non_exhaustive]
pub enum RestError { pub enum RestError {
/// Reqwest client error /// Reqwest client error.
#[error("communication: {0}")] #[error("communication: {0}")]
Communication(#[from] reqwest::Error), Communication(#[from] reqwest::Error),
/// HTTP protocol error /// HTTP protocol error.
#[error("HTTP error: {0}")] #[error("HTTP error: {0}")]
Http(#[from] http::Error), Http(#[from] http::Error),
} }

View File

@ -1,3 +1,5 @@
//! Helper types for jikan.moe responses.
pub mod anime; pub mod anime;
mod common; mod common;