-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with Endpoint lifetime #81
Comments
Yeah, I recently hit this issue myself. There's a bug in the rustc compiler that prevents using lifetime constraints and using the same lifetime against It appears like the issue has been fixed already so we can start using it. Edit: ahh, it seems like you've already tried it. |
Your example of fn bind<'b, 'x: 'b>(&'x mut self, addr: &str) -> NanoResult<Endpoint<'b>> Is what I imagined to work, but that doesn't seem to be the case. |
It works when it comes to prevent someone from using an endpoint outside the scope of a socket. let mut e;
{
let mut socket = ...
e = socket.bind(...).unwrap();
}
e.shutdown(); But we have now a problem because it seems that the socket mutability has been transfered to the endpoint. |
The suggestions I got on irc are
But we could also completely remove the lifetime constraint until we find the solution. |
Yeah, I think option 1 and 2 are a no go. Option 3 seems a bit contrary to the goal of having M endpoints to N sockets. I think the best option would be to remove the constraints until we find another solution like you suggested. |
Another option would be to make the self parameter of |
@blabaere I'd actually be ok with that because it would be considered interior mutability. As long as we can prove it to be safe given the extra freedom you have with Trying to think of what problems could occur if we were to do that, but none are coming up atm. |
I spoke too fast, that works only when not keeping the endpoint ... |
The rust nightly build cc19e3380 2014-12-20 introduced the warning reproduced below.
This drew my attention to the fact this conflicting lifetime name wasn't even used in the function !
So after resolving the name conflict, I changed the signature parameter to actually use that named lifetime but this had the effect of breaking almost all unit tests !!! 💥
With this modification, it becomes impossible to retrieve the endpoint and then to send or receive a message. For example you can use
test_bind
alone, but nottest_bind
and thentest_write
.Calling directly
bind
without storing the result in variable and thenwrite
works fine.Storing the NanoResult or the Endpoint will cause a compilation error.
It looks like constraining the lifetime of the Endpoint to the one of the Socket makes the Endpoint a 'borrower' of the Socket.
I will post something on reddit and add the link here when done.
Signature before and after the change:
Warning:
The text was updated successfully, but these errors were encountered: