Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Need to have structopt/serde as peer dependency #9

Open
killercup opened this issue Jan 21, 2018 · 2 comments
Open

Need to have structopt/serde as peer dependency #9

killercup opened this issue Jan 21, 2018 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@killercup
Copy link
Owner

killercup commented Jan 21, 2018

The structopt derive macro doesn't work unless the current project allows extern crate structopt;.

This means, user of quicli must cargo add structopt, which is not that cool.

This is part of this code which expands to something like:

const _IMPL_STRUCTOPT_FOR_Cli: () = {
    extern crate structopt as _structopt;
    use structopt::StructOpt;
    impl _structopt::StructOpt for Cli {

Maybe we can add a feature to either suppress or customize this upstream?


Same is also true for serde! (Thanks to this code)

@killercup killercup changed the title Need to have structopt as peer dependency Need to have structopt/serde as peer dependency Jan 22, 2018
killercup added a commit that referenced this issue Jan 22, 2018
@killercup killercup added the help wanted Extra attention is needed label Jan 22, 2018
@vitiral
Copy link
Contributor

vitiral commented Jan 22, 2018

I'm a bit confused: are you saying that because serde/structopt's derive have macros that themselves have extern crate MYSELF that means that cargo requires the crate to be in Cargo.toml?

Whew... does a workaround for this exist if a fix is made in serde/structopt?

Edit: I see you've opened issues asking that exact question to the authors of those crates.

@killercup
Copy link
Owner Author

Let's say you write a crate called "lorem", which has #[derive(Deserialize)] struct Foo { x: i32 }. The proc macro that of the Deserialize derive generates code that has extern crate serde as serde_; in it. This means that post-expansion your "lorem" crate now has extern crate serde … in it. So the compiler will try to load serde from your dependencies – which only works if serde is in your list of dependencies.

See serde-rs/serde#1147 for a few ideas how to solve this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants