bibby 0.1.0

The official Rust SDK for Bytebury — typed clients, smart .env initialization, and ergonomic macros for Geo, Images, PDF, Mailer, Uploader, Cron, Forms, Webhooks, Monitors, and Vault.
Documentation
//! Shared pagination types used across Bytebury list endpoints.

use serde::{Deserialize, Serialize};

/// A single page of items returned by a Bytebury list endpoint.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Page<T> {
    /// Items on this page.
    pub data: Vec<T>,
    /// Total number of matching items across all pages.
    pub total: i64,
    /// Current 1-based page number.
    pub page: i64,
    /// Number of items requested per page.
    pub page_size: i64,
    /// Whether another page of results follows this one.
    pub has_next_page: bool,
}

impl<T> Page<T> {
    /// Returns `true` if this page contains no items.
    pub fn is_empty(&self) -> bool {
        self.data.is_empty()
    }

    /// Returns the number of items on this page.
    pub fn len(&self) -> usize {
        self.data.len()
    }

    /// Returns the next page number if [`has_next_page`](Self::has_next_page) is `true`.
    pub fn next_page(&self) -> Option<i64> {
        self.has_next_page.then_some(self.page + 1)
    }
}

/// Common pagination query parameters (`page` and `page_size`).
#[derive(Debug, Clone, Default, Serialize)]
pub struct PageParams {
    /// 1-based page number (defaults to `1`).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
    /// Number of items per page, `1..=100` (server default varies by endpoint).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_size: Option<i64>,
}

impl PageParams {
    /// Creates pagination parameters for a specific page and page size.
    pub fn new(page: i64, page_size: i64) -> Self {
        Self {
            page: Some(page),
            page_size: Some(page_size),
        }
    }

    /// Sets the 1-based page number.
    pub fn page(mut self, page: i64) -> Self {
        self.page = Some(page);
        self
    }

    /// Sets the page size (`1..=100`).
    pub fn page_size(mut self, page_size: i64) -> Self {
        self.page_size = Some(page_size);
        self
    }
}