-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
Co-authored-by: Alice Ryhl <[email protected]>
tokio-util/src/io/sync_bridge.rs
Outdated
/// 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 | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
Motivation
When interacting with resources wrapped in a
SyncIoBridge
, it might be handy to interact with the inner resource.Solution
Implement
get_ref
andget_mut
onSyncIoBridge
.