use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct Collection<T> {
pub data: Vec<T>,
#[serde(default)]
pub page: Option<i64>,
#[serde(default)]
pub per_page: Option<i64>,
#[serde(default)]
pub total: Option<i64>,
#[serde(default)]
pub total_pages: Option<i64>,
#[serde(default)]
pub next_page_url: Option<String>,
}
impl<T> Collection<T> {
pub fn has_more(&self) -> bool {
self.next_page_url.is_some()
}
pub fn len(&self) -> usize {
self.data.len()
}
pub fn is_empty(&self) -> bool {
self.data.is_empty()
}
pub fn iter(&self) -> std::slice::Iter<'_, T> {
self.data.iter()
}
}
impl<T> IntoIterator for Collection<T> {
type Item = T;
type IntoIter = std::vec::IntoIter<T>;
fn into_iter(self) -> Self::IntoIter {
self.data.into_iter()
}
}
impl<'a, T> IntoIterator for &'a Collection<T> {
type Item = &'a T;
type IntoIter = std::slice::Iter<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.data.iter()
}
}