This Swift package provides a type, Box
.
Box
is a value type that wraps another value type for heap allocation like Rust's Box
. Also, it is implemented with copy-on-write behavior.
import Box
struct Foo: ~Copyable {
@Box var a: Int
var b: Box<Int>
}
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)