I am trying to write a function that takes an Array<UInt8> or ArraySlice<UInt8> as an argument.
My function needs to call withUnsafeBufferPointer. Both Array and ArraySlice implements this function but I cannot find if they both conform to a protocol that implements this.
The function would look something like this:
func someFunction<T: RandomAccessCollection>(bytes: T) -> UInt8 where T.Element == UInt8 {
bytes.withUnsafeBufferPointer({
return $0.count
})
}
In this case I am using RandomAccesCollection since both Array and ArraySlice conforms to it, but it is not the protocol that specifies withUnsafeBufferPointer.
Any idea what I should use instead of RandomAccesCollection, or should I take a completely differnet approacy? One that I thought about was to create a new protocol that specifies withUnsafeBufferPointer and to then have both Array and ArraySlice conform to it, but it feels to be like this should have already been done.
Thanks.