Include structs from another project

UPDATE:
The problem is solved by moving extern crate my_library; into my_project/src/lib.rs.

===================================================================================
I have two projects with the following structures:

. my_library
  ├── Cargo.toml
  └── src
      └── lib.rs
      └── client.rs
      └── server.rs
. my_project
├── Cargo.toml
└── src
    └── client
        └── mod.rs
    └── db
        └── mod.rs

I want to include structs/functions from my_library in my_project/src/client/mod.rs and my_project/src/db/mod.rs.

  • lib.rs defines struct MyQuery and struct MyReply.
  • client.rs defines struct MyClient.
  • server.rs defines struct MyServer.
  • Within lib.rs it has pub mod client; pub mod server;

Following the answer here https://stackoverflow.com/questions/45519176/how-do-i-use-or-import-a-local-rust-file, I added the path of my_library into my_project/Cargo.toml and tried the following:

extern crate my_library;
use my_library::client::MyClient;
use my_library::server::MyServer;
use my_library::MyQuery;
use my_library::MyReply;

Then the compiler throws out error:

error[E0433]: failed to resolve: unresolved import
help: a similar path exists: client::my_library

What would be the correct way to import?

My understanding : as of Rust 2018 you don't need to use extern at all. I haven't ever used it. See

https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html

Thanks for the reply. I'm working on two old projects, so I use extern for consistency.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.