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











share|improve this question




























    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











    share|improve this question


























      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











      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 8 at 14:44

























      asked Jun 23 at 9:03









      Tim Diekmann

      2,90691633




      2,90691633
























          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" }





          share|improve this answer






























            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)






            share|improve this answer























              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',
              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
              });


              }
              });














              draft saved

              draft discarded


















              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

























              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" }





              share|improve this answer



























                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" }





                share|improve this answer

























                  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" }





                  share|improve this answer














                  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" }






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 7 at 0:11









                  Shepmaster

                  145k11279413




                  145k11279413










                  answered Jul 24 at 23:17









                  Tim Diekmann

                  2,90691633




                  2,90691633
























                      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)






                      share|improve this answer



























                        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)






                        share|improve this answer

























                          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)






                          share|improve this answer














                          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)







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Dec 7 at 9:01

























                          answered Jun 23 at 9:12









                          Lukas Kalbertodt

                          24k252108




                          24k252108






























                              draft saved

                              draft discarded




















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                              ComboBox Display Member on multiple fields

                              Is it possible to collect Nectar points via Trainline?