Skip to content

retain improvements #2160

@eira-fransham

Description

@eira-fransham

Firstly, I believe it would be sound for the function passed to retain to take a mutable reference instead of an immutable one. There is no real reason to restrict this. Additionally, I've found it useful to return the removed array as an &mut [T] - since all the elements are at the end anyway this is essentially free. In my case I only allow this when the elements are Copy (as a hack around not being able to specify !Drop), but it would be sound to allow Drop types. The issue is that it would unconditionally leak, which would be solved by an additional type that derefences to &mut [T] but that drops its elements on drop. It would have to take a lifetime parameter to disallow mutating the vector after returning the elements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions