Skip to content

Commit cb868d6

Browse files
committed
RFC: Boil Down Externs
Dearest Reviewer, I hope all is well. I have been enjoying rust immensely. Recently I was working on converting an old ruby project to rust. I was adding my 20ish crate to my project and after scrolling down I thought, "Do I need all the `extern crate` lines?". I set out by making a macro, my first, which was easy and fun. I posted my macro to reddit wondering if I had missed something. After many great comments someone suggested an rfc with a wink face[1](https://www.reddit.com/r/rust/comments/5q7ssv/long_list_of_externs/). I figured why not. I wrote up this start and then went over to [internals.rust-lang.org](https://internals.rust-lang.org/t/pre-rfc-boil-down-externs/4676). Here I received advice on syntax and missing cases to my rfc. Excellent feedback again! I hope its considered to allow one line of `extern crate` to accept many crates. I understand completely if it is not. Thanks again Becker
1 parent 849ca2f commit cb868d6

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

text/0000-boil-down-externs.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

Comments
 (0)