Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kkebo/swift-box
Rust's Box for Swift
https://github.com/kkebo/swift-box
swift
Last synced: 17 days ago
JSON representation
Rust's Box for Swift
- Host: GitHub
- URL: https://github.com/kkebo/swift-box
- Owner: kkebo
- License: mit
- Created: 2021-08-04T14:36:28.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-14T09:36:42.000Z (2 months ago)
- Last Synced: 2024-09-15T06:44:29.980Z (about 2 months ago)
- Topics: swift
- Language: Swift
- Homepage:
- Size: 47.9 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Box
![coverage](coverage.svg)
[![Swift](https://img.shields.io/badge/Swift-6.0-orange.svg)](https://www.swift.org)
[![License](https://img.shields.io/github/license/kkebo/swift-box.svg)](LICENSE)This Swift package provides a type, `Box`.
[`Box`](./Sources/Box/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 Boxstruct 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 = 5assert(foo.a == 10)
assert(foo.b.value == 5)
```