-
Notifications
You must be signed in to change notification settings - Fork 995
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
feat: replace ProtocolName
with AsRef<str>
#3746
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
ProtocolName
to return &str
ProtocolName
with AsRef<str>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@thomaseizinger updating https://github.com/mxinden/kademlia-exporter/ right now. Was it a deliberate choice to not implement |
The need to abstract over the creation of What is your usecase? Why can you not use the existing, much more descriptive constructor? |
A user can provide a stream protocol name via a configuration file. I am parsing the stream protocol name as a string and would like to call
Works as well. Just a bit more verbose. |
Perhaps
A matter of taste for sure, feel free to send a PR! I tend to avoid calling conversion functions explicitly because they are mostly noise. |
Previously, a protocol could be any sequence of bytes as long as it started with `/`. Now, we directly parse a protocol as `String` which enforces it to be valid UTF8. To notify users of this change, we delete the `ProtocolName` trait. The new requirement is that users need to provide a type that implements `AsRef<str>`. We also add a `StreamProtocol` newtype in `libp2p-swarm` which provides an easy way for users to ensure their protocol strings are compliant. The newtype enforces that protocol strings start with `/`. `StreamProtocol` also implements `AsRef<str>`, meaning users can directly use it in their upgrades. `multistream-select` by itself only changes marginally with this patch. The only thing we enforce in the type-system is that protocols must implement `AsRef<str>`. Resolves: libp2p#2831. Pull-Request: libp2p#3746.
Description
Previously, a protocol could be any sequence of bytes as long as it started with
/
. Now, we directly parse a protocol asString
which enforces it to be valid UTF8.To notify users of this change, we delete the
ProtocolName
trait. The new requirement is that users need to provide a type that implementsAsRef<str>
.We also add a
StreamProtocol
newtype inlibp2p-swarm
which provides an easy way for users to ensure their protocol strings are compliant. The newtype enforces that protocol strings start with/
.StreamProtocol
also implementsAsRef<str>
, meaning users can directly use it in their upgrades.multistream-select
by itself only changes marginally with this patch. The only thing we enforce in the type-system is that protocols must implementAsRef<str>
.Resolves: #2831.
Notes & open questions
This is an alternative to #3745.
I am hoping that with this change, users will already accustom to use the
StreamProtocol
newtype. Regarding #2863, I think it makes the most sense to remove all these traits in one go and directly have the handler return a list ofStreamProtocol
s.Dependencies
support_floodsub
setting #3837EitherIter
#3841InfoIterChain
#3842Change checklist