Rust RefCell,无法返回引用临时值的值

时间:2019-07-05 17:54:09

标签: rust

我正在学习Rust,并尝试使用RefCell。我有给定的代码,

struct MyStruct {
    data: RefCell<Vec<i32>>
}

impl MyStruct {
    fn get_value(&self, index: usize) -> Option<&i32> {
        self.data.borrow().get(index)
    }
}

编译器不喜欢它

cannot return value referencing temporary value

returns a value referencing data owned by the current function

如何返回值?

0 个答案:

没有答案