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

Serialize/Deserialize WeightedIndex<T> is not enabled with feature "serde1" #967

Closed
CGMossa opened this issue Apr 24, 2020 · 4 comments
Closed

Comments

@CGMossa
Copy link
Contributor

CGMossa commented Apr 24, 2020

Common issues

Problem: WeightedIndex<T> is not serializeable.

Quick solution: Skipping it, but even using rand = {version = "0.7.3", features = ["serde1"]}
didn't amend the issue.

Details: I am curious as to whether it is possible to make this a Serialize/Deserialize pairing.
If so, would be happy to provide a PR.

@dhardy
Copy link
Member

dhardy commented Apr 24, 2020

Yes, I believe that's just an oversight.

A PR would be welcome. Note that master now has breaking changes since 0.7.

@CGMossa
Copy link
Contributor Author

CGMossa commented Apr 24, 2020

I tried a little bit, and faced an issue already. I need to add Serialize and Deserialize to the impl-block of WeightedIndex, but then this is not possible unless I include serde as a dependency.

Do you know how I can make a gated (with maybe cfg?) that enables me to add constraints if a feature is selected?

@dhardy
Copy link
Member

dhardy commented Apr 24, 2020

Ah, this is beacuse:

Cargo.toml
27:serde1 = [] # does nothing, deprecated

this used to be a dependency of Rand but is no longer. In contrast:

rand_core/Cargo.toml
24:serde1 = ["serde"] # enables serde for BlockRng wrapper
27:serde = { version = "1", features = ["derive"], optional = true }

@newpavlov @vks I think we can make serde a dependency again?

@vks
Copy link
Collaborator

vks commented Aug 1, 2020

Fixed with #974.

@vks vks closed this as completed Aug 1, 2020
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

3 participants