File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ use std::collections::HashMap;
5
5
use std:: future:: Future ;
6
6
use std:: net:: SocketAddr ;
7
7
use std:: pin:: Pin ;
8
+ use std:: str:: FromStr ;
8
9
use std:: sync:: Arc ;
9
10
use std:: task:: { Context , Poll } ;
10
11
@@ -40,6 +41,16 @@ impl Name {
40
41
}
41
42
}
42
43
44
+ impl FromStr for Name {
45
+ type Err = sealed:: InvalidNameError ;
46
+
47
+ fn from_str ( host : & str ) -> Result < Self , Self :: Err > {
48
+ HyperName :: from_str ( host. into ( ) )
49
+ . map ( Name )
50
+ . map_err ( |_| sealed:: InvalidNameError { _ext : ( ) } )
51
+ }
52
+ }
53
+
43
54
#[ derive( Clone ) ]
44
55
pub ( crate ) struct DynResolver {
45
56
resolver : Arc < dyn Resolve > ,
@@ -93,3 +104,20 @@ impl Resolve for DnsResolverWithOverrides {
93
104
}
94
105
}
95
106
}
107
+
108
+ mod sealed {
109
+ use std:: fmt;
110
+
111
+ #[ derive( Debug ) ]
112
+ pub struct InvalidNameError {
113
+ pub ( super ) _ext : ( ) ,
114
+ }
115
+
116
+ impl fmt:: Display for InvalidNameError {
117
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
118
+ f. write_str ( "invalid DNS name" )
119
+ }
120
+ }
121
+
122
+ impl std:: error:: Error for InvalidNameError { }
123
+ }
You can’t perform that action at this time.
0 commit comments