Skip to content

Conversation

@Azoy
Copy link
Contributor

@Azoy Azoy commented Jan 6, 2026

Proposing Box to the standard library which is a safe smart pointer that uniquely owns some value.

@MahdiBM
Copy link
Contributor

MahdiBM commented Jan 7, 2026

I barely skimmed through the proposal and I'm already pumped for it as it's 1 more utility that actually leverages non-copyable types.

What's the relation of this Box type to apple/swift-collections/Sources/ContainersPreview/Box.swift?

It looks like these are the same types, but I didn't see a mention of swift-collections in the proposal.

`take` comes from `Optional.take()` and `move` from `UnsafeMutablePointer.move()`.
Both of those methods don't actually consume the parent instance they are called
on however unlike `consume`. Calling `consume` ends the lifetime of `Box` and it
is immediately deallocated after returning the instance stored within.
Copy link
Contributor

@xwu xwu Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(There is also Result.get(), which is consuming, and for which as I recall the core team had previously stated get would become a term-of-art.)

@Azoy
Copy link
Contributor Author

Azoy commented Jan 7, 2026

@MahdiBM it's the same type as found in swift-collections

Reword some things
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants