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

Make serde-derive's implicit peer dependency on serde optional #1147

Open
killercup opened this issue Jan 22, 2018 · 8 comments
Open

Make serde-derive's implicit peer dependency on serde optional #1147

killercup opened this issue Jan 22, 2018 · 8 comments

Comments

@killercup
Copy link
Contributor

So, I have a very weird request. I'm trying to re-export serde-derive in my quicli crate, but since this code

let generated = quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const #dummy_const: () = {
extern crate serde as _serde;
#impl_block
};
};

expands to extern crate serde as _serde, my consumers would have to add serde to their dependencies—which I want to avoid (the selling point of the crate is to only add it as dependency). Is there another option of doing this? E.g., making this part of the derive optional (with a feature flag)?

cc killercup/quicli#9

@oli-obk
Copy link
Member

oli-obk commented Jan 22, 2018

E.g., making this part of the derive optional (with a feature flag)?

Not really. If there's a crate that depends on serde_derive and has the feature flag activated (and your users depend on it), it will be back on, and the users of your crate will again get compilation failures

@killercup
Copy link
Contributor Author

Hm, true. That's really unfortunate, though. I'd love to do this in some way that isn't "fork every proc macro and change stuff to extern crate quicli as serde_;… Do you have any other ideas?

@oli-obk
Copy link
Member

oli-obk commented Jan 22, 2018

Maybe serde_derive can reexport serde and then do use ::serde_derive::_serde;? It's not like it makes any sense to have serde_derive without serde.

@killercup
Copy link
Contributor Author

killercup commented Jan 22, 2018 via email

@dtolnay
Copy link
Member

dtolnay commented Feb 23, 2018

I agree we need a better story here. The url folks want this as well for a slightly different reason -- in their case we would want the macro to refer to serde1::... because serde::... means Serde 0.8 in their codebase. servo/rust-url#327

I expect it will be tricky but perhaps not impossible to have serde_derive re-export and refer to serde. The trouble is serde already optionally re-exports serde_derive and that would be broken by a circular dependency.

@c410-f3r
Copy link
Contributor

c410-f3r commented Jan 4, 2019

Sorry for bothering. Is there any news about this issue?

@jean-airoldie
Copy link

Perhaps a helper attribute could be added to optionally specify the identifier for the serde crate?

use serde as panini;

#[derive(Serialize, Deserialize)]
#[serde(import = "panini")]
struct Key(i32);

The proc_macro would then retrieve the import identifier an use #import instead of _serde.

@dtolnay
Copy link
Member

dtolnay commented Nov 6, 2019

That's implemented as #[serde(crate = "panini")].

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

No branches or pull requests

5 participants