How to idiomatically alias a crate in 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
add a comment |
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 |
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 13 '18 at 23:25
Shepmaster
160k16327471
160k16327471
asked Jun 23 '18 at 9:03
Tim DiekmannTim Diekmann
3,12291937
3,12291937
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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 |
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 |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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-idiomatically-alias-a-crate-in-rust-2018%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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 '18 at 0:11
Shepmaster
160k16327471
160k16327471
answered Jul 24 '18 at 23:17
Tim DiekmannTim Diekmann
3,12291937
3,12291937
add a comment |
add a comment |
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 |
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 |
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 '18 at 9:01
answered Jun 23 '18 at 9:12
Lukas KalbertodtLukas Kalbertodt
26.7k258122
26.7k258122
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.
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-idiomatically-alias-a-crate-in-rust-2018%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