Raw Pointer Address

Hi. I have the following code:

@inlinable
func setStreamData(on stream: UnsafeMutablePointer<some UVStreamRepresentable>, to data: UnsafeMutablePointer<some AnyObject>) {
    let stream = castToBaseStream(stream)

    func set(data: UnsafeMutableRawPointer) {
        stream.pointee.data = data
    }

    set(data: data)
}

In order to interact with a C library, I need to set the data to the address of some data object (so that I can load it back with a raw pointer later on in a callback). Swift infers the type of data as UnsafeMutableRawPointer!. Unfortunately, if I to use this code, it sets the value to the address of UnsafeMutableRawPointer struct itself, rather the address it is pointing to.

Can anyone suggest how to set data to what the raw pointer is pointing? Thanks.

Edit: It turns out that the logic in this snippet is correct. Although the address the pointer is pointing to is still valid, the pointer container itself is dereferenced by the time I try loading it. Facepalm.