Skip to content

Tracking Issue for Box::take #147212

Closed

Description

@edwloef

Feature gate: #![feature(box_take)]

This is a tracking issue for Box::take, which adds the ability to move the value out of a Box without consuming its allocation.

Public API

impl<T> Box<T> {
    pub fn take(boxed: Box<T>) -> (T, Box<MaybeUninit<T>>);
}

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩

Activity

  1. added
    T-libs-api[DEPRECATED; DO NOT USE]
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Oct 1, 2025
  2. camsteffen commented on Oct 1, 2025

    @camsteffen
    Contributor

    Name idea: into_inner_and_uninit

  3. added a commit that references this issue on Oct 2, 2025
  4. added a commit that references this issue on Oct 2, 2025
  5. added a commit that references this issue on Oct 2, 2025
  6. added a commit that references this issue on Oct 2, 2025
  7. added a commit that references this issue on Oct 2, 2025
  8. edwloef commented on Oct 2, 2025

    @edwloef
    ContributorAuthor

    @rustbot label -S-tracking-unimplemented

  9. 3 remaining items

  10. Fisch37 commented on Jan 1, 2026

    @Fisch37

    Maybe this is not my place to say (or the right place to for that matter), but if this is going to be added, shouldn't there also be a Box::<T>::swap(&mut self, value: T) -> T?

    The docs suggest take for reusing a Box in conjunction with write, which sounds like a common enough use case that there should just be a function for it. Using take and write is also rather limited as (due to the nature of both functions), it's not possible to swap a box you do not own.

  11. programmerjake commented on Jan 1, 2026

    @programmerjake
    Member

    Maybe this is not my place to say (or the right place to for that matter), but if this is going to be added, shouldn't there also be a Box::<T>::swap(&mut self, value: T) -> T?

    just use mem::replace

  12. Fisch37 commented on Jan 1, 2026

    @Fisch37

    Oh yeah, I suppose that works

  13. edwloef commented on Mar 20, 2026

    @edwloef
    ContributorAuthor

    I'd like to get the ball rolling on getting this stabilized. I assume the unresolved question needs to be resolved beforehand, so here goes.

    In the original message suggesting that take might not be the best name, it was mentioned that the name take was already a bit overloaded, doing different things across the standard library:

    • ManuallyDrop::take: duplicate the old value, leave soundness to caller
    • {mem, Option, Vec, Cell, RefCell}::take: take the old value and leave Default::default
    • {OnceCell, OnceLock}::take: take the old value and leave empty slot to be lazily re-initialized
    • {HashSet, BTreeSet}::take: take the old value and leave empty slot in collection
    • Iterator::take, Read::take: limit stream to specific item count

    Of those, I believe Box::take would be closest to the behavior of Option::take with Box<Option<T>>, except with the "value" and "no value" states being separate types instead of Some and None enum variants, making it infallible. Therefore I'd say the name sort-of mirrors alternatives that do similar things that already exist in std.

    The alternative that would most closely mirror its counterpart, Box::write, is Box::read, but that already exists through impl<R: Read + ?Sized> Read for Box<R>. I'm not sure whether the resolution/inference pain is worth the name here.

    I'm personally somewhat meh on into_inner_and_uninit, mainly because there's no other into_inner_and_* in the standard library anywhere, it's not a name I would think of if I wanted that functionality. I'm happy to hear counterarguments to that though.

  14. camsteffen commented on Mar 21, 2026

    @camsteffen
    Contributor

    FWIW I suggested a different name for discussion but I actually like take. It fits the common semantic of removing a value from something. The signature here is a bit peculiar, but it's really just the logical conclusion of taking from a Box.

  15. edwloef commented on Mar 24, 2026

    @edwloef
    ContributorAuthor

    Oh, good to hear 😄 so I guess this is just waiting on libs to agree then?

  16. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
  17. added 2 commits that reference this issue on Sep 22, 2026
  18. added a commit that references this issue on Sep 23, 2026
  19. added a commit that references this issue on Oct 2, 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

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions