Instead of adding more top-level functions, you could add a static method to each type:
extension UnsafeMutableRawBufferPointer {
public static func withEphemeral<R>(
byteCount: Int,
alignment: Int,
do body: (inout Self) throws -> R
) rethrows -> R
}
extension UnsafeMutableBufferPointer {
public static func withEphemeral<R>(
capacity: Int,
do body: (inout Self) throws -> R
) rethrows -> R
}
This may improve call sites, especially if the caller is using their own type aliases:
typealias Bytes = UnsafeMutableRawBufferPointer
Bytes.withEphemeral(byteCount: 42, alignment: 1) { bytes in /*...*/ }