1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//! Contains the implementation of [`Page`].

use crate::model::dto::Page;

impl<T> Page<T> {
    /// Used to convert from a page of entities to a page of dto.
    //
    // Implementing the [`From`] trait with the types used here leads to a conflicting implementation.
    // See. https://stackoverflow.com/a/37347504
    pub fn from_entity<U>(value: Page<U>) -> Self
    where
        T: From<U>,
    {
        Self {
            results: value.results.into_iter().map(Into::into).collect(),
            page: value.page,
            per_page: value.per_page,
            total_pages: value.total_pages,
        }
    }
}