sunfishcode / eyra

Rust programs written entirely in Rust
Other
765 stars 12 forks source link

Eliminate the need for `extern crate eyra;` #5

Closed sunfishcode closed 1 year ago

sunfishcode commented 1 year ago

Here's a fun trick. If we have Eyra re-export std, then users can use it as std = { package = "eyra", version = "..." }, which takes over the implied extern crate std;, so it gets pulled in without users having to add any extra code to their source files.

The result is, extern crate eyra; is no longer needed!

One downside is that there's no flag to cargo add for adding the package = "eyra" part, so it is necessary to add that dependency by hand. On the other hand, it means you don't need to edit src/main.rs by hand. Or examples/* and tests/* and so on. So now we're down to just two edits needed to use Eyra.

The extern crate eyra; approach still works. But overall this new approach seems convenient enough to present it as the default.

sunfishcode commented 1 year ago

And, just after posting that, I found cargo add --rename. So we can still use cargo add!