Skip to content

Add option::get_mut_ref() and friends. #7394

Closed
@bblum

Description

@bblum

With the new borrow-checker, &mut T is noncopyable, so the following functions are now safe:

fn get_mut_ref<'a,T>(x: &'a mut Option<T>) -> &'a mut T { 
    match x { 
        &Some(ref mut inner) => inner,
        &None => fail!(),
    }   
}
fn map_mut<T,U>(x: &mut Option<T>, blk: &fn(&mut T) -> U) -> Option<U> {
    match x { 
        &Some(ref mut inner) => Some(blk(inner)),
        &None => None
    }   
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions