Skip to main content

iadb_api/
schemas.rs

1use std::fmt;
2use serde::{Serialize, Deserialize};
3
4
5#[derive(Serialize, Deserialize)]
6/// Data series.
7pub struct IADBSeries {
8    /// IADB series code. 
9    pub name: String,
10    pub description: String,
11    pub data: Vec<IADBDataPoint>,
12}
13
14impl fmt::Display for IADBSeries {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        write!(f, "IADB Series: {} ({})\n", self.name, self.description)?;
17        for item in self.data.iter() {
18            write!(f, "{}\n", item.to_string())?;
19        }
20        Ok(())
21    }
22}
23
24
25#[derive(Serialize, Deserialize)]
26/// Describes a single entry in the series.
27pub struct IADBDataPoint {
28    // #[serde(rename = "DATE")]
29    /// Date of the data point.
30    pub date: String,
31    /// Value of the data point.
32    pub value: f64,
33}
34
35impl fmt::Display for IADBDataPoint {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        write!(f, "IADB Data Point ({}): {}", self.date, self.value)
38    }
39}