pub struct PaginatedResponse<T> {
pub items: Vec<T>,
pub total_count: u64,
pub has_more: bool,
pub limit: u64,
pub offset: u64,
}Expand description
Offset-based paginated response envelope with a flat shape.
Requires std or alloc.
All list endpoints that use PaginationParams should wrap their result
with this type so SDK consumers always see the same contract.
{
"items": [...],
"total_count": 42,
"has_more": true,
"limit": 20,
"offset": 0
}Fields§
§items: Vec<T>The items on this page.
total_count: u64Total number of items across all pages.
has_more: boolWhether more items exist beyond this page.
limit: u64Maximum number of items returned per page.
offset: u64Number of items skipped before this page.
Implementations§
Source§impl<T> PaginatedResponse<T>
impl<T> PaginatedResponse<T>
Sourcepub fn new(items: Vec<T>, total_count: u64, params: &PaginationParams) -> Self
pub fn new(items: Vec<T>, total_count: u64, params: &PaginationParams) -> Self
Build a paginated response from items, total count, and the query params.
has_more is set to true when offset + items.len() < total_count.
§Examples
use api_bones::pagination::{PaginatedResponse, PaginationParams};
let params = PaginationParams::default();
let resp = PaginatedResponse::new(vec![1, 2, 3], 25, ¶ms);
assert!(resp.has_more);
assert_eq!(resp.total_count, 25);
assert_eq!(resp.limit, 20);
assert_eq!(resp.offset, 0);
let resp = PaginatedResponse::new(vec![1, 2, 3], 3, ¶ms);
assert!(!resp.has_more);Trait Implementations§
Source§impl<T: Clone> Clone for PaginatedResponse<T>
impl<T: Clone> Clone for PaginatedResponse<T>
Source§fn clone(&self) -> PaginatedResponse<T>
fn clone(&self) -> PaginatedResponse<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for PaginatedResponse<T>
impl<T: Debug> Debug for PaginatedResponse<T>
Source§impl<'de, T> Deserialize<'de> for PaginatedResponse<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for PaginatedResponse<T>where
T: Deserialize<'de>,
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: PartialEq> PartialEq for PaginatedResponse<T>
impl<T: PartialEq> PartialEq for PaginatedResponse<T>
Source§impl<T> Serialize for PaginatedResponse<T>where
T: Serialize,
impl<T> Serialize for PaginatedResponse<T>where
T: Serialize,
impl<T> StructuralPartialEq for PaginatedResponse<T>
Auto Trait Implementations§
impl<T> Freeze for PaginatedResponse<T>
impl<T> RefUnwindSafe for PaginatedResponse<T>where
T: RefUnwindSafe,
impl<T> Send for PaginatedResponse<T>where
T: Send,
impl<T> Sync for PaginatedResponse<T>where
T: Sync,
impl<T> Unpin for PaginatedResponse<T>where
T: Unpin,
impl<T> UnsafeUnpin for PaginatedResponse<T>
impl<T> UnwindSafe for PaginatedResponse<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more