swift-testing icon indicating copy to clipboard operation
swift-testing copied to clipboard

Adopt `RawSpan` in `Attachable` protocol

Open grynspan opened this issue 1 year ago • 4 comments

Once RawSpan is in the mix, we should replace withUnsafeBufferPointer(for:_:) with:

    /// Get a span representing this instance.
    ///
    /// - Parameters:
    ///   - attachment: The attachment that is requesting a buffer (that is, the
    ///     attachment containing this instance.)
    ///
    /// - Returns: An instance of [`RawSpan`]() that represents this value as
    ///   memory of unspecified type.
    ///
    /// - Throws: Any error that prevented the creation of the span.
    ///
    /// The testing library uses this function when writing an attachment to a
    /// test report or to a file on disk. 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.
    @lifetime(borrow self)
    borrowing func span(for attachment: borrowing Test.Attachment<Self>) throws -> RawSpan

grynspan avatar Nov 11 '24 20:11 grynspan

Just FYI. From the current evolution status you would need to provide a scoped access to the RawSpan and cannot return it from the method until we get something like yields -> RawSpan to express that the span is borrowed.

FranzBusch avatar Nov 12 '24 13:11 FranzBusch

I don't anticipate adoption until non-escaping types have matured further. 👍🏻

grynspan avatar Nov 12 '24 13:11 grynspan

Tracked internally as rdar://139672372.

grynspan avatar Mar 12 '25 18:03 grynspan

Not planned for 6.2 due to our back-deployment needs.

grynspan avatar Mar 12 '25 18:03 grynspan