-
Notifications
You must be signed in to change notification settings - Fork 959
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
core/muxing: Replace Into<io::Error>
bound on StreamMuxer
with std::error::Error
#2710
Conversation
core/src/muxing/boxed.rs
Outdated
@@ -38,6 +39,7 @@ impl<T> StreamMuxer for Wrap<T> | |||
where | |||
T: StreamMuxer, | |||
T::Substream: AsyncRead + AsyncWrite + Send + Unpin + 'static, | |||
T::Error: Into<Box<dyn Error + Send + Sync>>, |
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.
T::Error: Into<Box<dyn Error + Send + Sync>>, | |
T::Error: Error + Send + Sync>, |
Nit: Wouldn't this simpler trait bound also work, given that Into<Box<dyn ..>>
is auto-implemented for E: Error + Send + Sync
?
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.
Probably yes. I've copied the bounds from std::io::Error::new
because that is where I am passing the type to. Omitting the Into
here is probably okay :)
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.
I decided to put the Error
bound directly on the associated type so I don't have to repeat it everywhere. The Send + Sync
bounds stay on higher layers for consistency with other bounds.
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.
I decided to put the
Error
bound directly on the associated type so I don't have to repeat it everywhere.
It is only in 4 locations, right? a479eb8 I would prefer bounds to be as close to where they are used as possible. If I am not mistaken StreamMuxer
doesn't need type Error
to implement Error
, right? I liked how previously this pull request would remove the bound on StreamMuxer
.
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.
It doesn't. It also doesn't necessarily need Substream
to implement AsyncRead + AsyncWrite
but it is a bit pointless if it doesn't.
If we remove the Error
bounds, we should also remove AsyncRead + AsyncWrite
for consistency but that will get a bit redundant I think.
The current style seems to be that functional bounds are put on associated types and auto-traits are left off.
@@ -134,7 +134,7 @@ where | |||
pub fn poll( | |||
&mut self, | |||
cx: &mut Context<'_>, | |||
) -> Poll<Result<SubstreamEvent<TMuxer, TUserData>, IoError>> { | |||
) -> Poll<Result<SubstreamEvent<TMuxer, TUserData>, TMuxer::Error>> { |
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.
Not in scope for this PR, but while reviewing I was wondering: Do we even need the TMuxer
generic on Muxing
? I think the actual type is always StreamMuxerBox
. Muxing
is private the swarm crate and only used by Connection
and there we already use the concrete StreamMuxerBox
.
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.
I am going to inline the entire Muxing
type into Connection
once poll_outbound
is removed from StreamMuxer
. This is already done in #2648 if you want to see what it looks like :)
I am also tempted to inline HandlerWrapper
and centralize all the connection handling logic directly in Connection
. This would remove quite a bit of indirection because substreams would directly be passed from the StreamMuxer
to the ConnectionHandler
.
Into<io::Error>
bound from StreamMuxer::Error
Into<io::Error>
bound from StreamMuxer::Error
with std::Error
Into<io::Error>
bound from StreamMuxer::Error
with std::Error
Into<io::Error>
bound on StreamMuxer
with std::error::Error
cdfa81e
to
f014c29
Compare
37a23c4
to
27638ac
Compare
Rebase only to stay up to date with #2707. |
This allows us to preserve the type information of a muxer's concrete error as long as possible. For `StreamMuxerBox`, we leverage `io::Error`'s capability of wrapping any error that implements `Into<Box<dyn Error>>`.
c2106db
to
a28a7c5
Compare
Rebase only includes diff of master since this has been opened: https://github.com/libp2p/rust-libp2p/compare/c2106db78e6af1fc78f33c1f780498c4c5f59a70..a28a7c51eded33886ccd279e64c423afafb5e907 |
Description
This allows us to preserve the type information of a muxer's concrete
error as long as possible. For
StreamMuxerBox
, we leverageio::Error
'scapability of wrapping any error that implements
Into<Box<dyn Error>>
.Links to any relevant issues
This is a stacked PR on top of #2707 and thus a draft but is otherwise ready to review.Open Questions
Change checklist
I have added tests that prove my fix is effective or that my feature works