Skip to content
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

use TryInto<SocketAddress> bound for bind/listen functions in rama #402

Merged
merged 6 commits into from
Jan 27, 2025

Conversation

fa993
Copy link
Contributor

@fa993 fa993 commented Jan 26, 2025

Closes #400

@fa993
Copy link
Contributor Author

fa993 commented Jan 26, 2025

I actually wanted to ask a bit about the error types, I've marked them as io::Error in the bounds since the functions originally returned a result type with an io::Error but I can see that this is causing issues with the callers as not all TryInto are implemented with that.

@GlenDC
Copy link
Member

GlenDC commented Jan 26, 2025

I actually wanted to ask a bit about the error types, I've marked them as io::Error in the bounds since the functions originally returned a result type with an io::Error but I can see that this is causing issues with the callers as not all TryInto are implemented with that.

So in this case we do not control all the different possible types that can be turned into a SocketAddress, given we use the non-sealed TryInto (std) trait. As such it can also be really any error. If you wanted to go very statically typed you could make an enum like enum Error<E> { AddrError(E), BindError(io::Error) }, but only because you expect people to handle it separately. However, there's no reason for that given people can also downcast a BoxError into an io::Error in case they want to catch something specific there.

As such I would just turn these errors into a BoxError and get it over with. This makes it also a lot easier to add more underlying errors in future. Another approach could be in future to split up the address injection from the actual network socket binding. But for now this is probably ok as-is.

Hope this helps you out together with my comments on your code.

Thank you for the swift resolution by te way, greatly appreciated.

@fa993
Copy link
Contributor Author

fa993 commented Jan 26, 2025

LMK if anything else is required

@GlenDC
Copy link
Member

GlenDC commented Jan 26, 2025

LMK if anything else is required

Is it possible that you forget to push that "last" commit mentioned in the comments? I still see io::Error being used?

@fa993
Copy link
Contributor Author

fa993 commented Jan 26, 2025

LMK if anything else is required

Is it possible that you forget to push that "last" commit mentioned in the comments? I still see io::Error being used?

Yeah, sorry about that 😅

Copy link
Member

@GlenDC GlenDC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, seems flawless. Thank you very much for this swift and great first contribution!

@GlenDC
Copy link
Member

GlenDC commented Jan 26, 2025

@fa993 there are some errors, not your fault, but more showing that the work is sadly still incomplete. Like described before, the goal was to keep this change non-breaking.

Atm this fails:

 ^^^^ the trait `From<&std::string::String>` is not implemented for `SocketAddress`

Meaning that TryFrom<&String> is not implemented for SocketAddress while I guess it is for ToSocketAddrs.

Problem is that it implements this: impl<T: ToSocketAddrs + ?Sized> ToSocketAddrs for &T

We cannot implement that. But perhaps you can atleast implement TryFrom<&String> for SocketAddress. Given we anyway parse the string and no own it.

Copy link
Member

@GlenDC GlenDC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the tests pass regarding &String -> SocketAddress I'll re-evaluate if we can merge, which I think should be possible.

Copy link
Member

@GlenDC GlenDC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this extra mile. Great work. Take care!

@GlenDC GlenDC merged commit dcdf410 into plabayo:main Jan 27, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use TryInto<SocketAddress> bound for bind/listen functions in rama
2 participants