use std::pin::Pin;
struct Borrower<T> {
strawman: *mut T
}
impl<T> Borrower<T> {
fn new() -> Self {
Self {strawman:std::ptr::null_mut()}
}
fn borrowing(self: &mut Pin<&mut Self>, value: Pin<&mut T>) {
self.strawman = unsafe { value.get_unchecked_mut() };
}
}
fn some_context() -> Pin<&'static mut Borrower<i32>> {
let mut i: i32 = 789456;
let i_pin = Pin::new(&mut i);
let mut b = Borrower::new();
let mut b = Pin::new(&mut b);
b.borrowing(i_pin);
b
}
fn main() {
let _ = some_context();
}
I find it really odd that nobody told me that I can just require T in my API, because T isn't bound by anything, Rust cannot assume that T: Unpin, and gives me errors for trying to move the value in any way, I also cannot escape from the context with my limited knowledge no matter what retarded code I try to write. Rust seems to work fine here, but it's so obtuse I honestly cannot know if this is 100% sound or might have some holes.
error[E0515]: cannot return value referencing local variable `b`
--> src/main.rs:24:5
|
21 | let mut b = Pin::new(&mut b);
| ------ `b` is borrowed here
...
24 | b
| ^ returns a value referencing data owned by the current function
For more information about this error, try `rustc --explain E0515`.
error: could not compile `test-pin` (bin "test-pin") due to 1 previous error