Rust 对于列为已实现的类型,未实现IntoHandlerError

Rust 对于列为已实现的类型,未实现IntoHandlerError,rust,Rust,我有一个类型为std::boxed::Box的错误,我希望能够使用将其转换为可以使用的错误。编译器告诉我: error[E0599]: no method named `into_handler_error` found for type `std::boxed::Box<dyn std::error::Error + std::marker::Send + std::marker::Sync>` in the current scope --> web/src/main

我有一个类型为std::boxed::Box的错误,我希望能够使用将其转换为可以使用的错误。编译器告诉我:

error[E0599]: no method named `into_handler_error` found for type `std::boxed::Box<dyn std::error::Error + std::marker::Send + std::marker::Sync>` in the current scope
   --> web/src/main.rs:112:31
    |
112 |                     (state, x.into_handler_error())
    |                               ^^^^^^^^^^^^^^^^^^ method not found in `std::boxed::Box<dyn std::error::Error + std::marker::Send + std::marker::Sync>`
    |
    = note: the method `into_handler_error` exists but the following trait bounds were not satisfied:
            `&dyn std::error::Error + std::marker::Send + std::marker::Sync : gotham::handler::error::IntoHandlerError`
            `&mut dyn std::error::Error + std::marker::Send + std::marker::Sync : gotham::handler::error::IntoHandlerError`
            `&mut std::boxed::Box<dyn std::error::Error + std::marker::Send + std::marker::Sync> : gotham::handler::error::IntoHandlerError`
            `&std::boxed::Box<dyn std::error::Error + std::marker::Send + std::marker::Sync> : gotham::handler::error::IntoHandlerError`
            `dyn std::error::Error + std::marker::Send + std::marker::Sync : gotham::handler::error::IntoHandlerError`
            `std::boxed::Box<dyn std::error::Error + std::marker::Send + std::marker::Sync> : gotham::handler::error::IntoHandlerError`

两者的区别在于,对象是一个
,impl是一个
&T
。由于
Box
实现了
Deref
,rustc也会在
T
上搜索impl,但不会在
&T
上搜索


您可以使用
&*x
取消引用
并以
&
的形式借用内容,因此请尝试
(&*x).into_handler_error()

嗨,Mike,感谢您的建议,我添加了一个编辑,以显示我得到的错误基本相同。它命名我的类型,并在实现列表中再次给出该名称,但声称两者不相等。该列表是不满足的边界。消息只是说,
Box
没有实现
IntoHandlerError
。就这么简单,当然。我真的是个傻瓜。在某种程度上,我确实知道编译器是这么说的,但出于某种原因,我把它翻了个底朝天,这是一个可以理解的错误。我认为这个错误信息过去是不同的,所以你可能记得旧的格式,它没有列出所有可以满足特质的方式(我不记得确切的细节)。
error[E0599]: no method named `into_handler_error` found for type `&dyn std::error::Error + std::marker::Send + std::marker::Sync` in the current scope
   --> web/src/main.rs:124:45
    |
124 |                 Err(e) => Err((state, (&*e).into_handler_error()))
    |                                             ^^^^^^^^^^^^^^^^^^ method not found in `&dyn std::error::Error + std::marker::Send + std::marker::Sync`
    |
    = note: the method `into_handler_error` exists but the following trait bounds were not satisfied:
            `&&dyn std::error::Error + std::marker::Send + std::marker::Sync : gotham::handler::error::IntoHandlerError`
            `&dyn std::error::Error + std::marker::Send + std::marker::Sync : gotham::handler::error::IntoHandlerError`
            `&mut &dyn std::error::Error + std::marker::Send + std::marker::Sync : gotham::handler::error::IntoHandlerError`
            `&mut dyn std::error::Error + std::marker::Send + std::marker::Sync : gotham::handler::error::IntoHandlerError`
            `dyn std::error::Error + std::marker::Send + std::marker::Sync : gotham::handler::error::IntoHandlerError`