How to use a local unpublished crate?

后端 未结 2 987
一向
一向 2020-11-28 23:13

I\'ve made a library:

cargo new my_lib

and I want to use that library in a different program:

cargo new my_program --bin
         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 23:33

    Add a dependency section to your executable's Cargo.toml and specify the path:

    [dependencies.my_lib]
    path = "../my_lib"
    

    or the equivalent alternate TOML:

    [dependencies]
    my_lib = { path = "../my_lib" }
    

    Check out the Cargo docs for specifying dependencies for more detail, like how to use a git repository instead of a local path.

提交回复
热议问题