pub struct Pagination {
pub page: u32,
pub limit: u32,
pub pages: u32,
pub total: u32,
pub next: Option<u32>,
pub prev: Option<u32>,
}Expand description
Pagination information for browse endpoints.
Contains information about the current page, total number of pages, and links to the next/previous pages.
§Fields
page- Current page number (1-indexed)limit- Number of items per pagepages- Total number of pages availabletotal- Total number of items across all pagesnext- Page number of the next page, if availableprev- Page number of the previous page, if available
§Example
use ghost_io_api::models::pagination::Pagination;
use serde_json::json;
let json = json!({
"page": 2,
"limit": 10,
"pages": 5,
"total": 47,
"next": 3,
"prev": 1
});
let pagination: Pagination = serde_json::from_value(json).unwrap();
assert_eq!(pagination.page, 2);
assert!(pagination.has_next());
assert!(pagination.has_prev());
assert!(!pagination.is_first_page());
assert!(!pagination.is_last_page());Fields§
§page: u32Current page number (1-indexed).
limit: u32Number of items per page.
pages: u32Total number of pages available.
total: u32Total number of items across all pages.
next: Option<u32>Page number of the next page, if available.
None if this is the last page.
prev: Option<u32>Page number of the previous page, if available.
None if this is the first page.
Implementations§
Source§impl Pagination
impl Pagination
Sourcepub fn has_next(&self) -> bool
pub fn has_next(&self) -> bool
Returns true if there is a next page available.
§Example
use ghost_io_api::models::pagination::Pagination;
let pagination = Pagination {
page: 1,
limit: 15,
pages: 5,
total: 73,
next: Some(2),
prev: None,
};
assert!(pagination.has_next());Sourcepub fn has_prev(&self) -> bool
pub fn has_prev(&self) -> bool
Returns true if there is a previous page available.
§Example
use ghost_io_api::models::pagination::Pagination;
let pagination = Pagination {
page: 2,
limit: 15,
pages: 5,
total: 73,
next: Some(3),
prev: Some(1),
};
assert!(pagination.has_prev());Sourcepub fn is_first_page(&self) -> bool
pub fn is_first_page(&self) -> bool
Returns true if this is the first page.
§Example
use ghost_io_api::models::pagination::Pagination;
let pagination = Pagination {
page: 1,
limit: 15,
pages: 5,
total: 73,
next: Some(2),
prev: None,
};
assert!(pagination.is_first_page());Sourcepub fn is_last_page(&self) -> bool
pub fn is_last_page(&self) -> bool
Returns true if this is the last page.
§Example
use ghost_io_api::models::pagination::Pagination;
let pagination = Pagination {
page: 5,
limit: 15,
pages: 5,
total: 73,
next: None,
prev: Some(4),
};
assert!(pagination.is_last_page());Sourcepub fn items_on_page(&self) -> u32
pub fn items_on_page(&self) -> u32
Returns the number of items on the current page.
For all pages except potentially the last one, this will equal limit.
On the last page, it may be less than limit.
§Example
use ghost_io_api::models::pagination::Pagination;
let pagination = Pagination {
page: 5,
limit: 15,
pages: 5,
total: 73,
next: None,
prev: Some(4),
};
// Last page: 73 total - (4 * 15) = 13 items on this page
assert_eq!(pagination.items_on_page(), 13);Sourcepub fn start_index(&self) -> u32
pub fn start_index(&self) -> u32
Returns the starting item index for the current page (0-indexed).
§Example
use ghost_io_api::models::pagination::Pagination;
let pagination = Pagination {
page: 2,
limit: 15,
pages: 5,
total: 73,
next: Some(3),
prev: Some(1),
};
// Page 2, limit 15: starts at index 15
assert_eq!(pagination.start_index(), 15);Sourcepub fn end_index(&self) -> u32
pub fn end_index(&self) -> u32
Returns the ending item index for the current page (0-indexed, exclusive).
§Example
use ghost_io_api::models::pagination::Pagination;
let pagination = Pagination {
page: 2,
limit: 15,
pages: 5,
total: 73,
next: Some(3),
prev: Some(1),
};
// Page 2, limit 15: ends at index 30 (exclusive)
assert_eq!(pagination.end_index(), 30);Trait Implementations§
Source§impl Clone for Pagination
impl Clone for Pagination
Source§fn clone(&self) -> Pagination
fn clone(&self) -> Pagination
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Pagination
impl Debug for Pagination
Source§impl<'de> Deserialize<'de> for Pagination
impl<'de> Deserialize<'de> for Pagination
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Pagination
Source§impl PartialEq for Pagination
impl PartialEq for Pagination
Source§fn eq(&self, other: &Pagination) -> bool
fn eq(&self, other: &Pagination) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for Pagination
impl Serialize for Pagination
impl StructuralPartialEq for Pagination
Auto Trait Implementations§
impl Freeze for Pagination
impl RefUnwindSafe for Pagination
impl Send for Pagination
impl Sync for Pagination
impl Unpin for Pagination
impl UnsafeUnpin for Pagination
impl UnwindSafe for Pagination
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.