在`std :: thread :: joinhandle`中都找不到方法或关联的常数`join``

发布于 2025-02-10 12:57:02 字数 1182 浏览 1 评论 0 原文

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[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`

但是很明显,该方法存在

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以畏孤独 2025-02-17 12:57:02

JoinHandle 不是一个特征,因此不适用完整的合格特征语法。直接调用该方法,而没有完全限定的特质语法:

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

错误消息当然不好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文