Questions tagged [serde]
Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.
serde
941
questions
0
votes
0
answers
37
views
Serde doesn't see untagged enum variant in input ("data did not match any variant of untagged ...") [duplicate]
Using Serde, I want to parse JSON data like this:
{
"data_type": "uint8",
"scales": [{
"encoding": "jpeg",
"key": "4.0x4....
0
votes
1
answer
56
views
Associate unique identifier with rust function definitions
I have a struct that I would like to serialize to disk as part of a JSON save file format. The (simplified) structure of the struct is like this:
pub struct Effect {
pub source: Source,
pub ...
5
votes
1
answer
126
views
Require a field to be an integer or null, but not missing in JSON
I want to deserialize the following struct using serde_json. The parent_id field should accept an integer or a null, but I want it to return an error if the field is missing.
#[derive(Debug, Serialize,...
1
vote
1
answer
52
views
Serde serialize a HashMap like flatten but keeping the field name of the HashMap
Here is a Rust playground link with what I have so far.
I am working on a Rust project where the serialization/deserialization MUST be interoperable with a C# project. I have these two structs that ...
0
votes
1
answer
76
views
missing field error during deserialization for toml file in rust
I am trying to read the config toml file into a config struct defined locally and I was given this basic error however I wasn't able to see what I have actually missed. I am using the 3rd party crate ...
0
votes
2
answers
101
views
How to deserialize a Map with custom value type in serde?
I have the following json file that I want to deserialize in a Rust struct:
{
"name": "Manuel",
"friends": {
"id1": 1703692376,
...
}
...
}
...
3
votes
1
answer
92
views
How to parse complicated JSON data in rust correctly?
I'm writing my own Magic the gathering implementation in rust as an exercise in (futility and) learning the language and I'm trying to parse the json data into data structures using serde and ...
-1
votes
0
answers
43
views
Getting a error trying to read and write to json in Rust
I'm new to rust and decided to throw myself in the deep end. So I'm currently making a notes taking app in the terminal, and I want to save the notes in json format. But I keep getting this error:
...
1
vote
1
answer
49
views
What serde format should I use to serialize a Hashmap keyed by [u8;32]?
I have data structure I want to save to disk. Just the holdings collection. SsStock is another struct. Currently I'm trying to endoce to cbor which gives a compile time error:
#[derive(Serialize, ...
2
votes
1
answer
126
views
Rust JSON serialization/deserialization with serde/serde_json whilst using generics and lifetimes?
This question is distinct from serde_json with deserialize and lifetimes for generic function because neither from_slice or from_str work, and the error messages are different.
This question is ...
0
votes
1
answer
61
views
Rust TOML reading table and key-value in order
How to read TOML in order?
I have this code:
let toml_content: Value = contents.parse::<toml::Value>().unwrap();
for key in toml_content.as_table().unwrap().keys() {
println!("{:?}&...
1
vote
1
answer
54
views
Deserialize struct containing tag and vector of enums with serde
I have a setup like this
#[derive(Deserialize)]
struct GameData {
game: String,
player_data: Vec<MarioPartyData>,
<more common data>
}
#[derive(Deserialize)]
#[serde(untagged)]...
3
votes
1
answer
103
views
Handling serialization for Surrealdb Rust SDK on relation fields with FETCH clause
I'm having some trouble on finding out the best way to deal with some relations in my Surrealdb project. As you can tell by this question title, I'm using Rust SDK.
I have the following structs on ...
1
vote
1
answer
68
views
serde/rust deserialize JSON into Hashmap
How to properly define the data types such that the JSON de-serialize works fine with Serde/Rust for the following examples? I believe the Hashmap is the culprit somehow. Unable to tell what precisely ...
2
votes
2
answers
103
views
Deserialize json array into existing Vec
I have some function, here called request, that returns a JSON string with some data. For example, an array with variable size. I can deserialize the JSON string into a Vec just fine with serde_json, ...