Cannot find method or associated constant `join` in `std::thread::JoinHandle`

Viewed 61
pub type RunnableJoinHandle = Box<dyn RunnableJoinHandleTrait>;
pub trait RunnableJoinHandleTrait {
    fn join(self) -> Result<(), ()>;
}
impl RunnableJoinHandleTrait for std::thread::JoinHandle<()> {
    fn join(self) -> Result<(), ()> {
        <Self as std::thread::JoinHandle<()>>::join(self)
    }
}

Error:

error[E0576]: cannot find method or associated constant `join` in `std::thread::JoinHandle`
 --> src/lib.rs:7:48
  |
7 |         <Self as std::thread::JoinHandle<()>>::join(self)
  |                                                ^^^^ not found in `std::thread::JoinHandle`

but clearly the method exists https://doc.rust-lang.org/stable/std/thread/struct.JoinHandle.html#method.join

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=fdf0883c23805adcae4b3ca4337e386c

1 Answers

JoinHandle isn't a trait, so full qualified trait syntax isn't applicable. Invoke the method directly, without the fully qualified trait syntax:

std::thread::JoinHandle::join(self).unwrap()

The error message is certainly bad.

Related