You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using the async TcpConnect. I have a struct that owns both the connector, and at most one socket. This looks a little like so:
structMyClient<T:TcpConnect>{connector:T,
connection:Option<T::Connection<'?>>,}impl<T:TcpConnect> MyClient<T>{fnconnect(&mutself){self.connection = self.connector.connect(remote);// lifetime that matches the function}}
The issue arises with lifetimes. T::Connection takes on a lifetime that must be less than that of the connector meaning (I think) that as far as the borrow checker is concerned, this is a self-referential struct.
If that is not the case, then I wonder what the lifetime parameter of T::Connection should be. If I give it one (say a) then the reference to self in connect must also receive the annotation which screws up borrowing in any code that tries to use it.
Is there a way to store T::Connection in this manner?
If the conceptual above is not clear enough, I can put an example together.
For context, I am porting some code that used TcpClientStack to have an async interface. If this is not supported (ie I am not just being dense) then I will just refactor to clean things up; this seemed like the path of least resistance from TcpClientStack::TcpSocket
The text was updated successfully, but these errors were encountered:
Hi!
I am using the async TcpConnect. I have a struct that owns both the connector, and at most one socket. This looks a little like so:
The issue arises with lifetimes. T::Connection takes on a lifetime that must be less than that of the connector meaning (I think) that as far as the borrow checker is concerned, this is a self-referential struct.
If that is not the case, then I wonder what the lifetime parameter of T::Connection should be. If I give it one (say a) then the reference to self in connect must also receive the annotation which screws up borrowing in any code that tries to use it.
Is there a way to store T::Connection in this manner?
If the conceptual above is not clear enough, I can put an example together.
For context, I am porting some code that used TcpClientStack to have an async interface. If this is not supported (ie I am not just being dense) then I will just refactor to clean things up; this seemed like the path of least resistance from TcpClientStack::TcpSocket
The text was updated successfully, but these errors were encountered: