给菜单做递归数组的反序列化遇到的问题,结构大致如下,报错信息附在文末。
#[derive(Deserialize)]
struct Menu {
title: String,
url: String,
children: Vec<Self>,
}
这是一个类型识别的 bug,参见 issue #1565。
只需要把 children: Vec<Self>,
改成 children: Vec<Menu>,
就可以了,上上周已经有人发了 Pull Request #1830 ,我还没有升级,估计新版已经修复了此问题。
error[E0277]: the trait bound `file::menu::_IMPL_DESERIALIZE_FOR_SiteMenu::<impl common::config::_IMPL_DESERIALIZE_FOR_Menus::_serde::Deserialize<'de> for file::menu::SiteMenu>::deserialize::__Visitor<'de>: common::config::_IMPL_DESERIALIZE_FOR_Menus::_serde::Deserialize<'_>` is not satisfied
--> src\file\menu.rs:13:5
|
13 | children: Vec<Self>,
| ^^^^^^^^ the trait `common::config::_IMPL_DESERIALIZE_FOR_Menus::_serde::Deserialize<'_>` is not implemented for `file::menu::_IMPL_DESERIALIZE_FOR_SiteMenu::<impl common::config::_IMPL_DESERIALIZE_FOR_Menus::_serde::Deserialize<'de> for file::menu::SiteMenu>::deserialize::__Visitor<'de>`
|
= note: required because of the requirements on the impl of `common::config::_IMPL_DESERIALIZE_FOR_Menus::_serde::Deserialize<'_>` for `std::vec::Vec<file::menu::_IMPL_DESERIALIZE_FOR_SiteMenu::<impl common::config::_IMPL_DESERIALIZE_FOR_Menus::_serde::Deserialize<'de> for file::menu::SiteMenu>::deserialize::__Visitor<'de>>`
= note: required by `common::config::_IMPL_DESERIALIZE_FOR_Menus::_serde::de::SeqAccess::next_element`
error[E0308]: mismatched types
--> src\file\menu.rs:9:21
|
9 | #[derive(Serialize, Deserialize, Clone)]
| ^^^^^^^^^^^ expected struct `file::menu::SiteMenu`, found struct `file::menu::_IMPL_DESERIALIZE_FOR_SiteMenu::<impl common::config::_IMPL_DESERIALIZE_FOR_Menus::_serde::Deserialize<'de> for file::menu::SiteMenu>::deserialize::__Visitor`
|
= note: expected struct `std::vec::Vec<file::menu::SiteMenu>`
found struct `std::vec::Vec<file::menu::_IMPL_DESERIALIZE_FOR_SiteMenu::<impl common::config::_IMPL_DESERIALIZE_FOR_Menus::_serde::Deserialize<'de> for file::menu::SiteMenu>::deserialize::__Visitor<'_>>`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)