【发布时间】:2018-12-31 13:52:27
【问题描述】:
我正在尝试实现Tree 结构,但每当我尝试运行以下代码时,我都会收到错误消息:
fn main() {
let tree = Tree::create(1, |_| Vec::new());
println!("{:?}", tree);
}
#[derive(Debug)]
struct Tree<T> {
value: T,
children: Vec<Tree<T>>,
}
impl<T> Tree<T> {
fn create<F>(value: T, get_children: F) -> Tree<T>
where
F: Fn(&T) -> Vec<T>,
{
let children = get_children(&value);
Tree {
value,
children: children
.into_iter()
.map(|x| Tree::create(x, |y| get_children(y)))
.collect(),
}
}
}
错误:
error: reached the type-length limit while instantiating `<std::vec::IntoIter<i32> as std::iter::Iterator>::map::<Tree<i32...`
|
= note: consider adding a `#![type_length_limit="2097152"]` attribute to your crate
【问题讨论】:
标签: rust