Uh oh!
There was an error while loading. Please reload this page.
Allow for niche optimization on Unix platforms - #222
Conversation
Thomasdezeeuw
commented
Apr 27, 2021
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 |
SabrinaJewson
commented
Apr 27, 2021
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 |
Thomasdezeeuw
left a comment
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Thomasdezeeuw
commented
Apr 28, 2021
FreeBSD failure seems unrelated, so I'm merging. |
Thomasdezeeuw
commented
Apr 28, 2021
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 aTcpStreaminternally instead of a raw file descriptor,Socketcan 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 aTcpStreamalso allows for closing to be implemented by the standard library instead of this one, which is a nice benefit.