@@ -35,6 +35,7 @@ pub mod ffi;
3535mod idna;
3636pub use idna:: Idna ;
3737
38+ use std:: os:: raw:: c_uint;
3839use std:: { borrow, fmt, hash, ops} ;
3940use thiserror:: Error ;
4041
@@ -47,6 +48,25 @@ pub enum Error {
4748 ParseUrl ( String ) ,
4849}
4950
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+
5070/// A parsed URL struct according to WHATWG URL specification.
5171#[ derive( Eq , Clone ) ]
5272pub struct Url {
@@ -114,6 +134,11 @@ impl Url {
114134 }
115135 }
116136
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+
117142 /// Return the origin of this URL
118143 ///
119144 /// For more information, read [WHATWG URL spec](https://url.spec.whatwg.org/#dom-url-origin)
@@ -699,6 +724,8 @@ mod test {
699724 assert ! ( out. has_search( ) ) ;
700725 assert ! ( out. has_hash( ) ) ;
701726 assert ! ( out. has_password( ) ) ;
727+
728+ assert_eq ! ( out. host_type( ) , HostType :: Domain ) ;
702729 }
703730
704731 #[ test]
0 commit comments