pub struct ResourceCollection<T> {
pub embedded: HashMap<String, Vec<T>>,
pub links: HashMap<String, LinkOrArray>,
pub page: Option<PageInfo>,
}Expand description
Collection of resources with pagination support
Provides a standardized way to return paginated collections with navigation links.
§Example
use rustapi_core::hateoas::{ResourceCollection, PageInfo};
use serde::Serialize;
#[derive(Serialize, Clone)]
struct User {
id: i64,
name: String,
}
let users = vec![
User { id: 1, name: "John".to_string() },
User { id: 2, name: "Jane".to_string() },
];
let collection = ResourceCollection::new("users", users)
.self_link("/users?page=1")
.next_link("/users?page=2")
.page_info(PageInfo::new(20, 100, 5, 1));Fields§
§embedded: HashMap<String, Vec<T>>Embedded resources
links: HashMap<String, LinkOrArray>Navigation links
page: Option<PageInfo>Pagination information
Implementations§
Source§impl<T> ResourceCollection<T>
impl<T> ResourceCollection<T>
Sourcepub fn first_link(self, href: impl Into<String>) -> Self
pub fn first_link(self, href: impl Into<String>) -> Self
Add first page link
Sourcepub fn with_pagination(self, base_url: &str) -> Self
pub fn with_pagination(self, base_url: &str) -> Self
Build pagination links from page info
Trait Implementations§
Source§impl<T: Clone> Clone for ResourceCollection<T>
impl<T: Clone> Clone for ResourceCollection<T>
Source§fn clone(&self) -> ResourceCollection<T>
fn clone(&self) -> ResourceCollection<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 ResourceCollection<T>
impl<T: Debug> Debug for ResourceCollection<T>
Source§impl<'de, T> Deserialize<'de> for ResourceCollection<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for ResourceCollection<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
Auto Trait Implementations§
impl<T> Freeze for ResourceCollection<T>
impl<T> RefUnwindSafe for ResourceCollection<T>where
T: RefUnwindSafe,
impl<T> Send for ResourceCollection<T>where
T: Send,
impl<T> Sync for ResourceCollection<T>where
T: Sync,
impl<T> Unpin for ResourceCollection<T>where
T: Unpin,
impl<T> UnwindSafe for ResourceCollection<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Linkable for Twhere
T: Serialize,
impl<T> Linkable for Twhere
T: Serialize,
Source§fn with_links(self) -> Resource<Self>
fn with_links(self) -> Resource<Self>
Wrap this value in a Resource with HATEOAS links