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

Document how to support Serde as an optional library feature #1021

Open
dhardy opened this issue Aug 17, 2017 · 5 comments
Open

Document how to support Serde as an optional library feature #1021

dhardy opened this issue Aug 17, 2017 · 5 comments
Labels

Comments

@dhardy
Copy link

dhardy commented Aug 17, 2017

This is mentioned under feature flags and in the source.

It would be nice to have an example or at least mention under Using derive.

As I understand it, doing so involves this:

serde = { version = "1.0", optional = true, features = ["derive"] }

and this:

#[cfg(feature="serde")]
#[macro_use]
extern crate serde;

and this:

#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
pub struct MyStruct { ...
@dhardy
Copy link
Author

dhardy commented Aug 17, 2017

Related to this is a question about dependency versions; e.g. if Serde 2.0 is ever released, should a library provide serde_1 and serde_2 optional features? Or must all libraries in the dependency chain upgrade their Serde versions at once?

@dtolnay dtolnay added the docs label Aug 17, 2017
@dtolnay
Copy link
Member

dtolnay commented Aug 17, 2017

Crates that want to support multiple Serde versions at once can use https://github.com/serde-rs/legacy.

@WiSaGaN
Copy link
Contributor

WiSaGaN commented Aug 18, 2017

In https://serde.rs/derive.html , it is still suggested to declare serde_derive as a dependency directly if you want to use #[derive(Deserialize, Serialize)]. Should an optional feature derive declaration of serde be prefered?

@dtolnay
Copy link
Member

dtolnay commented Aug 18, 2017

I typically still prefer depending on serde_derive. The re-export from serde is intended for crates that optionally depend on serde and need derive along with it, which is uncommon. Other than that, I don't have a compelling argument in either direction.

@dhardy
Copy link
Author

dhardy commented Aug 18, 2017

which is uncommon

and will remain that way without a clear guide.

Serde Legacy doesn't give much usage guide either. Is it possible to do something like #[derive(serde09::Deserialize)?

Can a library seamlessly migrate from using a single version of Serde to using Serde Legacy to support multiple versions without breaking dependant crates?

Is it likely that Serde 1 will be superseded in the future, or is there a promise never to release another breaking change?

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

No branches or pull requests

3 participants