Hi everybody, I'm Daniel, I'm still new to Rust and have been spending lots of times reading and watching about async in Rust, and all that pin stuff
I'm not very versed in rust, but I have some background in, C, so I wrote some code to illustrate what I'm trying to explain here... the whole idea is around why we need Pins, and how do we really need they? Again I'm pretty new to Rust so I'm may be saying some non-sense here. Well, let's go ...
From old times when I used to do some C I have that problems when you want to share a pointer to the user of your library, but there is some data that you need to go together with the user data, but you want it to be private to the user. What we did at that time was allocating something on the heap and giving to the user some opaque pointer to some member of some struct, where the struct is our private data, public data is just the opaque pointer that we give to user...
Now, sooner or latter we will have to retrieve that private data, and what we did was, the user pass their pointer. Since the pointer is hosted in the struct, the address to the struct is just of function of the
address of the opaque pointer, so it doesn't matter where the opaque pointer goes, our private data is there, (as long as we take care of the moving part, this is the whole point of the pointer being opaque, don't letting the user to know it's memory layout, so he depend on us to handle/move/allocate/free it for him, so... )
I wrote some C code to show how this would be possible, https://gist.github.com/dhilst/d5f3ca90a12840b4f17981f4e15674bd
The point is, we know at compile time the offsets members of structs, can't we encode this in the type system so that we safe self referencing pointers as something like OffsetRef, I don't know, but that encodes that offset and dereferencing at compile time (Zero cost abstractions), is that possible?