@@ -366,12 +366,25 @@ public struct ${Self}<Pointee>
366
366
% end
367
367
368
368
/// Rebinds memory at `self` to type `T` with capacity to hold `count`
369
- /// adjacent `T` values while executing the `body` closure. After executing
370
- /// the closure, rebinds memory back to `Pointee`.
369
+ /// adjacent `T` values while executing the `body` closure.
370
+ ///
371
+ /// After executing the closure, rebinds memory back to `Pointee`.
371
372
///
372
373
/// - Precondition: Type 'T' is layout compatible with type 'Pointee'.
373
374
/// - Precondition: The memory `self..<self + count * MemoryLayout<T>.stride`
374
375
/// is bound to `Pointee`.
376
+ ///
377
+ /// Accessing `${Self}<T>.pointee` requires that the memory be "bound" to
378
+ /// type `T`. A memory location may only be bound to one type at a time, so
379
+ /// accessing the same memory as an unrelated type without first rebinding the
380
+ /// memory is undefined. `self` may not be accessed within the `body` closure
381
+ /// because memory is no longer bound to `Pointee` while it executes. The
382
+ /// closure's `${Self}<T>` argument must not escape the closure because memory
383
+ /// is only temporarily bound to `T`.
384
+ ///
385
+ /// To persistently bind this memory to a different type, first obtain a
386
+ /// raw pointer to the memory, then invoke the `bindMemory` API:
387
+ /// `UnsafeRawPointer(typedPointer).bindMemory(to:capacity:)`.
375
388
public func withMemoryRebound< T, Result> ( to: T . Type, capacity count: Int,
376
389
_ body: ( ${ Self} < T> ) throws -> Result
377
390
) rethrows -> Result {
0 commit comments