As for the `self`/static thing: The problem there ...
# development
a
As for the `self`/static thing: The problem there is that because the
and_then
block will be run off-thread, there are no guarantees that the object referred to as
self
actually exists which that callback in scheduled.
a
thanks for the description! that makes sense -- i guess i'm not familiar with the futures impl to say why that can't be worked around (not easily -- but with some special interface, maybe)
omg and then you had more messages i will read them thank you
a
You're right that async/await would make the problem go away, because the
await
means that
self
must still be on the stack when the function is done executing.
a
is that the complete definition of what await means in rust? like a join point that requires
self
to be on the stack? / is there a better intro than just reading the rfc
a
I haven't actually read the RFC, but my assumption (possibly false) is that any async call which is awaited on will be able to be treated under the assumption that its enclosing scope exists throughout the async execution, and that nothing below it on the stack will move
a
ok that's great
cause that makes a lot of sense to me
is it right to say you can wrap something in an Arc to sidestep the
'static
lifetime requirement when using futures?
(going through the rfc)
a
Yes, ish. The Arc wrapping means you can clone the Arc and move the cloned Arc into the closure, which guarantees that the wrapped thing exists in memory, and that the Arc itself can exist on the stack when needed
But wrapping something in an Arc takes ownership of it. So you can't Arc &self.
So in the self case, being an Arc is equivalent to being Clone (but where the underlying data is guaranteed to be identical)
a
that makes a lot of sense
it looks like on the rfc that
await!
might approximately map to "keep this thread (with its stack) frozen until the future we're waiting on is ready" which would make extreme sense to me but might be jumping to conclusions, will look more
a
(but in the non-self case, wrapping in an Arc is what we do to reference things from e.g. multiple futures)
Cool :)
a
i understand why i can't Arc &self, but can that be gotten around with e.g. a top-level wrapper function that Arcs an instance of the trait?
a
The reason you can't Arc &self is because you can't move it. You can Arc self.
It's a reference Vs ownership issue, not a trait issue
a
ok, that makes sense. i was under the impression there was some specific restriction imparted by the &self parameter for some reason
a
Nope, just that is a reference, so you can't move it. Exactly the same as why you can move self into a future but you can't move &self into a future :)