I have three crates, two lib crates and a binary crate.
The first lib crate A defines a trait in mod inner_a, below are the relevant lines from crate A.
src/lib.rs
pub mod inner_a;
src/inner_a.rs
pub trait DoThings {
fn do_thing_1(&self);
fn do_thing_2();
}
Then in the second lib crate that defines a struct that implies the crate.
crate B src/lib.rs
use A::inner_a::DoThings;
pub struct MyStruct {
pub data: u32
}
impl DoThings for MyStruct {
fn do_thing_1(&self) { println!(self.data); }
fn do_thing_2() { todo!() }
in the binary crate I have
use A::inner_a::DoThings;
use B::MyStruct;
fn use_other_crates(my_struct: &MyStruct) {
my_struct.do_thing_1();
MyStruct::do_thing_2();
}
But I get a compiler error E0599
error[E0599]: no method named do_thing_1
found for struct MyStruct
in the current scope
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a use
for it:
|
1 + use A::DoThing; | For more information about this error, try rustc --explain E0599
.
This error occurs when a method is used on a type which doesn't implement it:
Erroneous code example:
struct Mouth;
let x = Mouth;
x.chocolate(); // error: no method named `chocolate` found for type `Mouth`
// in the current scope
In this case, you need to implement the chocolate
method to fix the error:
struct Mouth;
impl Mouth {
fn chocolate(&self) { // We implement the `chocolate` method here.
println!("Hmmm! I love chocolate!");
}
}
let x = Mouth;
x.chocolate(); // ok!
From what I can tell the trait is public, the struct it is implemented for is public, and there are use statements for both lib crates in the binary crate. So what am I missing?