simd-json
simd-json copied to clipboard
Incorrect handling of enums
Code:
use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
struct MyStruct {
field: [i32; 2]
}
#[derive(Debug, Serialize, Deserialize)]
enum MyEnum {
First(MyStruct),
Second(Box<[u8; 2]>)
}
fn main() {
let thing = MyEnum::First(MyStruct {field: [-1, -2]});
let mut ser = simd_json::serde::to_string(&thing).unwrap();
let des: MyEnum = simd_json::serde::from_str(&mut ser).unwrap();
println!("Got {:?}", des);
}
Cargo.toml:
[package]
name = "simd_json_serde_bug"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = { version = "1.0.144", features = ["derive"] }
simd-json = { version = "0.6.0", features = ["serde"] }
Output:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { index: 0, character: '💩', error: Serde("invalid type: map, expected enum MyEnum") }', src\main.rs:17:60
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\simd_json_serde_bug.exe` (exit code: 101)