In Rust tests, how to assert_eq some json that keeps reordering its keys

My Rust lib does some operations on JSON, and in unit tests I need to ensure the correctness of the lib. Yet, json to string conversion keeps key order unstable. I do NOT want to modify the lib to include json sorting, but I do need to compare the results effectively in my unit tests.… Read More In Rust tests, how to assert_eq some json that keeps reordering its keys

How to return an error from `deserialize`?

When implementing Deserialize, how to return an error? impl<‘de> Deserialize<‘de> for Response { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<‘de> { … // Which error to return here? } } Here every error must be convertible to D::Error, but D::Error maybe any whatsoever type. So, I cannot create a type convertible to D::Error.… Read More How to return an error from `deserialize`?

Serde deserialize String into u64

I can’t find how to deserialize a JSON string into an integer type using serde. My attempt won’t compile: #[derive(Debug, Deserialize)] struct WebsocketMessage { #[serde(deserialize_with = "str::parse")] timestamp: u64 } >Solution : Well, str::parse simply doesn’t have the right type. The type must be fn<‘de, D>(D) -> Result<T, D::Error> where D: Deserializer<‘de> as documented here.… Read More Serde deserialize String into u64

Rust Deserialization Lifetimes Problem : 'de must outlive 'a

I have the following two structs for which I derive serde traits. use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize)] pub struct Item<‘a> { pub id: &’a str, pub name: &’a str } #[derive(Serialize, Deserialize)] struct Set<‘a> { items: Vec<Item<‘a>> } When I try to compile this, I am getting am getting the following error message to ensure… Read More Rust Deserialization Lifetimes Problem : 'de must outlive 'a

Unable to parse graphql endpoint

I am trying to parse the response to a graphql endpoint using this code: extern crate serde_derive; use gql_client::Client; use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] pub struct DevActivity { pub data: Data, } #[derive(Debug, Serialize, Deserialize)] pub struct Data { #[serde(rename = "getMetric")] pub get_metric: GetMetric, } #[derive(Debug, Serialize, Deserialize)] pub struct GetMetric { #[serde(rename… Read More Unable to parse graphql endpoint

Comparing 2 HashMap with Key as String and Value as UserDefined Object

I want to output a boolean as true indicating both maps have same Key and values. If i use equals() it returns false. How can i output as true , Object references are different. But the entries are same I have 2 maps below Map<String,Information> map1=new HashMap<>(); map1.put("key1", new Information("10","20","30","40")); map1.put("key2", new Information("11","22","33","44")); Map<String,Information> map2=new… Read More Comparing 2 HashMap with Key as String and Value as UserDefined Object

Parsing Yaml file

For the last 3 days now, I tried to figure out how to parse my yaml in Rust. And I can’t figure out why it doesn’t work. My Yaml: default_verbosity: 0 logging: use_color: True, log_color: fatal: Red, error: Red, warn: Red, info: Green, debug: Blue, trace: Yellow log_output: file, file_location: "example.log" rocket: mount_location: "/", port:… Read More Parsing Yaml file