BlueGit

ict rusty-teams

Files

rusty-teams / crates / graph / src / page.rs

page.rs

Initial commit
metis Daniel Däschle · pushed by metis · 7 weeks ago
06e0ae51 History
page.rs 875 B Download Raw
1use serde::Deserialize;
2use serde::de::DeserializeOwned;
3use serde_json::Value;
4use session::Scope;
5
6use crate::error::Result;
7
8#[derive(Debug, Clone)]
9pub struct Page<T> {
10 pub items: Vec<T>,
11 pub next_link: Option<String>,
12 pub delta_link: Option<String>,
13 pub(crate) scope: Scope,
14}
15
16#[derive(Deserialize)]
17struct RawPage<T> {
18 #[serde(default = "Vec::new")]
19 value: Vec<T>,
20 #[serde(rename = "@odata.nextLink")]
21 next_link: Option<String>,
22 #[serde(rename = "@odata.deltaLink")]
23 delta_link: Option<String>,
24}
25
26impl<T: DeserializeOwned> Page<T> {
27 pub(crate) fn parse(body: Value, scope: Scope) -> Result<Self> {
28 let raw: RawPage<T> = serde_json::from_value(body)?;
29 Ok(Page {
30 items: raw.value,
31 next_link: raw.next_link,
32 delta_link: raw.delta_link,
33 scope,
34 })
35 }
36}