trakt_core/response.rs
1use crate::error::FromHttpError;
2
3/// A trait for converting an HTTP response into a result of `Self`.
4pub trait Response: Sized {
5 /// Converts an HTTP response into a result of `Self`, where `Self` refers to the implementing type.
6 ///
7 /// # Arguments
8 ///
9 /// * `response` - The HTTP response to convert.
10 ///
11 /// # Errors
12 ///
13 /// Will error if the HTTP response is not a succeeding status code as determined by the
14 /// type or if the response body cannot be deserialized into the implementing type.
15 ///
16 /// See [`FromHttpError`] for more details.
17 fn try_from_http_response<T: AsRef<[u8]>>(
18 response: http::Response<T>,
19 ) -> Result<Self, FromHttpError>;
20}
21
22/// A sub-trait of `Response` for paginated responses.
23pub trait PaginatedResponse: Response {
24 /// The type of item that the paginated response contains.
25 type Item;
26
27 /// Returns a slice of the items in the current page of the paginated response.
28 fn items(&self) -> &[Self::Item];
29
30 /// Returns the pagination of the next page of the paginated response.
31 fn next_page(&self) -> Option<crate::Pagination>;
32}