Skip to content

Mutable references in field #15868

Closed
Closed
@tprodanov

Description

@tprodanov

Sorry, maybe it is hundred times solved problem, but I cannot use structure filed, which is mutable reference with longer lifetime, than the structure itself. In this code

struct A<'r> {
    v: &'r mut Vec<int>
}

impl<'r> A<'r> {
    fn create(v: &'r mut Vec<int>) -> A<'r> {
        A::<'r> {
            v: v
        }
    }

    fn get_mut(&mut self, i: uint) -> &'r mut int {
        self.v.get_mut(i)
    }
}

in function get_mut I got an error, lifetime of 'self' is too short. But without all mut keywords code runs without errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions