@@ -35,6 +35,7 @@ pub mod ffi;
35
35
mod idna;
36
36
pub use idna:: Idna ;
37
37
38
+ use std:: os:: raw:: c_uint;
38
39
use std:: { borrow, fmt, hash, ops} ;
39
40
use thiserror:: Error ;
40
41
@@ -47,6 +48,25 @@ pub enum Error {
47
48
ParseUrl ( String ) ,
48
49
}
49
50
51
+ /// Defines the type of the host.
52
+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
53
+ pub enum HostType {
54
+ Domain = 0 ,
55
+ IPV4 = 1 ,
56
+ IPV6 = 2 ,
57
+ }
58
+
59
+ impl From < c_uint > for HostType {
60
+ fn from ( value : c_uint ) -> Self {
61
+ match value {
62
+ 0 => HostType :: Domain ,
63
+ 1 => HostType :: IPV4 ,
64
+ 2 => HostType :: IPV6 ,
65
+ _ => HostType :: Domain ,
66
+ }
67
+ }
68
+ }
69
+
50
70
/// A parsed URL struct according to WHATWG URL specification.
51
71
#[ derive( Eq , Clone ) ]
52
72
pub struct Url {
@@ -114,6 +134,11 @@ impl Url {
114
134
}
115
135
}
116
136
137
+ /// Returns the type of the host such as default, ipv4 or ipv6.
138
+ pub fn host_type ( & self ) -> HostType {
139
+ HostType :: from ( unsafe { ffi:: ada_get_url_host_type ( self . url ) } )
140
+ }
141
+
117
142
/// Return the origin of this URL
118
143
///
119
144
/// For more information, read [WHATWG URL spec](https://url.spec.whatwg.org/#dom-url-origin)
@@ -699,6 +724,8 @@ mod test {
699
724
assert ! ( out. has_search( ) ) ;
700
725
assert ! ( out. has_hash( ) ) ;
701
726
assert ! ( out. has_password( ) ) ;
727
+
728
+ assert_eq ! ( out. host_type( ) , HostType :: Domain ) ;
702
729
}
703
730
704
731
#[ test]
0 commit comments