Is `withMemoryRebound(to:)` recursive?

does rebinding an UnsafeMutablePointer<UnsafeMutablePointer<T>?> to a UnsafeMutablePointer<UnsafeMutablePointer<U>> also rebind the instance of T to U?

meaning, is the following code valid?

let buffer:UnsafeMutableBufferPointer<UnsafeMutablePointer<T>?> = 
    .init(start: start, count: count)

return try buffer.withMemoryRebound(to: UnsafeMutablePointer<U>.self) 
{
    ...
}

or is it also necessary to rebind each sub-pointee individually? the sub-pointers came from a C API, and were all previously checked to be non-nil.

No, it does not recursively chase through pointers.

2 Likes
Terms of Service

Privacy Policy

Cookie Policy