20 lines
703 B
Rust
20 lines
703 B
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
/// This is a generic struct that represents a page of content that has been paginated.
|
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
pub struct SearchResult<T> {
|
|
pub results: Vec<T>,
|
|
pub current_page: i32,
|
|
pub total_pages: i32,
|
|
}
|
|
|
|
/// This constant should be used everywhere so that it can easily changed.
|
|
pub const ROWS_PER_PAGE: i32 = 200;
|
|
|
|
/// This gets an i32 from an Option<&str>.
|
|
/// It is fail safe: for any "bad" value, it will return 1 instead of an error.
|
|
/// TODO: Maybe this should be an error instead...
|
|
pub fn get_page_number_as_i32_from_str(page_as_str: Option<&str>) -> i32 {
|
|
str::parse(page_as_str.unwrap_or("1")).unwrap_or(1)
|
|
}
|