我将 error-chain
引入了一个以前工作的应用程序。错误本身很明显,std::error::Error + 'static
缺少 trait std::marker::Send
的实现:
error[E0277]: the trait bound `std::error::Error + 'static: std::marker::Send` is not satisfied
--> src/main.rs:35:5
|
35 | / error_chain!{
36 | |
37 | | foreign_links {
38 | | Mqttc(::mqttc::Error);
... |
53 | | }
54 | | }
| |_____^ `std::error::Error + 'static` cannot be sent between threads safely
|
= help: the trait `std::marker::Send` is not implemented for `std::error::Error + 'static`
= note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<std::error::Error + 'static>`
= note: required because it appears within the type `std::boxed::Box<std::error::Error + 'static>`
= note: required because it appears within the type `mqttc::netopt::Error`
= note: required because it appears within the type `mqttc::Error`
= note: required because it appears within the type `errors::ErrorKind`
= note: required because it appears within the type `errors::Error`
= note: required by `error_chain::ChainedError`
= note: this error originates in a macro outside of the current crate
我不知道如何解决这个问题。请注意,我使用的是更多 up to date fork of mqttc/mqtt3
而不是上游箱子。
最佳答案
mqttc::Error
包含 mqttc::netopt::Error
,它又包含一个 Box<std::error::Error>
(它脱糖为 std::boxed::Box<std::error::Error + 'static>
。std::error::Error
这里是一个特征对象。因为 Error
特征没有 Send
作为超特征, Error
的实现不需要实现 Send
。因此, Box<std::error::Error>
没有实现 Send
因为不是所有类型 T: std::error::Error
都实现 Send
。
这可以通过更改 mqttc::netopt::Error
来解决。要使用的类型 Box<std::error::Error + Send>
而不是 Box<std::error::Error>
(这对图书馆来说是一个重大改变)。
关于multithreading - 多线程应用程序无法使用错误链进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46491293/