小编Blu*_*ion的帖子

在没有生命周期参数的类型上限制实现生命周期的问题

我正在尝试在 Rust 中实现 BST(对于 Rust 的可爱介绍中的 HW3 ,并且我遇到了生命周期错误,以及如何约束与没有生命周期的类型相关的类型的生命周期。

#[derive(Debug)]
pub struct BST<T>
    where T: Ord
{
    root: Option<Box<Node<T>>>,
}

// A couple dozen lines of BST stuff

impl<'a, T> IntoIterator for BST<T>
    where T: Ord
{
    type Item = T;
    type IntoIter = BSTIter<'a, T>; // <- my intuition is that I should
                                        // be able to say "BSTIter lives as
                                        // long as BST."

    fn into_iter(&'a mut self) -> BSTIter<'a, T> {
        BSTIter::new(&mut self)
    }
}


pub struct …
Run Code Online (Sandbox Code Playgroud)

lifetime rust

3
推荐指数
1
解决办法
1055
查看次数

标签 统计

lifetime ×1

rust ×1