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
-1
votes
1 answer

Rust deserialize Vec of u32 to Vec of enum

I'm looking for a good way to deserialize a Vec of u32 to a Vec of enum. So basically I'm receiving a json object like this: { "Account": "r...", "Flags": 20, ... } The struct I'm trying to deserialize it into looks something like…
-1
votes
1 answer

How to deserialize csv based on line format

I have a csv without headers that can have lines in these three following formats: char,int,int,string,int char,int,string char The first character defines the format and be one of the values (A,B,C) respectively. Does anyone know a way to…
ES04r3s
  • 29
  • 2
-1
votes
1 answer

Owned variable seems to not issue a borrow that lives as long as required by a serde deserialize lifetime

I am trying to write a trait that allows for gzip encode/decode of arbitrary (de)serializable structs. My primary use case is to persist some stateful struct on disk via a clean API. To that end, any time a struct S implements serde's Serialize and…
Aalekh Patel
  • 1
  • 1
  • 1
-1
votes
1 answer

How to return struct in Rust without 'use of moved value' error?

I think the problem I'm running into with this code is that the struct I'm trying to return has variables that are strings. Currently I am querying an InfluxDB database and storing the result in the result variable. The print line towards the bottom…
reeslabree
  • 127
  • 13
-1
votes
1 answer

Borrow checker problems with serde-reflection

I'm trying to use serde-reflection to create a JSON structure explaining the struct structure in order to transfer and receive structs as JavaScript an ArrayBuffer and then de-serialize that into a JavaScript Object in the browser. I want a way to…
tirithen
  • 3,219
  • 11
  • 41
  • 65
-1
votes
1 answer

how to not deserialize a specific field

I'm working on a wrapper for a spec called Appstream which consists of an XML file that describes a package to a software center. I have been struggling with how can I handle a case like this one, the sepc allows you to set a description tag similar…
-1
votes
1 answer

Why must a I specify a lifetime when using a generic type reference in Rust?

I am implementing Rust's TryFrom trait for a serde_json::value::Value reference, and a function that generically converts a Vec into a Vec, where T implements TryFrom<&Value>. Because I must specify a lifetime for the Value reference in my…
-2
votes
1 answer

Serde and Reqwest gives weird body

I am trying to turn a object into json with serde so I can post it reqwest. However, it doesn't seem to turn into proper json when I do what I believe I have to do. I have the struct Order: #[derive(Serialize, Deserialize, Clone, Debug)] pub struct…
RavenMan
  • 73
  • 1
  • 8
-2
votes
1 answer

Rust: write vec of structs to file and then read them in again

How do you efficiently save data to disk in Rust? I have a vec of ~100m structs in rust. I'd like to write them to a file that isn't too large and then read them again. I'd like to do this as fast as possible. I'm overwhelmed by the plethora of…
Test
  • 962
  • 9
  • 26
-2
votes
1 answer

Rust Serialize and Deserialize toml

I'm getting a very useless error from serde. No matter what I do I can't seem to get this toml file to be put in the structs. My toml file: [[list]] host = "127.0.0.1:8080" [[list.server_options.Static]] dir = "somedir" error_page =…
Rick
  • 3
  • 2
-2
votes
1 answer

Deserializing a struct with custom data types

I am trying to #[derive(Deserialize, Serialize)] some structs that involve other custom structs, so I can transform them in and out of JSON, for example: #[derive(Debug, Clone, Copy, Deserialize, Serialize)] pub struct Exercise { …
Zusier
  • 9
  • 1
  • 4
-2
votes
2 answers

Trying to loop over JSON keys

i have been wondering how to solve the following problem. you have a JSON like this and you parse using serde. { "student_name": "this guy", "subjects": [{"Chemistry": 0}, {"Politics": 0}, {"Biology": 0}, …
ImEsteban
  • 63
  • 2
  • 5
-3
votes
1 answer

Parsing a valid json string by serde will cause an error - "trailing characters"

I have a Rust library and Ruby project. I call a Rust function from Ruby via FFi. There's a function in the Rust library that receives a string and converts it into json. Ruby side: my_json_raw_str = { network: { server_address:…
-4
votes
1 answer

Convert all u64 values in JSON to string

I want to write a function in Rust that can parse a JSON string and output a modified JSON with all the number fields converted to string. All other fields should be unchanged. Structure of the JSON string is not known in advance. Here's the desired…
onyb
  • 68
  • 2
  • 4
1 2 3
55
56