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

Relax bound on blanket impl for Source #45

Closed
wants to merge 1 commit into from

Conversation

ybh1998
Copy link

@ybh1998 ybh1998 commented Nov 20, 2022

The current definition in this library is not friendly for dynamic use like dyn polling::Source, because the blanket implementation of Source for &T (instead of T). Consider the following code:

polling/src/lib.rs

Lines 539 to 543 in ca52490

impl<T: AsRawFd> Source for &T {
fn raw(&self) -> RawFd {
self.as_raw_fd()
}
}

The current implementation is effectively accepting a double reference because there are references in both the receiver type and &T, and it does not align with other traits that we might also be interested to have (e.g., Read, Write). Consider the following attempt to have a dynamic Source which is also Readable and Writeable:

pub trait ReadWriteSource: Read + Write + polling::Source {}
impl<T: Read + Write + polling::Source> ReadWriteSource {}

Unfortunately, (for example) TcpStream does not implement ReadWriteSource because it does not implement Source.

With the proposed changes, types TcpStream will properly implement ReadWriteSource. A platform-agnostic return type RawSource for Source::raw is also added to help if the users want to implement polling::Source by themselves.

@notgull
Copy link
Member

notgull commented Aug 4, 2023

This PR has been displaced by the merge of #123 changing the concept of the Source trait. Feel free to re-open if this is updated for the new codebase.

Thanks anyways!

@notgull notgull closed this Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants