|
| 1 | +- Feature Name: boil_down_externs |
| 2 | +- Start Date: 2017-01-26 |
| 3 | +- RFC PR: (leave this empty) |
| 4 | +- Rust Issue: (leave this empty) |
| 5 | + |
| 6 | +# Summary |
| 7 | +[summary]: #summary |
| 8 | + |
| 9 | +This RFC proposes to change the current `extern crate` syntax to allow |
| 10 | +for multiple crates to be listed. |
| 11 | + |
| 12 | +# Motivation |
| 13 | +[motivation]: #motivation |
| 14 | + |
| 15 | +This proposes will improve the ergonomics of the Rust language for |
| 16 | +projects that have many dependencies. |
| 17 | + |
| 18 | +# Detailed design |
| 19 | +[design]: #detailed-design |
| 20 | + |
| 21 | +Implementation would take the current `extern crate` but allow a list of |
| 22 | +crates instead of a single crate. A single create would just be a single |
| 23 | +list item. |
| 24 | + |
| 25 | +Example: |
| 26 | +``` |
| 27 | +extern crate { |
| 28 | + rocket, rocket_contrib, serde_json as json, chrono, |
| 29 | + dotenv, postgres, r2d2, r2d2_diesel, tera as template, |
| 30 | + serde_derive, toml, glob |
| 31 | +}; |
| 32 | +``` |
| 33 | + |
| 34 | +``` |
| 35 | +pub extern crate {rocket, rocket_contrib}; |
| 36 | +``` |
| 37 | + |
| 38 | +Meta items before the `extern` ie. `#[macro_use]` would be applied to |
| 39 | +all crates listed. |
| 40 | + |
| 41 | +Example: |
| 42 | +``` |
| 43 | +#[macro_use] |
| 44 | +extern crate {diesel, diesel_codegen, lazy_static, serde_derive}; |
| 45 | +``` |
| 46 | + |
| 47 | +Duplicate externs would error like it does currently. |
| 48 | + |
| 49 | +# How We Teach This |
| 50 | +[how-we-teach-this]: #how-we-teach-this |
| 51 | + |
| 52 | +No new names or terminology needed to teach this. Examples should be |
| 53 | +updated to include the list syntax. |
| 54 | + |
| 55 | +Examples in both books, The Rust Programming Language and Rust by |
| 56 | +Example, should be updated where more then one crate is used. A small |
| 57 | +section should be added to http://rustbyexample.com/crates.html |
| 58 | + |
| 59 | +rustfmt should have an opinion how to format the list of crates as well. |
| 60 | + |
| 61 | +# Drawbacks |
| 62 | +[drawbacks]: #drawbacks |
| 63 | + |
| 64 | +1. Adds multiple ways to do things to a language. |
| 65 | +2. Diffs can mask changes in lists. |
| 66 | +3. Would be replaced buy future improvements to crate ecosystem |
| 67 | +4. Differing opinions on `extern crate` and it's relationship to `mod` |
| 68 | + |
| 69 | +# Alternatives |
| 70 | +[alternatives]: #alternatives |
| 71 | + |
| 72 | +A crate could be release with a macro. Like the example but one that supports meta values. |
| 73 | + |
| 74 | +``` |
| 75 | +macro_rules! externs { |
| 76 | + ( $( $x:ident ),* ) => { |
| 77 | + $( |
| 78 | + extern crate $x; |
| 79 | + )* |
| 80 | + }; |
| 81 | +} |
| 82 | +externs![rocket, rocket_contrib, serde_json] |
| 83 | +``` |
| 84 | + |
| 85 | +Supporting meta values could be an issue with the macro. |
| 86 | +Recursion could also be an issue. [Details discussed |
| 87 | +here](https://botbot.me/mozilla/rust-internals/2017-01-29/?msg=80105364&page=1) |
| 88 | + |
| 89 | +# Unresolved questions |
| 90 | + |
0 commit comments