How to alias a crate in Rust 2018 idiomatically?
up vote
4
down vote
favorite
I have a crate foo_sys
. In Rust 2015 I used extern crate foo_sys as foo
for convenience, but in Rust 2018 extern crate
isn't needed anymore and I don't want to use it only for aliasing. When dropping extern crate
, I get
error[E0463]: can't find crate for
foo
rust rust-cargo rust-2018
add a comment |
up vote
4
down vote
favorite
I have a crate foo_sys
. In Rust 2015 I used extern crate foo_sys as foo
for convenience, but in Rust 2018 extern crate
isn't needed anymore and I don't want to use it only for aliasing. When dropping extern crate
, I get
error[E0463]: can't find crate for
foo
rust rust-cargo rust-2018
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I have a crate foo_sys
. In Rust 2015 I used extern crate foo_sys as foo
for convenience, but in Rust 2018 extern crate
isn't needed anymore and I don't want to use it only for aliasing. When dropping extern crate
, I get
error[E0463]: can't find crate for
foo
rust rust-cargo rust-2018
I have a crate foo_sys
. In Rust 2015 I used extern crate foo_sys as foo
for convenience, but in Rust 2018 extern crate
isn't needed anymore and I don't want to use it only for aliasing. When dropping extern crate
, I get
error[E0463]: can't find crate for
foo
rust rust-cargo rust-2018
rust rust-cargo rust-2018
edited Dec 8 at 14:44
asked Jun 23 at 9:03
Tim Diekmann
2,90691633
2,90691633
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
8
down vote
accepted
This can be achieved with the rename-dependency Cargo feature, available in Rust 1.31. With this feature, it's possible to provide a package attribute to the dependencies:
The rename-dependency feature allows you to import a dependency with a different name from the source. This can be useful in a few scenarios:
- Depending on crates with the same name from different registries.
- Depending on multiple versions of a crate.
- Avoid needing
extern crate foo as bar
in Rust source.
Instead of writing
[dependencies]
foo_sys = "0.2"
the package
key can be added to the dependency in Cargo.toml
:
[dependencies]
foo = { package = "foo_sys", version = "0.2" }
add a comment |
up vote
5
down vote
The idiomatic solution is to rename the crate in Cargo.toml
. See the answer by Tim Diekmann for more information about that.
But if you don't want to use Cargo.toml
renaming for some reason, you can still use the old syntax. It's soft-deprecated, but not removed. So this still works:
extern crate foo_sys as foo;
(Playground example)
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
This can be achieved with the rename-dependency Cargo feature, available in Rust 1.31. With this feature, it's possible to provide a package attribute to the dependencies:
The rename-dependency feature allows you to import a dependency with a different name from the source. This can be useful in a few scenarios:
- Depending on crates with the same name from different registries.
- Depending on multiple versions of a crate.
- Avoid needing
extern crate foo as bar
in Rust source.
Instead of writing
[dependencies]
foo_sys = "0.2"
the package
key can be added to the dependency in Cargo.toml
:
[dependencies]
foo = { package = "foo_sys", version = "0.2" }
add a comment |
up vote
8
down vote
accepted
This can be achieved with the rename-dependency Cargo feature, available in Rust 1.31. With this feature, it's possible to provide a package attribute to the dependencies:
The rename-dependency feature allows you to import a dependency with a different name from the source. This can be useful in a few scenarios:
- Depending on crates with the same name from different registries.
- Depending on multiple versions of a crate.
- Avoid needing
extern crate foo as bar
in Rust source.
Instead of writing
[dependencies]
foo_sys = "0.2"
the package
key can be added to the dependency in Cargo.toml
:
[dependencies]
foo = { package = "foo_sys", version = "0.2" }
add a comment |
up vote
8
down vote
accepted
up vote
8
down vote
accepted
This can be achieved with the rename-dependency Cargo feature, available in Rust 1.31. With this feature, it's possible to provide a package attribute to the dependencies:
The rename-dependency feature allows you to import a dependency with a different name from the source. This can be useful in a few scenarios:
- Depending on crates with the same name from different registries.
- Depending on multiple versions of a crate.
- Avoid needing
extern crate foo as bar
in Rust source.
Instead of writing
[dependencies]
foo_sys = "0.2"
the package
key can be added to the dependency in Cargo.toml
:
[dependencies]
foo = { package = "foo_sys", version = "0.2" }
This can be achieved with the rename-dependency Cargo feature, available in Rust 1.31. With this feature, it's possible to provide a package attribute to the dependencies:
The rename-dependency feature allows you to import a dependency with a different name from the source. This can be useful in a few scenarios:
- Depending on crates with the same name from different registries.
- Depending on multiple versions of a crate.
- Avoid needing
extern crate foo as bar
in Rust source.
Instead of writing
[dependencies]
foo_sys = "0.2"
the package
key can be added to the dependency in Cargo.toml
:
[dependencies]
foo = { package = "foo_sys", version = "0.2" }
edited Dec 7 at 0:11
Shepmaster
145k11279413
145k11279413
answered Jul 24 at 23:17
Tim Diekmann
2,90691633
2,90691633
add a comment |
add a comment |
up vote
5
down vote
The idiomatic solution is to rename the crate in Cargo.toml
. See the answer by Tim Diekmann for more information about that.
But if you don't want to use Cargo.toml
renaming for some reason, you can still use the old syntax. It's soft-deprecated, but not removed. So this still works:
extern crate foo_sys as foo;
(Playground example)
add a comment |
up vote
5
down vote
The idiomatic solution is to rename the crate in Cargo.toml
. See the answer by Tim Diekmann for more information about that.
But if you don't want to use Cargo.toml
renaming for some reason, you can still use the old syntax. It's soft-deprecated, but not removed. So this still works:
extern crate foo_sys as foo;
(Playground example)
add a comment |
up vote
5
down vote
up vote
5
down vote
The idiomatic solution is to rename the crate in Cargo.toml
. See the answer by Tim Diekmann for more information about that.
But if you don't want to use Cargo.toml
renaming for some reason, you can still use the old syntax. It's soft-deprecated, but not removed. So this still works:
extern crate foo_sys as foo;
(Playground example)
The idiomatic solution is to rename the crate in Cargo.toml
. See the answer by Tim Diekmann for more information about that.
But if you don't want to use Cargo.toml
renaming for some reason, you can still use the old syntax. It's soft-deprecated, but not removed. So this still works:
extern crate foo_sys as foo;
(Playground example)
edited Dec 7 at 9:01
answered Jun 23 at 9:12
Lukas Kalbertodt
24k252108
24k252108
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50999616%2fhow-to-alias-a-crate-in-rust-2018-idiomatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown