在我期望可变借用结束之后,我遇到了关于同时使用可变和不可变借用的令人困惑的错误。我对类似问题(1 , 2 , 3 , 4 , 5)进行了大量研究,这让我相信我的问题与词法生命周期有关(尽管打开 NLL 功能并每晚编译并没有) t 改变结果),我只是不知道是什么;我的情况似乎不适合其他问题的任何场景。
pub enum Chain<'a> {
Root {
value: String,
},
Child {
parent: &'a mut Chain<'a>,
},
}
impl Chain<'_> {
pub fn get(&self) -> &String {
match self {
Chain::Root { ref value } => value,
Chain::Child { ref parent } => parent.get(),
}
}
pub fn get_mut(&mut self) -> &mut String {
match self {
Chain::Root { ref mut value } => …Run Code Online (Sandbox Code Playgroud)