Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization issue #18

Open
Shatur opened this issue Aug 13, 2022 · 0 comments
Open

Serialization issue #18

Shatur opened this issue Aug 13, 2022 · 0 comments

Comments

@Shatur
Copy link

Shatur commented Aug 13, 2022

Consider the following Cargo.toml:

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

[dependencies]
toml_edit = { version = "0.14", features = ["easy"] }
serde = "1.0"
petitset = {version = "0.2", features = ["serde_compat"]}

and the following code with HashSet:

use std::collections::HashSet;

use serde::Serialize;

#[derive(Serialize)]
struct Bar {
    foo: HashSet<Foo>,
}

#[derive(Serialize, Hash, PartialEq, Eq, Clone, Copy)]
enum Foo {
    #[serde(rename = "hello")]
    Hello,
}

fn main() {
    let mut foo = HashSet::new();
    foo.insert(Foo::Hello);
    let bar = Bar {
        foo,
    };
    println!("{}", toml_edit::ser::to_string(&bar).unwrap());
}

It prints foo = ["hello"].

But with PetitSet:

use petitset::PetitSet;
use serde::Serialize;

#[derive(Serialize)]
struct Bar {
    foo: PetitSet<Foo, 3>,
}

#[derive(Serialize, Hash, PartialEq, Eq, Clone, Copy)]
enum Foo {
    #[serde(rename = "hello")]
    Hello,
}

fn main() {
    let mut foo = PetitSet::new();
    foo.insert(Foo::Hello);
    let bar = Bar {
        foo,
    };
    println!("{}", toml_edit::ser::to_string(&bar).unwrap());
}

it prints nothing. Is this expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant