mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-01 02:40:37 +08:00
Update
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user