Skip to content

Commit 5b7580d

Browse files
noncopyable fixes
1 parent a11a7d7 commit 5b7580d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Sources/VariableLengthArray/VLArray.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public struct VLArray<Element>: ~Copyable, @unchecked Sendable where Element: ~C
1313
public init(_storage: UnsafeMutableBufferPointer<Element>) {
1414
self._storage = _storage
1515
}
16+
}
1617

18+
extension VLArray where Element: ~Copyable {
1719
/// The index of the first element in a nonempty buffer.
1820
///
1921
/// The `startIndex` property of an `VLArray` instance

Tests/swift-variablelengtharrayTests/VariableLengthArrayTests.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Testing
55
@Suite
66
struct VariableLengthArrayTests {
77
@Test
8-
func vlArray() {
8+
func vlArrayCopyable() {
99
VLArray<UInt8>.create(amount: 5, default: 0, { array in
1010
#expect(array.count == 5)
1111
for i in array.indices {
@@ -45,6 +45,17 @@ struct VariableLengthArrayTests {
4545
})
4646
}
4747

48+
@Test
49+
func clArrayNonCopyable() {
50+
let amount = 1
51+
VLArray<Noncopyable>.create(amount: amount, initialize: ({ .init(bro: $0) }), { array in
52+
#expect(array.count == amount)
53+
for i in array.indices {
54+
#expect(i == array[i].bro)
55+
}
56+
})
57+
}
58+
4859
@Test
4960
func joinedVLArrayVL() {
5061
VLArray<UInt8>.create(amount: 5, default: 0) { first in
@@ -63,4 +74,8 @@ struct VariableLengthArrayTests {
6374
}
6475
}
6576
}
77+
}
78+
79+
struct Noncopyable: ~Copyable {
80+
let bro:Int
6681
}

0 commit comments

Comments
 (0)