#320·paperclip

添加对 `Box<T>` 的支持

作者: ManevilleF创建于 2021年5月5日更新于 2025年2月21日

如果我有以下结构体:

#[derive(Debug, Serialize, Deserialize, Apiv2Schema)]
pub struct Foo {
     pub elements: Vec<Box<Foo>>,
}

我会得到以下错误:

9 | #[derive(Debug, Serialize, Deserialize, Apiv2Schema)]
  |                                         ^^^^^^^^^^^ function or associated item cannot be called on `std::vec::Vec<std::boxed::Box<Foo>>` due to unsatisfied trait bounds
  |
  = note: the following trait bounds were not satisfied:
          `&std::vec::Vec<std::boxed::Box<Foo>>: paperclip::v2::schema::TypedData`
          which is required by `&std::vec::Vec<std::boxed::Box<Foo>>: paperclip::v2::schema::Apiv2Schema`
          `&mut std::vec::Vec<std::boxed::Box<Foo>>: paperclip::v2::schema::TypedData`
          which is required by `&mut std::vec::Vec<std::boxed::Box<Foo>>: paperclip::v2::schema::Apiv2Schema`
  = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error

我认为问题来自 Box 部分,因为 Vec<T> 通常会正确处理。我将尝试查看核心代码,看看是否可以打开一个 Pull Request,但如果有人知道如何解决这个问题,我会很乐意接受。

内容来源: paperclip-rs/paperclip