Question about internal crates import

I have a root crate, which contains two crates, one of which contains multiple crates. I import an crate but error in the outermost layer. Is this not allowed for cargo

| |
| |_crate_a_1
| | |__Cargo.toml
| |
| |_crate_a_2
| | |__Cargo.toml
| |
| |__Cargo.toml
| |

Test Cargo.toml file:

members = [
    "crate_a/crate_a_1 ",
    "crate_a/crate_a_2 ",
    "crate_a/crate_b ",

I also try to crate_a Add Cargo.toml configures the workspace, but the outermost workspace does not recognize it

I haven't seen such a configuration in books, materials and many crates. Is it not supported

By the way, the readability of this tree structure is too poor. If the community has a setting that supports tree directory structure, it will be very convenient

It's 04:07 in the morning. It seems that I have to go to bed. If anyone understands, please explain it for me. Thanks

I don't think it makes sense to have a crate be a member of more than one workspace. Quoting the rust book "A workspace is a set of packages that share the same Cargo.lock and output directory."

What is your goal with this arrangement? Workspaces aren't all that common, and I would guess from what you're describing that what you want might be a single crate with multiple modules.


Are you wanting nested workspaces? They aren't supported as of yet. There are some workarounds. Your exact situation will be more clear if you share your Cargo.toml contents.

If you have/install the tree command [1], you can run that [2] and paste its output into a ```text block.

├── Cargo.lock
├── Cargo.toml
└── src
|-- Cargo.lock
|-- Cargo.toml
`-- src

  1. on a unix-like anyway ↩ī¸Ž

  2. or tree -I target or maybe tree -I target --charset ascii if you have a non-UTF locale ↩ī¸Ž


Yep, I changed my thinking. I pulled out the main parts and put them in the root directory, Thanks

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.