'How to import types defined in root into a submodule? [duplicate]
If I have a project with a workspace that has the following directory structure, and I have a requirement to pass a type defined in foo/lib.rs to a function argument defined in bar/some_file.rs, how can I pass the type to a submodule?
foo
|_ foo
| |_ main.rs
| |_ lib.rs
|_ Cargo.toml
|_ bar
|_ src
| |_ lib.rs
| |_ some_file.rs
|_ Cargo.toml
For example:
In foo/lib.rs,
pub struct Foo {
foo: usize,
bar: String,
}
and in bar/some_file.rs
pub fn baz(f: Foo) {
// some code
}
And Cargo.toml file looks like this
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[workspace]
members = ["bar"]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
