No, we cannot use RawSpan here:
- If we were using
RawSpan, the signature of the protocol requirement would presumably be:func bytes(as imageFormat: AttachableImageFormat) throws -> RawSpan, however you cannot return aRawSpanfrom a function (yet). - If you could return
RawSpanfrom a function, you would have no way to declare its lifetime because it is derived from some value that is created inside the function and is destroyed when it returns. - The alternative signature would be
func withBytes<R>(as imageFormat: AttachableImageFormat, _ body: (borrowing RawSpan) throws -> R) throws -> R. This is not idiomatic Swift (insofar as there are no examples of awithfunction yielding a span that I can find in the stdlib).
Edit: I double-checked, and while one of the specific RawSpans we'd need here is back-deployed to macOS 10.14.4, iOS 12.2, etc., other ones we'd need are not back-deployed and require macOS/iOS 26. Since we do want this feature to be available on earlier Apple platforms, we cannot adopt RawSpan in Swift Testing's attachments feature.