json_placeholder_data/todos/
mod.rs

1use crate::{by_id, from_json};
2use serde::{Deserialize, Serialize};
3use serde_with::skip_serializing_none;
4
5const PLACEHOLDER_JSON_TODOS: &str = include_str!("todos.json");
6
7#[skip_serializing_none]
8#[derive(Deserialize, Serialize)]
9pub struct Todo {
10    #[serde(rename = "userId")]
11    pub user_id: i32,
12    pub id: Option<i32>,
13    pub title: String,
14    pub completed: bool,
15}
16
17/// Get all the todos available
18///
19/// # Example
20/// ```
21/// use json_placeholder_data::todos::get_all;
22/// assert_eq!(get_all().len(), 200);
23/// ```
24pub fn get_all() -> Vec<Todo> {
25    from_json!(PLACEHOLDER_JSON_TODOS)
26}
27
28/// Get a todo by id
29///
30/// # Example
31/// ```
32/// use json_placeholder_data::todos::get;
33/// assert_eq!(
34///     get(67).title.as_str(),
35///     "quia voluptatibus voluptatem quos similique maiores repellat",
36/// );
37/// ```
38pub fn get(id: i32) -> Todo {
39    by_id!(id)
40}