-
Notifications
You must be signed in to change notification settings - Fork 228
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
Allow for niche optimization on Unix platforms #222
Conversation
I actually plan to use socket2 in std lib (issue #212), so this change would make it a lot harder. Do you know if there are any plans to expose the valid range of an int (i.e. what |
I do not know of any plans for that, no. This niche actually makes things difficult because it would probably be considered a regression for std to remove the niche. Excluding adding more things to the language, we could hide |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's best to forward with this, we'll figure the use-in-std stuff later.
I've reviewed the changes, they look good. Two points and some small things (prefixed with nit). I do have one question: does self.as_raw
generate the same code as self.inner
in all functions, i.e. is as_raw
always inlined?
FreeBSD failure seems unrelated, so I'm merging. |
Thanks @KaiJewson. |
The standard library's file descriptor types have a niche of -1, allowing
Option<T>
to have the same size asT
. By storing aTcpStream
internally instead of a raw file descriptor,Socket
can also take advantage of this. Currently, this incurs a slightly cost as{from, as, into}_raw_{fd, socket}
won't be inlined, however if this Rust PR is merged it will be. Storing aTcpStream
also allows for closing to be implemented by the standard library instead of this one, which is a nice benefit.