https://github.com/kkebo/swift-box
Rust's Box for Swift
https://github.com/kkebo/swift-box
swift
Last synced: 2 months ago
JSON representation
Rust's Box for Swift
- Host: GitHub
- URL: https://github.com/kkebo/swift-box
- Owner: kkebo
- License: mit
- Archived: true
- Created: 2021-08-04T14:36:28.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-29T22:52:37.000Z (7 months ago)
- Last Synced: 2025-08-04T12:53:16.988Z (3 months ago)
- Topics: swift
- Language: Swift
- Homepage:
- Size: 59.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Box

[](https://www.swift.org)
[](LICENSE)
> [!WARNING]
> This repository is now deprecated. Instead, please use [`Box`](https://github.com/apple/swift-collections/blob/future/Sources/Future/Box.swift) of [swift-collections](https://github.com/apple/swift-collections).
This Swift package provides a type, `Box`.
[`Box`](./Sources/Box.swift) is a value type that wraps another value type for heap allocation like [Rust's `Box`](https://doc.rust-lang.org/std/boxed/struct.Box.html). Also, it is implemented with copy-on-write behavior.
## Examples
```swift
import Box
struct Foo: ~Copyable {
@Box var a: Int
var b: Box
}
var foo = Foo(a: 3, b: .init(4))
assert(foo.a == 3)
assert(foo.b.value == 4)
foo.a = 10
foo.b.value = 5
assert(foo.a == 10)
assert(foo.b.value == 5)
```