Skip to content

2.3.0 breaks HashMap serialization as Vec of pairs with bincode #570

@stefunctional

Description

@stefunctional

HashMap serialization as Vec of pairs with bincode that worked with serde_with 2.2.0 breaks with 2.3.0.

Reproduction

Cargo.toml:

[package]
name = "playground"
version = "0.1.0"
edition = "2021"

[dependencies]
bincode = "1.3.3"
serde = { version = "1.0.154", features = ["derive"] }
serde_with = "=2.3.0"

src/lib.rs:

use serde::Serialize;
use serde_with::serde_as;
use std::collections::HashMap;

#[serde_as]
#[derive(Debug, Default, Serialize)]
struct Foo {
    #[serde_as(as = "Vec<(_, _)>")]
    xs: HashMap<i32, i32>,
}

fn main() {
    bincode::serialize(&Foo::default()).unwrap();
}

Expected output

cargo run passes with no output.

Actual output

cargo run fails with:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SequenceMustHaveLength', src/main.rs:13:41

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions