finance_query/models/currencies/
response.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9#[cfg_attr(feature = "dataframe", derive(crate::ToDataFrame))]
10#[serde(rename_all = "camelCase")]
11#[non_exhaustive]
12pub struct Currency {
13 pub short_name: Option<String>,
15 pub long_name: Option<String>,
17 pub symbol: Option<String>,
19 pub local_long_name: Option<String>,
21}
22
23#[derive(Debug, Clone, Deserialize)]
25#[serde(rename_all = "camelCase")]
26pub(crate) struct RawCurrenciesResponse {
27 pub currencies: Option<CurrenciesResult>,
28}
29
30#[derive(Debug, Clone, Deserialize)]
31#[serde(rename_all = "camelCase")]
32pub(crate) struct CurrenciesResult {
33 pub result: Option<Vec<Currency>>,
34}
35
36impl Currency {
37 pub(crate) fn from_response(value: serde_json::Value) -> Result<Vec<Self>, serde_json::Error> {
39 let raw: RawCurrenciesResponse = serde_json::from_value(value)?;
40 Ok(raw.currencies.and_then(|c| c.result).unwrap_or_default())
41 }
42}