Is there any crate to do URI/path protocol parsing?

Hi folks,

Do you know a crate that parses URI/path and return a straightforward enum?

The library should parse a string with a protocol delimiter and return the correct protocol based on that string.

E.g

  • ws://ip:port => Uri::Ws(SockAddr)
  • wss://ip:port => Uri::Wss(SockAddr)
  • unix://path => Uri::Unix(SockAddr)
  • http ://path => Uri::Http(SockAddr)
  • https ://path => Uri::Https(SockAddr)
  • ssh://ip:port => Uri::Ssh(SockAddr)
  • ip:port => Uri::Tcp(SockAddr)

Related work:

if there is nothing that exists, I guess I know what I need to do :wink:

B. r

Well, there's the url crate, but I don't know if it's quite what you're looking for. Its scheme method returns a &str rather than an enum.

In my current contribution to rumqttd crate, I should parse a user configurable URI to handle the right protocol logic between these unix://, wss://, ws:// and tcp://. I don't want to redo the wheel.

@Cyborus04, the scheme method should do the trick. But parsing an ip:port is not possible without a scheme (e.g. 127.0.0.1:8080).

Thanks,

I have not heard of any crate that converts the scheme into an enum.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.