0

I can't catch the error cause. I have used the same procedure with other similar commands using the following tool: transform JSON to RUST

Another post takes the problem, but a don't understand the solution, I'm still very new to Rust.

Fragment of the main():

 match get_account_snapshot(&cfg.api_config.api_key, &cfg.api_config.secret_key).await { Ok(snapshot) => log::info!("{:#?}", snapshot), Err(e) => log::info!("{:#?}", e), }; 

Structures and function get_account_snapshot:

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct AccountSnapshot { pub code: i64, pub msg: String, #[serde(rename = "snapshotVos")] pub snapshot_vos: Vec<SnapshotVo>, } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SnapshotVo { #[serde(rename = "type")] pub type_field: String, #[serde(rename = "updateTime")] pub update_time: i64, pub data: Data, } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Data { #[serde(rename = "totalAssetOfBtc")] pub total_asset_of_btc: String, pub balances: Vec<Balance>, } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Balance { pub asset: String, pub free: String, pub locked: String, } pub async fn get_account_snapshot(api_key: &str, api_secret: &str) -> Result<Vec<AccountSnapshot>, BError> { let credentials = Credentials::from_hmac(api_key, api_secret); let client = BinanceHttpClient::default().credentials(credentials); let request = wallet::account_snapshot("SPOT"); let data = client.send(request).await.map_err(BError::Client)?.into_body_str().await.map_err(BError::Client)?; log::info!("Before deserialize ------> {}", data); let data = serde_json::from_str::<Vec<AccountSnapshot>>(data.as_str()).map_err(BError::SerdeJson)?; // log::info!("{:#?}", data); Ok(data) } 

Terminal output: Terminal output

1 Answer 1

1

It looks like you're attempting to deserialize a Vec directly from a JSON map, which won't work.

I would attempt to deserialize AccountSnapshot directly, without the Vec warparound.

Sign up to request clarification or add additional context in comments.

1 Comment

Dear Hammdist, you are right. Thank you very much!. I can not point you because I have not suffice reputation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.