withUnsafeBytes(for:_:)
Call a function and pass a buffer representing this instance to it.
Declaration
borrowing func withUnsafeBytes<R>(for attachment: borrowing Attachment<Self>, _ body: (UnsafeRawBufferPointer) throws -> R) throws -> RParameters
- attachment:
The attachment that is requesting a buffer (that is, the attachment containing this instance.)
- body:
A function to call. A temporary buffer containing a data representation of this instance is passed to it.
Mentioned in
Return Value
Whatever is returned by body.
Discussion
The testing library uses this function when saving an attachment. The format of the buffer is implementation-defined, but should be “idiomatic” for this type: for example, if this type represents an image, it would be appropriate for the buffer to contain an image in PNG format, JPEG format, etc., but it would not be idiomatic for the buffer to contain a textual description of the image.