# Is ~Escapable + ~Copyable sufficient to safely scope an UnsafeMutablePointer lifetime?

**URL:** <https://forums.swift.org/t/is-escapable-copyable-sufficient-to-safely-scope-an-unsafemutablepointer-lifetime/86153>\
**Category:** Using Swift\
**Tags:** pointers, noncopyable, nonescaping\
**Created:** [April 21, 2026, 5:11pm UTC](https://forums.swift.org/t/is-escapable-copyable-sufficient-to-safely-scope-an-unsafemutablepointer-lifetime/86153 "2026-04-21T17:11:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blacksmith](https://avatars.discourse-cdn.com/v4/letter/b/e99b99/32.png) [@Blacksmith](https://forums.swift.org/u/Blacksmith)\
**Post date:** [April 21, 2026, 5:11pm UTC](https://forums.swift.org/t/is-escapable-copyable-sufficient-to-safely-scope-an-unsafemutablepointer-lifetime/86153/1 "2026-04-21T17:11:40Z")

</div>

Hello everyone,

I've been experimenting with some of the newer Swift proposals and wanted to check whether my mental model aligns with the reality.

I have a type called `Context` that is generic over some `State`. It is both `~Copyable` and `~Escapable`, with its lifetime tied to the pointer it wraps:

```swift
public struct Context<State>: ~Copyable, ~Escapable {
    @usableFromInline
    internal let statePointer: UnsafeMutablePointer<State>

    @_lifetime(borrow statePointer)
    internal init(statePointer: UnsafeMutablePointer<State>) {
        self.statePointer = statePointer
    }

    @inlinable
    @inline(__always)
    public var state: State {
        _read {
            yield statePointer.pointee
        }
        nonmutating _modify {
            yield &statePointer.pointee
        }
    }
}

```

`Context` is borred by a synchronous function:

```swift
func process(action: Action, context: borrowing Context<State>) -> FeatureWork

```

And the call site constructs it like this

```swift
private func work(from action: Action) -> Work<Action, Dependency> {
    withUnsafeMutablePointer(to: &_state) { [feature] pointer in
        feature.process(
            action: action,
            context: Context<F.State>(
                statePointer: pointer
            )
        )
    }
}

```

**The intent** is to give `process` efficient, direct access to `_state` through the pointer, while keeping mutation contained within `Context`. My assumption is that `~Escapable` and `~Copyable` together do most of the safety work here. The compiler should prevent the `Context` (and therefore the pointer) from outliving the `withUnsafeMutablePointer` scope, and the non-copyable constraint prevents aliased access.

Does this reasoning hold, or is there an oversight or misunderstanding of the concepts from my end?
