Box

0.1.0

Rust's Box for Swift
kkebo/swift-box

What's New

2021-08-04T16:04:47Z

Box

This Swift package provides two types, Box and BoxObject.

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.

BoxObject is almost the same as Box, but it's a reference type. If you copy the wrapped value, you can call its copy() method.

Examples

import Box

struct Foo {
    @Box var a: Int
    var b: Box<Int>
    var c: BoxObject<Int>
}

var foo = Foo(a: 3, b: .init(4), c: .init(9))
print(foo)  // Foo(_a: 3, b: 4, c: 9)

var bar = foo
bar.a = 10
bar.b.value = 5
bar.c.value = 99
print(foo)  // Foo(_a: 3, b: 4, c: 99)
print(bar)  // Foo(_a: 10, b: 5, c: 99)

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Tue Apr 23 2024 20:05:44 GMT-0900 (Hawaii-Aleutian Daylight Time)