Closed notgull closed 10 months ago
I don't think this is possible.
I can just lie in my AsRawSource
implementation and always return a random number. Just because my struct is alive does not mean the underlying FD did not change.
Another random idea would be to break this with e.g. a Cell<File>
. I can change the FD without any unsafe
code even though the containing struct is still borrowed.
While you can safely lie in AsRawSource
, it is unsound to lie in AsSource
, which is what I would use for this method.
See https://github.com/smol-rs/polling/pull/171#issuecomment-1869185012. I don't think this is possible safely, without a breaking change.
If a specific file descriptor or source outlives the
Poller
, it can beadd
ed to it without any concerns of whether or not it will be dropped. It would be nice to have anadd_outlives()
function that takes a source that is guaranteed to outlive thePoller
, through lifetimes. While this doesn't work for the common use cases (async-io
andcalloop
), for simple, shorter scale use cases this could be used to avoid unsafe code (alacritty
).cc https://github.com/psychon/x11rb/issues/891