Questions tagged [serde]

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

Site

Repository

crates.io

839 questions
0
votes
1 answer

Save/load of struct works or fails depending on member vector length

I have defined the following structs with custom load/save methods using serde and bincode: use std::{ fs::File, io::{Read, Seek, SeekFrom, Write}, }; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Serialize, Deserialize)] pub…
Foveng
  • 47
  • 5
0
votes
1 answer

How to detect tcp disconnected in tokio sink item in tokio-serde library?

I've found a library named tokio-serde which will send and receive data using tokio tcp socket and serialize and deserialize that using serde json. There is two examples which will show how you can create a server and a client using this lib. In…
Amoo Hesam
  • 461
  • 3
  • 13
0
votes
1 answer

Can rust and serde-xml-rs parse comments from XML files?

100 I would like to get the comment from an XML file and was wondering if that was possible and if so how? I didn't see an example of that. In the above example, i…
mike
  • 167
  • 2
  • 6
0
votes
1 answer

Can't write field to MongoDB document if using skip_serialize serde attribute in Rust

I want to be able to write a field into a mongo document, but avoid serializing it when passing the object as a response to the client. I tried using #[serde(skip_serializing)]. However, it doesn't work as I intended, which I think is because when…
0
votes
1 answer

Resolving external string references ( IDs / "foreign keys" ) to structs present elsewhere in the same document, at deserialization time, with serde

I have Context objects - essentially a join record between a Cluster and a User - in a kubernetes config yaml ( ~/.kube/config ) i'd like to parse in to a struct that looks something like this: struct Context { name: String, cluster: Cluster, …
pgn
  • 669
  • 1
  • 6
  • 16
0
votes
0 answers

How can you use the Serialization and Deserialization macros on things you don't define?

Rust provides a Serialize and Deserialize macro which are applied by decorating the struct you're defining with #[derive(Serialize)] and #[derive(Deserialize)]. How do I apply these macros if I'm not defining the struct? Like let's say I have, use…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
0
votes
0 answers

Custom Serde Deserializer for JSON with Inconsistent Field Names in Rust

I'm trying to make a deserializer for the FullOrder struct from the CEX.IO exchange (https://cex.io/rest-api#/definitions/FullOrder). It unfortunately doesn't contain a consistent definition, and has fields as labelled below: ta:{symbol2} string …
AdmiralJonB
  • 2,038
  • 3
  • 23
  • 27
0
votes
1 answer

Using `DeserializedOwned` trait in a oneshot channel: object safety error

The following code: trait ClientResponse: DeserializeOwned + Send + Sized {} struct ClientMsg { ... resp: oneshot::Sender> } async fn client_thread(rx: mpsc::Receiver, client: reqwest::Client, base_url:…
jeanluc
  • 1,608
  • 1
  • 14
  • 28
0
votes
1 answer

Can I send an RMPV `Value` back to rmp_serde for deserialization?

I have a large, somewhat complicated data structure that I can serialize and deserialize with serde and rmp-serde, but I find that deserialization is quite slow. I think this is because my data structure includes two rather large HashMaps. I don't…
user655321
  • 1,572
  • 2
  • 16
  • 33
0
votes
1 answer

Serializing a Vec to CBOR byte string in Rust using serde_cbor

I want to encode Vec as CBOR byte string using serde_cbor. I tried the following code: use serde_cbor::{to_vec} let data = vec![0x01, 0x23, 0x45, 0x67, 0x89, 0xab]; let encoded_data = to_vec(&data)?; println!("encoded_data: {:x?}",…
Stefan
  • 83
  • 8
0
votes
1 answer

How do I pass a type bounded by a trait to Serde's deserialize_with?

A type satisfying MyTrait is supposed to be passed to deserialize_data specified by deserialize_with. Here is my sample code: use serde::{Deserialize, Deserializer}; // 1.0.117 use serde_json; // 1.0.59 type Item = Result
bruceyuan
  • 421
  • 1
  • 3
  • 8
0
votes
1 answer

How do I decouple wasm specific macros from functions and structs

I've got some core functionality, primarily an algorithm that i'm trying to reuse in web assembly and java. I'm using wasm-bindgen and serde, I notice that wasm-bindgen and serde is tightly coupled to my algorithm via the use of attributes. i.e;…
Grant
  • 446
  • 6
  • 24
0
votes
1 answer

How do I deserialize a configuration value from an environment variable as a Vec?

I'm trying to use Rust's config crate to handle a config struct that includes a field with type Vec. I can define my struct and everything compiles, but I can't seem to set the value using an environment variable - it seems like the default…
Greg Owen
  • 947
  • 8
  • 19
0
votes
1 answer

How to annotate code to generate artifacts during compilation?

I have a configuration struct like this: pub struct Configuration { flag1: bool, flag2: String, flag3: i32, flag4: String } I want to generate a configuration file template that users can edit with values. I will allow users to pass…
Avba
  • 14,822
  • 20
  • 92
  • 192
0
votes
1 answer

Deserializing a String with into_serde makes the app panick

With a friend of mine, we're trying to use the serde_json crate to deserialize some message sent by a WebSocket. We are having a specific error, and we managed to recreate it with the following snippet of code: use serde::{Deserialize,…
nugetchar
  • 172
  • 1
  • 3
  • 17