mail_tm_rs/
hydra.rs

1use serde::{Deserialize, Serialize};
2use rand::Rng;
3
4#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub struct HydraCollection<T>  {
7    #[serde(rename = "hydra:member")]
8    pub members: Vec<T>,
9    #[serde(rename = "hydra:totalItems")]
10    pub total_items: i64,
11    #[serde(rename = "hydra:view")]
12    pub view: Option<View>,
13    #[serde(rename = "hydra:search")]
14    pub search: Option<Search>,
15}
16
17impl <T: Clone> HydraCollection<T> {
18    pub fn any(&self) -> T {
19        self.members[rand::thread_rng().gen_range(0..self.members.len())].clone()
20    }
21}
22
23#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
24#[serde(rename_all = "camelCase")]
25pub struct View {
26    #[serde(rename = "@id")]
27    pub id: String,
28    #[serde(rename = "@type")]
29    pub type_field: String,
30    #[serde(rename = "hydra:first")]
31    pub first: String,
32    #[serde(rename = "hydra:last")]
33    pub last: String,
34    #[serde(rename = "hydra:next")]
35    pub next: String,
36}
37
38#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
39#[serde(rename_all = "camelCase")]
40pub struct Search {
41    #[serde(rename = "@type")]
42    pub type_field: String,
43    #[serde(rename = "hydra:template")]
44    pub template: String,
45    #[serde(rename = "hydra:variableRepresentation")]
46    pub variable_representation: String,
47    #[serde(rename = "hydra:mapping")]
48    pub mapping: Vec<Mapping>,
49}
50
51#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
52#[serde(rename_all = "camelCase")]
53pub struct Mapping {
54    #[serde(rename = "@type")]
55    pub type_field: String,
56    pub variable: String,
57    pub property: String,
58    pub required: bool,
59}
60