Earlier quoted context omitted.
> Pin is a way to create self referential structs, by pinning memory and preventing moves. This, exactly. Pin works more or less like a C++ class with a deleted move constructor. Copies may be allowed if clone/copy (aka, the implicit/explicit copy constructor) are defined, but move and RVO are not. Lots of Rust's concepts can often be described in terms of C++'s techniques, but more often than not in C++ it tends to…
How does this work? I want to wrap POSIX semaphores. You call sem_init, passing it the address of an int; later you call sem_destroy and pass it the same address. So the location of the int must not change. In C++ you would delete the move constructor: struct sema { int v; void sema(sema &&) = delete; }; In Rust you might try this, but it doesn't work: struct Sema { v: Pin , } there is no way to create a "Pin ". The…
Caveat, I haven't worked with Pin that much. Take this with a grain of salt.
My understanding is - you really shouldn't put copyable stuff in Pin. Period. If you want something like that wrap i32 in new struct and declare it !Unpin. Since negative traits are unstable, you just write PhantomPinned marker
struct NonPinI32 {
v: i32,
non_pin: PhantomPinned,
}