-
Notifications
You must be signed in to change notification settings - Fork 949
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/either: Remove EitherName
in favor of Either
#2798
Conversation
I don't have a strong opinion on this. Given the complication above I am inclined to just leave it as is. Any additional benefits of this patch beyond consistency? |
I'll give it a bit more thought but I don't think so. Instead of just adding impls that we need, I can see to refactor some code to streamline, how we generate It is a bit weird that we allow so many things to be
Maybe we should introduce a |
On the meta level, I think we could do better modelling protocol names. Part of the problem is the conflict between multistream select and libp2p-identify on the specification level. One accepts a
Or a unit type for each protocol name, each implementing |
Damn. Of course it wasn't that easy to fix :)
Nice idea but it won't allow us to enforce invariants, right? |
True. Would be great to enforce these at runtime. Would be wonderful to enforce these at compile time 😇 |
Something for a future issue? I have some ideas :) To progress on this issue, would it be okay to transition all/most usages to std types like |
👍
Given that https://docs.rs/either/latest/either/enum.Either.html#impl-AsRef%3C%5BTarget%5D%3E |
(Un)fortunately yes. I remember trying this and it is not working. I think the reason is in Rust's explicit strong-typing system. Just because something implements all super traits of a trait A does not mean it implements trait A by itself unless it is actively declared as such. In Golang, this would work :) |
I am fine with that. |
@@ -6,13 +6,16 @@ | |||
- Change `StreamMuxer` interface to be entirely poll-based. All functions on `StreamMuxer` now | |||
require a `Context` and return `Poll`. This gives callers fine-grained control over what they | |||
would like to make progress on. See [PR 2724] and [PR 2797]. | |||
- Remove `EitherName` in favor of `Either` from the `either` crate. See [PR 2798]. | |||
- Replace blanket `ProtocolName` impl with specific ones on `&'static [u8]` and `Cow<'static, [u8]>`. See [PR 2798]. |
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 could split this out into a different PR if you want.
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 fine with a single pull request only.
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 would actually suggest making String
the default protocol representation. See #2831. What do you think @thomaseizinger?
@@ -6,13 +6,16 @@ | |||
- Change `StreamMuxer` interface to be entirely poll-based. All functions on `StreamMuxer` now | |||
require a `Context` and return `Poll`. This gives callers fine-grained control over what they | |||
would like to make progress on. See [PR 2724] and [PR 2797]. | |||
- Remove `EitherName` in favor of `Either` from the `either` crate. See [PR 2798]. | |||
- Replace blanket `ProtocolName` impl with specific ones on `&'static [u8]` and `Cow<'static, [u8]>`. See [PR 2798]. |
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 fine with a single pull request only.
B: ProtocolName, | ||
{ | ||
fn protocol_name(&self) -> &[u8] { | ||
::either::for_both!(self, inner => inner.protocol_name()) |
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.
Neat!
@@ -6,13 +6,16 @@ | |||
- Change `StreamMuxer` interface to be entirely poll-based. All functions on `StreamMuxer` now | |||
require a `Context` and return `Poll`. This gives callers fine-grained control over what they | |||
would like to make progress on. See [PR 2724] and [PR 2797]. | |||
- Remove `EitherName` in favor of `Either` from the `either` crate. See [PR 2798]. | |||
- Replace blanket `ProtocolName` impl with specific ones on `&'static [u8]` and `Cow<'static, [u8]>`. See [PR 2798]. |
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.
Why not implement ProtocolName
for String
and str
?
Yeah we can move to string! Should we do that as part of this PR or make another one? It is getting a bit OT from the original goal haha. I am happy to fix #2831 first and then come back to this! |
I think the following order makes most sense:
That said, I don't think we have to stick with that order. |
I agree, leave it with me 😊 |
Closing in favor of #2966. |
Description
Links to any relevant issues
#2650
Open Questions
Change checklist
- [ ] I have made corresponding changes to the documentation- [ ] I have added tests that prove my fix is effective or that my feature works