Skip to content

Add Box::replace #23309

Description

@mahkoh

Box currently has no way to replace the contained value while returning the old one.

Activity

  1. dotdash commented on Mar 12, 2015

    @dotdash
    Contributor

    Does this really need a method on Box?

    let mut b = Box::new(5);
    let old = std::mem::replace(&mut *b, 10);

    doesn't look that bad.

    Edit: Made b mutable.

  2. mahkoh commented on Mar 12, 2015

    @mahkoh
    ContributorAuthor

    You're right. Didn't think of that one.

  3. added a commit that references this issue on Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions