Im new to Rust and i cant for the life of me figure out how to actually use the Data that I have in my Struct. Im pulling the Data from an API and it changes roughly every few seconds. This is what i have so far
use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct KujiraAsset {
pub tickers: Vec<KujiraAssetInfo>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct KujiraAssetInfo {
pub ask:String,
pub base_currency: String,
pub bid:String,
pub pool_id: String,
pub target_currency: String,
pub ticker_id: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let resp = reqwest::get("https://api.kujira.app/api/coingecko/tickers").await?;
let resp_json = resp.json::<KujiraAsset>()
.await?;
println!("Responce Json: {:#?}", resp_json);
Ok(())
}
it returns
Responce Json: KujiraAsset {
tickers: [
KujiraAssetInfo {
ask: "1.1130000000",
base_currency: "KUJI",
bid: "1.0930000000",
pool_id: "kujira14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sl4e867",
target_currency: "axlUSDC",
ticker_id: "KUJI_axlUSDC",
},
KujiraAssetInfo {
ask: "1.9700000000",
base_currency: "EVMOS",
bid: "1.6800000000",
pool_id: "kujira182nff4ttmvshn6yjlqj5czapfcav9434l2qzz8aahf5pxnyd33tsz30aw6",
target_currency: "axlUSDC",
ticker_id: "EVMOS_axlUSDC",
....
KujiraAssetInfo {
ask: "1.4640000000",
base_currency: "SCRT",
bid: "1.4260000000",
pool_id: "kujira1fkwjqyfdyktgu5f59jpwhvl23zh8aav7f98ml9quly62jx2sehysqa4unf",
target_currency: "axlUSDC",
ticker_id: "SCRT_axlUSDC",
is there a way for me to bind the values in each field to a variable that i can use elsewhere?
Any help or insights is always greatly appreciated