json_placeholder_data/users/
mod.rs1use crate::{by_id, from_json};
2use serde::{Deserialize, Serialize};
3use serde_with::skip_serializing_none;
4
5const PLACEHOLDER_JSON_USERS: &str = include_str!("users.json");
6
7#[skip_serializing_none]
8#[derive(Deserialize, Serialize)]
9pub struct Geo {
10 pub lat: String,
11 pub lng: String,
12}
13
14#[skip_serializing_none]
15#[derive(Deserialize, Serialize)]
16pub struct Address {
17 pub street: String,
18 pub suite: String,
19 pub city: String,
20 pub zipcode: String,
21 pub geo: Geo,
22}
23
24#[skip_serializing_none]
25#[derive(Deserialize, Serialize)]
26pub struct Company {
27 pub name: String,
28 #[serde(rename = "catchPhrase")]
29 pub catch_phrase: String,
30 pub bs: String,
31}
32
33#[skip_serializing_none]
34#[derive(Deserialize, Serialize)]
35pub struct User {
36 pub id: Option<i32>,
37 pub name: String,
38 pub username: String,
39 pub email: String,
40 pub address: Address,
41 pub phone: String,
42 pub website: String,
43 pub company: Company,
44}
45
46pub fn get_all() -> Vec<User> {
54 from_json!(PLACEHOLDER_JSON_USERS)
55}
56
57pub fn get(id: i32) -> User {
68 by_id!(id)
69}