@@ -1427,10 +1427,10 @@ impl Url {
1427
1427
/// # }
1428
1428
/// # run().unwrap();
1429
1429
/// ```
1430
- pub fn set_port ( & mut self , mut port : Option < u16 > ) -> Result < ( ) , ( ) > {
1430
+ pub fn set_port ( & mut self , mut port : Option < u16 > ) -> Result < ( ) , ParseError > {
1431
1431
// has_host implies !cannot_be_a_base
1432
1432
if !self . has_host ( ) || self . host ( ) == Some ( Host :: Domain ( "" ) ) || self . scheme ( ) == "file" {
1433
- return Err ( ( ) ) ;
1433
+ return Err ( ParseError :: EmptyHost ) ;
1434
1434
}
1435
1435
if port. is_some ( ) && port == parser:: default_port ( self . scheme ( ) ) {
1436
1436
port = None
@@ -1679,9 +1679,9 @@ impl Url {
1679
1679
/// # run().unwrap();
1680
1680
/// ```
1681
1681
///
1682
- pub fn set_ip_host ( & mut self , address : IpAddr ) -> Result < ( ) , ( ) > {
1682
+ pub fn set_ip_host ( & mut self , address : IpAddr ) -> Result < ( ) , ParseError > {
1683
1683
if self . cannot_be_a_base ( ) {
1684
- return Err ( ( ) ) ;
1684
+ return Err ( ParseError :: SetHostOnCannotBeABaseUrl ) ;
1685
1685
}
1686
1686
1687
1687
let address = match address {
@@ -1718,10 +1718,10 @@ impl Url {
1718
1718
/// # }
1719
1719
/// # run().unwrap();
1720
1720
/// ```
1721
- pub fn set_password ( & mut self , password : Option < & str > ) -> Result < ( ) , ( ) > {
1721
+ pub fn set_password ( & mut self , password : Option < & str > ) -> Result < ( ) , ParseError > {
1722
1722
// has_host implies !cannot_be_a_base
1723
1723
if !self . has_host ( ) || self . host ( ) == Some ( Host :: Domain ( "" ) ) || self . scheme ( ) == "file" {
1724
- return Err ( ( ) ) ;
1724
+ return Err ( ParseError :: EmptyHost ) ;
1725
1725
}
1726
1726
if let Some ( password) = password {
1727
1727
let host_and_after = self . slice ( self . host_start ..) . to_owned ( ) ;
@@ -1810,10 +1810,10 @@ impl Url {
1810
1810
/// # }
1811
1811
/// # run().unwrap();
1812
1812
/// ```
1813
- pub fn set_username ( & mut self , username : & str ) -> Result < ( ) , ( ) > {
1813
+ pub fn set_username ( & mut self , username : & str ) -> Result < ( ) , ParseError > {
1814
1814
// has_host implies !cannot_be_a_base
1815
1815
if !self . has_host ( ) || self . host ( ) == Some ( Host :: Domain ( "" ) ) || self . scheme ( ) == "file" {
1816
- return Err ( ( ) ) ;
1816
+ return Err ( ParseError :: EmptyHost ) ;
1817
1817
}
1818
1818
let username_start = self . scheme_end + 3 ;
1819
1819
debug_assert ! ( self . slice( self . scheme_end..username_start) == "://" ) ;
@@ -1919,13 +1919,13 @@ impl Url {
1919
1919
/// # }
1920
1920
/// # run().unwrap();
1921
1921
/// ```
1922
- pub fn set_scheme ( & mut self , scheme : & str ) -> Result < ( ) , ( ) > {
1922
+ pub fn set_scheme ( & mut self , scheme : & str ) -> Result < ( ) , ParseError > {
1923
1923
let mut parser = Parser :: for_setter ( String :: new ( ) ) ;
1924
1924
let remaining = parser. parse_scheme ( parser:: Input :: new ( scheme) ) ?;
1925
1925
if !remaining. is_empty ( )
1926
1926
|| ( !self . has_host ( ) && SchemeType :: from ( & parser. serialization ) . is_special ( ) )
1927
1927
{
1928
- return Err ( ( ) ) ;
1928
+ return Err ( ParseError :: InvalidScheme ) ;
1929
1929
}
1930
1930
let old_scheme_end = self . scheme_end ;
1931
1931
let new_scheme_end = to_u32 ( parser. serialization . len ( ) ) . unwrap ( ) ;
@@ -1964,7 +1964,7 @@ impl Url {
1964
1964
/// # if cfg!(unix) {
1965
1965
/// use url::Url;
1966
1966
///
1967
- /// # fn run() -> Result<(), () > {
1967
+ /// # fn run() -> Result<(), url::ParseError > {
1968
1968
/// let url = Url::from_file_path("/tmp/foo.txt")?;
1969
1969
/// assert_eq!(url.as_str(), "file:///tmp/foo.txt");
1970
1970
///
@@ -1979,7 +1979,7 @@ impl Url {
1979
1979
/// # }
1980
1980
/// ```
1981
1981
#[ cfg( any( unix, windows, target_os = "redox" ) ) ]
1982
- pub fn from_file_path < P : AsRef < Path > > ( path : P ) -> Result < Url , ( ) > {
1982
+ pub fn from_file_path < P : AsRef < Path > > ( path : P ) -> Result < Url , ParseError > {
1983
1983
let mut serialization = "file://" . to_owned ( ) ;
1984
1984
let host_start = serialization. len ( ) as u32 ;
1985
1985
let ( host_end, host) = path_to_file_url_segments ( path. as_ref ( ) , & mut serialization) ?;
@@ -2015,7 +2015,7 @@ impl Url {
2015
2015
/// Note that `std::path` does not consider trailing slashes significant
2016
2016
/// and usually does not include them (e.g. in `Path::parent()`).
2017
2017
#[ cfg( any( unix, windows, target_os = "redox" ) ) ]
2018
- pub fn from_directory_path < P : AsRef < Path > > ( path : P ) -> Result < Url , ( ) > {
2018
+ pub fn from_directory_path < P : AsRef < Path > > ( path : P ) -> Result < Url , ParseError > {
2019
2019
let mut url = Url :: from_file_path ( path) ?;
2020
2020
if !url. serialization . ends_with ( '/' ) {
2021
2021
url. serialization . push ( '/' )
@@ -2124,26 +2124,26 @@ impl Url {
2124
2124
/// let path = url.to_file_path();
2125
2125
/// ```
2126
2126
///
2127
- /// Returns `Err` if the host is neither empty nor `"localhost"` (except on Windows, where
2127
+ /// Returns `Err(ParseError::InvalidLocalPath) ` if the host is neither empty nor `"localhost"` (except on Windows, where
2128
2128
/// `file:` URLs may have a non-local host),
2129
2129
/// or if `Path::new_opt()` returns `None`.
2130
2130
/// (That is, if the percent-decoded path contains a NUL byte or,
2131
2131
/// for a Windows path, is not UTF-8.)
2132
2132
#[ inline]
2133
2133
#[ cfg( any( unix, windows, target_os = "redox" ) ) ]
2134
- pub fn to_file_path ( & self ) -> Result < PathBuf , ( ) > {
2134
+ pub fn to_file_path ( & self ) -> Result < PathBuf , ParseError > {
2135
2135
if let Some ( segments) = self . path_segments ( ) {
2136
2136
let host = match self . host ( ) {
2137
2137
None | Some ( Host :: Domain ( "localhost" ) ) => None ,
2138
2138
Some ( _) if cfg ! ( windows) && self . scheme ( ) == "file" => {
2139
2139
Some ( & self . serialization [ self . host_start as usize ..self . host_end as usize ] )
2140
2140
}
2141
- _ => return Err ( ( ) ) ,
2141
+ _ => return Err ( ParseError :: InvalidLocalPath ) ,
2142
2142
} ;
2143
2143
2144
2144
return file_url_segments_to_pathbuf ( host, segments) ;
2145
2145
}
2146
- Err ( ( ) )
2146
+ Err ( ParseError :: InvalidLocalPath )
2147
2147
}
2148
2148
2149
2149
// Private helper methods:
@@ -2293,10 +2293,10 @@ impl<'de> serde::Deserialize<'de> for Url {
2293
2293
fn path_to_file_url_segments (
2294
2294
path : & Path ,
2295
2295
serialization : & mut String ,
2296
- ) -> Result < ( u32 , HostInternal ) , ( ) > {
2296
+ ) -> Result < ( u32 , HostInternal ) , ParseError > {
2297
2297
use std:: os:: unix:: prelude:: OsStrExt ;
2298
2298
if !path. is_absolute ( ) {
2299
- return Err ( ( ) ) ;
2299
+ return Err ( ParseError :: PathNotAbsolute ) ;
2300
2300
}
2301
2301
let host_end = to_u32 ( serialization. len ( ) ) . unwrap ( ) ;
2302
2302
let mut empty = true ;
@@ -2378,12 +2378,12 @@ fn path_to_file_url_segments_windows(
2378
2378
fn file_url_segments_to_pathbuf (
2379
2379
host : Option < & str > ,
2380
2380
segments : str:: Split < char > ,
2381
- ) -> Result < PathBuf , ( ) > {
2381
+ ) -> Result < PathBuf , ParseError > {
2382
2382
use std:: ffi:: OsStr ;
2383
2383
use std:: os:: unix:: prelude:: OsStrExt ;
2384
2384
2385
2385
if host. is_some ( ) {
2386
- return Err ( ( ) ) ;
2386
+ return Err ( ParseError :: InvalidLocalPath ) ;
2387
2387
}
2388
2388
2389
2389
let mut bytes = if cfg ! ( target_os = "redox" ) {
0 commit comments