diff --git a/src/server/cors.rs b/src/server/cors.rs index 53624f2..fb347bf 100644 --- a/src/server/cors.rs +++ b/src/server/cors.rs @@ -5,6 +5,7 @@ use http::Uri; use std::cmp::PartialEq; use std::convert::TryFrom; use std::fmt::Display; +use std::net::SocketAddr; use std::str::FromStr; #[derive(Clone, Debug, PartialEq)] @@ -129,6 +130,27 @@ impl TryFrom<&str> for CorsHost { } } +impl TryFrom for CorsHost { + type Error = CorsHostError; + fn try_from(value: String) -> Result { + Self::try_from(value.as_str()) + } +} + +impl TryFrom<&SocketAddr> for CorsHost { + type Error = CorsHostError; + fn try_from(value: &SocketAddr) -> Result { + Self::try_from(value.to_string()) + } +} + +impl TryFrom for CorsHost { + type Error = CorsHostError; + fn try_from(value: SocketAddr) -> Result { + Self::try_from(value.to_string()) + } +} + #[derive(Debug, derive_more::Display, derive_more::From)] pub enum CorsHostError { String(String), @@ -164,4 +186,5 @@ fn test_cors_host() { assert!(host3 != Uri::from_str("http://127.0.0.1").unwrap()); assert!(host != host3); assert!(host == CorsHost::try_from("http://127.0.0.1:8080").unwrap()); + assert!(host == CorsHost::try_from(SocketAddr::from_str("127.0.0.1:8080").unwrap()).unwrap()); }