Swiftpack.co - kkk669/swift-box as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by kkk669.
kkk669/swift-box 0.1.0
Rust's Box for Swift
⭐️ 0
🕓 17 weeks ago
.package(url: "https://github.com/kkk669/swift-box.git", from: "0.1.0")

Box

Swift License

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)

GitHub

link
Stars: 0
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Related Packages

Release Notes

17 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics