programatik29 / axum-server

High level server designed to be used with axum framework.
MIT License
174 stars 60 forks source link

Unable to pass `SocketAddr` to `bind` / `bind_rustls` #15

Closed RabidFire closed 2 years ago

RabidFire commented 2 years ago

I'm getting the following error when I try to pass a SocketAddr type into bind / bind_rustls:

         axum_server::bind_rustls(addr)
         ^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::vec::IntoIter`, found struct `std::option::IntoIter`

Details: I'm trying to implement TLS on my axum server. I have a variable addr of type SocketAddr. I thought I would be able to pass this directly into bind / bind_rustls because it accepts A: ToSocketAddrs and there's an impl ToSocketAddrs for SocketAddr.

I see that impl ToSocketAddrs for String uses std::vec::IntoIter while impl ToSocketAddrs for SocketAddr uses std::option::IntoIter (possibly because it's a single address). I tried forking the repo and changing std::vec::IntoIter to std::iter::Iterable to support both, but seems like that was a bit naive. I get another error "doesn't have a size known at compile-time" because of the BoxedToSocketAddrs type.

For now, I've gotten past it by doing addr.to_string(). Happy to submit a PR if I get some guidance on how to make this work. Thanks!

programatik29 commented 2 years ago

I will fix that ASAP.