backend/model/dto/page_impl.rs
1//! Contains the implementation of [`Page`].
2
3use crate::model::dto::Page;
4
5impl<T> Page<T> {
6 /// Used to convert from a page of entities to a page of dto.
7 //
8 // Implementing the [`From`] trait with the types used here leads to a conflicting implementation.
9 // See. https://stackoverflow.com/a/37347504
10 pub fn from_entity<U>(value: Page<U>) -> Self
11 where
12 T: From<U>,
13 {
14 Self {
15 results: value.results.into_iter().map(Into::into).collect(),
16 page: value.page,
17 per_page: value.per_page,
18 total_pages: value.total_pages,
19 }
20 }
21}