This commit is contained in:
2022-07-09 02:21:02 +00:00
committed by GitHub
parent fe54695d5e
commit 9cb9b5bf75

View File

@@ -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<String> for CorsHost {
type Error = CorsHostError;
fn try_from(value: String) -> Result<Self, Self::Error> {
Self::try_from(value.as_str())
}
}
impl TryFrom<&SocketAddr> for CorsHost {
type Error = CorsHostError;
fn try_from(value: &SocketAddr) -> Result<Self, Self::Error> {
Self::try_from(value.to_string())
}
}
impl TryFrom<SocketAddr> for CorsHost {
type Error = CorsHostError;
fn try_from(value: SocketAddr) -> Result<Self, Self::Error> {
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());
}