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

io: implemented get_ref and get_mut for SyncIoBridge #7128

Merged
merged 3 commits into from
Jan 28, 2025

Conversation

wngr
Copy link
Contributor

@wngr wngr commented Jan 27, 2025

Motivation

When interacting with resources wrapped in a SyncIoBridge, it might be handy to interact with the inner resource.

Solution

Implement get_ref and get_mut on SyncIoBridge.

@Darksonn Darksonn added A-tokio-util Area: The tokio-util crate M-io Module: tokio/io labels Jan 27, 2025
Comment on lines 157 to 169
/// Returns a shared reference to the inner resource.
///
/// It is inadvisable to directly read/write from the underlying resource.
pub fn get_ref(&self) -> &T {
&self.src
}

/// Returns a mutable reference to the inner resource.
///
/// It is inadvisable to directly read/write from the underlying resource.
pub fn get_mut(&mut self) -> &mut T {
&mut self.src
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably should use the AsRef/AsMut traits instead? I think we do that in most places where we provide accessor to the inner value.

Copy link
Contributor Author

@wngr wngr Jan 27, 2025

Choose a reason for hiding this comment

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

There's precedent for both (Framed for example offers explicit get_{ref,mut} methods, whereas stream_wrappers implement {AsMut,AsRef}).

I now switched to implement the traits instead here.

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.

Thanks.

@Darksonn Darksonn merged commit 5086e56 into tokio-rs:master Jan 28, 2025
82 checks passed
@wngr wngr deleted the ow/sync-io-bridge-inner branch January 30, 2025 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-util Area: The tokio-util crate M-io Module: tokio/io
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants