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
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tokio-util/src/io/sync_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,18 @@ impl<T: Unpin> SyncIoBridge<T> {
pub fn into_inner(self) -> T {
self.src
}

/// 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.

}
Loading