In other languages and in rust itself, the first argument of a method (not a function) is the self keyword, which refers to the instance of the object/struct etc.. that calls the method through the use of the dot symbol followed by the method's name. And in this case, the type of the struct is its type. To be clear, I meant that the first argument of a method is always self (the instance) which by definition is the instance of type Self.
And I might be confusing between different concepts, but I can't wrap my head around the poll method's definition.
Here's the struct definition:
struct AsyncFuture {
fut_one: FutOne,
fut_two: FutTwo,
state: State,
}
Here is the code that implements future.
impl Future for AsyncFuture {
type Output = ();
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
/*...*/
}
}
It means that the future struct 'AsyncFuture' needs first to be wrapped inside a Pin before being allowed to call the method poll?
let fut = AsyncFuture {/../}; //hypothetical code
let pinned_fut = Pin::new(fut); //this code might not be correct I am just trying to understand the concept.
And only then, can call its implemented method (trait) pinned_fut.poll(...)
I understand that the code is generated but still, I guess that the generated code compiles as rust code and thus is valid syntax.
Thank you in advance
Edit:
Forgot to mention the link to the documentation from where I took the above code snippets.
Thinking out loud, I feel like it might just be a way to introduce another constraint on how the future trait's method 'poll' should be called by preventing a any type that implements future to directly call it and force it to be wrapped inside a Pin before it can basically make any progress by invoking its poll method.