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

Eliminate the need for extern crate eyra; #5

Merged
merged 3 commits into from
Oct 2, 2023
Merged

Conversation

sunfishcode
Copy link
Owner

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.

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
Copy link
Owner Author

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

And clarify that Eyra needs Nightly Rust, Linux, and only supports
some architectures.
@sunfishcode sunfishcode merged commit 331e836 into main Oct 2, 2023
5 checks passed
@sunfishcode sunfishcode deleted the sunfishcode/be-std branch October 2, 2023 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant