Dan*_*ous 8 rust rust-cargo rust-poem
有时,当您遇到错误时,例如关于其他类型实现特征的错误,您会看到如下错误消息:
error[E0277]: the trait bound `Vec<u8>: ToHeader` is not satisfied
--> src/main.rs:3:35
|
3 | #[derive(Clone, Debug, PartialEq, NewType)]
| ^^^^^^^ the trait `ToHeader` is not implemented for `Vec<u8>`
|
= help: the following other types implement trait `ToHeader`:
&T
Arc<T>
Box<T>
HexEncodedBytes
MaybeUndefined<T>
Uri
bool
f32
and 13 others
= note: this error originates in the derive macro `NewType` (in Nightly builds, run with -Z macro-backtrace for more info)
Run Code Online (Sandbox Code Playgroud)
我如何才能看到上面示例中的其他 13 个?我已经尝试过-vv,但没有成功,并且在帮助消息中看不到任何其他内容。
您可以使用以下代码重现此内容:
# Cargo.toml
[dependencies]
poem = "1"
poem-openapi = "2"
Run Code Online (Sandbox Code Playgroud)
//! src/main.rs
use poem_openapi::NewType;
#[derive(Clone, Debug, PartialEq, NewType)]
pub struct HexEncodedBytes(Vec<u8>);
fn main() {
println!("Hello, world!");
}
Run Code Online (Sandbox Code Playgroud)
没有办法放松检查。这些数字被硬编码到编译器中。
可能有一种方法可以通过打印 rustc 日志(使用跟踪/日志记录工具 - rustc-dev-guide) - 我还没有检查过,但即使这样,它也很可能处于debug需要本地构建 rustc 的级别,所以它可能对你没有帮助(如果你可以在本地构建 rustc,你只需更改数字即可)。
因此,您最好遵循该特征的文档。rustdoc 有一些用于实现该特征的类型的部分。