24
24
/// A type should conform to this protocol if it can be represented as a
25
25
/// sequence of bytes that would be diagnostically useful if a test fails. If a
26
26
/// type cannot conform directly to this protocol (such as a non-final class or
27
- /// a type declared in a third-party module), you can create a container type
28
- /// that conforms to ``AttachableContainer`` to act as a proxy.
29
- @_spi ( Experimental)
27
+ /// a type declared in a third-party module), you can create a wrapper type that
28
+ /// conforms to ``AttachableWrapper`` to act as a proxy.
29
+ ///
30
+ /// @Metadata {
31
+ /// @Available(Swift, introduced: 6.2)
32
+ /// }
30
33
public protocol Attachable : ~ Copyable {
31
34
/// An estimate of the number of bytes of memory needed to store this value as
32
35
/// an attachment.
@@ -42,6 +45,10 @@ public protocol Attachable: ~Copyable {
42
45
///
43
46
/// - Complexity: O(1) unless `Self` conforms to `Collection`, in which case
44
47
/// up to O(_n_) where _n_ is the length of the collection.
48
+ ///
49
+ /// @Metadata {
50
+ /// @Available(Swift, introduced: 6.2)
51
+ /// }
45
52
var estimatedAttachmentByteCount : Int ? { get }
46
53
47
54
/// Call a function and pass a buffer representing this instance to it.
@@ -64,6 +71,10 @@ public protocol Attachable: ~Copyable {
64
71
/// the buffer to contain an image in PNG format, JPEG format, etc., but it
65
72
/// would not be idiomatic for the buffer to contain a textual description of
66
73
/// the image.
74
+ ///
75
+ /// @Metadata {
76
+ /// @Available(Swift, introduced: 6.2)
77
+ /// }
67
78
borrowing func withUnsafeBytes< R> ( for attachment: borrowing Attachment < Self > , _ body: ( UnsafeRawBufferPointer ) throws -> R ) throws -> R
68
79
69
80
/// Generate a preferred name for the given attachment.
@@ -80,6 +91,10 @@ public protocol Attachable: ~Copyable {
80
91
/// when adding `attachment` to a test report or persisting it to storage. The
81
92
/// default implementation of this function returns `suggestedName` without
82
93
/// any changes.
94
+ ///
95
+ /// @Metadata {
96
+ /// @Available(Swift, introduced: 6.2)
97
+ /// }
83
98
borrowing func preferredName( for attachment: borrowing Attachment < Self > , basedOn suggestedName: String ) -> String
84
99
}
85
100
@@ -119,28 +134,24 @@ extension Attachable where Self: StringProtocol {
119
134
120
135
// Implement the protocol requirements for byte arrays and buffers so that
121
136
// developers can attach raw data when needed.
122
- @_spi ( Experimental)
123
137
extension Array < UInt8 > : Attachable {
124
138
public func withUnsafeBytes< R> ( for attachment: borrowing Attachment < Self > , _ body: ( UnsafeRawBufferPointer ) throws -> R ) throws -> R {
125
139
try withUnsafeBytes ( body)
126
140
}
127
141
}
128
142
129
- @_spi ( Experimental)
130
143
extension ContiguousArray < UInt8 > : Attachable {
131
144
public func withUnsafeBytes< R> ( for attachment: borrowing Attachment < Self > , _ body: ( UnsafeRawBufferPointer ) throws -> R ) throws -> R {
132
145
try withUnsafeBytes ( body)
133
146
}
134
147
}
135
148
136
- @_spi ( Experimental)
137
149
extension ArraySlice < UInt8 > : Attachable {
138
150
public func withUnsafeBytes< R> ( for attachment: borrowing Attachment < Self > , _ body: ( UnsafeRawBufferPointer ) throws -> R ) throws -> R {
139
151
try withUnsafeBytes ( body)
140
152
}
141
153
}
142
154
143
- @_spi ( Experimental)
144
155
extension String : Attachable {
145
156
public func withUnsafeBytes< R> ( for attachment: borrowing Attachment < Self > , _ body: ( UnsafeRawBufferPointer ) throws -> R ) throws -> R {
146
157
var selfCopy = self
@@ -150,7 +161,6 @@ extension String: Attachable {
150
161
}
151
162
}
152
163
153
- @_spi ( Experimental)
154
164
extension Substring : Attachable {
155
165
public func withUnsafeBytes< R> ( for attachment: borrowing Attachment < Self > , _ body: ( UnsafeRawBufferPointer ) throws -> R ) throws -> R {
156
166
var selfCopy = self
0 commit comments