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

Derive common traits for NamedPipeInfo struct #6586

Merged
merged 2 commits into from
May 25, 2024

Conversation

Tacklebox
Copy link
Contributor

Motivation

I would like to use windows named pipes as the transport for GRPC with tonic. That requires that the transport implement Connected, which requires the info struct implement Clone. While a wrapper struct could be used, NamedPipeInfo doesn't seem to have any particular reason not to implement Clone directly.

Solution

Add Clone (And a few other useful traits already derived on the members of NamedPipeInfo) to the derive macro.

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-net Module: tokio/net labels May 25, 2024
Comment on lines 2629 to 2631
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct PipeInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

This type is #[non_exhaustive] so that we can add additional fields in the future. Adding Copy goes against that since it prevents the addition of non-copy fields in the future.

The same could apply to the other traits, but in a lesser extent.

Copy link
Contributor Author

@Tacklebox Tacklebox May 25, 2024

Choose a reason for hiding this comment

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

Since this is only constructed from calling NamedPipe[Server|Client]::info() and those are convenience methods to call GetNamedPipeInfo, I wouldn't expect tokio to ever return a different substantially different struct than the one from the win32 api. With that in mind, I don't think #[non_exhaustive] is super useful here.

But if that's a dealbreaker, would this change be acceptable without Copy? Or at least with only the addition of Clone?

Copy link
Contributor

Choose a reason for hiding this comment

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

OS apis such as GetNamedPipeInfo are sometimes extended to return additional data in newer versions of the OS.

The change is acceptable with just Clone.

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thank you.

@Darksonn Darksonn merged commit 0a85a96 into tokio-rs:master May 25, 2024
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-net Module: tokio/net
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants